private void btnNhapHang_Click(object sender, EventArgs e) { txtMaHDNhap.Text = hdn_BUS.LayMaTiepTheo(); if (spChon_DTO != null) { clsChiTietHDNhap_DTO ct = lsChiTiet.Find(o => o.MaSP == spChon_DTO.MaSP); if (ct != null) { ct.SoLuong += int.Parse(txtSoLuongNhap.Text); } else { //ct.MaHDNhap = txtMaHDNhap.Text; ct = new clsChiTietHDNhap_DTO(); ct.MaSP = spChon_DTO.MaSP; ct.MaHDNhap = txtMaHDNhap.Text; ct.SoLuong = int.Parse(txtSoLuongNhap.Text); ct.DonGia = spChon_DTO.GiaBan; lsChiTiet.Add(ct); } txtThanhTien.Text = lsChiTiet.Sum(o => o.ThanhTien).ToString(); dgvChiTietHoaDon.DataSource = lsRong; dgvChiTietHoaDon.DataSource = lsChiTiet; btnLuuHoaDon.Enabled = true; } }
public static bool ThemChiTietHDNhap(clsChiTietHDNhap_DTO cthd) { string query = string.Format("insert into ChiTietHDNhap(MaHDNhap, MaChiTietSP, DonGiaNhap, SoLuong, TrangThai) values('{0}', '{1}', {2}, {3} ,'{4}')", cthd.MaHDNhap, cthd.MaChiTietSP, cthd.DonGia, cthd.SoLuong, cthd.TrangThai); int kq = DataProvider.ExecuteInsertUpdateDelete(query); DataProvider.CloseConnect(); return(kq == 1); }
public bool LuuChiTietHoaDon(clsChiTietHDNhap_DTO cthd_DTO) { string strQuery = "Insert Into ChiTietHDNhap ([MaHDNhap],[MaSP],[SoLuong],[DonGia]) Values ( @MaHDNhap, @MaSP, @SoLuong, @DonGia )"; SqlParameter[] para = new SqlParameter[4]; para[0] = new SqlParameter("@MaHDNhap", cthd_DTO.MaHDNhap); para[1] = new SqlParameter("@MaSP", cthd_DTO.MaSP); para[2] = new SqlParameter("@SoLuong", cthd_DTO.SoLuong); para[3] = new SqlParameter("@DonGia", cthd_DTO.DonGia); SqlConnection conn = DataProvider.TaoKetNoi(); int kq = DataProvider.ThucThiCauLenh(strQuery, para, conn); conn.Close(); return(kq > 0); }
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; }
public static List <clsChiTietHDNhap_DTO> LayDSCTHDNhap(string maCTSP) { List <clsChiTietHDNhap_DTO> dsCTHD = new List <clsChiTietHDNhap_DTO>(); string query = "select * from ChiTietHDNhap "; if (maCTSP != "") { query += string.Format(" where MaChiTietSP = '{0}'", maCTSP); } SqlDataReader dr = DataProvider.Retrieve_Table(query); while (dr.Read()) { clsChiTietHDNhap_DTO cthd = new clsChiTietHDNhap_DTO(); if (!dr.IsDBNull(0)) { cthd.MaHDNhap = dr.GetString(0); } if (!dr.IsDBNull(1)) { cthd.MaChiTietSP = dr.GetString(1); } if (!dr.IsDBNull(2)) { cthd.DonGia = dr.GetInt32(2); } if (!dr.IsDBNull(3)) { cthd.SoLuong = dr.GetInt32(3); } if (!dr.IsDBNull(4)) { cthd.TrangThai = dr.GetBoolean(4); } dsCTHD.Add(cthd); } DataProvider.CloseConnect(); return(dsCTHD); }
private void btnThem_Click(object sender, RoutedEventArgs e) { if (txtGiaSP.Text == "" || txtSoLuongNhap.Text == "") { MessageBox.Show("Vui lòng nhập đầy đủ thông tin"); } else { txtMaHDNhap.Text = hdn_BUS.LayMaTiepTheo(); if (spChon_DTO != null) { clsChiTietHDNhap_DTO ct = lsChiTiet.Find(o => o.MaSP == spChon_DTO.MaSP); if (ct != null) { ct.SoLuong += int.Parse(txtSoLuongNhap.Text); } else { //ct.MaHDNhap = txtMaHDNhap.Text; ct = new clsChiTietHDNhap_DTO(); ct.MaSP = spChon_DTO.MaSP; ct.MaHDNhap = txtMaHDNhap.Text; ct.SoLuong = int.Parse(txtSoLuongNhap.Text); string giaban = spChon_DTO.GiaBan.ToString(); int chieudai = giaban.Length; string gia = giaban.Substring(0, chieudai - 3); ct.DonGia = spChon_DTO.GiaBan; long tt = ct.SoLuong * int.Parse(gia); ct.ThanhTien = tt * 1000; lsChiTiet.Add(ct); } txtThanhTien.Text = lsChiTiet.Sum(o => o.ThanhTien).ToString(); lsChiTietHoaDon.Items.Clear(); foreach (var item in lsChiTiet) { lsChiTietHoaDon.Items.Add(item); } btnLuu.IsEnabled = true; } } }
public static bool ThemChiTietHDNhap(clsChiTietHDNhap_DTO cthd) { return(clsChiTietHDNhap_DAO.ThemChiTietHDNhap(cthd)); }
public bool LuuChiTietHoaDon(clsChiTietHDNhap_DTO cthd_DTO) { return(cthd_DAO.LuuChiTietHoaDon(cthd_DTO)); }
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Đ"; }