Esempio n. 1
0
 private void PortHelper_SerialPortConnection(string portname)
 {
     if (PortHelper.IsConnection)
     {
         return;
     }
     PortHelper.sp.PortName = portname;
     try
     {
         PortHelper.sp.Open();
         byte[] by = PortAgreement.GetDistanceEncryption(Dal_DevicePwd.DistanceSystemPassword.Pwd);
         PortHelper.sp.Write(by);
         by = null;
         Thread.Sleep(550);
         if (PortHelper.IsConnection)
         {
             return;
         }
         PortHelper.sp.Close();
         Thread.Sleep(10);
     }
     catch
     {
     }
 }
Esempio n. 2
0
        private void Btn_SerialPortConnection_Click(object sender, EventArgs e)
        {
            Tab4_Form.GetInstance.IsReadIcCard = false;
            if (PortHelper.sp.IsOpen)
            {
                try
                {
                    PortHelper.sp.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                SerialPortChange(PortHelper.IsConnection);
            }
            else
            {
                PortHelper.sp.PortName = cb_SerialPortName.SelectedItem.ToString();
                try
                {
                    PortHelper.sp.Open();

                    PortHelper.SerialPortWrite(PortAgreement.GetDistanceEncryption(Dal_DevicePwd.DistanceSystemPassword.Pwd));

                    Thread.Sleep(600);

                    if (!PortHelper.IsConnection)
                    {
                        PortHelper.sp.Close();
                        MessageBox.Show("当前端口连接失败,请选择正确的端口进行连接。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        SerialPortChange(PortHelper.IsConnection);
                    }
                }
                catch (Exception ex)
                {
                    CustomExceptionHandler.GetExceptionMessage(ex);
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 3
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();

            if (oldpwd.Length != tb_OldPwd.MaxLength)
            {
                DisplayContent("旧口令长度为 6 位数字,请重新输入旧口令。");
                tb_OldPwd.Focus();
                return;
            }
            try
            {
                IsEnd = false;
                byte[] by = PortAgreement.GetDistanceEncryption(oldpwd);
                PortHelper.SerialPortWrite(by);
                p_Top.Enabled = false;
            }
            catch (Exception ex)
            {
                CustomExceptionHandler.GetExceptionMessage(ex);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 设置设备新密码
 /// </summary>
 private void SetDevicedNewPwd()
 {
     PortHelper.SerialPortWrite(PortAgreement.GetDistanceEncryption(Dal_DevicePwd.DistanceSystemPassword.Pwd));
 }
Esempio n. 5
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);
            }
        }