using Newtonsoft.Json.Linq;
|
using Yw;
|
using Yw.Auth;
|
using Yw.Untity;
|
using Yw.WinFrmUI;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class PersonalCenterDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public PersonalCenterDlg()
|
{
|
InitializeComponent();
|
this.Load += PersonalCenterDlg_Load;
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
}
|
|
private const string _smsTemplate = "hzkw_sms_template";//手机号登录模板
|
private const string _vxTemplate = "hzkw_wx_template";//微信登录模板
|
private const string _software = "HStation_XHS_DESKTOP";//软件编码
|
|
private long _wxId;
|
private long _phoneId;
|
|
//初始化
|
private async void PersonalCenterDlg_Load(object? sender, EventArgs e)
|
{
|
this.txtEditUserName.Text = LoginUserInfo.UserName;
|
this.txtEditAdminType.Text = LoginUserInfo.AdminType.GetDisplayText();
|
this.txtAccountName.Text = LoginUserInfo.LoginAccountName;
|
this.textAccountType.Text = LoginUserInfo.LoginTypeName;
|
var allPhones = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.GetSmsByUserID(LoginUserInfo.UserID);
|
var allWeChat = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.GetWechatByUserID(LoginUserInfo.UserID);
|
if (allPhones != null && allPhones.Any())
|
{
|
_phoneId = allPhones.First().ID;
|
this.buttonEditPhone.EditValue = allPhones.First().Credential;
|
}
|
if (allWeChat != null && allWeChat.Any())
|
{
|
_wxId = allWeChat.First().ID;
|
JObject jObject = JObject.Parse(allWeChat.First().ExtraInfo);
|
if (jObject != null)
|
{
|
string nickname = (string)jObject["nickname"];
|
if (nickname != null)
|
{
|
this.buttonEditWeChat.EditValue = nickname;
|
}
|
}
|
}
|
}
|
|
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 void BtnEditPwd_Click(object sender, EventArgs e)
|
{
|
var dlg = new UpdatePwdDlg();
|
dlg.SetBindingData(LoginUserInfo.LoginAccountID);
|
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 userInfo = await BLLFactory<Yw.BLL.ToolWechat>.Instance.GetUserInfo(tokenInfo.access_token, tokenInfo.openid);
|
if (userInfo == null)
|
{
|
return default;
|
}
|
|
var isExist = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.IsExist
|
(
|
Yw.WinFrmUI.LoginUserInfo.CorpID,
|
loginType.ID,
|
_vxTemplate,
|
tokenInfo.openid
|
);
|
if (isExist)
|
{
|
TipFormHelper.ShowError("账户已存在!");
|
return default;
|
}
|
|
var vmo = new Yw.Vmo.AddUserLoginAccountVmo()
|
{
|
CorpID = Yw.WinFrmUI.LoginUserInfo.CorpID,
|
UserID = Yw.WinFrmUI.LoginUserInfo.UserID,
|
LoginTypeID = loginType.ID,
|
Identifier = _vxTemplate,
|
Credential = tokenInfo.openid,
|
IfVerified = true,
|
ExtraInfo = JsonHelper.Object2Json(userInfo)
|
};
|
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
|
(
|
Yw.WinFrmUI.LoginUserInfo.CorpID,
|
loginType.ID,
|
_smsTemplate,
|
number
|
);
|
if (isExist)
|
{
|
TipFormHelper.ShowError("账户已存在!");
|
return default;
|
}
|
var vmo = new Yw.Vmo.AddUserLoginAccountVmo()
|
{
|
CorpID = Yw.WinFrmUI.LoginUserInfo.CorpID,
|
UserID = Yw.WinFrmUI.LoginUserInfo.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(LoginUserInfo.UserID);
|
vmo.Name = this.txtEditUserName.Text;
|
var bol = await BLLFactory<Yw.BLL.User>.Instance.Update(vmo);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("更新失败!");
|
return;
|
}
|
else
|
{
|
LoginUserInfo.UserName = 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 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();
|
}*/
|
|
private async void buttonEditPhone_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
{
|
if (e.Button.Tag.ToString() == "import")
|
{
|
if (this.buttonEditPhone.EditValue != null)
|
{
|
TipFormHelper.ShowWarn("已存在手机号");
|
return;
|
}
|
var dlg = new AddPhoneNumberDlg();
|
dlg.ReloadDataEvent += async (phoneNumber) =>
|
{
|
var id = await PhoneBinding(phoneNumber);
|
if (id > 0)
|
{
|
_phoneId = id;
|
this.buttonEditPhone.EditValue = phoneNumber;
|
}
|
};
|
dlg.ShowDialog();
|
}
|
else if (e.Button.Tag.ToString() == "delete")
|
{
|
if (_phoneId > 0)
|
{
|
var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.DeleteByID(_phoneId);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("删除失败!");
|
return;
|
}
|
TipFormHelper.ShowSucceed("删除成功!");
|
_phoneId = default;
|
this.buttonEditPhone.EditValue = null;
|
}
|
}
|
}
|
|
private async void buttonEditWeChat_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
{
|
if (e.Button.Tag.ToString() == "import")
|
{
|
if (this.buttonEditWeChat.EditValue != null)
|
{
|
TipFormHelper.ShowWarn("已存在微信");
|
return;
|
}
|
var dlg = new WechatBindingDlg();
|
dlg.SetBindingData();
|
dlg.CodeReloadData += async (code) =>
|
{
|
var id = await WechatBinding(code);
|
if (id > 0)
|
{
|
_wxId = id;
|
var allWeChat = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.GetWechatByUserID(LoginUserInfo.UserID);
|
if (allWeChat != null && allWeChat.Any())
|
{
|
JObject jObject = JObject.Parse(allWeChat.First().ExtraInfo);
|
if (jObject != null)
|
{
|
string nickname = (string)jObject["nickname"];
|
if (nickname != null)
|
{
|
this.buttonEditWeChat.EditValue = nickname;
|
}
|
}
|
}
|
}
|
};
|
dlg.ShowDialog();
|
}
|
else if (e.Button.Tag.ToString() == "delete")
|
{
|
if (_wxId > 0)
|
{
|
var bol = await BLLFactory<Yw.BLL.UserLoginAccount>.Instance.DeleteByID(_wxId);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("删除失败!");
|
return;
|
}
|
TipFormHelper.ShowSucceed("删除成功!");
|
_wxId = default;
|
this.buttonEditWeChat.EditValue = null;
|
}
|
}
|
}
|
}
|
}
|