public static bool CapNhatCTSP(clsChiTietSanPham_DTO ctsp) { string query = string.Format("update ChiTietSanPham set HinhAnh = '{0}', GiaBan = {1}, TrangThai = '{2}' where MaSP = '{3}' and MaMau = '{4}' and MaChatLieu = '{5}' and MaSize = '{6}'", ctsp.HinhAnh, ctsp.GiaTien, ctsp.TrangThai, ctsp.MaSP, ctsp.MaMau, ctsp.MaChatLieu, ctsp.MaSize); int kq = DataProvider.ExecuteInsertUpdateDelete(query); DataProvider.CloseConnect(); return(kq == 1); }
public static bool ThemChiTietSP(clsChiTietSanPham_DTO ctsp) { string query = string.Format("insert into ChiTietSanPham(MaChiTietSP, MaSP, MaMau, MaChatLieu, MaSize, HinhAnh, SoLuongTonKho, GiaBan, TrangThai) values('{8}', '{0}','{1}', '{2}', '{3}', '{4}', {5}, {6}, '{7}')", ctsp.MaSP, ctsp.MaMau, ctsp.MaChatLieu, ctsp.MaSize, ctsp.HinhAnh, ctsp.SoLuongTonKho, ctsp.GiaTien, ctsp.TrangThai, ctsp.MaChiTietSP); int kq = DataProvider.ExecuteInsertUpdateDelete(query); DataProvider.CloseConnect(); return(kq == 1); }
public static List <clsChiTietSanPham_DTO> LayDSCTSPTheoMaSP(string maSP) { List <clsChiTietSanPham_DTO> dsCtsp = new List <clsChiTietSanPham_DTO>(); string query = string.Format("select * from ChiTietSanPham where trangthai = 1 and MaSP = '{0}'", maSP); SqlDataReader dr = DataProvider.Retrieve_Table(query); while (dr.Read()) { clsChiTietSanPham_DTO ctsp = new clsChiTietSanPham_DTO(); if (!dr.IsDBNull(0)) { ctsp.MaChiTietSP = (string)dr["MaChiTietSP"]; } if (!dr.IsDBNull(1)) { ctsp.MaSP = (string)dr["MaSP"]; } if (!dr.IsDBNull(2)) { ctsp.MaMau = (string)dr["MaMau"]; } if (!dr.IsDBNull(3)) { ctsp.MaChatLieu = (string)dr["MaChatLieu"]; } if (!dr.IsDBNull(4)) { ctsp.MaSize = (string)dr["MaSize"]; } if (!dr.IsDBNull(5)) { ctsp.HinhAnh = (string)dr["HinhAnh"]; } if (!dr.IsDBNull(6)) { ctsp.SoLuongTonKho = (int)dr["SoLuongTonKho"]; } if (!dr.IsDBNull(7)) { ctsp.GiaTien = dr.GetInt32(7); } if (!dr.IsDBNull(8)) { ctsp.TrangThai = (Boolean)dr["TrangThai"]; } dsCtsp.Add(ctsp); } DataProvider.CloseConnect(); return(dsCtsp); }
void getData(clsChiTietHDNhap_DTO cthd, clsChiTietSanPham_DTO ctsp, clsSanPham_DTO sp, int i) { sp.TenSP = dgvHoaDonNhap.Rows[i].Cells["colTen"].Value.ToString(); int n = clsSanPham_BUS.DemSLSanPham(sp.TenSP); if (n == 0) { sp.MaSP = autoID_SP(); } else { List <clsSanPham_DTO> SP = clsSanPham_BUS.LayDSSPTheoTen(sp.TenSP); sp.MaSP = SP[0].MaSP; } sp.MaLoaiSP = dgvHoaDonNhap.Rows[i].Cells["colLoaiSP"].Value.ToString(); sp.MaNhaSX = dgvHoaDonNhap.Rows[i].Cells["colTenNSX"].Value.ToString(); sp.NgayNhapKho = DateTime.Now; sp.GioiTinh = dgvHoaDonNhap.Rows[i].Cells["colGioiTinh"].Value.ToString(); sp.TrangThai_SP = true; ctsp.MaSP = sp.MaSP; ctsp.MaMau = dgvHoaDonNhap.Rows[i].Cells["colMaMau"].Value.ToString(); ctsp.MaChatLieu = dgvHoaDonNhap.Rows[i].Cells["colMaChatLieu"].Value.ToString(); ctsp.MaSize = dgvHoaDonNhap.Rows[i].Cells["colMaSize"].Value.ToString(); n = clsChiTietSanPham_BUS.Retrieve_ChiTietSanPham(ctsp.MaSP, ctsp.MaMau, ctsp.MaChatLieu, ctsp.MaSize).Count; if (n == 0) { ctsp.MaChiTietSP = autoID_CTSP(); } else { List <clsChiTietSanPham_DTO> CT = clsChiTietSanPham_BUS.Retrieve_ChiTietSanPham(ctsp.MaSP, ctsp.MaMau, ctsp.MaChatLieu, ctsp.MaSize); ctsp.MaChiTietSP = CT[0].MaChiTietSP; } ctsp.GiaTien = Convert.ToInt32(dgvHoaDonNhap.Rows[i].Cells["colGiaBan"].Value.ToString()); ctsp.HinhAnh = "Data\\AnhDaiDien\\" + ofdHinh.SafeFileName; ctsp.SoLuongTonKho = Program.convertToInt(dgvHoaDonNhap.Rows[i].Cells["colSoLuong"].Value.ToString()); ctsp.TrangThai = true; cthd.MaChiTietSP = ctsp.MaChiTietSP; cthd.DonGia = Program.convertToInt(dgvHoaDonNhap.Rows[i].Cells["colGiaNhap"].Value.ToString()); cthd.SoLuong = ctsp.SoLuongTonKho; cthd.TrangThai = true; }
private void btnSua_Click(object sender, EventArgs e) { clsSanPham_DTO sp = new clsSanPham_DTO(); clsChiTietSanPham_DTO ctsp = new clsChiTietSanPham_DTO(); getData(ctsp, sp); if (clsSanPham_BUS.CapNhatSanPham(sp)) { if (clsChiTietSanPham_BUS.CapNhatCTSP(ctsp)) { MessageBox.Show("Cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); List <clsChiTietSanPham_DTO> dsSP = clsChiTietSanPham_BUS.Retrieve_ChiTietSanPham("", "", "", "", false, 0, 0, 0, ""); dgvSanPham.AutoGenerateColumns = false; dgvSanPham.DataSource = dsSP; resetControl(); } } }
void getData(clsChiTietSanPham_DTO ctsp, clsSanPham_DTO sp) { ctsp.MaSP = lblMa.Text; ctsp.MaMau = cboMau.SelectedValue.ToString(); ctsp.MaChatLieu = cboChatLieu.SelectedValue.ToString(); ctsp.MaSize = cboSize.SelectedValue.ToString(); ctsp.HinhAnh = lblDuongDan.Text; ctsp.SoLuongTonKho = Program.convertToInt(lblSLTK.Text); ctsp.TrangThai = true; sp.MaSP = ctsp.MaSP; clsSanPham_DTO SP = clsSanPham_BUS.Retrieve_SanPham(sp.MaSP); sp.NgayNhapKho = SP.NgayNhapKho; sp.MaLoaiSP = cboLoai.SelectedValue.ToString(); sp.TenSP = txtTenHang.Text; sp.MaNhaSX = cboNSX.SelectedValue.ToString(); sp.GioiTinh = radNam.Checked ? "Nam" : "Nữ"; sp.TrangThai_SP = true; }
public static bool CapNhatCTSP(clsChiTietSanPham_DTO ctsp) { return(clsChiTietSanPham_DAO.CapNhatCTSP(ctsp)); }
public static bool ThemChiTietSP(clsChiTietSanPham_DTO ctsp) { return(clsChiTietSanPham_DAO.ThemChiTietSP(ctsp)); }
public static List <clsChiTietSanPham_DTO> Retrieve_ChiTietSanPham(string tenSP, string maMau, string maCL, string maSize, bool lonHon, int soLuong, int giaBanMin, int giaBanMax, string loaiSP) { List <clsChiTietSanPham_DTO> dsChiTietSP = new List <clsChiTietSanPham_DTO>(); string sql = @"select * from ChiTietSanPham, SanPham where ChiTietSanPham.trangthai = 1 and ChiTietSanPham.MaSP = SanPham.MaSP"; if (tenSP != "") { sql += string.Format(" and TenSP Like N'%{0}%'", tenSP); } if (maMau != "") { sql += string.Format(" and MaMau = '{0}'", maMau); } if (maCL != "") { sql += string.Format(" and MaChatLieu = '{0}'", maCL); } if (maSize != "") { sql += string.Format(" and maSize = '{0}'", maSize); } if (soLuong > 0) { if (lonHon) { sql += string.Format(" and SoLuongTonKho >= {0}", soLuong); } else { sql += string.Format(" and SoLuongTonKho <= {0}", soLuong); } } if (giaBanMin > 0) { sql += string.Format(" and GiaBan >= {0}", giaBanMin); } if (giaBanMax > 0) { sql += string.Format(" and GiaBan <= {0}", giaBanMax); } if (loaiSP != "") { sql += string.Format(" and MaLoaiSP = '{0}'", loaiSP); } SqlDataReader dr = DataProvider.Retrieve_Table(sql); while (dr.Read()) { clsChiTietSanPham_DTO ctsp = new clsChiTietSanPham_DTO(); if (!dr.IsDBNull(0)) { ctsp.MaChiTietSP = (string)dr["MaChiTietSP"]; } if (!dr.IsDBNull(1)) { ctsp.MaSP = (string)dr["MaSP"]; } if (!dr.IsDBNull(2)) { ctsp.MaMau = (string)dr["MaMau"]; } if (!dr.IsDBNull(3)) { ctsp.MaChatLieu = (string)dr["MaChatLieu"]; } if (!dr.IsDBNull(4)) { ctsp.MaSize = (string)dr["MaSize"]; } if (!dr.IsDBNull(5)) { ctsp.HinhAnh = (string)dr["HinhAnh"]; } if (!dr.IsDBNull(6)) { ctsp.SoLuongTonKho = (int)dr["SoLuongTonKho"]; } if (!dr.IsDBNull(7)) { ctsp.GiaTien = dr.GetInt32(7); } if (!dr.IsDBNull(8)) { ctsp.TrangThai = (Boolean)dr["TrangThai"]; } dsChiTietSP.Add(ctsp); } DataProvider.CloseConnect(); return(dsChiTietSP); }
private void btnXacNhan_Click(object sender, EventArgs e) { bool check = true; string maHD = autoID_HDNhap(); int n = dgvHoaDonNhap.Rows.Count; clsHoaDonNhap_DTO hd = new clsHoaDonNhap_DTO(); hd.MaHDNhap = maHD; hd.MaNVLap = Program.NV_Login.MaNV; hd.NgayLapHD = DateTime.Now; hd.TrangThai = true; hd.TongTien = Program.convertToInt(lblTongTien.Text.Substring(0, lblTongTien.Text.Length - 4)); if (clsHoaDonNhap_BUS.ThemHDNhap(hd)) { for (int i = 0; i < n; i++) { clsChiTietHDNhap_DTO cthd = new clsChiTietHDNhap_DTO(); clsChiTietSanPham_DTO ctsp = new clsChiTietSanPham_DTO(); clsSanPham_DTO sp = new clsSanPham_DTO(); getData(cthd, ctsp, sp, i); cthd.MaHDNhap = hd.MaHDNhap; List <clsChiTietSanPham_DTO> ct = clsChiTietSanPham_BUS.Retrieve_ChiTietSanPham(sp.MaSP, ctsp.MaMau, ctsp.MaChatLieu, ctsp.MaSize); if (ct.Count > 0) { if (ct[0].MaSP != null) { if (clsChiTietSanPham_BUS.CapNhatSoLuong(ctsp.MaChiTietSP, cthd.SoLuong) && clsChiTietHDNhap_BUS.ThemChiTietHDNhap(cthd)) { MessageBox.Show("Thêm số lượng thành công"); } else { check = false; break; } } } else if (clsSanPham_BUS.DemSLSanPham(dgvHoaDonNhap.Rows[i].Cells["colTen"].Value.ToString()) > 0) { if (clsSanPham_BUS.Retrieve_SanPham(sp.MaSP).MaSP != null) { if (clsChiTietSanPham_BUS.ThemChiTietSP(ctsp) && clsChiTietHDNhap_BUS.ThemChiTietHDNhap(cthd)) { MessageBox.Show("Thêm mẫu mã thành công"); } else { check = false; break; } } } else if (clsSanPham_BUS.ThemSanPham(sp) && clsChiTietSanPham_BUS.ThemChiTietSP(ctsp) && clsChiTietHDNhap_BUS.ThemChiTietHDNhap(cthd)) { MessageBox.Show("Thêm sản phẩm mới thành công"); } else { check = false; } } if (!check) { MessageBox.Show("Thất bại"); } else { while (dgvHoaDonNhap.Rows.Count > 0) { dgvHoaDonNhap.Rows.Remove(dgvHoaDonNhap.Rows[0]); } } } else { MessageBox.Show("Không thể tạo hóa đơn"); } lblTongTien.Text = "0 VNĐ"; }