123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- using LYFZ.BLL.MicroApplet;
- using LYFZ.Model;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.MicroApplet
- {
- public class frmMicroAppletAccountManager:LYFZ.Software.MicroApplet.frmMicroAppletAccountManager
- {
- public frmMicroAppletAccountManager() {
- this.Load += FrmMicroAppletAccountManager_Load;
- this.Shown += FrmMicroAppletAccountManager_Shown;
- this.dataGridViewEx1.CellContentClick += DataGridViewEx1_CellContentClick;
- this.btnSave.Click += BtnSave_Click;
- this.btnReset.Click += BtnReset_Click;
- }
- private void BtnReset_Click(object sender, EventArgs e)
- {
- currentViewRow = null;
- this.txtAccount.Text = "";
- this.txtPassword.Text = "";
- this.txtRemarks.Text = "";
- this.comboBoxMdian.Enabled = true;
- }
- public bool isUpdate = false;
- private void BtnSave_Click(object sender, EventArgs e)
- {
- if (this.comboBoxMdian.SelectedItem != null)
- {
- LYFZ.Model.Model_ErpCompanyInfo comp = (LYFZ.Model.Model_ErpCompanyInfo)((ItemValue)this.comboBoxMdian.SelectedItem).Value;
- MicroAppletAccount account = null;
- if (currentViewRow != null)
- {
- account = (MicroAppletAccount)currentViewRow.Tag;
- }
- else {
- account = new MicroAppletAccount();
- account.ID = LYFZ.WinAPI.CustomPublicMethod.GenerateId().ToString();
- account.ShopID = comp.Company_DividedShop;
- if (this.MicroAppletAccountList.Any(a => a.ShopID.ToLower() == account.ShopID.ToLower()))
- {
- MessageBoxCustom.Show(String.Format("门店“{0}”小程序帐号已存在,不能重复添加",comp.Company_Name));
- return;
- }
-
- }
-
- account.Account = this.txtAccount.Text.Trim();
- account.Password = this.txtPassword.Text.Trim();
- account.Remarks = this.txtRemarks.Text.Trim();
- if (String.IsNullOrEmpty(account.Account) || String.IsNullOrEmpty(account.Password))
- {
- MessageBoxCustom.Show("帐号和密码不能为空");
- return;
- }
- bool loginState = false;
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
-
- backgroundWorker.ReportProgress(0, "正在验证授权...");
- MicroAppLoginReturn loginModel = frmMicroAppletAdmin.CompanyLoginReturnToken(account.Account, account.Password);
- if (loginModel.Code != 200)
- {
- MessageBoxCustom.Show("获取授权失败:" + loginModel.Message, backgroundWorker: backgroundWorker);
- }
- else {
- loginState = true;
- }
-
-
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("获取授权时错误:{0}", ex.Message), backgroundWorker: backgroundWorker);
- }
- });
- if (!loginState)
- {
- return;
- }
-
- bool saveState = false;
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
- backgroundWorker.ReportProgress(0, "正在保存...");
- if (currentViewRow == null)
- {
- this.MicroAppletAccountList.Add(account);
- }
- saveState = configBll.SaveMicroAppletAccountList(this.MicroAppletAccountList);
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("加载帐号信息时错误:{0}", ex.Message), backgroundWorker: backgroundWorker);
- }
- });
- BtnReset_Click(null, null);
- if (saveState)
- {
- isUpdate = true;
- MessageBoxCustom.Show("保存成功");
-
- }
- else
- {
- MessageBoxCustom.Show("保存失败,请重试!");
- }
- FrmMicroAppletAccountManager_Shown(null, null);
- } else {
- MessageBoxCustom.Show("请选择门店");
- }
- }
- private void DataGridViewEx1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
- {
- switch (e.ColumnIndex)
- {
- case 3:
- SetMicroAppletAccount(this.dataGridViewEx1.Rows[e.RowIndex]);
- break;
- case 4:
- DelMicroAppletAccount(this.dataGridViewEx1.Rows[e.RowIndex]);
- break;
- }
- }
- }
- DataGridViewRow currentViewRow = null;
- void SetMicroAppletAccount(DataGridViewRow row)
- {
-
- currentViewRow = row;
- MicroAppletAccount account = (MicroAppletAccount)row.Tag;
- foreach (ItemValue item in this.comboBoxMdian.Items)
- {
- LYFZ.Model.Model_ErpCompanyInfo comp = (LYFZ.Model.Model_ErpCompanyInfo)item.Value;
- if (comp.Company_DividedShop.ToLower() == account.ShopID.ToLower())
- {
- this.comboBoxMdian.SelectedItem = item;
- break;
- }
- }
- this.comboBoxMdian.Enabled = false;
- this.txtAccount.Text = account.Account;
- this.txtPassword.Text = account.Password;
- this.txtRemarks.Text = account.Remarks;
-
-
- }
- void DelMicroAppletAccount(DataGridViewRow row)
- {
- MicroAppletAccount account = (MicroAppletAccount)row.Tag;
- this.MicroAppletAccountList.Remove(this.MicroAppletAccountList.Find(m => m.ID.ToLower() == account.ID.ToLower()));
- bool delState = false;
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
- backgroundWorker.ReportProgress(0, "正在删除...");
- delState = configBll.SaveMicroAppletAccountList(this.MicroAppletAccountList);
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("加载帐号信息时错误:{0}", ex.Message), backgroundWorker: backgroundWorker);
- }
- });
- if (delState)
- {
- isUpdate = true;
- FrmMicroAppletAccountManager_Shown(null, null);
- }
- else
- {
- MessageBoxCustom.Show("删除失败,请重试!");
- }
- }
- BLL.BLL_ErpSystemConfigure configBll=new BLL.BLL_ErpSystemConfigure();
- private void FrmMicroAppletAccountManager_Shown(object sender, EventArgs e)
- {
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
-
- backgroundWorker.ReportProgress(0, "正在加载帐号信息...");
- _MicroAppletAccountList = configBll.GetMicroAppletAccountList();
-
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("加载帐号信息时错误:{0}", ex.Message), backgroundWorker: backgroundWorker);
- }
- });
- this.dataGridViewEx1.Rows.Clear();
- foreach (MicroAppletAccount account in _MicroAppletAccountList)
- {
- DataGridViewRow row = new DataGridViewRow();
- row.CreateCells(this.dataGridViewEx1);
- row.Cells[0].Value = GetCompanyInfo(account.ShopID).Company_Name;
- row.Cells[1].Value = account.Account;
- row.Cells[2].Value = account.Remarks;
- row.Cells[3].Value = "编辑";
- row.Cells[4].Value = "删除";
- row.Tag = account;
- this.dataGridViewEx1.Rows.Add(row);
- }
- }
- List<MicroAppletAccount> _MicroAppletAccountList = new List<MicroAppletAccount>();
- List<MicroAppletAccount> MicroAppletAccountList
- {
- get { return _MicroAppletAccountList; }
- set { this._MicroAppletAccountList = value; }
- }
- string _PrimitiveID = "";
- /// <summary>
- /// 门店ID 每个门店只能添加一个小程序
- /// </summary>
- public string PrimitiveID
- {
- get { return _PrimitiveID; }
- set { _PrimitiveID = value; }
- }
- private void FrmMicroAppletAccountManager_Load(object sender, EventArgs e)
- {
- this.PrimitiveID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID;
- BindMenDianList(this.comboBoxMdian,this.PrimitiveID);
-
- }
- LYFZ.Model.Model_ErpCompanyInfo GetCompanyInfo(string shopID)
- {
- if (_CompayList.Any(c => c.Company_DividedShop.ToLower() == shopID.ToLower()))
- {
- return _CompayList.Find(c => c.Company_DividedShop.ToLower() == shopID.ToLower());
- }
- else {
- return new Model.Model_ErpCompanyInfo();
- }
- }
- List<LYFZ.Model.Model_ErpCompanyInfo> _CompayList = new List<Model.Model_ErpCompanyInfo>();
- public List<LYFZ.Model.Model_ErpCompanyInfo> CompayList
- {
- get
- {
- if (_CompayList.Count <= 0)
- {
- _CompayList= new LYFZ.BLL.BLL_ErpCompanyInfo().GetModelList("1=1");
- }
- return _CompayList;
- }
- }
- public void BindMenDianList(ComponentLibrary.ComboBoxEx comBox,string dfShopID)
- {
- comBox.Items.Clear();
- foreach (LYFZ.Model.Model_ErpCompanyInfo com in CompayList)
- {
- ItemValue item = new ItemValue(com, com.Company_Name);
- comBox.Items.Add(item);
- if (dfShopID.Trim().Length > 0 && com.Company_DividedShop.ToLower() == dfShopID.ToLower())
- {
- comBox.SelectedItem = item;
- }
- else if (dfShopID.Trim().Length <= 0 && com.Company_DividedShop.ToLower() == LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID.ToLower())
- {
- comBox.SelectedItem = item;
- }
- }
- }
- }
- }
|