public void deleteData(Class.trangThietBi data) { sqlQuery = "delete from TrangThietBi where ma ='" + data.ma + "'"; conString.ConString constring = new conString.ConString(); //this will hide the database info ... sort of try { using (var con = new SqlConnection(constring.initString())) { using (var cmd = new SqlCommand(sqlQuery, con)) { con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } catch (SqlException ex) { } }
private void detailToolStripMenuItem_Click(object sender, EventArgs e) { Class.trangThietBi thietBi = new Class.trangThietBi(); int currentRowIndex = dtgv_ThietBiList.CurrentCellAddress.Y;// 'current row selected if (-1 < currentRowIndex && currentRowIndex < dtgv_ThietBiList.RowCount) { thietBi.ten = dtgv_ThietBiList.Rows[currentRowIndex].Cells["ten"].Value.ToString(); thietBi.ma = dtgv_ThietBiList.Rows[currentRowIndex].Cells["ma"].Value.ToString(); thietBi.tinhTrang = dtgv_ThietBiList.Rows[currentRowIndex].Cells["tinhTrang"].Value.ToString(); //invisible part--------- thietBi.ngayMua = Convert.ToDateTime(dtgv_ThietBiList.Rows[currentRowIndex].Cells["ngayMua"].Value.ToString()); thietBi.giaThanh = int.Parse(dtgv_ThietBiList.Rows[currentRowIndex].Cells["giaThanh"].Value.ToString()); thietBi.baoHanh = int.Parse(dtgv_ThietBiList.Rows[currentRowIndex].Cells["baoHanh"].Value.ToString()); thietBi.ngayHetHanBaoHanh = Convert.ToDateTime(dtgv_ThietBiList.Rows[currentRowIndex].Cells["ngayHetHanBaoHanh"].Value.ToString()); thietBi.hangSanXuat = dtgv_ThietBiList.Rows[currentRowIndex].Cells["hangSanXuat"].Value.ToString(); } ChiTietThietBi chiTietThietBi = new ChiTietThietBi(thietBi); chiTietThietBi.ShowDialog(); LoadData(); }
public void updateData(Class.trangThietBi data) { sqlQuery = "update TrangThietBi set ten = N'" + data.ten + "', tinhTrang = N'" + data.tinhTrang + "', ngayMua= '" + data.ngayMua + "', giaThanh=" + data.giaThanh + ", baoHanh=" + data.baoHanh + ", ngayHetHanBaoHanh= '" + data.ngayHetHanBaoHanh + "', hangSanXuat= '" + data.hangSanXuat + "' where ma ='" + data.ma + "'"; conString.ConString constring = new conString.ConString(); try { using (var con = new SqlConnection(constring.initString())) { using (var cmd = new SqlCommand(sqlQuery, con)) { con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } catch (SqlException ex) { } }
public void insertData(Class.trangThietBi data) { sqlQuery = "insert into TrangThietBi (ten, ma, tinhTrang, ngayMua, giaThanh, baoHanh, ngayHetHanBaoHanh, hangSanXuat) values (N'" + data.ten + "','" + data.ma + "',N'" + data.tinhTrang + "','" + data.ngayMua + "'," + data.giaThanh + "," + data.baoHanh + ",'" + data.ngayHetHanBaoHanh + "',N'" + data.hangSanXuat + "') "; conString.ConString constring = new conString.ConString(); try { using (var con = new SqlConnection(constring.initString())) { using (var cmd = new SqlCommand(sqlQuery, con)) { con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } catch (SqlException ex) { } }
private void xóaThiếtBịToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Xác nhận xóa thiết bị này khỏi danh sách?", "Caution!", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { Class.trangThietBi thietBi = new Class.trangThietBi(); int currentRowIndex = dtgv_ThietBiList.CurrentCellAddress.Y;// 'current row selected if (-1 < currentRowIndex && currentRowIndex < dtgv_ThietBiList.RowCount) { thietBi.ten = dtgv_ThietBiList.Rows[currentRowIndex].Cells["ten"].Value.ToString(); thietBi.ma = dtgv_ThietBiList.Rows[currentRowIndex].Cells["ma"].Value.ToString(); thietBi.tinhTrang = dtgv_ThietBiList.Rows[currentRowIndex].Cells["tinhTrang"].Value.ToString(); } trangThietBi trangThietBi = new trangThietBi(); trangThietBi.deleteData(thietBi); Log.Insert("Xóa thông tin thiết bị " + thietBi.ten); LoadData(); } else if (dialogResult == DialogResult.No) { //do something else } }