private void btXoa_Click(object sender, EventArgs e) { int id = int.Parse(dgvDanhSach.SelectedRows[0].Cells["ID"].Value.ToString()); DBAccess dba = new QLVatTu.DBAccess(); dba.Ghi("Delete tbVatTu Where ID = " + id.ToString()); DocDanhSachVatTu(); }
private void DocDanhSachDVSD() { DBAccess dba = new QLVatTu.DBAccess(); DataTable tb = dba.Doc("Select * From tbDonVi"); if (tb != null) { cbDonVi.DataSource = tb; cbDonVi.DisplayMember = "Ten"; cbDonVi.ValueMember = "ID"; } else { cbDonVi.Items.Clear(); } }
private void DocDanhSachVatTu() { DBAccess dba = new QLVatTu.DBAccess(); DataTable tb = dba.Doc("Select * From tbVatTu"); if (tb != null) { DataTable tb1 = new DataTable(); tb1.Columns.Add("ID", typeof(int)); tb1.Columns.Add("Ten", typeof(String)); tb1.Columns.Add("NgayNhap", typeof(DateTime)); tb1.Columns.Add("DangSuDung", typeof(Boolean)); tb1.Columns.Add("MaCode", typeof(String)); tb1.Columns.Add("GiaNhap", typeof(float)); tb1.Columns.Add("Anh", typeof(Image)); tb1.Columns.Add("DonViSuDungID", typeof(int)); MD5 md5 = new MD5(); foreach (DataRow r in tb.Rows) { DataRow r1 = tb1.NewRow(); r1["ID"] = r["ID"]; r1["Ten"] = md5.GiaiMa((byte[])r["Ten"]).Replace("#", " "); r1["NgayNhap"] = r["NgayNhap"]; r1["DangSuDung"] = r["DangSuDung"]; r1["MaCode"] = r["MaCode"]; r1["GiaNhap"] = r["GiaNhap"]; r1["Anh"] = Image.FromStream(new System.IO.MemoryStream((byte[])r["Anh"])); r1["DonViSuDungID"] = r["DonViSuDungID"]; tb1.Rows.Add(r1); } dgvDanhSach.DataSource = tb1; } else { dgvDanhSach.DataSource = null; } tbTen.Text = ""; cbDangSD.Checked = false; tbMaCode.Text = ""; tbGiaNhap.Text = ""; pbAnh.ImageLocation = ""; tbTen.Focus(); }