예제 #1
0
        private void Main_Form_Load(object sender, EventArgs e)
        {
            CbDevicePwd mDistanceSystemPwd = null;

            try
            {
                mDistanceSystemPwd = Dbhelper.Db.FirstDefault <CbDevicePwd>();
            }
            finally
            {
                if (mDistanceSystemPwd == null)
                {
                    mDistanceSystemPwd = new CbDevicePwd()
                    {
                        Pwd = "766554"
                    };
                }
            }
            Dal_DevicePwd.DistanceSystemPassword = mDistanceSystemPwd;
        }
예제 #2
0
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Enter_Click(object sender, EventArgs e)
        {
            string oldpwd     = tb_OldPwd.Text.Trim();
            string newpwd     = tb_NewPwd.Text.Trim();
            string confirmpwd = tb_ConfirmPwd.Text.Trim();

            if (Dal_DevicePwd.DistanceSystemPassword.ID != 0)
            {
                if (oldpwd.Length != tb_OldPwd.MaxLength)
                {
                    DisplayContent("旧口令长度为 6 位数字,请重新输入旧口令。");
                    tb_OldPwd.Focus();
                    return;
                }
                if (oldpwd != Dal_DevicePwd.DistanceSystemPassword.Pwd)
                {
                    DisplayContent("验证旧口令错误,请重新输入旧口令。");
                    tb_OldPwd.Focus();
                    return;
                }
            }
            if (newpwd.Length != tb_NewPwd.MaxLength)
            {
                DisplayContent("新口令长度为 6 位数字,请重新输入新口令。");
                tb_NewPwd.Focus();
                return;
            }
            if (confirmpwd.Length != tb_ConfirmPwd.MaxLength)
            {
                DisplayContent("确认口令长度为 6 位数字,请重新输入确认口令。");
                tb_ConfirmPwd.Focus();
                return;
            }
            if (newpwd != confirmpwd)
            {
                DisplayContent("新口令与确认口令不一致。");
                tb_ConfirmPwd.Focus();
                return;
            }
            try
            {
                if (Dal_DevicePwd.DistanceSystemPassword.ID == 0)
                {
                    //插入新密码
                    CbDevicePwd mDistanceSystemPwd = new CbDevicePwd()
                    {
                        Pwd = newpwd
                    };
                    mDistanceSystemPwd.ID = Dbhelper.Db.Insert <CbDevicePwd>(mDistanceSystemPwd);
                    Dal_DevicePwd.DistanceSystemPassword   = mDistanceSystemPwd;
                    Tab1_Form.GetInstance.btn_Tab3.Enabled = true;
                }
                else
                {
                    //更新新密码
                    Dal_DevicePwd.DistanceSystemPassword.Pwd = newpwd;
                    Dbhelper.Db.Update <CbDevicePwd>(Dal_DevicePwd.DistanceSystemPassword);
                }
                if (PortHelper.IsConnection)
                {
                    byte[] by = PortAgreement.GetDistanceEncryption(newpwd);
                    PortHelper.SerialPortWrite(by);
                }
                else
                {
                    DisplayContent("多功能操作平台口令设置成功,请保管好口令。", Color.Black);
                    ClearTxt();
                }
            }
            catch (Exception ex)
            {
                CustomExceptionHandler.GetExceptionMessage(ex);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }