Beispiel #1
0
        public static bool SuaChiTietPhieuBanHang(ChiTietHoaDonBan_DTO phieuhang)
        {
            SqlConnection con = DataProvider.KetNoi();

            try
            {
                cmd             = new SqlCommand("SuaChiTietPHBan", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p = new SqlParameter("@MaHDB", phieuhang.MaHDB);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@MaSPCH", phieuhang.MaSPCH);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@SoLuong", phieuhang.SoLuong);
                cmd.Parameters.Add(p);

                cmd.ExecuteNonQuery();

                DataProvider.DongKetNoi(con);
                return(true);
            }
            catch
            {
                DataProvider.DongKetNoi(con);
                return(false);
            }
        }
        public static bool ThemChiTietPHBanHang(ChiTietHoaDonBan_DTO phieu)
        {
            SqlConnection con = DataProvider.KetNoi();

            try
            {
                cmd             = new SqlCommand("ThemChiTietPHBan", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter p = new SqlParameter("@MaHDB", phieu.MaHDB);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@MaSPCH", phieu.MaSPCH);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@SoLuong", phieu.SoLuong);
                cmd.Parameters.Add(p);

                p = new SqlParameter("@DonViTinh", phieu.DonViTinh);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@HinhThucBan", phieu.HinhThucBan);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@SoLuongMuaLe", phieu.SoLuongMuaLe);
                cmd.Parameters.Add(p);

                cmd.ExecuteNonQuery();

                DataProvider.DongKetNoi(con);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DataProvider.DongKetNoi(con);
                return(false);
            }
        }
        public static bool XoaChiTietPhieuBanHang(ChiTietHoaDonBan_DTO phieuhang)
        {
            SqlConnection con = DataProvider.KetNoi();

            try
            {
                cmd             = new SqlCommand("XoaChiTietPHBan", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p = new SqlParameter("@MaHDB", phieuhang.MaHDB);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@MaSPCH", phieuhang.MaSPCH);
                cmd.Parameters.Add(p);

                cmd.ExecuteNonQuery();

                DataProvider.DongKetNoi(con);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DataProvider.DongKetNoi(con);
                return(false);
            }
        }
Beispiel #4
0
 private void luuHD_Click(object sender, EventArgs e)
 {
     if (!hdb_BUS.CheckMaHDB(txtMaHD.Text))
     {
         hdB.MaHDB    = txtMaHD.Text;
         hdB.MaKH     = cbBMaKH.Text;
         hdB.MaNV     = cbBMaNV.Text;
         hdB.NgayBan  = dateNgayBan.Value;
         hdB.TongTien = double.Parse(txtTongTien.Text);
         hdb_BUS.ThemHDB(hdB);
         for (int i = 0; i < lvCTHDB.Items.Count; i++)
         {
             int    soLuong   = int.Parse(lvCTHDB.Items[i].SubItems[2].Text);
             long   thanhTien = long.Parse(lvCTHDB.Items[i].SubItems[4].Text);
             string maHH      = lvCTHDB.Items[i].Text;
             ChiTietHoaDonBan_DTO cTHDB_DTO = new ChiTietHoaDonBan_DTO();
             cTHDB_DTO.MaHDB     = txtMaHD.Text;
             cTHDB_DTO.MaHH      = maHH;
             cTHDB_DTO.SoLuong   = soLuong;
             cTHDB_DTO.ThanhTien = thanhTien;
             cTHDB_DTO.KhuyenMai = 0;
             cTHDB_DTO.GiamGia   = 0;
             cTHDB_BUS.ThemCTHDB(cTHDB_DTO);
         }
     }
     if (hdb_BUS.CheckMaHDB(txtMaHD.Text))
     {
         cTHDB_BUS.XoaCTHDB(txtMaHD.Text);
         for (int i = 0; i < lvCTHDB.Items.Count; i++)
         {
             int    soLuong   = int.Parse(lvCTHDB.Items[i].SubItems[2].Text);
             long   thanhTien = long.Parse(lvCTHDB.Items[i].SubItems[4].Text);
             string maHH      = lvCTHDB.Items[i].Text;
             ChiTietHoaDonBan_DTO cTHDB_DTO = new ChiTietHoaDonBan_DTO();
             cTHDB_DTO.MaHDB     = txtMaHD.Text;
             cTHDB_DTO.MaHH      = maHH;
             cTHDB_DTO.SoLuong   = soLuong;
             cTHDB_DTO.ThanhTien = thanhTien;
             cTHDB_DTO.KhuyenMai = 0;
             cTHDB_DTO.GiamGia   = 0;
             cTHDB_BUS.ThemCTHDB(cTHDB_DTO);
         }
     }
     //for (int i = 0; i < lvCTHDB.Items.Count; i++)
     //{
     //    if (cTHDB_BUS.checkCTHDB(txtMaHD.Text, lvCTHDB.Items[i].Text))
     //    {
     //        int soLuong = int.Parse(lvCTHDB.Items[i].SubItems[2].Text);
     //        long thanhTien = long.Parse(lvCTHDB.Items[i].SubItems[4].Text);
     //        string maHH = lvCTHDB.Items[i].Text;
     //        cTHDB_BUS.CapNhatCTHDB(soLuong, thanhTien, txtMaHD.Text, maHH);
     //    }
     //}
     trangThaiBanDau();
     loadDuLieu();
     luuHD.Enabled = huyHD.Enabled = false;
 }
Beispiel #5
0
 private void lvCTHDB_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lvCTHDB.SelectedItems.Count > 0)
     {
         ListViewItem         item  = lvCTHDB.SelectedItems[0];
         ChiTietHoaDonBan_DTO ctHDB = new ChiTietHoaDonBan_DTO(item.SubItems[1].Text, item.Text, int.Parse(item.SubItems[2].Text), 0, double.Parse(item.SubItems[3].Text), long.Parse(item.SubItems[4].Text));
         txtTenHang.Text         = ctHDB.MaHDB;
         cbBMaHang.SelectedValue = ctHDB.MaHH;
         numberSoLuong.Value     = ctHDB.SoLuong;
         txtGia.Text             = ctHDB.GiamGia.ToString();
         txtThanhTien.Text       = ctHDB.ThanhTien.ToString();
     }
 }
