예제 #1
0
 public void BatchInsertProduces(IEnumerable <Produce> produces)
 {
     produces.ToList().ForEach(x =>
     {
         x.CreatedBy      = "admin";
         x.CreatedOn      = DateTime.Now;
         x.LastModifiedBy = "admin";
         x.LastModifiedOn = DateTime.Now;
         x.RowVersion     = DateTime.Now;
         x.BarCode        = !string.IsNullOrEmpty(x.BarCode) ? x.BarCode : x.ProduceNo;
         x.Enable         = true;
     });
     _produceRepository.BatchInsertProduces(produces);
     _unitOfWork.Commit();
 }
예제 #2
0
        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();
        }