public void DataLoad() { dbCTNhapHang = new DBChiTietNhapHang(); dtCTNhapHang = new DataTable(); dtCTNhapHang = dbCTNhapHang.GetAllChiTietNhapHang().Tables[0]; dgvDanhMucCTNhapHang.DataSource = dtCTNhapHang; foreach (DataGridViewRow row in dgvDanhMucCTNhapHang.Rows) { row.HeaderCell.Value = (row.Index + 1).ToString(); } dgvDanhMucCTNhapHang.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders); DBSanPham dbSanPham; DataSet dsSanPham; dbSanPham = new DBSanPham(); dsSanPham = new DataSet(); dsSanPham = dbSanPham.GetGiaBan(); DBHopDong dbHopDong = new DBHopDong(); DataSet dsHopDong = new DataSet(); dsHopDong = dbHopDong.GetSoHopDong(); cmSoHopDong.DataSource = dsHopDong.Tables[0]; cmSoHopDong.DisplayMember = "SoHopDong"; cmSoHopDong.ValueMember = "SoHopDong"; cmMaSP.DataSource = dsSanPham.Tables[0]; cmMaSP.DisplayMember = "MaSP"; cmMaSP.ValueMember = "MaSP"; txtMaNhapHang.DataBindings.Clear(); cmSoHopDong.DataBindings.Clear(); cmMaSP.DataBindings.Clear(); txtSoLuong.DataBindings.Clear(); dtpNgayNhapHang.DataBindings.Clear(); txtMaNhapHang.DataBindings.Add("Text", dtCTNhapHang, "MaNhapHang"); cmSoHopDong.DataBindings.Add("Text", dtCTNhapHang, "SoHopDong"); cmMaSP.DataBindings.Add("Text", dtCTNhapHang, "MaSP"); txtSoLuong.DataBindings.Add("Text", dtCTNhapHang, "SoLuong"); dtpNgayNhapHang.DataBindings.Add("Text", dtCTNhapHang, "NgayNhapHang"); if (dgvDanhMucCTNhapHang.Rows.Count == 0) { btnXoa.Enabled = false; } string[] strs = new string[dtCTNhapHang.Columns.Count]; int idx = 0; foreach (DataColumn col in dtCTNhapHang.Columns) { strs[idx++] += col.ColumnName; } cmCotTimKiem.DataSource = strs; }
private void frmXemDanhMucCTNhapHang_Load(object sender, EventArgs e) { dbCTNhapHang = new DBChiTietNhapHang(); dtCTNhapHang = new DataTable(); dtCTNhapHang = dbCTNhapHang.GetAllChiTietNhapHang().Tables[0]; dgvDanhMucCTNhapHang.DataSource = dtCTNhapHang; foreach (DataGridViewRow row in dgvDanhMucCTNhapHang.Rows) { row.HeaderCell.Value = (row.Index + 1).ToString(); } dgvDanhMucCTNhapHang.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders); string[] strs = new string[dtCTNhapHang.Columns.Count]; int idx = 0; foreach (DataColumn col in dtCTNhapHang.Columns) { strs[idx++] += col.ColumnName; } cmCotTimKiem.DataSource = strs; }