コード例 #1
0
        public static PhieuXuatDTO SelectPhieuXuatById(string MaPhieuXuat)
        {
            List <SqlParameter> sqlParamas = new List <SqlParameter>();

            sqlParamas.Add(new SqlParameter("@MaPhieuXuat", MaPhieuXuat));
            DataTable dataTable = DataProvider.ExecuteReader("usp_SelectPhieuXuatById", sqlParamas);

            PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO();

            if (dataTable.Rows.Count > 0)
            {
                DataRow dataRow = dataTable.Rows[0];
                phieuXuatDTO.MaPhieuXuat     = dataRow["MaPhieuXuat"].ToString();
                phieuXuatDTO.NgayBan         = DateTime.Parse(dataRow["NgayBan"].ToString());
                phieuXuatDTO.MaThanhVien     = dataRow["MaThanhVien"].ToString();
                phieuXuatDTO.MaNhanVien      = dataRow["MaNhanVien"].ToString();
                phieuXuatDTO.TenKhachHang    = dataRow["TenKhachHang"].ToString();
                phieuXuatDTO.DiaChi          = dataRow["DiaChi"].ToString();
                phieuXuatDTO.MaLoaiPhieuXuat = dataRow["MaLoaiPhieuXuat"].ToString();
            }
            else
            {
                phieuXuatDTO = null;
            }
            return(phieuXuatDTO);
        }
コード例 #2
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (KiemTraDong_KhongTonTai() == false)
            {
                FormXuatHang fQLXuatHang = new FormXuatHang();
                fQLXuatHang.Status      = 2;
                fQLXuatHang.MaPhieuXuat = dataGridView_TraCuuXuatHang.CurrentRow.Cells[clMaPhieuXuat.Index].Value.ToString();
                fQLXuatHang.ShowDialog();

                PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(fQLXuatHang.MaPhieuXuat);
                int          soLuong      = 0;
                float        thanhTien    = 0;
                List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();
                listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(phieuXuatDTO.MaPhieuXuat);
                if (listChiTietPhieuXuatDTO != null)
                {
                    for (int j = 0; j < listChiTietPhieuXuatDTO.Count; j++)
                    {
                        soLuong   += listChiTietPhieuXuatDTO[j].SoLuong;
                        thanhTien += listChiTietPhieuXuatDTO[j].ThanhTien;
                    }
                }

                dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSoLuong.Index].Value = soLuong;
                dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSoTien.Index].Value  = string.Format("{0:#,0.##}", thanhTien);
            }
            else
            {
                MessageBox.Show("Không có dữ liệu để cập nhật", "Quản lý xuất hàng");
            }
        }
コード例 #3
0
        public static List <PhieuXuatDTO> SelectPhieuXuatAll()
        {
            DataTable           dataTable        = DataProvider.ExecuteReader("usp_SelectPhieuXuatAll");
            List <PhieuXuatDTO> listPhieuXuatDTO = new List <PhieuXuatDTO>();

            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO();
                    phieuXuatDTO.MaPhieuXuat     = dataRow["MaPhieuXuat"].ToString();
                    phieuXuatDTO.NgayBan         = DateTime.Parse(dataRow["NgayBan"].ToString());
                    phieuXuatDTO.MaThanhVien     = dataRow["MaThanhVien"].ToString();
                    phieuXuatDTO.MaNhanVien      = dataRow["MaNhanVien"].ToString();
                    phieuXuatDTO.TenKhachHang    = dataRow["TenKhachHang"].ToString();
                    phieuXuatDTO.DiaChi          = dataRow["DiaChi"].ToString();
                    phieuXuatDTO.MaLoaiPhieuXuat = dataRow["MaLoaiPhieuXuat"].ToString();
                    listPhieuXuatDTO.Add(phieuXuatDTO);
                }
            }
            else
            {
                listPhieuXuatDTO = null;
            }

            return(listPhieuXuatDTO);
        }
