Пример #1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserID.Text == string.Empty)
                {
                    //MessageBox.Show(string.Format("用户ID不能为空。"), "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MessageBox.Show(string.Format(tsmiYhidbnwk.Text), tsmiYhdl.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtUserID.Focus();
                    return;
                }

                if (txtPassword.Text == string.Empty)
                {
                    //MessageBox.Show(string.Format("密码不能为空。"), "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MessageBox.Show(string.Format(tsmiMmbnwk.Text), tsmiYhdl.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPassword.Focus();
                    return;
                }
                EncryptMD5 en = new EncryptMD5(txtPassword.Text);                //实例化EncryptMD5, 加密后值引用en.str2
                if (FrmLoginBLL.CheckUser(txtUserID.Text, en.str2, cboLanguage)) // en.str2为加密后密码
                {
                    new SystemHandler().InitializationSystemInfo(txtPassword.Text);

                    if (SystemInfo.IsCheckServer)//启动服务端检测
                    {
                        SocketHandler socket     = new SocketHandler();
                        string        messageStr = "";
                        if (!socket.ConnectServer(ref messageStr))
                        {
                            MessageHandler.ShowMessageBox(messageStr);
                            return;
                        }
                    }

                    string iniPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase.TrimEnd('\\') + "\\Config.ini";
                    new FileHandler().IniWriteValue(iniPath, "System", "LastLanguage", cboLanguage.SelectedValue.ToString());

                    //Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    // cfa.AppSettings.Settings["last"].Value = "111";
                    //            cfa.Save();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    txtPassword.Focus();
                }
            }
            catch (Exception ex)
            {
                //ExceptionHandler.HandleException(this.Text + "--用户登录错误。", ex);
                ExceptionHandler.HandleException(this.Text + "--" + tsmiYhdlcw.Text, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserID.Text == string.Empty)
                {
                    //MessageHandler.ShowMessageBox(string.Format("用户ID不能为空。"), "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MessageHandler.ShowMessageBox("用户ID不能为空。");
                    txtUserID.Focus();
                    return;
                }

                if (txtPassword.Text == string.Empty)
                {
                    //MessageHandler.ShowMessageBox(string.Format("密码不能为空。"), "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MessageHandler.ShowMessageBox("密码不能为空。");
                    txtPassword.Focus();
                    return;
                }

                FileHandler fileHandler = new FileHandler();
                string      iniPath     = System.Windows.Forms.Application.StartupPath + "\\Config.ini";

                try
                {
                    //Data Source=192.168.0.3;Initial Catalog=PSAP;Persist Security Info=True;User ID=sa;Password=1qaz2wsx

                    string dataSourceStr = fileHandler.IniReadValue(iniPath, "System", "DataSource");
                    string userIDStr     = fileHandler.IniReadValue(iniPath, "System", "UserID");
                    string passwordStr   = fileHandler.IniReadValue(iniPath, "System", "Password");

                    BaseSQL.connectionString = BaseSQL.GetConnectionString(dataSourceStr, "PSAP", userIDStr, passwordStr);

                    string tempStr      = BaseSQL.connectionString.Replace("Data Source=", "");
                    string ipAddressStr = tempStr.Substring(0, tempStr.IndexOf(";"));

                    if (!new SystemHandler().TestIPAddress(ipAddressStr, 1000))
                    {
                        MessageHandler.ShowMessageBox(string.Format("IP地址【{0}】连接不通,请确认客户端和服务端的网络是否正常。", ipAddressStr));
                        btnSet.Visible = true;
                        return;
                    }
                    if (!BaseSQL.TestSqlConnection())
                    {
                        MessageHandler.ShowMessageBox("服务端的数据库不能正常访问,请确认数据库是否正常");
                        btnSet.Visible = true;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageHandler.ShowMessageBox(ex.Message);
                    return;
                }

                EncryptMD5 en = new EncryptMD5(txtPassword.Text);                //实例化EncryptMD5, 加密后值引用en.str2
                if (FrmLoginBLL.CheckUser(txtUserID.Text, en.str2, cboLanguage)) // en.str2为加密后密码
                {
                    if (SystemInfo.user.IsDisable == 1)
                    {
                        MessageHandler.ShowMessageBox("当前用户已经停用,不可以登陆系统。");
                        txtUserID.Focus();
                        return;
                    }

                    new SystemHandler().InitializationSystemInfo(txtPassword.Text);

                    if (SystemInfo.IsCheckServer)//启动服务端检测
                    {
                        SocketHandler socket     = new SocketHandler();
                        string        messageStr = "";
                        if (!socket.ConnectServer(ref messageStr))
                        {
                            MessageHandler.ShowMessageBox(messageStr);
                            return;
                        }
                    }

                    fileHandler.IniWriteValue(iniPath, "System", "LastLanguage", cboLanguage.SelectedValue.ToString());

                    //Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    // cfa.AppSettings.Settings["last"].Value = "111";
                    //            cfa.Save();


                    Thread formThread = new Thread(ThreadInitializeForm);
                    formThread.Start();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    txtPassword.Focus();
                }
            }
            catch (Exception ex)
            {
                //ExceptionHandler.HandleException(this.Text + "--用户登录错误。", ex);
                ExceptionHandler.HandleException(this.Text + "--" + tsmiYhdlcw.Text, ex);
            }
        }