private void txtPhone_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); string s = txtPhone.Text; try { double tmp; if (!double.TryParse(s, out tmp) && !string.IsNullOrEmpty(s)) { lblStatusThongTinTaiKhoan.Text = "Số điện thoại không hợp lệ!!!"; txtPhone.Text = emp.SoDT; txtPhone.SelectAll(); return; } } catch { lblStatusThongTinTaiKhoan.Text = "Số điện thoại không hợp lệ!!!"; txtPhone.Text = emp.SoDT; return; } lblStatusThongTinTaiKhoan.Text = ""; emp.SoDT = s; da.updateNhanvien(emp); }
private void txtPosition_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); emp.Chucvu = txtPosition.Text; da.updateNhanvien(emp); }
private void txtBirthYear_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); //string s = cboBirthDay.Text + "/" + cboBirthMonth.Text + "/" + txtBirthYear.Text; int bYear = Convert.ToInt16(txtBirthYear.Text); int bMonth = cboBirthMonth.SelectedIndex + 1; int bDay = cboBirthDay.SelectedIndex + 1; try { //emp.Ngaysinh = Convert.ToDateTime(s); emp.Ngaysinh = new DateTime(bYear, bMonth, bDay); } catch { lblStatusThongTinTaiKhoan.Text = "Thông tin Ngày sinh không hợp lệ"; txtBirthYear.Focus(); return; } lblStatusThongTinTaiKhoan.Text = ""; da.updateNhanvien(emp); }
private void txtName_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); string s = txtName.Text; if (s == "") { lblStatusThongTinTaiKhoan.Text = "Thông tin Họ và tên không hợp lệ"; txtName.Text = emp.Ten; txtName.SelectAll(); return; } lblStatusThongTinTaiKhoan.Text = ""; emp.Ten = s; if (da.updateNhanvien(emp)) { if (string.Equals(Program.username, currentItem.Username)) { customListBoxCurrentUser.Items.Clear(); LoadCurrentUser(); } else { LoadOtherUser(""); } } }
private void txtAddress_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); emp.Diachi = txtAddress.Text; da.updateNhanvien(emp); }
private void cboUserGroupName_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); // Admin can not modify "Admin" GroupName if ((emp.Loai == "Quản lý") || (username == Program.username)) { cboUserGroupName.Text = emp.Loai; return; } else { lblStatusThongTinTaiKhoan.Text = ""; string s = cboUserGroupName.Text; if (!string.Equals(s, oldSelectedNhanvien.Loai)) { emp.Loai = s; da.updateNhanvien(emp); QuyenTruycap quyentruycap = getDefaultPermissionByGroupname(cboUserGroupName.Text); quyentruycap.IDQuyentruycap = emp.IDQuyenTruycap; quyentruycap.TenLoaiNV = s; quyentruycap.Ngaythietlap = DateTime.Now.Date; da.updateQuyenTruycap(quyentruycap); int selectedIndex = currentIndex; customListBoxOtherUser.Items.Clear(); LoadOtherUser(""); customListBoxOtherUser.SelectedIndex = selectedIndex; } } }
private void cboSex_Leave(object sender, EventArgs e) { string username = currentItem.Username; DataAccess da = new DataAccess(); Nhanvien emp = da.getNhanvienbyUserName(username); emp.Gioitinh = cboSex.Text; da.updateNhanvien(emp); }
private void btnConfirm_Click(object sender, EventArgs e) { string currentPassword; string newPassword; string newPasswordConfirm; if (string.Equals(currentItem.Username, Program.username)) { // Check current password currentPassword = txtPassword.Text; if (currentPassword == "") { //lblMessPassword.Text = "Nhập mật khẩu hiện tại"; MessageBox.Show("Nhập mật khẩu hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); return; } else { DataAccess da = new DataAccess(); Nhanvien employee = da.getNhanvienbyUserName(currentItem.Username); if (!string.Equals(currentPassword, employee.Password)) { //lblMessPassword.Text = "Mật khẩu không đúng!"; MessageBox.Show("Mật khẩu không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); txtPassword.SelectAll(); txtNewPassword.Text = ""; txtNewPasswordConfirm.Text = ""; return; } } } // Check new password newPassword = txtNewPassword.Text; newPasswordConfirm = txtNewPasswordConfirm.Text; if (newPassword == "") { //lblMessPassword.Text = "Nhập mật khẩu hiện tại"; MessageBox.Show("Vui lòng nhập Mật khẩu mới", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtNewPassword.Focus(); return; } if (newPasswordConfirm == "") { //lblMessPassword.Text = "Nhập mật khẩu hiện tại"; MessageBox.Show("Vui lòng nhập Xác nhận lại Mật khẩu mới", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtNewPasswordConfirm.Focus(); return; } if (String.Equals(newPassword, newPasswordConfirm)) { DataAccess da = new DataAccess(); Nhanvien employee = da.getNhanvienbyUserName(currentItem.Username); employee.Password = newPassword; //employee.PasswordHint = txtPasswordHint.Text; if (da.updateNhanvien(employee)) { MessageBox.Show("Thay đổi mật khẩu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } txtPassword.Text = ""; txtNewPassword.Text = ""; txtNewPasswordConfirm.Text = ""; txtPasswordHint.Text = ""; } else { MessageBox.Show("Mật khẩu mới và Mật khẩu xác nhận phải giống nhau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); //lblMessPasswordRetype.Text = "Mật khẩu mới và Mật khẩu xác nhận phải giống nhau!"; txtNewPasswordConfirm.Text = ""; txtNewPassword.Focus(); txtNewPassword.SelectAll(); } }
private void btnConfirm_Click(object sender, EventArgs e) { Nhanvien emp = new Nhanvien(); Nhanvien existEmp; DataAccess da = new DataAccess(); string s; try { //Name s = txtName.Text; if (s == "") { lblStatusBar.Text = "Nhập họ và tên!"; txtName.Focus(); return; } lblStatusBar.Text = ""; emp.Ten = s; // Sex s = cboSex.Text; if (s == "") { lblStatusBar.Text = "Nhập giới tính!"; cboSex.Focus(); return; } lblStatusBar.Text = ""; emp.Gioitinh = s; // Chức vụ -optional emp.Chucvu = txtPosition.Text; // Dia chi s = txtAddress.Text; if (s == "") { lblStatusBar.Text = "Nhập Địa chỉ!"; txtAddress.Focus(); return; } lblStatusBar.Text = ""; emp.Diachi = s; //Phone -optional s = txtPhone.Text; if (s != "") { try { Int32.Parse(s); } catch { lblStatusBar.Text = "Số điện thoại không hợp lệ!!!"; txtPhone.Focus(); return; } } lblStatusBar.Text = ""; emp.SoDT = s; //BirthDate if (cboBirthDay.Text == null || cboBirthMonth.Text == null || txtBirthYear == null) { lblStatusBar.Text = "Nhập Ngày sinh"; cboBirthDay.Focus(); return; } lblStatusBar.Text = ""; //s = cboBirthDay.Text + "-" + cboBirthMonth.Text + "-" + txtBirthYear.Text; int bYear = Convert.ToInt16(txtBirthYear.Text); int bMonth = cboBirthMonth.SelectedIndex + 1; int bDay = cboBirthDay.SelectedIndex + 1; try { //emp.Ngaysinh = Convert.ToDateTime(s); emp.Ngaysinh = new DateTime(bYear, bMonth, bDay); } catch { lblStatusBar.Text = "Thông tin Ngày sinh không đúng"; cboBirthDay.Focus(); return; } lblStatusBar.Text = ""; //IDUserGroup //s = cboUserGroupName.EditValue.ToString(); s = cboUserGroupName.Text; if (s == "") { lblStatusBar.Text = "Chọn nhóm người dùng"; cboUserGroupName.Focus(); return; } lblStatusBar.Text = ""; emp.Loai = s; //Username s = txtUsername.Text; if (s == "") { lblStatusBar.Text = "Nhập Tên đăng nhập"; txtUsername.Focus(); return; } lblStatusBar.Text = ""; existEmp = da.getNhanvienbyUserName(s); if (existEmp != null) { lblStatusBar.Text = "Tên đăng nhập đã tồn tại!"; txtUsername.Focus(); txtUsername.SelectAll(); return; } lblStatusBar.Text = ""; emp.Username = s; //public string Password; s = txtPassword.Text; if (s == "") { lblStatusBar.Text = "Nhập Mật khẩu"; txtPassword.Focus(); return; } lblStatusBar.Text = ""; emp.Password = s; s = txtPasswordRetype.Text; if (!string.Equals(emp.Password, s)) { lblStatusBar.Text = "Mật khẩu nhập lại không khớp"; txtPassword.Focus(); txtPassword.SelectAll(); return; } lblStatusBar.Text = ""; // PasswordHinh //emp.PasswordHint = txtPasswordHint.Text; // Avatar //Image imageAvatar = pictureAvatar.Image; //emp.Avatar = frmUserManager.StrFromImage(imageAvatar); ///////////// if (da.insertNhanvien(emp) != -1) { AddedUser = emp; QuyenTruycap permission = frmEmployeeManager.getDefaultPermissionByGroupname(cboUserGroupName.Text); emp.IDQuyenTruycap = da.insertQuyenTruycap(permission); da.updateNhanvien(emp); //this.Visible = false; MessageBox.Show("Tạo thành công tài khoản: " + emp.Username, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { lblStatusBar.Text = ex.Message; } }