コード例 #4
0
        //Load khi status =1
        //Chuyen sang trang thai cho XemChiTiet phieuxuat
        private void Load_Update()
        {
            //Load_Default();

            //Load Thong tin PhieuXuat
            PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(MaPhieuXuat);

            txtMaPhieuXuat.Text = phieuXuatDTO.MaPhieuXuat;
            if (phieuXuatDTO.MaThanhVien != "")
            {
                txtMaThanhVien.Text     = phieuXuatDTO.MaThanhVien;
                txtMaThanhVien.ReadOnly = true;
            }
            else
            {
                txtTenKhachHang.Text = phieuXuatDTO.TenKhachHang;
                txtDiaChi.Text       = phieuXuatDTO.DiaChi;
            }

            txtNgayBan.Text         = phieuXuatDTO.NgayBan.ToString("dd/MM/yyyy");
            txtMaNhanVien.Text      = phieuXuatDTO.MaNhanVien;
            txtNhanVienBanHang.Text = NhanVienBUS.SelectNhanVienById(phieuXuatDTO.MaNhanVien).TenNhanVien;

            //Kiểm tra Khách hàng có là Thành viên không
            if (txtMaThanhVien.Text == "")
            {
                IsThanhVien = false;
            }



            //Thay đổi button Tạo thành Cập nhật
            btnTao.Text    = "Cập nhật";
            btnTao.Enabled = true;

            btnTaoMoi.Visible       = false;
            btnLamLai.Visible       = false;
            btnTimPhieuXuat.Visible = false;

            //Truy vấn lấy ChiTietPhieuXuat theo MaDonHang
            List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();

            listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(MaPhieuXuat);



            //Lấy tên sản phẩm
            SanPhamDTO sanphamDTO = new SanPhamDTO();

            for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++)
            {
                sanphamDTO = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham);
                dataGridView_XuatHang.Rows.Add(i + 1, listChiTietPhieuXuatDTO[i].MaSanPham, sanphamDTO.TenSanPham, listChiTietPhieuXuatDTO[i].CV, listChiTietPhieuXuatDTO[i].DonGia, (sanphamDTO.SoLuongTon + listChiTietPhieuXuatDTO[i].SoLuong), listChiTietPhieuXuatDTO[i].SoLuong, string.Format("{0:#,0.##}", listChiTietPhieuXuatDTO[i].ThanhTien));
                dataGridView_XuatHang.Rows[i].ReadOnly = true;
            }
            dataGridView_XuatHang.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }
コード例 #5
0
        public static bool UpdatePhieuXuatById(PhieuXuatDTO phieuXuatDTO)
        {
            List <SqlParameter> sqlParamas = new List <SqlParameter>();

            sqlParamas.Add(new SqlParameter("@MaPhieuXuat", phieuXuatDTO.MaPhieuXuat));
            sqlParamas.Add(new SqlParameter("@NgayBan", phieuXuatDTO.NgayBan));
            sqlParamas.Add(new SqlParameter("@MaThanhVien", phieuXuatDTO.MaThanhVien));
            sqlParamas.Add(new SqlParameter("@MaNhanVien", phieuXuatDTO.MaNhanVien));
            sqlParamas.Add(new SqlParameter("@TenKhachHang", phieuXuatDTO.TenKhachHang));
            sqlParamas.Add(new SqlParameter("@DiaChi", phieuXuatDTO.DiaChi));
            sqlParamas.Add(new SqlParameter("@MaLoaiPhieuXuat", phieuXuatDTO.MaLoaiPhieuXuat));
            return(DataProvider.ExecuteNoneQuery("usp_UpdatePhieuXuatById", sqlParamas));
        }
コード例 #6
0
        //Sửa phiếu xuất
        public int UpdatePX(PhieuXuatDTO phieuXuatDTO)
        {
            int    result = 0;
            string Query  = "Update PhieuXuat set NgayXuat ='" + phieuXuatDTO.NgayXuat.ToShortDateString() + "'";

            try
            {
                result = DBcon.ExecuteSPNoneQuery(Query);
            }
            catch (SqlException ex)
            {
            }
            return(result);
        }
