MetroAccount.cs 15.2 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dal;
using Comm;

namespace App
{
    public partial class MetroAccount : FrmBase
    {
        Fuction fuction = new Fuction();
        LoginManager _loginManger;
        public MetroAccount(LoginManager loginManager)
        {
            InitializeComponent();
            this.SetLanguage(this);
            this._loginManger = loginManager;
            init();

            loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
            loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
            loadAccount(this.cmbRePWDAccount, this.textBox1, this.textBox2);//刷新重置密码下拉框S
            //showAdd();
        }

        /// <summary>
        /// 初始化国际化
        /// </summary>
        private void init()
        {

            this.Text = getMsg("frmLoginManageckb_AMAccountManage3");
            this.panelAddAccount.Text = getMsg("FrmMDIAuth_5020");
            this.panelUpdateAccount.Text = getMsg("FrmMDIAuth_5030");
            this.panelDeleteAccount.Text = getMsg("FrmMDIAuth_5040");
            this.groupBox1.Text = getMsg("FrmMDIAuth_5010");
            this.button1.Text = getMsg("back");

            this.lblAddAccount.Text = getMsg("frmLoginManagelbl_Login")+" ";
            this.lblAddCompany.Text = getMsg("frmLoginManagelbl_Company") + " ";
            this.lblAddDepartment.Text = getMsg("frmLoginManagelbl_Department") + " ";
            this.lblAddEnterPWD.Text = getMsg("frmLoginManagelbl_NewPSW") + " ";
            this.lblAddReEnterPWD.Text = getMsg("frmLoginManagelbl_RePSW") + " ";
            this.btnAddSave.Text = getMsg("FrmMDIbtn_Save");

            this.lblUpdataAccount.Text = getMsg("frmLoginManagelbl_Login") + " ";
            this.lblUpdataCompany.Text = getMsg("frmLoginManagelbl_Company") + " ";
            this.lblUpdataDepartment.Text = getMsg("frmLoginManagelbl_Department") + " ";
            this.lblUpdataNewPWD.Text = getMsg("frmLoginManagelbl_NewPSW") + " ";
            this.lblUpdataReNewPWD.Text = getMsg("frmLoginManagelbl_RePSW") + " ";
            this.btnUpdataSave.Text = getMsg("FrmMDIbtn_Save");
            this.label1.Text = getMsg("frmLoginManagelbl_Login") + " ";
            this.btnRePWDSave.Text = getMsg("FrmMDIbtn_Save");

            this.lblDeleteAccounts.Text = getMsg("frmLoginManagelbl_Login") + " ";
            this.lblDeleteCompany.Text = getMsg("frmLoginManagelbl_Company") + " ";
            this.lblDeleteDepartment.Text = getMsg("frmLoginManagelbl_Department") + " ";
            this.btnDeleteSave.Text = getMsg("frmProductbtn_Delete");
            
        }

