public BindingList <NhomHangHoaDTO> LayDanhSach() { BindingList <NhomHangHoaDTO> danhSach = new BindingList <NhomHangHoaDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From DanhMucNhomHangHoa"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { NhomHangHoaDTO itemDTO = new NhomHangHoaDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaNhomHangHoa = (string)dr["MaNhomHangHoa"]; itemDTO.TenNhomHangHoa = (string)dr["TenNhomHangHoa"]; itemDTO.GhiChu = (string)dr["GhiChu"]; danhSach.Add(itemDTO); } return(danhSach); }
public void Them(NhomHangHoaDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Insert into DanhMucNhomHangHoa (MaNhomHangHoa,TenNhomHangHoa,GhiChu) values (?, ?, ?)"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaNhomHangHoa", OleDbType.WChar).Value = itemDTO.MaNhomHangHoa; cmd.Parameters.Add("@TenNhomHangHoa", OleDbType.WChar).Value = itemDTO.TenNhomHangHoa; cmd.Parameters.Add("@GhiChu", OleDbType.WChar).Value = itemDTO.GhiChu; cmd.ExecuteNonQuery(); cn.Close(); }
public void Sua(NhomHangHoaDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Update DanhMucNhomHangHoa Set MaNhomHangHoa = ?, TenNhomHangHoa = ?, GhiChu = ? Where Id = ?"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaBacSy", OleDbType.WChar).Value = itemDTO.MaNhomHangHoa; cmd.Parameters.Add("@TenBacSy", OleDbType.WChar).Value = itemDTO.TenNhomHangHoa; cmd.Parameters.Add("@GhiChu", OleDbType.WChar).Value = itemDTO.GhiChu; cmd.Parameters.Add("@Id", OleDbType.Numeric).Value = itemDTO.Id; cmd.ExecuteNonQuery(); cn.Close(); }
private void gvDanhMucNhomHangHoa_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { if (gvDanhMucNhomHangHoa.FocusedRowHandle > -1) { try { NhomHangHoaDTO itemDTO = new NhomHangHoaDTO(); NhomHangHoaBUS itemBUS = new NhomHangHoaBUS(); itemDTO.MaNhomHangHoa = gvDanhMucNhomHangHoa.GetFocusedRowCellValue("MaNhomHangHoa").ToString(); itemDTO.TenNhomHangHoa = gvDanhMucNhomHangHoa.GetFocusedRowCellValue("TenNhomHangHoa").ToString(); itemDTO.GhiChu = gvDanhMucNhomHangHoa.GetFocusedRowCellValue("GhiChu").ToString(); itemDTO.Id = int.Parse(gvDanhMucNhomHangHoa.GetFocusedRowCellValue("Id").ToString()); if (this.flagThem && gvDanhMucNhomHangHoa.FocusedRowHandle == gvDanhMucNhomHangHoa.RowCount - 2) { if (itemDTO.MaNhomHangHoa.Length > 0) { DialogResult hopThoai = MessageBox.Show("Bạn chắc chắn muốn thêm mới?", "Thêm mới", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (hopThoai == DialogResult.Yes) { itemBUS.Them(itemDTO); this.flagThem = false; } } else { MessageBox.Show("Bạn chưa nhập mã!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { DialogResult hopThoai = MessageBox.Show("Bạn chắc chắn muốn cập nhật?", "Cập nhật", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (hopThoai == DialogResult.Yes) { itemBUS.Sua(itemDTO); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } this.LayDanhSachNhomHangHoa(); } }
public BindingList<NhomHangHoaDTO> LayDanhSach() { BindingList<NhomHangHoaDTO> danhSach = new BindingList<NhomHangHoaDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From DanhMucNhomHangHoa"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { NhomHangHoaDTO itemDTO = new NhomHangHoaDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaNhomHangHoa = (string)dr["MaNhomHangHoa"]; itemDTO.TenNhomHangHoa = (string)dr["TenNhomHangHoa"]; itemDTO.GhiChu = (string)dr["GhiChu"]; danhSach.Add(itemDTO); } return danhSach; }
public void Them(NhomHangHoaDTO itemDTO) { NhomHangHoaDAO itemDAO = new NhomHangHoaDAO(); itemDAO.Them(itemDTO); }
public void Sua(NhomHangHoaDTO itemDTO) { NhomHangHoaDAO itemDAO = new NhomHangHoaDAO(); itemDAO.Sua(itemDTO); }