コード例 #7
0
        //THÊM PHIẾU XUẤT
        public int InsertPX(PhieuXuatDTO phieuXuatDTO)
        {
            int    result = 0;
            string Query  = "Insert into PhieuXuat(MaPX, NgayXuat) values('" + phieuXuatDTO.MaPX + "', N'" + phieuXuatDTO.NgayXuat.ToShortDateString() + "')";

            try
            {
                result = DBcon.ExecuteSPNoneQuery(Query);
            }
            catch (SqlException ex)
            {
            }
            return(result);
        }
コード例 #8
0
        public IHttpActionResult PostPhieuXuat(PhieuXuat phieuXuat)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            unitOfWork.PhieuXuatRepository.Insert(phieuXuat);
            unitOfWork.Save();
            var phieuXuatDto = new PhieuXuatDTO
            {
                NhanVienId = phieuXuat.NhanVienId,
                TongTien   = phieuXuat.TongTien
            };

            return(CreatedAtRoute("DefaultApi", new { id = phieuXuat.Id }, phieuXuatDto));
        }
コード例 #9
0
        private void KhoiTao()
        {
            List <PhieuXuatDTO>        listPhieuXuatDTO        = PhieuXuatBUS.SelectPhieuXuatAll();
            List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();
            int   soLuong   = 0;
            float thanhTien = 0;

            if (listPhieuXuatDTO != null)
            {
                dataGridView_TraCuuXuatHang.Rows.Clear();
                PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO();
                for (int i = 0; i < listPhieuXuatDTO.Count; i++)
                {
                    phieuXuatDTO            = listPhieuXuatDTO[i];
                    listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(phieuXuatDTO.MaPhieuXuat);
                    if (listChiTietPhieuXuatDTO != null)
                    {
                        soLuong   = 0;
                        thanhTien = 0;
                        for (int j = 0; j < listChiTietPhieuXuatDTO.Count; j++)
                        {
                            soLuong   += listChiTietPhieuXuatDTO[j].SoLuong;
                            thanhTien += listChiTietPhieuXuatDTO[j].ThanhTien;
                        }
                    }

                    dataGridView_TraCuuXuatHang.Rows.Add(
                        (i + 1).ToString(),
                        phieuXuatDTO.MaPhieuXuat,
                        phieuXuatDTO.NgayBan.ToString("dd/MM/yyyy"),
                        phieuXuatDTO.TenKhachHang,
                        NhanVienBUS.SelectNhanVienById(phieuXuatDTO.MaNhanVien).TenNhanVien,
                        soLuong.ToString(),
                        string.Format("{0:#,0.##}", thanhTien));
                }
                btnLamLai.Enabled = true;
            }
            else
            {
                buttonDisabled();
                btnLamLai.Enabled = false;
            }
        }
コード例 #10
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Xóa phiếu xuất", "Phiếu xuất", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            //Lấy vị trí cần xóa
            if (result == DialogResult.Yes)
            {
                int    Index = dataGridView_TraCuuXuatHang.CurrentRow.Index;
                int    stt   = int.Parse(dataGridView_TraCuuXuatHang.CurrentRow.Cells[clSTT.Index].Value.ToString());
                string id    = dataGridView_TraCuuXuatHang.CurrentRow.Cells["clMaPhieuXuat"].Value.ToString();
                List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = ChiTietPhieuXuatBUS.SelectChiTietPhieuXuatByMaPhieuXuat(id);
                PhieuXuatDTO phieuXuatDTO = PhieuXuatBUS.SelectPhieuXuatById(id);
                if (PhieuXuatBUS.DeletePhieuXuatById(id))
                {
                    dataGridView_TraCuuXuatHang.Rows.RemoveAt(Index);
                    if (dataGridView_TraCuuXuatHang.RowCount > 0)
                    {
                        bool f = false;
                        for (int i = 0; i < Index; i++)
                        {
                            if (dataGridView_TraCuuXuatHang.Rows[i].Visible == true)
                            {
                                f = true;
                                break;
                            }
                        }

                        for (int i = Index; i < dataGridView_TraCuuXuatHang.RowCount; i++)
                        {
                            if (dataGridView_TraCuuXuatHang.Rows[i].Visible == true)
                            {
                                dataGridView_TraCuuXuatHang.Rows[i].Cells["clSTT"].Value = stt.ToString();
                                stt++;
                                f = true;
                            }
                        }

                        if (f == false)
                        {
                            buttonDisabled();
                        }
                        else
                        {
                            buttonEnabled();
                        }
                    }
                    else
                    {
                        buttonDisabled();
                    }


                    int        cv         = 0;
                    SanPhamDTO sanPhamDTO = new SanPhamDTO();
                    for (int i = 0; i < listChiTietPhieuXuatDTO.Count; i++)
                    {
                        //Tính lại SoLuongTon của sản phẩm
                        sanPhamDTO            = SanPhamBUS.SelectSanPhamById(listChiTietPhieuXuatDTO[i].MaSanPham);
                        sanPhamDTO.SoLuongTon = sanPhamDTO.SoLuongTon + listChiTietPhieuXuatDTO[i].SoLuong;
                        SanPhamBUS.UpdateSanPhamById(sanPhamDTO);

                        //cv
                        cv += listChiTietPhieuXuatDTO[i].CV * listChiTietPhieuXuatDTO[i].SoLuong;
                    }

                    //Tinh lai TongCV
                    if (phieuXuatDTO.MaThanhVien != "")
                    {
                        ThanhVienDTO thanhVien = ThanhVienBUS.SelectThanhVienById(phieuXuatDTO.MaThanhVien);
                        thanhVien.CV = thanhVien.CV - cv;
                        ThanhVienBUS.UpdateThanhVienById(thanhVien);
                    }

                    MessageBox.Show("Xóa thành công");
                }
            }
        }
コード例 #11
0
        private bool Process_Button()
        {
            //Lấy các trường để insert vào bảng PhieuXuat
            PhieuXuatDTO phieuXuatDTO = new PhieuXuatDTO();

            phieuXuatDTO.MaPhieuXuat = txtMaPhieuXuat.Text;
            phieuXuatDTO.NgayBan     = DateTimeSystem;
            phieuXuatDTO.MaNhanVien  = ThongTin.NhanVienDTO.MaNhanVien;

            if (txtMaThanhVien.Text == "")
            {
                //MaThanhVien Thamchieu bang ThanhVien => notnull=>sua storeproc
                phieuXuatDTO.MaThanhVien = null;

                if (txtTenKhachHang.Text == "")
                {
                    MessageBox.Show("Tên khách hàng không hợp lệ");
                    return(false);
                }
                else
                {
                    phieuXuatDTO.TenKhachHang = txtTenKhachHang.Text;
                }

                if (txtDiaChi.Text == "")
                {
                    MessageBox.Show("Địa chỉ không hợp lệ");
                    return(false);
                }
                else
                {
                    phieuXuatDTO.DiaChi = txtDiaChi.Text;
                }
                phieuXuatDTO.MaLoaiPhieuXuat = "LPX02";
            }
            else
            {
                phieuXuatDTO.MaThanhVien     = txtMaThanhVien.Text;
                phieuXuatDTO.TenKhachHang    = txtTenKhachHang.Text;
                phieuXuatDTO.DiaChi          = txtDiaChi.Text;
                phieuXuatDTO.MaLoaiPhieuXuat = "LPX01";
            }

            //Lấy các trường để insert vào bảng ChiTietPhieuXuat
            List <ChiTietPhieuXuatDTO> listChiTietPhieuXuatDTO = new List <ChiTietPhieuXuatDTO>();
            SanPhamDTO sanPhamDTO = new SanPhamDTO();

            for (int i = 0; i < dataGridView_XuatHang.Rows.Count; i++)
            {
                ChiTietPhieuXuatDTO chiTietPhieuXuatDTO = new ChiTietPhieuXuatDTO();
                DataGridViewRow     Row = dataGridView_XuatHang.Rows[i];
                int check;
                int.TryParse(Row.Cells["clSoLuong"].Value.ToString(), out check);
                if (check > 0)
                {
                    chiTietPhieuXuatDTO.MaChiTietPhieuXuat = txtMaPhieuXuat.Text;
                    if (i > 100)
                    {
                        chiTietPhieuXuatDTO.MaChiTietPhieuXuat += (i + 1).ToString();
                    }
                    else if (i > 100)
                    {
                        chiTietPhieuXuatDTO.MaChiTietPhieuXuat += "0" + (i + 1).ToString();
                    }
                    else
                    {
                        chiTietPhieuXuatDTO.MaChiTietPhieuXuat += "00" + (i + 1).ToString();
                    }

                    chiTietPhieuXuatDTO.MaPhieuXuat = txtMaPhieuXuat.Text;
                    chiTietPhieuXuatDTO.MaSanPham   = Row.Cells["clMaSanPham"].Value.ToString();
                    chiTietPhieuXuatDTO.CV          = int.Parse(Row.Cells["clCV"].Value.ToString());
                    chiTietPhieuXuatDTO.SoLuong     = int.Parse(Row.Cells["clSoLuong"].Value.ToString());
                    chiTietPhieuXuatDTO.DonGia      = float.Parse(Row.Cells["clDonGia"].Value.ToString());
                    chiTietPhieuXuatDTO.ThanhTien   = float.Parse(Row.Cells["clThanhTien"].Value.ToString());
                    listChiTietPhieuXuatDTO.Add(chiTietPhieuXuatDTO);

                    //Tinh SoLuongTon của sản phẩm
                    int SoLuongTon = int.Parse(Row.Cells["clSoLuongTon"].Value.ToString()) - int.Parse(Row.Cells["clSoLuong"].Value.ToString());
                    sanPhamDTO            = SanPhamBUS.SelectSanPhamById(chiTietPhieuXuatDTO.MaSanPham);
                    sanPhamDTO.SoLuongTon = SoLuongTon;
                    SanPhamBUS.UpdateSanPhamById(sanPhamDTO);

                    //Tinh TongCV
                    TongCV += int.Parse(Row.Cells["clCV"].Value.ToString()) * int.Parse(Row.Cells["clSoLuong"].Value.ToString());
                }
            }

            //insert dữ liệu
            if (PhieuXuatBUS.InsertPhieuXuat(phieuXuatDTO))
            {
                foreach (ChiTietPhieuXuatDTO chiTietPhieuXuatDTO in listChiTietPhieuXuatDTO)
                {
                    ChiTietPhieuXuatBUS.InsertChiTietPhieuXuat(chiTietPhieuXuatDTO);
                }
                if (IsThanhVien == true)
                {
                    thanhVienDTO.CV += TongCV;
                    ThanhVienBUS.UpdateThanhVienById(thanhVienDTO);
                }

                MessageBox.Show("Nhập dữ liệu thành công");
                return(true);
            }
            else
            {
                MessageBox.Show("Nhập dữ liệu thất bại");
            }
            return(false);
        }
コード例 #12
0
        public bool sua(PhieuXuatDTO lb)
        {
            bool re = bdal.sua(lb);

            return(re);
        }
コード例 #13
0
 public int UpdatePX(PhieuXuatDTO phieuXuatDTO)
 {
     return(pxDAL.UpdatePX(phieuXuatDTO));
 }
コード例 #14
0
 public int InsertPX(PhieuXuatDTO phieuXuatDTO)
 {
     return(pxDAL.InsertPX(phieuXuatDTO));
 }
コード例 #15
0
 public static bool InsertPhieuXuat(PhieuXuatDTO phieuXuatDTO)
 {
     return(PhieuXuatDAO.InsertPhieuXuat(phieuXuatDTO));
 }
コード例 #16
0
 public static bool UpdatePhieuXuatById(PhieuXuatDTO phieuXuatDTO)
 {
     return(PhieuXuatDAO.UpdatePhieuXuatById(phieuXuatDTO));
 }
コード例 #17
0
        public bool them(PhieuXuatDTO lb)
        {
            bool re = bdal.them(lb);

            return(re);
        }