コード例 #1
0
        private void CalcDiscount(ref ImportProductModel model, List <Product> products)
        {
            Product product;
            var     discounts     = model.ToDiscount();
            var     totalQuantity = model.Quantity;
            var     totalDiscount = 0;

            foreach (var discount in discounts)
            {
                if (string.IsNullOrEmpty(discount.Barcode))
                {
                    continue;
                }
                product = products.FirstOrDefault(x => x.Barcode.Equals(discount.Barcode));
                if (product != null)
                {
                    if (model.Barcode.Equals(discount.Barcode))
                    {
                        totalQuantity += 1;
                    }
                    else
                    {
                        totalDiscount += product.PriceBuy.Value * discount.Quantity;
                    }
                }
            }
            if (model.Discount > 0)
            {
                model.Total = model.Total - Convert.ToInt32((model.Discount / 100) * model.Total);
            }
            model.PriceBuy = ((model.Total - totalDiscount) / totalQuantity).Round100();
        }
コード例 #2
0
ファイル: ImportProductView.cs プロジェクト: rizonemeer/PoS
        public void InitView(ImportProductModel model)
        {
            try
            {
                _model = model;
                _dtpToDate.DataBindings.Add("Value", _model, "SearchDateTo", true, DataSourceUpdateMode.OnPropertyChanged);
                _txtDescription.DataBindings.Add("Text", _model, "Description", true, DataSourceUpdateMode.OnPropertyChanged);
                _dtpFromDate.DataBindings.Add("Value", _model, "SearchDateFrom", true, DataSourceUpdateMode.OnPropertyChanged);
                _dtpImportDate.DataBindings.Add("Value", _model, "Date", true, DataSourceUpdateMode.OnPropertyChanged);
                _dgvImportList.DataBindings.Add("DataSource", _model, "Imports", true, DataSourceUpdateMode.OnPropertyChanged);

                _txtDescription.DataBindings.Add("Enabled", _model, "IsEditingStatus");
                _dtpImportDate.DataBindings.Add("Enabled", _model, "IsEditingStatus");
                ucSaleProduct.DataBindings.Add("Enabled", _model, "IsEditingStatus");

                _dtpToDate.DataBindings.Add("Enabled", _model, "IsNotEditingStatus");
                _dgvImportList.DataBindings.Add("Enabled", _model, "IsNotEditingStatus");
                _dtpFromDate.DataBindings.Add("Enabled", _model, "IsNotEditingStatus");
                _btnSearch.DataBindings.Add("Enabled", _model, "IsNotEditingStatus");
                btnExcuteImport.DataBindings.Add("Enabled", _model, "IsNotEditingStatus");
            }
            catch (Exception exc)
            {
                AppLogger.logError(this.ToString(), exc);
            }
        }
