public void Them(LoaiHangHoaDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Insert into DanhMucLoaiHangHoa (MaLoaiHangHoa,TenLoaiHangHoa,GhiChu) values (?, ?, ?)"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaLoaiHangHoa", OleDbType.WChar).Value = itemDTO.MaLoaiHangHoa; cmd.Parameters.Add("@TenLoaiHangHoa", OleDbType.WChar).Value = itemDTO.TenLoaiHangHoa; cmd.Parameters.Add("@GhiChu", OleDbType.WChar).Value = itemDTO.GhiChu; cmd.ExecuteNonQuery(); cn.Close(); }
public void Sua(LoaiHangHoaDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Update DanhMucLoaiHangHoa Set MaLoaiHangHoa = ?, TenLoaiHangHoa = ?, GhiChu = ? Where Id = ?"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaBacSy", OleDbType.WChar).Value = itemDTO.MaLoaiHangHoa; cmd.Parameters.Add("@TenBacSy", OleDbType.WChar).Value = itemDTO.TenLoaiHangHoa; cmd.Parameters.Add("@GhiChu", OleDbType.WChar).Value = itemDTO.GhiChu; cmd.Parameters.Add("@Id", OleDbType.Numeric).Value = itemDTO.Id; cmd.ExecuteNonQuery(); cn.Close(); }
private void gvDanhMucLoaiHangHoa_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { if (gvDanhMucLoaiHangHoa.FocusedRowHandle > -1) { try { LoaiHangHoaDTO itemDTO = new LoaiHangHoaDTO(); LoaiHangHoaBUS itemBUS = new LoaiHangHoaBUS(); itemDTO.MaLoaiHangHoa = gvDanhMucLoaiHangHoa.GetFocusedRowCellValue("MaLoaiHangHoa").ToString(); itemDTO.TenLoaiHangHoa = gvDanhMucLoaiHangHoa.GetFocusedRowCellValue("TenLoaiHangHoa").ToString(); itemDTO.GhiChu = gvDanhMucLoaiHangHoa.GetFocusedRowCellValue("GhiChu").ToString(); itemDTO.Id = int.Parse(gvDanhMucLoaiHangHoa.GetFocusedRowCellValue("Id").ToString()); if (this.flagThem && gvDanhMucLoaiHangHoa.FocusedRowHandle == gvDanhMucLoaiHangHoa.RowCount - 2) { if (itemDTO.MaLoaiHangHoa.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.LayDanhSachLoaiHangHoa(); } }
public BindingList<LoaiHangHoaDTO> LayDanhSach() { BindingList<LoaiHangHoaDTO> danhSach = new BindingList<LoaiHangHoaDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From DanhMucLoaiHangHoa"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { LoaiHangHoaDTO itemDTO = new LoaiHangHoaDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaLoaiHangHoa = (string)dr["MaLoaiHangHoa"]; itemDTO.TenLoaiHangHoa = (string)dr["TenLoaiHangHoa"]; itemDTO.GhiChu = (string)dr["GhiChu"]; danhSach.Add(itemDTO); } return danhSach; }
public void Them(LoaiHangHoaDTO itemDTO) { LoaiHangHoaDAO itemDAO = new LoaiHangHoaDAO(); itemDAO.Them(itemDTO); }
public void Sua(LoaiHangHoaDTO itemDTO) { LoaiHangHoaDAO itemDAO = new LoaiHangHoaDAO(); itemDAO.Sua(itemDTO); }