private void buttonThem_Click(object sender, EventArgs e) { if (textBoxTenNhanVien.Text == "") { MessageBox.Show("Chọn nhân viên!"); } else if (comboBoxLoaiHopDong.Text == "") { MessageBox.Show("Chọn loại hợp đồng!"); } else if (comboBoxTrangThai.Text == "") { MessageBox.Show("Chọn trạng thái hợp đồng!"); } else if (!Regex.IsMatch(textBoxNgayHieuLuc.Text, @"(((0[1-9]|1[0-2])\/(0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$")) { MessageBox.Show("Nhập sai ngày hiệu lực! mm/dd/yyyy"); } else if (!Regex.IsMatch(textBoxNgayHetHan.Text, @"(((0[1-9]|1[0-2])\/(0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$")) { MessageBox.Show("Nhập sai ngày hết hạn! mm/dd/yyyy"); } else if (textBoxNoiDung.Text == "") { MessageBox.Show("Chưa nhập nội dung!"); } else { DTO.HopDongNhanSu hd = new DTO.HopDongNhanSu(textBoxSoHopDong.Text, comboBoxMaNhanVien.Text, textBoxTenNhanVien.Text, comboBoxLoaiHopDong.Text, comboBoxTrangThai.Text, Convert.ToDateTime(textBoxNgayHieuLuc.Text), Convert.ToDateTime(textBoxNgayHetHan.Text), textBoxNoiDung.Text); if (hopDongBUS.AddHopDong(hd)) { MessageBox.Show("Đã thêm thành công!"); this.Close(); } else { MessageBox.Show("Lỗi!"); } } }
public bool AddHopDong(DTO.HopDongNhanSu hd) { string query = string.Format("AddHopDong '{0}', '{1}', N'{2}', N'{3}', N'{4}', '{5}', '{6}', N'{7}'", hd.SoHopDong, hd.MaNV, hd.HoTenNV, hd.LoaiHopDong, hd.TrangThai, hd.NgayHieuLuc, hd.NgayHetHan, hd.NoiDung); return(DataProvider.Instance.ExecuteNonQuery(query) > 0); }