Beispiel #6
0
        private void btnAddProductExportDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbIDBillExportDetail.Text == "" || cmbIDProductDetailStore.Text == "" || txtAmountOfProductExportDetail.Text == "")
                {
                    XtraMessageBox.Show("Bạn phải điền đầy đủ thông tin !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                ChiTietHoaDonBan_DTO phieunhap = new ChiTietHoaDonBan_DTO();
                phieunhap.MaHDB  = cmbIDBillExportDetail.Text;
                phieunhap.MaSPCH = cmbIDProductDetailStore.Text;
                if (txtAmountOfProductExportDetail.Text == "")
                {
                    phieunhap.SoLuong = 0;
                }
                else
                {
                    phieunhap.SoLuong = Convert.ToInt32(txtAmountOfProductExportDetail.Text.ToString());
                }

                phieunhap.DonViTinh    = cmbUnitCalculator.Text;
                phieunhap.SoLuongMuaLe = Convert.ToInt32(txtRetail.Text.ToString());
                if (cbRetail.Checked == true)
                {
                    phieunhap.HinhThucBan = 1;
                }
                else
                {
                    phieunhap.HinhThucBan = 0;
                }


                if (ChiTietHoaDonBan_BUS.ThemChiTietPHBan(phieunhap))
                {
                    LoadPhieuBanHang();
                    LoadChiTietPhieuBanHang();
                    uctSanPhamCH.uctSPCH.LoadSanPhamCH1();
                    XtraMessageBox.Show("Thêm chi tiết hóa đơn bán hàng thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    ClearDisplay1();
                    return;
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        public List <ChiTietHoaDonBan_DTO> LayDanhSachTheoMa(string maHDB)
        {
            List <ChiTietHoaDonBan_DTO> dsCTHDB = new List <ChiTietHoaDonBan_DTO>();
            List <HangHoa_DTO>          dsHH    = new List <HangHoa_DTO>();
            // 1. Tạo đối tượng kết nối
            SqlConnection conn = DataProvider.TaoKetNoi();
            SqlDataReader dr   = null;

            try
            {
                // 2. mở kết nối
                // 3. tạo đối tượng command
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT cthdb.MAHH,TENHH,cthdb.SOLUONG,hh.DONGIABAN ,cthdb.THANHTIEN FROM [dbo].[CHITIETHOADONBAN] cthdb,[dbo].[HANGHOA] hh WHERE cthdb.MAHH=hh.MAHH AND cthdb.TRANGTHAI = 1 AND MAHDB='" + maHDB + "'";
                cmd.Connection  = conn;
                // 4. thực thi cmd và xử lý kết quả
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ChiTietHoaDonBan_DTO cTHDB = new ChiTietHoaDonBan_DTO();
                    if (!dr.IsDBNull(0))
                    {
                        cTHDB.MaHH = (string)dr[0];
                    }
                    if (!dr.IsDBNull(1))
                    {
                        cTHDB.TenHH = (string)dr[1];
                    }
                    if (!dr.IsDBNull(2))
                    {
                        cTHDB.SoLuong = (int)dr[2];
                    }
                    if (!dr.IsDBNull(3))
                    {
                        cTHDB.DonGia = (double)dr[3];
                    }
                    if (!dr.IsDBNull(4))
                    {
                        cTHDB.ThanhTien = (double)dr[4];
                    }
                    dsCTHDB.Add(cTHDB);
                }
            }
            finally
            {
                dr.Close();
                // 5. đóng kết nối
                conn.Close();
            }
            return(dsCTHDB);
        }
Beispiel #8
0
        private void btnUpdateProductExportDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbIDBillExportDetail.Text == "" || cmbIDProductDetailStore.Text == "" || txtAmountOfProductExportDetail.Text == "")
                {
                    XtraMessageBox.Show("Bạn phải chọn chi tiết phiếu cần chỉnh sửa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (cmbIDBillExportDetail.Text != (string)dtgvDetailBillSale.CurrentRow.Cells["MaHDB1"].Value || cmbIDProductDetailStore.Text != (string)dtgvDetailBillSale.CurrentRow.Cells["MaSPCH"].Value)
                {
                    XtraMessageBox.Show("Chi tiết hóa đơn bán hàng cập nhật thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ChiTietHoaDonBan_DTO phieunhap = new ChiTietHoaDonBan_DTO();
                phieunhap.MaHDB  = (string)dtgvDetailBillSale.CurrentRow.Cells["MaHDB1"].Value;
                phieunhap.MaSPCH = (string)dtgvDetailBillSale.CurrentRow.Cells["MaSPCH"].Value;

                phieunhap.SoLuong   = Convert.ToInt32(txtAmountOfProductExportDetail.Text.ToString());
                phieunhap.DonViTinh = cmbUnitCalculator.Text;


                if (cbRetail.Checked == true)
                {
                    phieunhap.HinhThucBan  = 1;
                    phieunhap.SoLuongMuaLe = Convert.ToInt32(txtRetail.Text.ToString());
                }
                else
                {
                    phieunhap.HinhThucBan  = 0;
                    phieunhap.SoLuongMuaLe = 0;
                }

                if (ChiTietHoaDonBan_BUS.SuaChiTietPHBan(phieunhap))
                {
                    LoadPhieuBanHang();
                    LoadChiTietPhieuBanHang();
                    uctSanPhamCH.uctSPCH.LoadSanPhamCH1();
                    XtraMessageBox.Show("Chi tiết hóa đơn bán hàng cập nhật thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearDisplay1();
                    return;
                }
            }catch
            {
                XtraMessageBox.Show("Chi tiết hóa đơn bán hàng cập nhật thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        public static List <ChiTietHoaDonBan_DTO> LoadChiTietPhieuBan()
        {
            SqlConnection con = DataProvider.KetNoi();

            try
            {
                cmd             = new SqlCommand("DSChiTietPhieuBan", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.ExecuteNonQuery();
                da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                dt = new DataTable();

                da.Fill(dt);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            List <ChiTietHoaDonBan_DTO> dsChiTietPhieuBan = new List <ChiTietHoaDonBan_DTO>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ChiTietHoaDonBan_DTO phieuhang = new ChiTietHoaDonBan_DTO();
                phieuhang.MaHDB   = dt.Rows[i]["MaHDB"].ToString();
                phieuhang.MaSPCH  = dt.Rows[i]["MaSPCH"].ToString();
                phieuhang.SoLuong = Convert.ToInt32(dt.Rows[i]["SoLuong"].ToString());

                phieuhang.DonViTinh    = dt.Rows[i]["DonViTinh"].ToString();
                phieuhang.HinhThucBan  = Convert.ToInt32(dt.Rows[i]["HinhThucBan"].ToString());
                phieuhang.SoLuongMuaLe = Convert.ToInt32(dt.Rows[i]["SoLuongMuaLe"].ToString());


                dsChiTietPhieuBan.Add(phieuhang);
            }
            DataProvider.DongKetNoi(con);
            return(dsChiTietPhieuBan);
        }
Beispiel #10
0
        public static List <ChiTietHoaDonBan_DTO> LoadChiTietPhieuBan()
        {
            SqlConnection con = DataProvider.KetNoi();

            try
            {
                cmd             = new SqlCommand("DSChiTietPhieuBan", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.ExecuteNonQuery();
                da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                dt = new DataTable();

                da.Fill(dt);
            }
            catch
            {
                return(null);
            }

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            List <ChiTietHoaDonBan_DTO> dsChiTietPhieuBan = new List <ChiTietHoaDonBan_DTO>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ChiTietHoaDonBan_DTO phieuhang = new ChiTietHoaDonBan_DTO();
                phieuhang.MaHDB   = dt.Rows[i]["MaHDB"].ToString();
                phieuhang.MaSPCH  = dt.Rows[i]["MaSPCH"].ToString();
                phieuhang.SoLuong = Convert.ToInt32(dt.Rows[i]["SoLuong"].ToString());

                dsChiTietPhieuBan.Add(phieuhang);
            }
            DataProvider.DongKetNoi(con);
            return(dsChiTietPhieuBan);
        }
        public void ThemCTHDB(ChiTietHoaDonBan_DTO cTHDB_DTO)
        {
            // 1. Tạo đối tượng kết nối
            SqlConnection conn = DataProvider.TaoKetNoi();

            try
            {
                // 3. tạo đối tượng command
                SqlCommand cmd = new SqlCommand();
                //"DELETE FROM FC WHERE FCName = 'Chelsea'"

                cmd.CommandText = string.Format("EXEC sp_ThemCTHoaDon '{0}','{1}','{2}','{3}','{4}','{5}'", cTHDB_DTO.MaHDB, cTHDB_DTO.MaHH, cTHDB_DTO.SoLuong, cTHDB_DTO.KhuyenMai, cTHDB_DTO.GiamGia, cTHDB_DTO.ThanhTien);
                cmd.Connection  = conn;
                // 4. thực thi cmd và xử lý kết quả
                cmd.ExecuteNonQuery();
            }
            finally
            {
                // 5. đóng kết nối
                conn.Close();
            }
        }
 public static bool SuaChiTietPHBan(ChiTietHoaDonBan_DTO phieu)
 {
     return(ChiTietHoaDonBan_DAL.SuaChiTietPhieuBanHang(phieu));
 }
 public static bool XoaChiTietPHBan(ChiTietHoaDonBan_DTO phieunhap)
 {
     return(ChiTietHoaDonBan_DAL.XoaChiTietPhieuBanHang(phieunhap));
 }
 public static bool ThemChiTietPHBan(ChiTietHoaDonBan_DTO phieu)
 {
     return(ChiTietHoaDonBan_DAL.ThemChiTietPHBanHang(phieu));
 }
 public void ThemCTHDB(ChiTietHoaDonBan_DTO cTHDB_DTO)
 {
     objCTHDB_DAO.ThemCTHDB(cTHDB_DTO);
 }
Beispiel #16
0
        private void btnDeleteProductExportDetail_Click(object sender, EventArgs e)
        {
            try {
                if (cmbIDBillExportDetail.Text == "" || cmbIDProductDetailStore.Text == "" || txtAmountOfProductExportDetail.Text == "")
                {
                    XtraMessageBox.Show("Bạn phải chọn chi tiết phiếu cần xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                ChiTietHoaDonBan_DTO phieunhap = new ChiTietHoaDonBan_DTO();
                phieunhap.MaHDB  = (string)dtgvDetailBillSale.CurrentRow.Cells["MaHDB1"].Value;
                phieunhap.MaSPCH = cmbIDProductDetailStore.Text;

                if (ChiTietHoaDonBan_BUS.XoaChiTietPHBan(phieunhap))
                {
                    LoadPhieuBanHang();
                    LoadChiTietPhieuBanHang();
                    uctSanPhamCH.uctSPCH.LoadSanPhamCH1();
                    XtraMessageBox.Show("Chi tiết phiếu Bán hàng xóa thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearDisplay1();
                    if (dtgvDetailBillSale.Rows.Count == 0)
                    {
                        dtgvDetailBillSale.ColumnCount          = 6;
                        dtgvDetailBillSale.ColumnHeadersVisible = true;
                        dtgvDetailBillSale.Columns[0].Name      = "MaHDB1";
                        dtgvDetailBillSale.Columns[1].Name      = "MaSPCH";
                        dtgvDetailBillSale.Columns[2].Name      = "SoLuong";
                        dtgvDetailBillSale.Columns[3].Name      = "DonViTinh";
                        dtgvDetailBillSale.Columns[4].Name      = "HinhThucBan";
                        dtgvDetailBillSale.Columns[5].Name      = "SoLuongMuaLe";

                        dtgvDetailBillSale.Columns[0].DataPropertyName = "MaHDB";
                        dtgvDetailBillSale.Columns[1].DataPropertyName = "MaSPCH";
                        dtgvDetailBillSale.Columns[2].DataPropertyName = "SoLuong";
                        dtgvDetailBillSale.Columns[3].DataPropertyName = "DonViTinh";
                        dtgvDetailBillSale.Columns[4].DataPropertyName = "HinhThucBan";
                        dtgvDetailBillSale.Columns[5].DataPropertyName = "SoLuongMuaLe";

                        dtgvDetailBillSale.Columns[0].HeaderText = "Mã HDB";
                        dtgvDetailBillSale.Columns[1].HeaderText = "Mã SPCH";
                        dtgvDetailBillSale.Columns[2].HeaderText = "Số lượng";
                        dtgvDetailBillSale.Columns[3].HeaderText = "Đơn vị tính";
                        dtgvDetailBillSale.Columns[4].HeaderText = "Hình thức bán";
                        dtgvDetailBillSale.Columns[5].HeaderText = "Số lượng mua lẻ";

                        dtgvDetailBillSale.Columns[0].Width = 75;
                        dtgvDetailBillSale.Columns[1].Width = 80;
                        dtgvDetailBillSale.Columns[2].Width = 75;
                        dtgvDetailBillSale.Columns[3].Width = 85;
                        dtgvDetailBillSale.Columns[4].Width = 100;
                        dtgvDetailBillSale.Columns[5].Width = 120;
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }