private void ExecuteSearchText() { InitUnitOfWork(); _categories.AddRange(_categoryRepository.Query().OrderBy(x => x.Name)); _produces.Clear(); _produceRepository .Query() .Where(x => x.BarCode.Contains(TxtSearchBox.Text) || x.ProduceNo.Contains(TxtSearchBox.Text) || x.Name.Contains(TxtSearchBox.Text)) .ToList() .ForEach(x => _produces.Add(x)); InitBlankRow(); if (!ResourcesHelper.CurrentUserRolePermission.ProduceFactoryPriceEdit) { TxtTotalInfo.Text = string.Format("共{0}种商品, 合计{1}件", _produces.Count.ToString("F2"), _produces.Sum(x => x.Quantity).ToString("F2")); } else { TxtTotalInfo.Text = string.Format("共{0}种商品, 合计{1}件, 零售价合计金额: {2}, 折扣零售价合计金额: {3}, 最低折扣零售价合计金额: {4}, 出厂价合计金额: {5}", _produces.Count.ToString("F2"), _produces.Sum(x => x.Quantity).ToString("F2"), _produces.Sum(x => x.RetailPrice * x.Quantity).ToString("F2"), _produces.Sum(x => x.RetailPrice * x.DiscountRate * x.Quantity).ToString("F2"), _produces.Sum(x => x.RetailPrice * (x.LowestDiscountRate ?? x.DiscountRate) * x.Quantity).ToString("F2"), _produces.Sum(x => x.Quantity * x.FactoryPrice).ToString("F2")); } }
private void TxtBarCode_OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { var barCode = (TextBox)sender; if (barCode.IsFocused) { var produce = _produceRepository.Query().FirstOrDefault(x => x.BarCode.StartsWith(barCode.Text)); if (produce != null) { var poItemDomainModel = GridPOItems.SelectedItem as POItemDomainModel; //if (poItemDomainModel == null) //{ // poItemDomainModel = new POItemDomainModel // { // POItem = new POItem // { // Produce = produce, // ProduceId = produce.ProduceId, // } // }; // _poItemDomainModels.Add(poItemDomainModel); //} //else //{ // poItemDomainModel.POItem.Produce = produce; // poItemDomainModel.POItem.ProduceId = produce.ProduceId; //} poItemDomainModel = new POItemDomainModel { POItem = new POItem { Produce = produce, ProduceId = produce.ProduceId, } }; _poItemDomainModels.Insert(_poItemDomainModels.Count(x => x.POItem.ProduceId > 0), poItemDomainModel); barCode.Text = string.Empty; } } } }
private void TxtBarCode_OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { var barCode = (TextBox)sender; if (barCode.IsFocused) { var produce = _produceRepository.Query().FirstOrDefault(x => x.BarCode.StartsWith(barCode.Text)); if (produce != null) { var soProduceDomainModel = GridSOProduces.SelectedItem as SOProduceDomainModel; if (soProduceDomainModel == null) { soProduceDomainModel = new SOProduceDomainModel { SOProduce = new SOProduce { Produce = produce, ProduceId = produce.ProduceId, Quantity = 1, CostPerUnit = produce.RetailPrice * produce.DiscountRate, SaleOrder = _saleOrder, SaleOrderId = _saleOrder.SaleOrderId, RetailPrice = produce.RetailPrice, DiscountRate = produce.DiscountRate }, CostPerUnit = produce.RetailPrice * produce.DiscountRate, SOProduceTotal = produce.RetailPrice * produce.DiscountRate * 1, }; _soProduceDomainModels.Add(soProduceDomainModel); } barCode.Text = string.Empty; } } } }
private void ImportProduces() { List <DataModel.Model.Produce> produces = new List <DataModel.Model.Produce>(); IEnumerable <Category> categories = _categoryRepository.Query().ToList(); IEnumerable <IEnumerable <KeyValuePair <string, string> > > csvContengs = CsvHepler.GetCsvData(tbPath.Text); IEnumerable <KeyValuePair <byte, string> > procedureUnits = CommonHelper.Enumerate <DataType.ProduceUnit>(); csvContengs.ForEach(x => { DataModel.Model.Produce produce = new DataModel.Model.Produce(); foreach (var y in x) { if (!string.IsNullOrEmpty(y.Value)) { DataType.ProduceField produceField = (DataType.ProduceField)Enum.Parse(typeof(DataType.ProduceField), y.Key); switch (produceField) { case DataType.ProduceField.Category: Category category = categories .Single(c => y.Value.Equals(c.Name, StringComparison.CurrentCultureIgnoreCase)); produce.CategoryId = category != null ? category.CategoryId : categories.OrderBy(c => c.CategoryId).First().CategoryId; continue; case DataType.ProduceField.ProduceNo: produce.ProduceNo = y.Value; continue; case DataType.ProduceField.Name: produce.Name = y.Value; continue; case DataType.ProduceField.HowUsed: KeyValuePair <byte, string>?howUsed = procedureUnits .SingleOrDefault( u => y.Value.Equals(u.Value, StringComparison.CurrentCultureIgnoreCase)); produce.HowUsed = (sbyte?)howUsed.Value.Key; continue; case DataType.ProduceField.FactoryPrice: produce.FactoryPrice = float.Parse(y.Value); continue; case DataType.ProduceField.RetailPrice: produce.RetailPrice = float.Parse(y.Value); continue; default: continue; } } } produces.Add(produce); }); var existedProduceNos = _produceRepository.Query().Select(x => x.ProduceNo); produces.RemoveAll(x => existedProduceNos.Contains(x.ProduceNo)); _produceRepository.BatchInsertProduces(produces); _unitOfWork.Commit(); System.Windows.MessageBox.Show("商品导入成功!", Properties.Resources.SystemName, MessageBoxButton.OK, MessageBoxImage.Information); Close(); }