private void login() { Cursor = Cursors.WaitCursor; Result res; if (UserNameTxt.Text != string.Empty && PasswordTxt.Text != string.Empty) { SesionHelper shlp = new SesionHelper(); res = shlp.Login(new User { UserName = UserNameTxt.Text, Password = PasswordTxt.Text }); Cursor = Cursors.Default; if (res.type == ResultType.SUCCESS) { this.Hide(); var frm = new frm_main(); frm.Show(); } else if (res.type == ResultType.USER_FAIL) { var msg = MessageBox.Show("Los datos no coinciden", "Entrar", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (res.type == ResultType.FAILED) { var msg = MessageBox.Show(res.message, "Entrar", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btn_dn_Click(object sender, EventArgs e) { if (txtuser.Text == "admin" && txtpass.Text == "admin") { this.Hide(); frm_main frm = new frm_main(); frm.Show(); } else { MessageBox.Show("Tên Đăng Nhập Hoặc Mật Khẩu Sai!", "Thông Báo", MessageBoxButtons.OKCancel); txtuser.Focus(); } }
private void btn_dangnhap_Click(object sender, EventArgs e) { nhanvien_ctrl nhanvien = new nhanvien_ctrl(); var temp = nhanvien.select_all_nhanvien(); switch (temp.errcode) { case Models.ErrorCode.NaN: break; case Models.ErrorCode.sucess: bool check = false; foreach (nhanvien_ett item in temp.data) { if (txt_ten.Text == item.taikhoan && txt_mk.Text == item.matkhau && item.taikhoan != "" && item.taikhoan != null) { check = true; break; } } if (!check) { MessageBox.Show("Sai thông tin đăng nhập mời bạn nhập lại!"); txt_ten.Focus(); txt_ten.SelectAll(); } else { MessageBox.Show("Bạn đã đăng nhập thành công!"); this.Hide(); if (txt_ten.Text == "admin" && txt_mk.Text == "admin") { frm_main main_form = new frm_main(); main_form.Show(); break; } frm_main nhanvien_form = new frm_main(txt_ten.Text); nhanvien_form.Show(); } break; case Models.ErrorCode.fail: break; default: break; } }
private void but_ConfirmChangePass_Click(object sender, EventArgs e) { TaiKhoanBus _tkBUS = new TaiKhoanBus(); #region "Check valid front end" string l_PasswordOld = Extensions.EncryptMD5(txt_passwordOld.Text, true).Trim(); string l_PasswordNew = Extensions.EncryptMD5(txt_passwordNew.Text, true).Trim(); string l_PasswordRe = Extensions.EncryptMD5(txt_PasswordRe.Text, true).Trim(); string ErrorValidPassword = string.Empty; if (string.IsNullOrEmpty(l_PasswordOld) || string.IsNullOrEmpty(l_PasswordNew) || string.IsNullOrEmpty(l_PasswordRe)) { DialogResult dialogResult = MessageBox.Show("Thông tin nhập vào không được rỗng!!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); if (dialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(l_PasswordOld)) { txt_passwordOld.Focus(); } if (string.IsNullOrEmpty(l_PasswordNew)) { txt_passwordNew.Focus(); } if (string.IsNullOrEmpty(l_PasswordRe)) { txt_PasswordRe.Focus(); } if (string.IsNullOrEmpty(l_PasswordOld) && string.IsNullOrEmpty(l_PasswordNew) && string.IsNullOrEmpty(l_PasswordRe)) { txt_passwordOld.Focus(); } } } #endregion else if (l_PasswordNew != l_PasswordRe) { MessageBox.Show("Mật khẩu nhập lại không trùng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (Extensions.IsValidPassword(txt_passwordNew.Text, out ErrorValidPassword) == false) { MessageBox.Show(ErrorValidPassword, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_passwordNew.Focus(); } else { int result = _tkBUS.ChangePassWord(_loginTaiKhoan.MaNhanVien, l_PasswordOld, l_PasswordNew); if (result == 0) { MessageBox.Show("Sai mật khẩu cũ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_passwordOld.Focus(); } else if (result == 1) { DialogResult dialogResult = MessageBox.Show("Đổi mật khẩu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dialogResult == DialogResult.OK && getDataChangePasswordFormFromLoginForm != null) { this.Hide(); frm_main _frmMain = new frm_main(); _frmMain.accountLoginOrchangePasswordDelegate += delegate { return(_loginTaiKhoan); };//Set data from form change password _frmMain.Show(); } else if (dialogResult == DialogResult.OK && getDataChangePasswordFormFromMainForm != null) { this.Dispose(); } } else if (result == 2) { MessageBox.Show("Có lỗi trong quá trình đổi mật khẩu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_passwordOld.Focus(); } } }
private void Button1_Click(object sender, EventArgs e) { int randomno; Random ran = new Random(); randomno = ran.Next(999999, 9999999); if (textBox1.Text == "") { MessageBox.Show("Enter username"); textBox1.Focus(); return; } else if (textBox2.Text == "") { MessageBox.Show("Enter password"); textBox2.Focus(); return; } else if (textBox3.Text == "") { MessageBox.Show("Select firm name"); textBox3.Focus(); return; } else if (textBox4.Text == "") { MessageBox.Show("Select financial year"); textBox4.Focus(); return; } strCmd = "SELECT Firm_name, Firm_Period_name, Firm_database, Firm_odate, Firm_edate FROM FIRMINFO WHERE (Firm_name = '" + textBox3.Text + "') AND (Firm_Period_name = '" + textBox4.Text + "')";; DataTable dtLogin = new DataTable(); Database.GetOtherSqlData(strCmd, dtLogin); if (dtLogin.Rows.Count > 0) { DataTable dtInfo = new DataTable(); Database.LoginbyDb = Database.GetOtherScalarBool("Select Gststatus from Firminfo where Firm_name = '" + textBox3.Text + "' and Firm_Period_name='" + textBox4.Text + "'"); if (Database.LoginbyDb == false) { strCmd = "SELECT FIRMINFO.Firm_name, USERINFO.UName,USERINFO.Upass ,USERINFO.Utype, FIRMINFO.Firm_database, FIRMINFO.Firm_Period_name,Firm_odate,Firm_edate FROM (USERWCOMPANY INNER JOIN FIRMINFO ON USERWCOMPANY.F_id=FIRMINFO.F_id) INNER JOIN USERINFO ON USERWCOMPANY.U_id=USERINFO.U_id WHERE (((USERINFO.UName)='" + textBox1.Text + "') AND ((USERINFO.Upass)='" + textBox2.Text + "')) AND Firm_name='" + textBox3.Text + "' and Firm_Period_name='" + textBox4.Text + "'"; Database.GetOtherSqlData(strCmd, dtInfo); } else { strCmd = "SELECT * from Userinfo where uname='" + textBox1.Text + "' and upass='******'"; Database.databaseName = dtLogin.Rows[0]["Firm_database"].ToString(); Database.OpenConnection(); Database.GetSqlData(strCmd, dtInfo); Database.CloseConnection(); } if (dtInfo.Rows.Count > 0) { Database.uname = dtInfo.Rows[0]["UName"].ToString(); Database.utype = funs.Select_Role_Name(int.Parse(dtInfo.Rows[0]["RoleId"].ToString())); Database.upass = dtInfo.Rows[0]["Upass"].ToString(); Database.fname = dtLogin.Rows[0]["Firm_name"].ToString(); Database.fyear = dtLogin.Rows[0]["Firm_Period_name"].ToString(); Database.databaseName = dtLogin.Rows[0]["Firm_database"].ToString(); Database.stDate = DateTime.Parse(dtLogin.Rows[0]["Firm_odate"].ToString()); Database.enDate = DateTime.Parse(dtLogin.Rows[0]["Firm_edate"].ToString()); } else if (dtInfo.Rows.Count == 0) { MessageBox.Show("Invalid username or password"); textBox1.Focus(); return; } Database.ldate = DateTime.Parse(dateTimePicker1.Text); if (Database.ldate < Database.stDate) { MessageBox.Show("login date cann't be less than starting date"); dateTimePicker1.Focus(); return; } else if (Database.ldate > Database.enDate) { MessageBox.Show("login date cann't be greator than ending date"); dateTimePicker1.Focus(); return; } if (dtInfo.Rows.Count > 0) { Database.setVariable(dtLogin.Rows[0]["Firm_name"].ToString(), dtLogin.Rows[0]["Firm_Period_name"].ToString(), Database.uname, Database.upass, Database.utype.ToUpper(), dtLogin.Rows[0]["Firm_database"].ToString(), DateTime.Parse(dtLogin.Rows[0]["Firm_odate"].ToString()), DateTime.Parse(dtLogin.Rows[0]["Firm_edate"].ToString())); Database.SoftwareName = Database.GetOtherScalarText("SELECT SOFTWARENAME.Name as SoftwareName FROM SOFTWARENAME WHERE (((SOFTWARENAME.Value)=" + access_sql.Singlequote + "True" + access_sql.Singlequote + "))"); } DirectoryInfo dInfo = new System.IO.DirectoryInfo(Application.StartupPath + "\\efile"); if (dInfo.Exists == false) { Directory.CreateDirectory(Application.StartupPath + "\\efile"); } frm_main frm = new frm_main(); frm.random = randomno; frm.Show(); this.Hide(); } else { MessageBox.Show("Invalid username or password"); textBox1.Focus(); } }
private void Login() { string l_UserName = txt_UserName.Text.Trim(); string en_Password = string.Empty; if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName) && Properties.Settings.Default.passWord == txt_Password.Text) { en_Password = Extensions.DecryptMD5(Properties.Settings.Default.passWord, true); } string l_Password = string.IsNullOrEmpty(en_Password) ? Extensions.EncryptMD5(txt_Password.Text, true).Trim(): Extensions.EncryptMD5(en_Password, true).Trim(); if (string.IsNullOrEmpty(l_UserName) || string.IsNullOrEmpty(l_Password)) { DialogResult dialogResult = MessageBox.Show("Tên đăng nhập hoặc mật khẩu không được trống!!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); if (dialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(l_UserName)) { txt_UserName.Focus(); } if (string.IsNullOrEmpty(l_Password)) { txt_Password.Focus(); } if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password)) { txt_UserName.Focus(); } } } else { try { TaiKhoanBus _tk = new TaiKhoanBus(); var _login = _tk.Login(l_UserName, l_Password); if (_login == null) { DialogResult dialogResult = MessageBox.Show("Không lấy được thông tin đăng nhập!!!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { if (string.IsNullOrEmpty(l_UserName)) { txt_UserName.Focus(); } if (string.IsNullOrEmpty(l_Password)) { txt_Password.Focus(); } if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password)) { txt_UserName.Focus(); } } else if (dialogResult == DialogResult.No) { Application.Exit(); } } else { _tkDto = _login; NhanVienDto _nvDTO = new NhanVienDto(); NhanVienBus _nvBUS = new NhanVienBus(); _nvDTO = _nvBUS.ReadStaff(_tkDto.MaNhanVien); if (_nvDTO != null) { if (!_nvDTO.DoiMatKhau) { DialogResult dialogResult = MessageBox.Show("Vui lòng đổi mật khẩu cho lần đầu tiên đăng nhập", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { this.Hide(); frm_DoiMatKhau_HeThong _frmChangPass = new frm_DoiMatKhau_HeThong(); _frmChangPass.getDataChangePasswordFormFromLoginForm += delegate { return(_login); };//set data from login form _frmChangPass.Show(); } else if (dialogResult == DialogResult.No) { Application.Exit(); } } else { this.Hide(); if (chkRememberUser.Checked) { if (Properties.Settings.Default.userName != string.Empty) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.userName = l_UserName; Properties.Settings.Default.passWord = l_Password; Properties.Settings.Default.is_Check = chkRememberUser.Checked; Properties.Settings.Default.Save(); } else { Properties.Settings.Default.userName = l_UserName; Properties.Settings.Default.passWord = l_Password; Properties.Settings.Default.is_Check = chkRememberUser.Checked; Properties.Settings.Default.Save(); } } else { Properties.Settings.Default.Reset(); Properties.Settings.Default.Save(); } frm_main _frmMain = new frm_main(); _frmMain.accountLoginOrchangePasswordDelegate += delegate { return(_login); };//Set data from form login _frmMain.Show(); } } else { DialogResult dialogResult = MessageBox.Show("Vui lòng kiểm tra trạng thái nhân viên", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { if (string.IsNullOrEmpty(l_UserName)) { txt_UserName.Focus(); } if (string.IsNullOrEmpty(l_Password)) { txt_Password.Focus(); } if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password)) { txt_UserName.Focus(); } } else if (dialogResult == DialogResult.No) { Application.Exit(); } } } } catch (Exception ex) { Logger.WriteLogError("Login Login", ex.ToString()); DialogResult dialogResult = MessageBox.Show("Vui lòng kiểm tra trạng thái nhận viên", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }