//Button Thêm private void AddButton_Click(object sender, EventArgs e) { if (rtxtDiaChi.Text == "" || txtBacLuong.Text == "" || txtChucVu.Text == "" || txtSoDienThoai.Text == "" || txtHoTen.Text == "" || cbLoaiCV.Text == "") { MessageBox.Show("Vui Lòng Nhập Đầy Đủ Thông Tin ..."); return; } NhanVien_DTO nhanVien = new NhanVien_DTO(); nhanVien.MaNhanVien = XacDinhMaNV(); nhanVien.TenNhanVien = txtHoTen.Text; nhanVien.NgaySinh = dtpNgaySinh.Text; if (rdNam.Checked) { nhanVien.GioiTinh = "Nam"; } else { nhanVien.GioiTinh = "Nữ"; } nhanVien.SoDienThoai = txtSoDienThoai.Text; nhanVien.ChucVu = txtChucVu.Text; nhanVien.Luong = txtBacLuong.Text; nhanVien.DiaChi = rtxtDiaChi.Text; if (danhSachNhanVien != null) { foreach (NhanVien_DTO nv in danhSachNhanVien) { if (nhanVien.MaNhanVien == nv.MaNhanVien) { MessageBox.Show("Mã nhân viên đã có rồi"); return; } } } //Thêm nhân viên và tài khoản của nhân viên với tên là mã số nv TaiKhoan_DTO tk = new TaiKhoan_DTO(); tk.Tentk = nhanVien.MaNhanVien; tk.Matkhau = nhanVien.SoDienThoai; tk.Loaitk = nhanVien.MaNhanVien.Substring(0, 2); if (NhanVien_BUS.ThemNhanVien(nhanVien) && TaiKhoan_BUS.ThemTaiKhoan(tk)) { txtHoTen.Text = ""; txtSoDienThoai.Text = ""; txtChucVu.Text = ""; txtBacLuong.Text = ""; rtxtDiaChi.Text = ""; LoadNhanVien(); MessageBox.Show("Thêm thành công"); return; } MessageBox.Show("Thêm thất bại"); }
private void BtnLUU_Click(object sender, EventArgs e) { if (flag == 1) { TaiKhoan_DTO Tk = new TaiKhoan_DTO(); if (rdNhanVien.Checked == true) { Tk.TaiKhoan = cboTaiKhoan.Text; } else if (rdSinhVien.Checked == true) { Tk.TaiKhoan = comboBox1.Text; } Tk.TenHienThi = cboTenHT.Text; Tk.MauKhau = txtMatKhau.Text; Tk.QuyenHan = cboQuyenHan.Text; if (TaiKhoan_BUS.TimTk_TheoTen(comboBox1.Text.Trim()) != null) { XtraMessageBox.Show("Tài khoản đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } //else if (TaiKhoan_BUS.TimTk_TheoTen(cboTaiKhoan.Text.Trim()) != null) //{ // XtraMessageBox.Show("Tài khoản đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); //} else if (TaiKhoan_BUS.ThemTaiKhoan(Tk)) { frmTaiKhoan_Load(sender, e); XtraMessageBox.Show("Bạn đã thêm thành công tài khoản ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (flag == 2) { TaiKhoan_DTO Tk = new TaiKhoan_DTO(); Tk.ID = int.Parse(nmID.Text); Tk.TaiKhoan = txtTaiKhoan.Text; Tk.TenHienThi = txtTenHT.Text; Tk.MauKhau = txtMatKhau.Text; Tk.QuyenHan = cboQuyenHan.Text; if (txtTaiKhoan.Text.Trim() == "") { XtraMessageBox.Show("Bạn chưa chọn dòng cần sửa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TaiKhoan_BUS.TimTk_TheoTen(txtTaiKhoan.Text.Trim()) != null) { XtraMessageBox.Show("Tên tài khoản trùng rồi !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (TaiKhoan_BUS.TimTk_TheoTenHT(txtTenHT.Text.Trim()) != null) { XtraMessageBox.Show("Tên hiển thị đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TaiKhoan_BUS.SuaTaiKhoan(Tk)) { frmTaiKhoan_Load(sender, e); XtraMessageBox.Show("Bạn đã sửa thành công tài khoản ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }