using System.Data;
|
using Yw;
|
using Yw.Auth;
|
using Yw.Dto;
|
using Yw.WinFrmUI;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class PersonalCenterDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public PersonalCenterDlg()
|
{
|
InitializeComponent();
|
this.Load += PersonalCenterDlg_Load;
|
this.gridView1.SetNormalView(20);
|
this.gridView2.SetNormalView(20);
|
}
|
|
private const string _smsTemplate = "hzkw_sms_template";//手机号登录模板
|
private const string _vxTemplate = "hzkw_wx_template";//微信登录模板
|
private const string _software = "HStation_XHS_DESKTOP";//软件编码
|
|
private List<PhoneData> _phoneNuberBinding;
|
private List<WxData> _WxBinding;
|
|
//初始化
|
private void PersonalCenterDlg_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;
|
phoneInitialize();
|
wxInitialize();
|
}
|
|
public class PhoneData
|
{
|
public long ID { get; set; }
|
public string Phone { get; set; }
|
}
|
|
public class WxData
|
{
|
public long ID { get; set; }
|
public string Wxid { get; set; }
|
}
|
|
//手机号初始化
|
private async void phoneInitialize()
|
{
|
_phoneNuberBinding = new List<PhoneData>();
|
var allPhones = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.GetSmsByUserID(GlobalParas._GlobalParas.UserID);
|
foreach (var item in allPhones)
|
{
|
_phoneNuberBinding.Add(new PhoneData
|
{
|
Phone = item.Credential,
|
ID = item.ID
|
});
|
}
|
this.gridControl1.DataSource = _phoneNuberBinding;
|
}
|
|
//微信绑定初始化
|
private async void wxInitialize()
|
{
|
_WxBinding = new List<WxData>();
|
var allPhones = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.GetWechatByUserID(GlobalParas._GlobalParas.UserID);
|
foreach (var item in allPhones)
|
{
|
_WxBinding.Add(new WxData
|
{
|
Wxid = item.Credential,
|
ID = item.ID
|
});
|
}
|
this.gridControl2.DataSource = _WxBinding;
|
}
|
|
//修改密码
|
private void BtnEditPwd_Click(object sender, EventArgs e)
|
{
|
var dlg = new UpdatePwdDlg();
|
dlg.SetBindingData(GlobalParas._GlobalParas.LoginID);
|
dlg.ShowDialog();
|
}
|
|
//微信绑定
|
private async Task<long> WechatBinding(string 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 default;
|
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 default;
|
}
|
var vmo = new Yw.Vmo.AddUserLoginAccountVmo
|
{
|
CorpID = GlobalParas._GlobalParas.CorpID,
|
UserID = GlobalParas._GlobalParas.UserID,
|
LoginTypeID = loginType.ID,
|
Identifier = _vxTemplate,
|
Credential = tokenInfo.openid,
|
IfVerified = true
|
};
|
var id = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.Insert(vmo);
|
if (id > 0)
|
{
|
TipFormHelper.ShowSucceed("绑定成功!");
|
return id;
|
}
|
else
|
{
|
TipFormHelper.ShowError("绑定失败!");
|
return default;
|
}
|
};
|
return default;
|
}
|
|
//手机绑定
|
private async Task<long> PhoneBinding(string number)
|
{
|
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 = number
|
});
|
if (isExist)
|
{
|
TipFormHelper.ShowError("账户已存在!");
|
return default;
|
}
|
var vmo = new Yw.Vmo.AddUserLoginAccountVmo
|
{
|
CorpID = GlobalParas._GlobalParas.CorpID,
|
UserID = GlobalParas._GlobalParas.UserID,
|
LoginTypeID = loginType.ID,
|
Identifier = _smsTemplate,
|
Credential = number,
|
IfVerified = true
|
};
|
var id = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.Insert(vmo);
|
if (id > 0)
|
{
|
TipFormHelper.ShowSucceed("绑定成功!");
|
return id;
|
}
|
else
|
{
|
TipFormHelper.ShowError("绑定失败!");
|
return default;
|
}
|
}
|
return default;
|
}
|
|
//个人信息保存
|
private async void BtnSave_Click(object sender, EventArgs e)
|
{
|
var vmo = await BLLFactory<Yw.BLL.User>.Instance.GetByID(GlobalParas._GlobalParas.UserID);
|
vmo.Name = this.txtEditUserName.Text;
|
var bol = await BLLFactory<Yw.BLL.User>.Instance.Update(vmo);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("更新失败!");
|
return;
|
}
|
else
|
{
|
GlobalParas._GlobalParas.LoginName = this.txtEditUserName.Text;
|
TipFormHelper.ShowSucceed("更新成功!");
|
}
|
}
|
|
//添加手机号
|
private void btnAddPhone_Click(object sender, EventArgs e)
|
{
|
var dlg = new AddPhoneNumberDlg();
|
dlg.ReloadDataEvent += async (phoneNumber) =>
|
{
|
var id = await PhoneBinding(phoneNumber);
|
if (id > 0)
|
{
|
_phoneNuberBinding.Add(new PhoneData { Phone = phoneNumber, ID = id });
|
this.gridControl1.RefreshDataSource();
|
}
|
};
|
dlg.ShowDialog();
|
}
|
|
//手机号单元格点击事件
|
private async void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
var vm = this.gridView1.GetCurrentViewModel(_phoneNuberBinding);
|
if (vm == null)
|
{
|
return;
|
}
|
if (e.Column == this.colDel)
|
{
|
var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.DeleteByID(vm.ID);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("删除失败!");
|
return;
|
}
|
TipFormHelper.ShowError("删除成功!");
|
_phoneNuberBinding.Remove(vm);
|
this.gridControl1.RefreshDataSource();
|
}
|
}
|
|
//微信单元格点击事件
|
private async void gridView2_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
var vm = this.gridView2.GetCurrentViewModel(_WxBinding);
|
if (vm == null)
|
{
|
return;
|
}
|
if (e.Column == this.colWxDel)
|
{
|
var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.DeleteByID(vm.ID);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("删除失败!");
|
return;
|
}
|
TipFormHelper.ShowError("删除成功!");
|
_WxBinding.Remove(vm);
|
this.gridControl2.RefreshDataSource();
|
}
|
}
|
|
//添加微信
|
private void btnAddWx_Click(object sender, EventArgs e)
|
{
|
var dlg = new WechatBindingDlg();
|
dlg.SetBindingData();
|
dlg.CodeReloadData += async (code) =>
|
{
|
var id = await WechatBinding(code);
|
if (id > 0)
|
{
|
_WxBinding.Add(new WxData { Wxid = code, ID = id });
|
this.gridControl2.RefreshDataSource();
|
}
|
};
|
dlg.ShowDialog();
|
}
|
}
|
}
|