private void LoadEdit(string id) { FollowID = id; o = new Follow();//.Select(UsersID); o = Follow.Select(id); CustomerID = o.CustomerID; customerCbx.Text = CustomerDictionary.First(e => e.Value == o.CustomerID).Key; customerCbx_SelectedIndexChanged(null, null); UserID = o.UserID; userCbx.Text = UserDictionary.First(e => e.Value == o.UserID).Key; userCbx_SelectedIndexChanged(null, null); ItemID = o.ItemID; productCbx.Text = ProductDictionary.First(e => e.Value == o.ItemID).Key; productCbx_SelectedIndexChanged(null, null); typePhoneChk.Checked = (o.Type == "Phone") ? true : false; typeVisitChk.Checked = (o.Type == "Visit") ? true : false; diagnosisTxt.Text = o.Diagnosis; hospitalTxt.Text = o.Hospitalisation; sourceTxt.Text = o.Source; foreach (ItemReview i in Model.ItemReview.List(o.Id)) { ItemReview t = new ItemReview(id, i.FollowID, i.Title, i.Status, i.Details, DateTime.Now.ToString("dd-MM-yyyy H:m:s"), "false", Helper.CompanyID); GenericCollection.itemReviews.Add(t); } LoadItemReview(); foreach (ItemStatus i in Model.ItemStatus.List(o.Id)) { ItemStatus t = new ItemStatus(id, i.FollowID, i.Title, i.Status, i.Details, DateTime.Now.ToString("dd-MM-yyyy H:m:s"), "false", Helper.CompanyID); GenericCollection.itemStatus.Add(t); } LoadItemStatus(); foreach (PatientStatus i in Model.PatientStatus.List(o.Id)) { PatientStatus t = new PatientStatus(id, i.FollowID, i.Title, i.Status, i.Details, DateTime.Now.ToString("dd-MM-yyyy H:m:s"), "false", Helper.CompanyID); GenericCollection.patientStatus.Add(t); } LoadPatientStatus(); lengthTxt.Text = o.Length; needTxt.Text = o.Need; goalTxt.Text = o.Goal; resultTxt.Text = o.Results; visitChk.Checked = (o.FollowVisit == "Yes") ? true : false; phoneChk.Checked = (o.FollowPhone == "Yes") ? true : false; nextTxt.Text = o.Next; puTxt.Text = o.Pu; authoriserTxt.Text = o.Authoriser; employeeTxt.Text = o.Signature; reasonTxt.Text = o.Reason; authSignatureTxt.Text = o.Authoriser; }
private void AutoCompleteProduct() { AutoCompleteStringCollection AutoItem = new AutoCompleteStringCollection(); ProductDictionary.Clear(); foreach (Product v in Product.List()) { AutoItem.Add((v.Name)); if (!ProductDictionary.ContainsKey(v.Name)) { ProductDictionary.Add(v.Name, v.Id); productCbx.Items.Add(v.Name); } } }
static void AddProducts(int count) { Parallel.For(0, count, (i) => { Product product = new Product { Name = "name" + i, Category = "Category" + i, SellPrice = i }; ProductList.Add(product); ProductDictionary.Add(Guid.NewGuid().ToString(), product); ProductBlockList.Add(product); ProducutConcurrentDictionary.TryAdd(Guid.NewGuid().ToString(), product); }); }
private List <OrderEntity> ResolveOrders(CsvReader csv, string file, List <OrderEntity> items) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { OrderDTO orderDTO = new OrderDTO(); orderDTO.fileName = file; orderDTO.source = this.Name; orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(orderDTO.source); orderDTO.sourceSN = csv.GetField <string>("订单编号").Trim(); orderDTO.orderType = 0; if (string.IsNullOrEmpty(orderDTO.sourceSN)) { InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull); continue; } var orderDate = csv.GetField <string>("行权日期"); var orderTime = csv.GetField <string>("行权时间"); orderDTO.createdDate = DateTime.ParseExact(string.Format("{0}{1}", orderDate, orderTime), "yyyyMMddHHmmss", CultureInfo.InvariantCulture); // orderDTO.orderSN_old = string.Format("{0}-{1}", orderDTO.source, orderDTO.sourceSN); //订单SN=来源+原来的SN orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd")); orderDTO.orderStatus = OrderStatus.Confirmed; var sourceStatus = csv.GetField <string>("订单状态").Trim(); if (sourceStatus.Contains("撤消")) { orderDTO.orderStatus = OrderStatus.Cancelled; orderDTO.orderType = 2; } orderDTO.productName = csv.GetField <string>("服务项目").Trim(); orderDTO.count = csv.GetField <int>("本人次数"); orderDTO.consigneeName = csv.GetField <string>("使用人姓名").Trim(); if (string.IsNullOrEmpty(orderDTO.consigneeName)) { orderDTO.consigneeName = csv.GetField <string>("姓名").Trim(); } orderDTO.consigneePhone = csv.GetField <string>("手机号").Trim(); orderDTO.consigneeAddress = csv.GetField <string>("地址").Trim(); if (string.IsNullOrEmpty(orderDTO.consigneeProvince) && string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress)) { var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress); orderDTO.consigneeProvince = addrInfo.Province; orderDTO.consigneeCity = addrInfo.City; orderDTO.consigneeCounty = addrInfo.County; } //数据库中查找订单,如果找到订单了就跳过 if (CheckOrderInDataBase(orderDTO)) { continue; } //内存中查找,没找到就新增对象,找到就关联新的商品 var item = items.Find(o => o.OrderSn == orderDTO.orderSN); if (item == null) { OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO); //处理订单与地址、收货人、商品的关联关系。消除重复项 using (var db = new OMSContext()) { //查找联系人 if (!string.IsNullOrEmpty(orderItem.Consignee.Phone)) { OrderEntityService.InputConsigneeInfo(orderItem, db); } else //异常订单 { InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull); continue; } if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem)) { continue; } items.Add(orderItem); db.OrderRepurchases.Add(orderItem.OrderRepurchase); db.OrderDateInfos.Add(orderItem.OrderDateInfo); db.SaveChanges(); } } else { using (var db = new OMSContext()) { var bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName); if (bar == null || string.IsNullOrEmpty(bar.ProductCode)) { Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Error($"订单文件:{file}中平台商品:{orderDTO.productName}未找到"); // Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Debug($"订单文件:{file}中平台商品:{productName}未找到.order:{Util.Helpers.Json.ToJson(item)}"); if (bar == null) { ProductDictionary productDictionary = new ProductDictionary() { ProductNameInPlatform = orderDTO.productName }; db.ProductDictionarySet.Add(productDictionary); db.SaveChanges(); } items.Remove(item); continue; } var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku == bar.ProductCode); if (foo == null) { Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Error($"订单文件:{file}中平台商品名称:{orderDTO.productName}对应系统商品未找到"); items.Remove(item); continue; } decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count; if (orderDTO.orderStatus == OrderStatus.Cancelled) { var p = item.Products.FirstOrDefault(o => o.sku == foo.sku); if (p != null) { p.ProductCount -= orderDTO.count; p.ProductWeight -= weight; } } else { if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null) { OrderProductInfo orderProductInfo = new OrderProductInfo() { ProductPlatId = orderDTO.productsku, ProductPlatName = orderDTO.productName.Trim(), // Warehouse = item.OrderLogistics.Logistics, MonthNum = orderDTO.createdDate.Month, weightCode = foo.weightModel == null ? 0 : foo.weightModel.Code, weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g", OrderSn = orderDTO.orderSN, // TotalAmount = totalAmount, ProductCount = orderDTO.count, ProductWeight = weight, Source = orderDTO.source, sku = foo.sku }; item.Products.Add(orderProductInfo); } } } } } return(items); }
/// <summary> /// 订单商品来自京东仓,商品ID需要做对应关系 /// </summary> /// <param name="db"></param> /// <param name="orderDTO"></param> /// <param name="item"></param> /// <returns></returns> protected bool InputProductInfoWithoutSaveChange_JD(OMSContext db, OrderDTO orderDTO, OrderEntity item) { ProductDictionary pd = null; pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId.Trim() == orderDTO.productsku.Trim() && orderDTO.productsku != null && p.ProductCode != null); if (pd == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})录入失败"); InputExceptionOrder(orderDTO, ExceptionType.ProductIdUnKnown); if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == orderDTO.productsku) == null) { ProductDictionary productDictionary = new ProductDictionary() { ProductId = orderDTO.productsku, Source = orderDTO.source, ProductNameInPlatform = orderDTO.productName.Trim() }; db.ProductDictionarySet.Add(productDictionary); db.SaveChanges(); } return(false); } string temp = pd.ProductCode.Trim();//"S0010040003\t" var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == temp); if (foo == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})对应ERP商品记录未找到"); InputExceptionOrder(orderDTO, ExceptionType.ProductCodeUnKnown); return(false); } /* * 订单来源是ERP,同时商品SKU是周期购商品的SKU,判定为周期购日常发货订单 * 周期购日常发货订单不纳入日常统计中,为了和客户下的周期购订单区分开 * 统计报表中只统计销售订单 * */ if (foo.sku == "S0010030002" || foo.sku == "S0010040002")//标识该订单是周期购订单 { item.OrderType += 4; } var bar = item.Products.FirstOrDefault(p => p.sku == foo.sku); decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count; if (bar == null) { OrderProductInfo orderProductInfo = new OrderProductInfo() { ProductPlatId = orderDTO.productsku, ProductPlatName = orderDTO.productName, // Warehouse = item.OrderLogistics.Logistics, MonthNum = orderDTO.createdDate.Month, weightCode = foo.weightModel == null ? 0 : foo.weightModel.Code, weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g", OrderSn = orderDTO.orderSN, TotalAmount = orderDTO.totalAmount, DiscountFee = orderDTO.discountFee, AmounPerUnit = orderDTO.pricePerUnit, ProductCount = orderDTO.count, ProductWeight = weight, Source = orderDTO.source, sku = foo.sku }; item.Products.Add(orderProductInfo); } else { bar.ProductWeight += weight; bar.ProductCount += orderDTO.count; } OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})解析完毕"); return(true); }
/// <summary> /// 插入商品记录 /// </summary> /// <param name="db"></param> /// <param name="orderDTO"></param> /// <param name="item"></param> protected virtual bool InputProductInfoWithoutSaveChange(OMSContext db, OrderDTO orderDTO, OrderEntity item) { ProductDictionary pd = null; switch (item.Source) { case OrderSource.CIB: case OrderSource.CIBAPP: case OrderSource.CIBEVT: case OrderSource.CIBSTM: pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId.Trim() == orderDTO.productsku.Trim() && orderDTO.productsku != null && p.ProductCode != null); if (pd == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})录入失败"); InputExceptionOrder(orderDTO, ExceptionType.ProductIdUnKnown); if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == orderDTO.productsku) == null) { ProductDictionary productDictionary = new ProductDictionary() { ProductId = orderDTO.productsku, Source = orderDTO.source, ProductNameInPlatform = orderDTO.productName.Trim() }; db.ProductDictionarySet.Add(productDictionary); db.SaveChanges(); } return(false); } break; case OrderSource.CMBC: case OrderSource.CIBVIP: case OrderSource.ICBC_JINWEN: case OrderSource.BANK_JINWEN: case OrderSource.XUNXIAO: case OrderSource.JINGDONG: case OrderSource.ICIB: pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform.Trim() == orderDTO.productName.Trim() && orderDTO.productName != null && p.ProductCode != null); if (pd == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productName})录入失败"); InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown); if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName) == null) { ProductDictionary productDictionary = new ProductDictionary() { ProductId = orderDTO.productsku, Source = orderDTO.source, ProductNameInPlatform = orderDTO.productName.Trim() }; db.ProductDictionarySet.Add(productDictionary); db.SaveChanges(); } return(false); } break; default: if (string.IsNullOrEmpty(orderDTO.productsku)) { pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform.Trim() == orderDTO.productName.Trim() && orderDTO.productName != null && p.ProductCode != null); if (pd == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productName})录入失败"); InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown); if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName) == null) { ProductDictionary productDictionary = new ProductDictionary() { ProductId = orderDTO.productsku, Source = orderDTO.source, ProductNameInPlatform = orderDTO.productName.Trim() }; db.ProductDictionarySet.Add(productDictionary); db.SaveChanges(); } return(false); } } else { pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId.Trim() == orderDTO.productsku.Trim() && orderDTO.productsku != null && p.ProductCode != null); if (pd == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})录入失败"); InputExceptionOrder(orderDTO, ExceptionType.ProductIdUnKnown); if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == orderDTO.productsku) == null) { ProductDictionary productDictionary = new ProductDictionary() { ProductId = orderDTO.productsku, Source = orderDTO.source, ProductNameInPlatform = orderDTO.productName.Trim() }; db.ProductDictionarySet.Add(productDictionary); db.SaveChanges(); } return(false); } } break; } // var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == "S0010040003\t".Trim()); string temp = pd.ProductCode.Trim();//"S0010040003\t" var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == temp); if (foo == null) { OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})对应ERP商品记录未找到"); InputExceptionOrder(orderDTO, ExceptionType.ProductCodeUnKnown); return(false); } if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null) { decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count; decimal totalAmount = pd.PayPrice * orderDTO.count; decimal totalCostPrice = foo.CostPrice * orderDTO.count; decimal totalFlatAmount = foo.FlatPrice * orderDTO.count; OrderProductInfo orderProductInfo = new OrderProductInfo() { ProductPlatId = orderDTO.productsku, ProductPlatName = orderDTO.productName.Trim(), // Warehouse = item.OrderLogistics.Logistics, MonthNum = orderDTO.createdDate.Month, weightCode = foo.weightModel == null ? 0 : foo.weightModel.Code, weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g", OrderSn = orderDTO.orderSN, TotalAmount = totalAmount, TotalCostPrice = totalCostPrice, TotalFlatAmount = totalFlatAmount, ProductCount = orderDTO.count, ProductWeight = weight, Source = orderDTO.source, sku = foo.sku }; item.Products.Add(orderProductInfo); } OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})解析完毕"); return(true); }