private void btCapNhat_Click(object sender, EventArgs e) { if (isEmpty()) { return; } NhanVien_obj nv = new NhanVien_obj(); nv.IDNV = txtID.Text; nv.hotenNV = txthoten.Text; nv.ngaysinhNV = dtpngaysinh.Value; nv.emailNV = txtemail.Text; nv.dienthoaiNV = txtdienthoai.Text; nv.quequanNV = txtquequan.Text; nv.diachiNV = txtdiachi.Text; nv.soCMNDNV = txtsoCMND.Text; nv.CV_IDNV = cmbChucVu.SelectedValue.ToString(); nv.PB_IDNV = cmbPhongBan.SelectedValue.ToString(); NhanVienBus bus = new NhanVienBus(); int ret; ret = bus.update(nv); bus.close(); if (ret < 0) { MessageBox.Show("Không sửa được dữ liệu ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtdiachi.Enabled = false; txtdienthoai.Enabled = false; txtemail.Enabled = false; txthoten.Enabled = false; txtquequan.Enabled = false; txtsoCMND.Enabled = false; dtpngaysinh.Enabled = false; cmbChucVu.Enabled = false; cmbPhongBan.Enabled = false; btnthemnv.Enabled = true; btnsuanv.Enabled = true; btnxoanv.Enabled = true; btCapNhat.Enabled = false; btnHuy.Enabled = false; dvgnhanvien.Enabled = true; }
private void btLuu_Click(object sender, EventArgs e) { if (isEmpty()) { return; } nv = new NhanVien_obj(); //try //{ if (datetimeNgaySinh.Value < DateTime.Today) { nv.ngaysinhNV = datetimeNgaySinh.Value; nv.IDNV = txtID.Text; nv.hotenNV = txtHoten.Text; if (rdbNam.Checked == true) { nv.gioitinhNV = true; } else if (rdbNu.Checked == true) { nv.gioitinhNV = false; } nv.quequanNV = txtQuequan.Text; nv.diachiNV = txtDiachi.Text; nv.emailNV = txtEmail.Text; nv.dienthoaiNV = txtDienthoai.Text; nv.soCMNDNV = txtCMND.Text; nv.PB_IDNV = cmbTenPhongBan.SelectedValue.ToString(); nv.CV_IDNV = cmbChucVu.SelectedValue.ToString(); NhanVienBus bus = new NhanVienBus(); int ret; ret = bus.insert(nv); bus.close(); if (ret < 0) { MessageBox.Show("Dữ liệu không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; //this.Hide(); //FormNhanVien nv = new FormNhanVien(); //nv.Show(); } else { MessageBox.Show("Thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (MessageBox.Show("Bạn có muốn tiếp tục thêm mới?", "?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { txtID.Clear(); txtHoten.Clear(); txtEmail.Clear(); txtDienthoai.Clear(); txtDiachi.Clear(); txtCMND.Clear(); txtQuequan.Clear(); cmbChucVu.Text = ""; cmbTenPhongBan.Text = ""; return; } this.Hide(); FormNhanVien nv = new FormNhanVien(); nv.Show(); } } else { MessageBox.Show("Nhập sai ngày!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //} //catch (Exception ex) //{ // MessageBox.Show("Dữ liệu không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} }