qin
2025-03-01 3af4899e6f417eee965ecac792b4eeb425b3e3c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using DevExpress.XtraEditors.TextEditController.Win32;
using HStation.RevitDev.RevitDataExport.Common;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace HStation.RevitDev.RevitDataExport.Forms
{
    public partial class Form_Login : Form
    {
        public Form_Login()
        {
            InitializeComponent();
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (textEdit1.Text == "")
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            if (textEdit2.Text == "")
            {
                MessageBox.Show("请输入密码");
                return;
            }
            else
            {
 
                var loginModel = new
                {
                    LoginName = textEdit1.Text,
                    LoginPwd = textEdit2.Text,
                    Software = GlobalResource.ConfigSettingModel.Software,
                };
 
                try
                {
                    using (var client = new HttpClient())
                    {
                        var content = new StringContent(JsonHelper.ToJson(loginModel), Encoding.UTF8, "application/json");
 
                        var res = client.PostAsync(GlobalResource.ConfigSettingModel.ApiUrl + "/Auth/User/Login/LoginSoftwareStandardBySystemAccount@V1.0", content)
                            .Result.Content.ReadAsStringAsync().Result;
                        var result = JsonHelper.ToObject<HttpResultModel>(res);
                        if (result.Code == 0 && result.Data.Status == 0)
                        {
                            var rst = JsonHelper.ToObject<JObject>(res);
                            var rsv = rst["Data"];
                            var rv = JsonHelper.ToJson(rsv);
                            if (!File.Exists(GlobalResource.LoginUserFilePath))
                                File.Create(GlobalResource.LoginUserFilePath).Dispose();
                            File.WriteAllText(GlobalResource.LoginUserFilePath, rv);
                            DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("登录失败,请重试!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("登录失败,请检查网络设置!");
                }
            }
        }
 
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}