Exemplo n.º 1
0
        //Nút lưu phiếu nhập
        private void btnLuu_Click(object sender, RoutedEventArgs e)
        {
            bool t = false;

            //Kiểm tra thông tin nhập vào
            for (int i = 0; i < _ListSpNhap.Count; i++)
            {
                if (_ListSpNhap[i].SoLuong_SP > 0)
                {
                    t = true;
                }
            }

            if (!t)
            {
                MessageBox.Show("Chưa có sản phẩm nào.");
                return;
            }

            //Lấy thông tin
            _phieuNhap.NgayNhap_PN = dtNgayNhap.SelectedDate.Value;
            rtxtGhiChu.SelectAll();
            _phieuNhap.GhiChu_PN = rtxtGhiChu.Selection.Text;

            //Thực hiện lưu phiếu nhập
            NhapMuaBusiness.NhapHang(_phieuNhap, _ListSpNhap);

            //Tạo đơn nhập mới
            TaoPhieuNhap();
            dgSanPhamNhapMua.ItemsSource = _ListSpNhap;
            dgSanPhamNhapMua.Items.Refresh();
        }
        void Loaded_dowork()
        {
            //Load datatable
            _dtSP = NhapMuaBusiness.DsSanPham().Tables[0];

            //Load cbo nhóm sản phẩm
            _ListNSP = NhapMuaBusiness.ListNSP();
        }
        //Loaded
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lbSoPhieu.Content   = _phieuNhap.SoPhieu_PN;
            lbNgayNhap.Content  = _phieuNhap.NgayNhap_PN.ToString("dd-MM-yyyy");
            lbNguoiNhap.Content = _phieuNhap.NguoiNhap_PN.HoTen_NV;
            lbNguoiNhap.ToolTip = _phieuNhap.NguoiNhap_PN.MaNV_NV;

            dgDsHangNhap.ItemsSource = NhapMuaBusiness.LayHangNhap(_phieuNhap.SoPhieu_PN).DefaultView;
        }
Exemplo n.º 4
0
        //Nhập excel Dowork
        private void NhapExcel_dowork(string _excel)
        {
            //Lấy dữ liệu trong Excel
            string    _strSql  = "SELECT [Mã sản phẩm] as MaSP_SP, [Số lượng nhập] as SoLuong_SP FROM [Sheet1$]";
            DataTable _dtExcel = UntilitiesBusiness.ExcelToDatatable(_excel, _strSql);

            if (_dtExcel.Rows.Count == 0)
            {
                MessageBox.Show("Tập tin Excel đang được mở hoặc bị sai cấu trúc.Vui lòng kiểm tra lại.");
                return;
            }

            //Lấy danh sách sản phẩm để kiểm tra
            DataTable _dtSP = NhapMuaBusiness.DsSanPham().Tables[0];

            //Duyệt từng bản ghi
            SanPhamPublic _sp;

            for (int i = 0; i < _dtExcel.Rows.Count; i++)
            {
                string _MaSP_SP    = _dtExcel.Rows[i]["MaSP_SP"].ToString();
                string _SoLuong_SP = _dtExcel.Rows[i]["SoLuong_SP"].ToString();

                //Kiểm tra có rỗng ko?
                if (String.IsNullOrEmpty(_MaSP_SP) || String.IsNullOrEmpty(_SoLuong_SP))
                {
                    continue;
                }

                //Kiểm tra sp này có trong list sp chọn chưa?
                if (KiemTraTonTai(_MaSP_SP))
                {
                    continue;
                }

                //Kiểm tra số lượng có âm không?
                if (Convert.ToInt32(_SoLuong_SP) < 0)
                {
                    continue;
                }

                //Kiểm tra xem sp này có tồn tại trong hệ thống ko?
                DataView _dvSP = new DataView(_dtSP);
                _dvSP.Sort = "MaSP_SP";
                int _index = _dvSP.Find(_MaSP_SP);
                if (_index == -1)
                {
                    continue;
                }

                //Thêm vào list sản phẩm chọn
                _sp                  = new SanPhamPublic();
                _sp.MaSP_SP          = _MaSP_SP;
                _sp.TenSP_SP         = _dvSP[_index]["TenSP_SP"].ToString();
                _sp.GiaNhap_SP       = UntilitiesBusiness.ThemDauPhay(_dvSP[_index]["GiaNhap_SP"].ToString());
                _sp.GiaBanLe_SP      = UntilitiesBusiness.ThemDauPhay(_dvSP[_index]["GiaBanLe_SP"].ToString());
                _sp.GiaBanSi_SP      = UntilitiesBusiness.ThemDauPhay(_dvSP[_index]["GiaBanSi_SP"].ToString());
                _sp.NCC_SP.MaNCC_NCC = _dvSP[_index]["MaNCC_SP"].ToString();
                _sp.NSP_SP.MaNSP_NSP = _dvSP[_index]["MaNSP_SP"].ToString();
                _sp.DVT_SP.MaDVT_DVT = _dvSP[_index]["MaDVT_SP"].ToString();
                _sp.GhiChu_SP        = _dvSP[_index]["GhiChu_SP"].ToString();
                _sp.SoLuong_SP       = Convert.ToInt32(_SoLuong_SP);
                _sp.CKPhanTram_SP    = Convert.ToInt32(_dvSP[_index]["CKPhanTram_SP"].ToString());
                _sp.Anh_SP           = _dvSP[_index]["Anh_SP"].ToString();
                _sp.NgayTao_SP       = Convert.ToDateTime(_dvSP[_index]["NgayTao_SP"].ToString());

                _ListSpNhap.Add(_sp);

                //Tính tổng tiền
                int           _SoLuongNhap = _sp.SoLuong_SP;
                int           _GiaNhap     = Convert.ToInt32(UntilitiesBusiness.BoDauPhay(_sp.GiaNhap_SP));
                int           _ThanhTien   = _SoLuongNhap * _GiaNhap;
                SanPhamPublic _spFind      = _ListSpNhap.Find(item => item.MaSP_SP == _sp.MaSP_SP);
                if (_spFind != null)
                {
                    _ListSpNhap.Where(u => u.MaSP_SP == _sp.MaSP_SP).First().ThanhTien_SP = UntilitiesBusiness.ThemDauPhay(_ThanhTien.ToString());
                }
            }
        }