コード例 #3
0
        public List <ImportProductModel> Read(string path)
        {
            var results   = new List <ImportProductModel>();
            var inputFile = new ExcelPackage(new FileInfo(path));
            var sheet     = inputFile.Workbook.Worksheets[1];
            var maxRow    = sheet.Dimension.End.Row;
            var units     = _db.Units.Select(x => new KeyValueInt()
            {
                Key = x.Id, Value = x.Name
            }).ToList();
            var suppliers = _db.Suppliers.Select(x => new KeyValueInt()
            {
                Key = x.Id, Value = x.Name
            }).ToList();
            var products = _db.Products.ToList();

            for (var row = 2; row <= maxRow; row++)
            {
                if (sheet.Row(row) == null)
                {
                    continue;
                }
                var elm = new ImportProductModel()
                {
                    Barcode     = sheet.Cells["A" + row].Value.ToString(),
                    ProductName = sheet.Cells["B" + row].Value.ToString(),
                    Total       = sheet.Cells["C" + row].Value.ToString().IsNumberic() ? int.Parse(sheet.Cells["C" + row].Value.ToString()) : 0,
                    Quantity    = sheet.Cells["D" + row].Value.ToString().IsNumberic() ? int.Parse(sheet.Cells["D" + row].Value.ToString()) : 0,
                    PriceBuy    = sheet.Cells["E" + row].Value.ToString().IsNumberic() ? int.Parse(sheet.Cells["E" + row].Value.ToString()) : 0,
                    Unit        = units.Where(x => x.Value.Equals(sheet.Cells["F" + row].Value.ToString())).Select(x => x.Key).First(),
                    Price       = (sheet.Cells["G" + row].Value != null && sheet.Cells["G" + row].Value.ToString().IsNumberic()) ? int.Parse(sheet.Cells["G" + row].Value.ToString()) : 0,
                    Ex          = DateTime.Parse(sheet.Cells["H" + row].Value.ToString()),
                    Supplier    = suppliers.Where(x => x.Value.Equals(sheet.Cells["I" + row].Value.ToString())).Select(x => x.Key).First(),

                    Discount          = (sheet.Cells["K" + row].Value != null && sheet.Cells["K" + row].Value.ToString().IsNumberic()) ? double.Parse(sheet.Cells["K" + row].Value.ToString()) : 0,
                    DiscountBarcode1  = sheet.Cells["L" + row].Value != null ? sheet.Cells["L" + row].Value.ToString() : string.Empty,
                    DiscountQuantity1 = (sheet.Cells["M" + row].Value != null && sheet.Cells["M" + row].Value.ToString().IsNumberic()) ? int.Parse(sheet.Cells["M" + row].Value.ToString()) : 0,
                    DiscountBarcode2  = sheet.Cells["N" + row].Value != null ? sheet.Cells["N" + row].Value.ToString() : string.Empty,
                    DiscountQuantity2 = (sheet.Cells["O" + row].Value != null && sheet.Cells["O" + row].Value.ToString().IsNumberic()) ? int.Parse(sheet.Cells["O" + row].Value.ToString()) : 0,
                    DiscountBarcode3  = sheet.Cells["P" + row].Value != null ? sheet.Cells["P" + row].Value.ToString() : string.Empty,
                    DiscountQuantity3 = (sheet.Cells["Q" + row].Value != null && sheet.Cells["Q" + row].Value.ToString().IsNumberic()) ? int.Parse(sheet.Cells["Q" + row].Value.ToString()) : 0,
                    DiscountBarcode4  = sheet.Cells["R" + row].Value != null ? sheet.Cells["R" + row].Value.ToString() : string.Empty,
                    DiscountQuantity4 = (sheet.Cells["S" + row].Value != null && sheet.Cells["S" + row].Value.ToString().IsNumberic()) ? int.Parse(sheet.Cells["S" + row].Value.ToString()) : 0,
                };
                FillNameDiscount(ref elm, products);
                CalcDiscount(ref elm, products);
                elm.Cal();
                results.Add(elm);
            }
            var validMess = Valid(results, products);

            if (validMess.Length > 0)
            {
                MessageUtil.Error(validMess);
            }
            return(results);
        }
コード例 #4
0
        public ImportProductPresenter(IImportProductView view)
        {
            _business        = new ImportProductBusiness(Singleton <PosEngine> .Instance.Resolve <IRepository <Import> >());
            _businessProduct = new ProductBusiness(Singleton <PosEngine> .Instance.Resolve <IRepository <Product> >());

            _view = view;

            Import import        = new Import();
            var    units         = new UnitBusiness(Singleton <PosEngine> .Instance.Resolve <IRepository <Unit> >()).GetAll().ToList();
            var    manufacturers = new ManufacturerBusiness(Singleton <PosEngine> .Instance.Resolve <IRepository <Manufacturer> >()).GetAll().ToList();

            _model = new ImportProductModel(import);
            _view.InitView(_model);
        }
コード例 #5
0
        public async Task <IActionResult> Import(ImportProductModel importModel)
        {
            if (ModelState.IsValid)
            {
                var command = _mapper.Map <AddProductCommand>(importModel);
                var result  = await _mediator.Send(command);

                if (result)
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }

            return(View(importModel));
        }
コード例 #6
0
        private void FillNameDiscount(ref ImportProductModel model, List <Product> products)
        {
            Product product   = null;
            var     tempModel = model;

            if (!string.IsNullOrEmpty(model.DiscountBarcode1))
            {
                product = products.FirstOrDefault(x => x.Barcode.Equals(tempModel.DiscountBarcode1));
            }
            if (product != null)
            {
                model.DiscountName1 = product.Name;
            }
            product = null;
            if (!string.IsNullOrEmpty(model.DiscountBarcode2))
            {
                product = products.FirstOrDefault(x => x.Barcode.Equals(tempModel.DiscountBarcode2));
            }
            if (product != null)
            {
                model.DiscountName2 = product.Name;
            }
            product = null;
            if (!string.IsNullOrEmpty(model.DiscountBarcode3))
            {
                product = products.FirstOrDefault(x => x.Barcode.Equals(tempModel.DiscountBarcode3));
            }
            if (product != null)
            {
                model.DiscountName3 = product.Name;
            }
            product = null;
            if (!string.IsNullOrEmpty(model.DiscountBarcode4))
            {
                product = products.FirstOrDefault(x => x.Barcode.Equals(tempModel.DiscountBarcode4));
            }
            if (product != null)
            {
                model.DiscountName4 = product.Name;
            }
        }