tangxu
2024-06-19 9cfdf165b8364eb8d5614fa6b86258ffd717ab29
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using DevExpress.XtraEditors;
 
namespace HStation.Desktop
{
    public partial class LoginFrm : DevExpress.XtraEditors.XtraForm
    {
        public LoginFrm()
        {
            InitializeComponent();
            //this.IconOptions.Icon = Properties.Resources.App;
            //this.layoutControl1.SetupLayoutControl();
            //this.layoutControl2.SetupLayoutControl();
            this.Load += LoginBigFrm_Load;
        }
 
        private void LoginBigFrm_Load(object sender, EventArgs e)
        {
            try
            {
                var settings = new UserLoginSettings();
                this.txtLoginName.EditValue = settings.LoginName;
                if (settings.ExpireTime != null && settings.ExpireTime.Value > DateTime.Now)
                {
                    this.txtPwd.EditValue = settings.Password;
                    this.ckRemember.Checked = true;
                }
            }
            catch
            {
            }
        }
 
        private void labSysTitle_MouseDown(object sender, MouseEventArgs e)
        {
            //this.DragMove();
        }
 
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Login();
        }
 
        /// <summary>
        /// 新增绘制边框
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            using (var pen = new Pen(Color.FromArgb(0, 122, 204), 1f))
            {
                e.Graphics.DrawRectangle(pen, 0.5f, 0.5f, this.Width - 1, this.Height - 1);
            }
        }
 
        //验证
        private bool Valid()
        {
            this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            if (string.IsNullOrEmpty(this.txtLoginName.Text.Trim()))
            {
                XtraMessageBox.Show("请输入用户名!");
                this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                return default;
            }
            if (string.IsNullOrEmpty(this.txtPwd.Text.Trim()))
            {
                XtraMessageBox.Show("请输入密码!");
                this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                return default;
            }
            return true;
        }
 
        //取消
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
 
        //用户名Enter
        private void txtLoginName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                this.txtPwd.Focus();
            }
        }
 
        //密码 Enter
        private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                Login();
            }
        }
 
        //登录
        private async void Login()
        {
            if (!Valid())
                return;
 
            // 用户登录
            var loginModel = new Yw.Dto.UserLoginSoftwareBySystemAccountStandardInput();
            loginModel.Software = "HStation_XHS_DESKTOP";
            loginModel.LoginName = this.txtLoginName.Text.Trim();
            loginModel.LoginPwd = this.txtPwd.Text.Trim();
            var bll = new Yw.BLL.UserLogin();
            var result = await bll.LoginSoftwareStandardBySystemAccount(loginModel);
            if (result.Status != Yw.Auth.eLoginStatus.Success)
            {
                XtraMessageBox.Show($"登录失败,信息:{(int)result.Status}");
                this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                return;
            }
 
 
            var settings = new UserLoginSettings();
            settings.LoginName = this.txtLoginName.Text.Trim();
            settings.Password = null;
            settings.ExpireTime = DateTime.Now;
            if (this.ckRemember.Checked)
            {
                settings.Password = this.txtPwd.Text.Trim();
                settings.ExpireTime = DateTime.Now.AddMonths(1);
            }
            settings.Save();
 
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
    }
}