public static void ThemHopDong(HopDong hd) { string sql = "insert into HDLD(MaHD, TenHD, MaNV, NgayKiHopDong, NgayKetThucKiHopDong) values(@mahd, @tenhd, @manv,CONVERT(date, @ngaybd, 111),CONVERT(date, @ngaykt, 111))"; SqlCommand cmd = new SqlCommand(sql, conn); using (SqlCommand command = new SqlCommand(sql, conn)) { command.Parameters.Add(new SqlParameter("@mahd", hd.MaHD)); command.Parameters.Add(new SqlParameter("@tenhd", hd.TenHD)); command.Parameters.Add(new SqlParameter("@manv", hd.MaNV)); command.Parameters.Add(new SqlParameter("@ngaybd", hd.DateBD.GetDateTimeFormats()[6])); command.Parameters.Add(new SqlParameter("@ngaykt", hd.DateKT.GetDateTimeFormats()[6])); int kq = command.ExecuteNonQuery(); if (kq > 0) { MessageBox.Show("Thêm hợp đồng mới thành công!"); } else { MessageBox.Show("Thêm hợp đồng mới thất bại!"); } command.Cancel(); } }
public static void XoaHopDong(HopDong hd) { string sql = "DELETE from HDLD where MaHD=@mahd"; using (SqlCommand command = new SqlCommand(sql, conn)) { command.Parameters.Add(new SqlParameter("@mahd", hd.MaHD)); command.ExecuteNonQuery(); command.Cancel(); } }
public static void SuaHopDong(HopDong hd) { string sql = "UPDATE HDLD set TenHD=@tenhd, MaNV=@manv, NgayKiHopDong=CONVERT(date, @datebd, 111), NgayKetThucKiHopDong = CONVERT(date,@datekt, 111) where MaHD=@mahd"; using (SqlCommand command = new SqlCommand(sql, conn)) { command.Parameters.Add(new SqlParameter("@mahd", hd.MaHD)); command.Parameters.Add(new SqlParameter("@tenhd", hd.TenHD)); command.Parameters.Add(new SqlParameter("@manv", hd.MaNV)); command.Parameters.Add(new SqlParameter("@datebd", hd.DateBD.GetDateTimeFormats()[6])); command.Parameters.Add(new SqlParameter("@datekt", hd.DateKT.GetDateTimeFormats()[6])); command.ExecuteNonQuery(); command.Cancel(); } }
private void tbnSua_Click(object sender, EventArgs e) { if (btnTV.Enabled == false) { this.tbnThem.Enabled = false; this.tbnXoa.Enabled = false; this.tbnGiaHan.Enabled = false; enableInput(); btnTV.Enabled = true; txtMaHD.ReadOnly = true; } else { HopDong temp = new HopDong(txtMaHD.Text, txtTenHD.Text, txtMaNV.Text, dateBD.Value, dateKT.Value); ConnectDatabase.SuaHopDong(temp); dgvHienThi.DataSource = ConnectDatabase.getAllHopDong(); } }
private void tbnXoa_Click(object sender, EventArgs e) { if (btnTV.Enabled == false) { this.tbnThem.Enabled = false; this.tbnSua.Enabled = false; this.tbnGiaHan.Enabled = false; //enableInput(); disableInput(); btnTV.Enabled = true; //txtMaHD.ReadOnly = true; } else { HopDong temp = new HopDong(txtMaHD.Text, txtTenHD.Text, txtMaNV.Text, dateBD.Value, dateKT.Value); ConnectDatabase.XoaHopDong(temp); MessageBox.Show("Xóa hợp đồng thành công!!"); dgvHienThi.DataSource = ConnectDatabase.getAllHopDong(); } }