duheng
2025-02-07 e3ca589482a056449963e7bbbd77824ded3928bc
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using DevExpress.XtraEditors;
using DevExpress.XtraReports.Templates;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw;
using Yw.Auth;
using Yw.Dto;
using Yw.WinFrmUI;
using Timer = System.Windows.Forms.Timer;
 
namespace HStation.WinFrmUI
{
    public partial class UserInfoPage : DocumentPage
    {
        public UserInfoPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "个人中心";
            this.PageTitle.SvgImageSize = new Size(24, 24);
            this.Load += UserInfoPage_Load;
        }
 
        private const string _smsTemplate = "hzkw_sms_template";//手机号登录模板
        private const string _vxTemplate = "hzkw_wx_template";//微信登录模板
        private const string _software = "HStation_XHS_DESKTOP";//软件编码
 
        //修改密码
        private void BtnEditPwd_Click(object sender, EventArgs e)
        {
            var dlg = new UpdatePwdDlg();
            dlg.SetBindingData(GlobalParas._GlobalParas.LoginID);
            dlg.ShowDialog();
        }
 
        //初始化
        private void UserInfoPage_Load(object? sender, EventArgs e)
        {
            this.txtEditUserName.Text = GlobalParas._GlobalParas.LoginName;
            this.txtEditAdminType.Text = GlobalParas._GlobalParas.AdminType;
            this.txtAccountName.Text = GlobalParas._GlobalParas.AccountName;
            this.textAccountType.Text = GlobalParas._GlobalParas.LoginType;
        }
 
        //手机绑定
        private async void PhoneBinding()
        {
            if (!IsValidMobileNumber(this.txtMobileNumber.Text.Trim()))
            {
                TipFormHelper.ShowError("手机号有误!");
                return;
            }
 
            var loginType = await BLLFactory<Yw.BLL.UserLoginType>.Instance.GetByIdentifier(LoginType.SMS);
            if (loginType != null)
            {
                var isExist = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.IsExist(new IsExistUserLoginAccountInput
                {
                    CorpID = GlobalParas._GlobalParas.CorpID,
                    LoginTypeID = loginType.ID,
                    Identifier = _smsTemplate,
                    Credential = this.txtMobileNumber.Text.Trim()
                });
                if (isExist)
                {
                    TipFormHelper.ShowError("账户已存在!");
                    return;
                }
                var vmo = new Yw.Vmo.AddUserLoginAccountVmo
                {
                    CorpID = GlobalParas._GlobalParas.CorpID,
                    UserID = GlobalParas._GlobalParas.UserID,
                    LoginTypeID = loginType.ID,
                    Identifier = _smsTemplate,
                    Credential = this.txtMobileNumber.Text.Trim(),
                    IfVerified = true
                };
                var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.Insert(vmo);
                if (bol > 0)
                {
                    TipFormHelper.ShowSucceed("绑定成功!");
                }
                else
                {
                    TipFormHelper.ShowError("绑定失败!");
                }
            }
        }
 
        private bool IsValidMobileNumber(string mobile)
        {
            var regex = new System.Text.RegularExpressions.Regex(@"^1\d{10}$");
            return regex.IsMatch(mobile);
        }
 
        //微信绑定
        private void WechatBinding()
        {
            var dlg = new WechatBindingDlg();
            dlg.SetBindingData();
            dlg.CodeReloadData += async (code) =>
            {
                var loginType = await BLLFactory<Yw.BLL.UserLoginType>.Instance.GetByIdentifier(LoginType.Wechat);
                if (loginType != null)
                {
                    var tokenInfo = await BLLFactory<Yw.BLL.ToolWechat>.Instance.GetTokenInfo(code, _vxTemplate);
                    if (tokenInfo == null)
                        return;
                    var isExist = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.IsExist(new IsExistUserLoginAccountInput
                    {
                        CorpID = GlobalParas._GlobalParas.CorpID,
                        LoginTypeID = loginType.ID,
                        Identifier = _vxTemplate,
                        Credential = tokenInfo.openid
                    });
                    if (isExist)
                    {
                        TipFormHelper.ShowError("账户已存在!");
                        return;
                    }
                    var vmo = new Yw.Vmo.AddUserLoginAccountVmo();
                    vmo.CorpID = GlobalParas._GlobalParas.CorpID;
                    vmo.UserID = GlobalParas._GlobalParas.UserID;
                    vmo.LoginTypeID = loginType.ID;
                    vmo.Identifier = _vxTemplate;
                    vmo.Credential = tokenInfo.openid;
                    vmo.IfVerified = true;
                    var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.Insert(vmo);
                    if (bol > 0)
                    {
                        TipFormHelper.ShowSucceed("绑定成功!");
                    }
                    else
                    {
                        TipFormHelper.ShowError("绑定失败!");
                    }
                }
            };
            dlg.ShowDialog();
        }
 
        //重置密码
        private async void BtnResetPwd_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show($"确认重置密码吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                return;
            if (!await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.ResetSystemLoginPwd(GlobalParas._GlobalParas.LoginID))
            {
                MessageBoxHelper.ShowError("重置失败!");
                return;
            }
            MessageBoxHelper.ShowSuccess("重置成功!");
        }
 
        private void buttonEditBinding_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var tag_obj = e.Button.Tag;
            switch (tag_obj)
            {
                case "Phone":
                    PhoneBinding();
                    break;
 
                case "Wechat":
                    WechatBinding();
                    break;
            }
        }
    }
}