private void buttonRestore_Click(object sender, EventArgs e)
        {
            if (this.textBoxRestore.Text != "")
            {
                DialogResult result = DevExpress.XtraEditors.XtraMessageBox.Show("是否要覆盖以前的数据库?\n如果覆盖则原有数据丢失!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    formWait = new FormWaitEx();
                    thread = new Thread(new ThreadStart(FunctionRecoverDatabase));
                    thread.Start();
                    timer.Start();
                    formWait.ShowDialog();
                }
                else
                {
                    return;
                }

                if (0 != KMC_API.ulResult)
                {
                    KMC_API.KMS_MessageBox((eErrorCode)KMC_API.ulResult);
                }
                else
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_OK_DB_RECOVER), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_DB_RECOVER_PATH));
            }
        }
        private void buttonInitAdmin_Click(object sender, EventArgs e)
        {
            if (!textBoxPin.Text.Equals(textBoxPinOK.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("两次密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            uint ulPort = 0;
            try
            {
                ulPort = uint.Parse(textBoxPORT.Text);
            }
            catch (System.Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);

                return;
            }

            if (ulPort > 65537)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请输入正确的端口!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // 用户 输入 新用户信息
            // 格式

            if (textBoxEmail.Text.Length > 0 && !textBoxEmail.Text.Contains('@'))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_EMAIL_DATA), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (textBoxPhone.Text.Length > 0)
            {
                Regex regexPhone = new Regex("^0?\\d{11}$");            // 手机
                Regex regexCell = new Regex("^\\(?\\d{3,4}[-\\)]?\\d{7,8}$"); // 电话

                if (!regexCell.IsMatch(textBoxPhone.Text) && !regexPhone.IsMatch(textBoxPhone.Text))
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_PHONE_DATA), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
            }

            // 用户名
            if (System.Text.Encoding.Default.GetBytes(textBoxUserName.Text).Length < KMC_API.iUserNameMinLen || System.Text.Encoding.Default.GetBytes(textBoxUserName.Text).Length > KMC_API.iUserNameMaxLen)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_NAME_LEN), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // 部门
            if (System.Text.Encoding.Default.GetBytes(textBoxUnit.Text).Length > KMC_API.iUserUnitMaxLen)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_UNIT_LEN), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // 邮箱
            if (System.Text.Encoding.Default.GetBytes(textBoxEmail.Text).Length > KMC_API.iUserEmailMaxLen)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_EMAIL_LEN), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // 电话
            if (System.Text.Encoding.Default.GetBytes(textBoxPhone.Text).Length > KMC_API.iUserPhoneMaxLen)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_PHONE_LEN), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // 备注
            if (System.Text.Encoding.Default.GetBytes(textBoxNote.Text).Length > KMC_API.iUserNoteMaxLen)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_USER_NOTE_LEN), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            formWait = new FormWaitEx();
            thread = new Thread(new ThreadStart(FunctionCreateAdmin));
            thread.Start();
            timer.Start();
            formWait.ShowDialog();

            if (0 != KMC_API.ulResult)
            {
                KMC_API.KMS_MessageBox((eErrorCode)KMC_API.ulResult);
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("创建系统管理员成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void buttonInitDB_Click(object sender, EventArgs e)
        {
            uint ulPort = 0;
            try
            {
                ulPort = uint.Parse(textBoxPORT.Text);
            }
            catch (System.Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message);

                return;
            }

            if (ulPort > 65537)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请输入正确的端口!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (!File.Exists("CertificateKMS.sql"))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("SQL脚本文件不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            formWait = new FormWaitEx();
            thread = new Thread(new ThreadStart(FunctionCreateDataBase));
            thread.Start();
            timer.Start();
            formWait.ShowDialog();

            if (0 != KMC_API.ulResult)
            {
                KMC_API.KMS_MessageBox((eErrorCode)KMC_API.ulResult);

            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("创建数据库成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void buttonBackup_Click(object sender, EventArgs e)
        {
            if (this.textBoxBackup.Text != "")
            {
                formWait = new FormWaitEx();
                thread = new Thread(new ThreadStart(FunctionBackupDatabase));
                thread.Start();
                timer.Start();
                formWait.ShowDialog();

                if (0 != KMC_API.ulResult)
                {
                    KMC_API.KMS_MessageBox((eErrorCode)KMC_API.ulResult);
                }
                else
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_OK_DB_BACKUP), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(ClassCommonMSG.MSG(ECommonMSG.ECommonMSG_ERR_DB_BACKUP_PATH));
            }
        }