Ejemplo n.º 1
0
 private void txtMoney_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (DataValidate.NumberDotTextbox_KeyPress(sender, e) == true)
     {
         e.Handled = true;
     }
 }
Ejemplo n.º 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //数据验证
            if (this.txtLoginId.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入登录账号!", "提示");
                this.txtLoginId.Focus();
                return;
            }
            if (!DataValidate.IsInteger(this.txtLoginId.Text.Trim()))
            {
                MessageBox.Show("登录账号必须是正整数!", "登录提示");
                this.txtLoginId.Focus();
                this.txtLoginId.SelectAll();
                return;
            }
            if (this.txtLoginPwd.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入登录密码!", "提示");
                this.txtLoginPwd.Focus();
                return;
            }
            //封装用户信息到用户对象
            Admin objAdmin = new Admin()
            {
                userid = this.txtLoginId.Text.Trim(),
                pwd    = this.txtLoginPwd.Text.Trim(),
                dept   = this.cboDept.Text.Trim()
            };

            try
            {
                //提交用户信息
                objAdmin = objAdminService.AdminLogin(objAdmin, Program.salaryDate.loginDate);
                if (objAdmin == null)
                {
                    MessageBox.Show("登录账号或密码错误!", "提示");
                }
                else
                {
                    //(1)保存用户信息到全局变量
                    Program.currentAdmin = objAdmin; //保存用户对象

                    //(2)提示用户变更初始密码
                    if (objAdmin.pwd == "SAP123")
                    {
                        FrmModifyPwd objModyfyPwd = new FrmModifyPwd();
                        objModyfyPwd.ShowDialog();
                    }
                    else
                    {
                        //(2)将用户登录信息写入日志
                        LoginLog objLoginLog = new LoginLog()  //初始化登录对象
                        {
                            LoginId    = Convert.ToInt32(objAdmin.userid),
                            SPName     = objAdmin.username,
                            ServerName = Dns.GetHostName(),
                            LoginAddr  = objLoginLogService.GetLocalIp(true),
                            LoginDept  = objAdmin.dept,
                        };
                        Program.currentLoginLog            = objLoginLog;                                   //保存登录用户对象
                        Program.currentLoginLog.LoginLogId = objLoginLogService.WriteLoginLog(objLoginLog); //将登录用户对象写入日志

                        //(3)设置登录窗体返回值
                        this.DialogResult = DialogResult.OK;//设置登录成功信息提示
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "登录失败!");
            }
        }