        //创建和删除账户
        private void addAndDeleteAccount(string operation, string login, string Parameter, string Value)
        {
            fuction.CreateParaConfig(operation ,login,Parameter,Value);
        }
        //点击添加账号
        private void btnAdd_Click(object sender, EventArgs e)
        {
            showAdd();
        }
        private void showAdd()
        {
            this.panelAddAccount.Visible = true;
            this.panelDeleteAccount.Visible = false;
            this.panelUpdateAccount.Visible = false;
        }
        //点击删除账号
        private void btnDelete_Click(object sender, EventArgs e)
        {
            this.panelAddAccount.Visible = false;
            this.panelDeleteAccount.Visible = true;
            this.panelUpdateAccount.Visible = false;
            loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);
        }
        string[,] Accounts;
        //加载账户
        private void loadAccount(System.Windows.Forms.ComboBox cmb,System.Windows.Forms.TextBox companyName,System.Windows.Forms.TextBox department )
        {
            List<string[]> AllAccountsList = fuction.GetAllLoginName(Const.PARAMETERCONFIGNAME);
            Accounts = new string[AllAccountsList.Count,3];
            cmb.Items.Clear();
            for (int i=0;i<AllAccountsList.Count;i++)
            {
                cmb.Items.Add(AllAccountsList[i][1]);//账户名称
                Accounts[i,0] = AllAccountsList[i][1];
                Accounts[i,1] = AllAccountsList[i][2];
                Accounts[i,2] = AllAccountsList[i][3];
            }
            cmb.SelectedIndex = 0;
            companyName.Text = Accounts[0,1];//公司
            department.Text = Accounts[0,2];//部门
        }
        //点击修改账号
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            this.panelAddAccount.Visible = false;
            this.panelDeleteAccount.Visible = false;
            this.panelUpdateAccount.Visible = true;
            loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);
        }
        //保存账户添加
        private void btnSaveAdd_Click(object sender, EventArgs e)
        {
            //先判断内容是否不为空
            if (!CheckNull(this.lblAddAccount.Text,this.txtAddCount)||
                !CheckNull(this.lblAddCompany.Text, this.txtAddCompany)||
                !CheckNull(this.lblAddDepartment.Text, this.lblAddDepartment)||
                !CheckNull(this.lblAddEnterPWD.Text, this.txtAddEnterPWD)
                )
            {
            }else
            //判断再次密码输入是否一致
            if (!(txtAddEnterPWD.Text.Trim().Equals(txtAddReEnterPWD.Text.Trim())))
            {
                //提示再次输入密码不一致
                ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
            }
            else
            {
                //判断用户名是否存在
                if (fuction.CheckSameName("", Const.PARAMETERCONFIGNAME, this.txtAddCount.Text.Trim()))
                {
                    //提示该用户名已存在
                    ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_SAME);
                }
                else
                {
                    //保存相关数据
                    if (fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_NAME, this.txtAddCount.Text.Trim()) &&
                        fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_LOGIN, this.txtAddCount.Text.Trim()) &&
                        fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_COMP, this.txtAddCompany.Text.Trim()) &&
                        fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_DEP, this.txtAddDepartment.Text.Trim()) &&
                        fuction.CreateParaConfig("", this.txtAddCount.Text.Trim(), Const.USER_PWD, Utility.SimpleEncode(this.txtAddEnterPWD.Text.Trim(), Utility.getExpandString(this.txtAddCount.Text.Trim(), 10))))
                    {
                        //提示保存成功
                        ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
                        loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
                        loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
                        loadAccount(this.cmbRePWDAccount, this.textBox1,this.textBox2 );//刷新重置密码下拉框
                    }
                    else
                    {
                        //提示保存失败
                        ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
                    }
                }
            }
        }
        //删除某个用户
        private void btnSaveDelete_Click(object sender, EventArgs e)
        {
            if ("admin".Equals(this.cmbDeleteAccounts.Text))
            {
                ShowMessageBox.ShowError(Const.MESSAGEBOX_WARNING_NOTE, "", Const.ERROR_CANT_DELETE);
            }else
            //提示确认要删除?
            if (ShowMessageBox.ShowQuestionForDeleteProduce(Const.MESSAGEBOX_QUESTION_NOTE,cmbDeleteAccounts.Text.Trim()))
            {
                //确认删除后删除该用户
                if (fuction.CreateParaConfig(Const.OPERATION_DELETE, this.cmbDeleteAccounts.Text.Trim(), Const.USER_PWD, this.txtAddEnterPWD.Text.Trim()))
                {
                    //提示操作成功
                    ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);

                    loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
                    loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
                    loadAccount(this.cmbRePWDAccount, this.textBox1, this.textBox2);//刷新重置密码下拉框
                }
                else
                {
                    //提示操作失败
                    ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
                }
            }
            
        }
        //保存更新
        private void button3_Click(object sender, EventArgs e)
        {
            //先判断内容是否不为空
            if (!CheckNull(this.lblUpdataAccount.Text, this.cmbUpdataAccount) ||
                !CheckNull(this.lblUpdataCompany.Text, this.txtUpdataCompanyName) ||
                !CheckNull(this.lblUpdataDepartment.Text, this.lblUpdataDepartment)
                )
            {
                ShowMessageBox.ShowError(Const.MESSAGEBOX_WARNING_NOTE, "", Const.ERROR_NONE);
            }
            else
            //确认再次输入的密码是否一致
            if (!(txtAddEnterPWD.Text.Trim().Equals(txtAddReEnterPWD.Text.Trim())))
            {
                //提示再次输入密码不一致
                ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
            }
            else
            {
                //保存相关数据
                if (fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_NAME, this.cmbUpdataAccount.Text.Trim()) &&
                    fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_LOGIN, this.cmbUpdataAccount.Text.Trim()) &&
                    fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_COMP, this.txtUpdataCompanyName.Text.Trim()) &&
                    fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_DEP, this.txtUpdataDepartment.Text.Trim()) &&
                    fuction.CreateParaConfig("", this.cmbUpdataAccount.Text.Trim(), Const.USER_PWD, this.txtUpdataNewPWD.Text.Trim()))
                {
                    //提示操作成功
                    ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
                    loadAccount(this.cmbDeleteAccounts, this.txtDeleteCompanyName, this.txtDeleteDepartment);//刷新删除下拉框
                    loadAccount(this.cmbUpdataAccount, this.txtUpdataCompanyName, this.txtUpdataDepartment);//刷新更新下拉框
                    loadAccount(this.cmbRePWDAccount, this.textBox1, this.textBox2);//刷新重置密码下拉框
                }
                else
                {
                    //提示操作失败
                    ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
                }
            }
        }

        private void checkInputNull(List<Dictionary<string,System.Windows.Forms.Control>> InputInfo)
        {
            for (int i = 0; i < InputInfo.Count; i++)
            {
                Dictionary<string, System.Windows.Forms.Control> controlInfo = InputInfo[i];
                
            }
        }

        #region 上一步,返回主菜单
        private void btnUpdataCancel_Click(object sender, EventArgs e)
        {
            showMainMenu();
        }

        private void btnDeleteCance_Click(object sender, EventArgs e)
        {
            showMainMenu();
        }

        private void btnAddCancel_Click(object sender, EventArgs e)
        {
            showMainMenu();
        }

        private void showMainMenu()
        {
            this.Close();
            MetroMDI mm = new MetroMDI(this._loginManger);
            mm.ShowInTaskbar = true;
            mm.Show();
            mm.Activate();
        }

        #endregion
        //保存密码重置
        private void btnRePWDSave_Click(object sender, EventArgs e)
        {
            if (!CheckNull(this.lblUpdataNewPWD.Text, this.txtUpdataNewPWD)||
                !CheckNull(this.lblUpdataReNewPWD.Text, this.txtUpdataReNewPWD))
            {
                
            }
            else
                //确认再次输入的密码是否一致
                if (!(txtAddEnterPWD.Text.Trim().Equals(txtAddReEnterPWD.Text.Trim())))
                {
                    //提示再次输入密码不一致
                    ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_REPEWWRONG);
                }
                else
                {
                    //保存相关数据
                    if (fuction.CreateParaConfig("", this.cmbRePWDAccount.Text, Const.USER_PWD, Utility.SimpleEncode(this.txtUpdataNewPWD.Text.Trim(), Utility.getExpandString(this.cmbRePWDAccount.Text.Trim(), 10))))
                    {
                        //提示操作成功
                        ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
                    }
                    else
                    {
                        //提示操作失败
                        ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_OPERATION);
                    }
                }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            showMainMenu();
        }
        //切换下拉框
        private void cmbUpdataAccount_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.txtUpdataCompanyName.Text = Accounts[cmbUpdataAccount.SelectedIndex,1];
            this.txtUpdataDepartment.Text = Accounts[cmbUpdataAccount.SelectedIndex,2];
        }
        //切换下拉框
        private void cmbDeleteAccounts_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.txtDeleteCompanyName.Text = Accounts[cmbDeleteAccounts.SelectedIndex,1];
            this.txtDeleteDepartment.Text = Accounts[cmbDeleteAccounts.SelectedIndex,2];
        }

        private void MetroAccount_Load(object sender, EventArgs e)
        {
            this.panelAddAccount.Width = this.panel1.Width / 2 - 10;
            this.panelDeleteAccount.Width = this.panel1.Width / 2 - 10;
            this.panelUpdateAccount.Width = this.panel1.Width / 2 - 10;
            this.groupBox1.Width = this.panel1.Width / 2 - 10;
            this.panelUpdateAccount.Location = new Point(this.panelAddAccount.Location.X + this.panelAddAccount.Width+10, this.panelAddAccount.Location.Y);
            this.groupBox1.Location = new Point(this.panelDeleteAccount.Location.X + this.panelDeleteAccount.Width+10, this.panelDeleteAccount.Location.Y);
        }

    }
}