private void btnMarkPopDelivery_Click(object sender, RoutedEventArgs e) { try { var selected = this.GetSelected(sender); this.ResetViewState(selected); WPFHelper.DoEvents(); foreach (var item in selected) { try { item.Background = Brushes.Yellow; item.State = ""; ServiceContainer.GetService <OrderService>().MarkPopDelivery(item.Source.OrderId, ""); ServiceContainer.GetService <PrintHistoryService>().Update(item.Source); item.State = "标记发货成功"; item.Background = null; } catch (Exception ex) { item.State = ex.Message; item.Background = Brushes.Red; } finally { WPFHelper.DoEvents(); } } MessageBox.Show("已完成"); } catch (Exception ex) { MessageBox.Show("标记发货失败:" + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnUpload_Click(object sender, RoutedEventArgs e) { try { var printHistorys = this.GetSelected(sender); if (printHistorys.Length < 1) { return; } this.ResetViewState(printHistorys); foreach (var item in printHistorys) { try { this.printHistoryService.Upload(item.Source); item.State = "上传成功"; item.Background = null; } catch (Exception ex) { item.Background = Brushes.Red; item.State = ex.Message; } WPFHelper.DoEvents(); } MessageBox.Show("已完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnMark_Click(object sender, RoutedEventArgs e) { if (this.OrderReturns.Count < 1) { MessageBox.Show("没有需要打印的数据"); return; } try { foreach (var item in this.OrderReturns) { item.ProcessState = "处理中"; WPFHelper.DoEvents(); this.OrderReturnService.Update(item.Source); item.ProcessState = "退货中"; WPFHelper.DoEvents(); } MessageBox.Show("已完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnMarkDelivery_Click(object sender, RoutedEventArgs e) { try { var so = this.orders.Where(obj => obj.IsChecked).ToArray(); if (so.Length < 1) { throw new Exception("没有选择订单"); } var os = ServiceContainer.GetService <OrderService>(); foreach (var o in so) { WPFHelper.DoEvents(); try { os.MarkPopDelivery(o.Source.Id, ""); o.State = "标记成功"; o.Background = null; } catch (Exception ex) { o.State = ex.Message; o.Background = Brushes.Red; } } MessageBox.Show("所有订单标记完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnUpload_Click(object sender, RoutedEventArgs e) { try { var s = ServiceContainer.GetService <DeliveryInService>(); List <string> uploadedDeliveryNumbers = new List <string>(); foreach (var item in this.deliveryInViewModels) { WPFHelper.DoEvents(); //已经上传过 if (item.Id > 0) { item.State = "上传成功"; continue; } //货到付款订单,标记已拒签 if (item.SourceOrder != null && item.SourceOrder.PopPayType == PopPayType.COD) { item.SourceOrder.Refused = true; ServiceContainer.GetService <OrderService>().Update(item.SourceOrder); } //上传记录 DeliveryIn di = new DeliveryIn { Comment = item.OrderGoodsInfo, CreateTime = DateTime.Now, DeliveryCompany = item.DeliveryCompany, DeliveryNumber = item.DeliveryNumber, CreateOperator = OperatorService.LoginOperator.Number, Id = 0, }; di.Id = s.Save(di); item.Id = di.Id; WPFHelper.DoEvents(); //如果是拒签就创建退货,并处理 if (item.IsRefused) { var ors = ServiceContainer.GetService <OrderReturnService>(); var id = ors.Create(item.OrderId, item.SourceOrderGoods.Id, item.DeliveryCompany, item.DeliveryNumber, OrderReturnType.REFUSED, OrderReturnReason.DAY7, item.SourceOrderGoods.Count); var or = ors.GetById(id.data); or.ProcessOperator = OperatorService.LoginOperator.Number; or.ProcessTime = DateTime.Now; or.State = OrderReturnState.PROCESSED; ors.Update(or); } item.State = "上传成功"; WPFHelper.DoEvents(); } MessageBox.Show("上传成功"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ResetViewState(IEnumerable <PrintHistoryViewModel> ph) { foreach (var item in ph) { item.State = ""; item.Background = null; WPFHelper.DoEvents(); } }
private void btnMarkDelivery_Click(object sender, RoutedEventArgs e) { try { var so = this.orders.Where(obj => obj.IsChecked).ToArray(); if (so.Length < 1) { throw new Exception("没有选择订单"); } if (so.Any(obj => obj.Source.State == OrderState.RETURNING)) { if (MessageBox.Show("所选订单中含有退款中订单是否确认发货?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) != MessageBoxResult.Yes) { return; } } var dcs = ServiceContainer.GetService <DeliveryCompanyService>().GetByAll().Datas; var os = ServiceContainer.GetService <OrderService>(); foreach (var o in so) { WPFHelper.DoEvents(); try { var dc = dcs.FirstOrDefault(obj => obj.Name == o.DeliveryCompany).PopMapTaobao; MarkPopDelivery(o.Source.PopOrderId, dc, o.DeliveryNumber); o.State = "标记成功"; o.Background = null; } catch (Exception ex) { o.State = ex.Message; o.Background = Brushes.Red; } } MessageBox.Show("所有订单标记完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void UploadPrintHistory(PrintOrderViewModel[] orderViewModels) { foreach (var vm in orderViewModels) { try { if (string.IsNullOrWhiteSpace(vm.DeliveryCompany) || string.IsNullOrWhiteSpace(vm.DeliveryNumber)) { throw new Exception("上传打印信息失败:物流公司和编号为空"); } PrintHistory ph = new PrintHistory { UploadTime = this.orderService.GetDBMinTime(), DeliveryCompany = vm.DeliveryCompany, DeliveryNumber = vm.DeliveryNumber, DeliveryTemplate = this.WuliuPrintTemplate.Name, Operator = OperatorService.LoginOperator.Number, OrderId = vm.Source.Id, ReceiverAddress = vm.Source.ReceiverAddress, ReceiverMobile = vm.Source.ReceiverMobile, ReceiverName = vm.Source.ReceiverName, ReceiverPhone = vm.Source.ReceiverPhone, CreateTime = DateTime.Now, GoodsInfo = vm.Goods, PopOrderId = vm.Source.PopOrderId, ShopId = vm.Source.ShopId, Id = 0, PageNumber = vm.PageNumber, }; this.printHistoryService.Save(ph); vm.State = "打印成功"; vm.Background = null; WPFHelper.DoEvents(); } catch (Exception ee) { vm.State = "保存打印记录失败:" + ee.Message; vm.Background = Brushes.Red; } } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { var printHistorys = this.GetSelected(sender); if (printHistorys.Length < 1) { return; } if (MessageBox.Show("是否删除打印历史?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Error) != MessageBoxResult.Yes) { return; } this.ResetViewState(printHistorys); foreach (var ph in printHistorys) { string state = "删除成功"; try { ServiceContainer.GetService <PrintHistoryService>().Delete(ph.Source.Id); } catch (Exception ex) { state = ex.Message; } finally { ph.State = state; } WPFHelper.DoEvents(); } MessageBox.Show("已完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnRestPrintState_Click(object sender, RoutedEventArgs e) { try { if (MessageBox.Show("是否重置?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) != MessageBoxResult.Yes) { return; } OrderService os = ServiceContainer.GetService <OrderService>(); var printHistorys = this.GetSelected(sender); if (printHistorys.Length < 1) { return; } this.ResetViewState(printHistorys); WPFHelper.DoEvents(); foreach (var item in printHistorys) { try { os.ResetPrintState(item.Source.OrderId); item.State = "重置成功"; } catch (Exception ex) { item.State = ex.Message; } WPFHelper.DoEvents(); } MessageBox.Show("已完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnQuery_Click(object sender, RoutedEventArgs e) { try { this.shoes.Clear(); string strId = this.tbIdOrUrl.Text.Trim(); if (string.IsNullOrWhiteSpace(strId) == false) { int id = 0; int.TryParse(strId, out id); if (id > 0) { var d = this.shoesService.GetById(id); if (d != null) { this.shoes.Add(new GoodUpdateViewModel { Source = d }); } } else { var d = this.shoesService.GetByAll(0, GoodsState.NONE, 0, DateTime.MinValue, DateTime.MinValue, strId, "", GoodsType.GOODS_SHOES_NONE, "", ColorFlag.None, GoodsVideoType.NONE, "", "", "", 0, 0).Datas; foreach (var gu in d) { this.shoes.Add(new GoodUpdateViewModel { Source = gu }); } } return; } int pageIndex = 0; do { var data = this.shoesService.GetByAll(0, GoodsState.NONE, 0, DateTime.MinValue, DateTime.MinValue, "", "", GoodsType.GOODS_SHOES_NONE, "", ColorFlag.None, GoodsVideoType.NONE, "", "", "", pageIndex, 500); if (data.Datas.Count < 1) { break; } foreach (var d in data.Datas) { this.shoes.Add(new GoodUpdateViewModel { Source = d }); } this.tbProgress.Text = "已经下载:" + (pageIndex + 1) + "/" + (data.Total + 499) / 500 + "页,当前共:" + this.shoes.Count; if (this.shoes.Count > 20) { this.dgvShoes.ScrollIntoView(this.shoes.Last()); } WPFHelper.DoEvents(); } while (++pageIndex > 0); } catch (Exception ex) { if (ex.Message.Equals("NO_MORE_DATA") == false) { MessageBox.Show(ex.Message); } } finally { this.tbProgress.Text = "读取到数据:" + this.shoes.Count; } }
private void btnTest_Click(object sender, RoutedEventArgs e) { try { this.isStop = false; this.isRunning = true; this.current = 0; this.Dispatcher.BeginInvoke(new Action(() => this.btnUpdate.Content = "停止")); string dir = LocalConfigService.GetValue(SystemNames.CONFIG_WEB_IMAGE_DIR, ""); if (string.IsNullOrWhiteSpace(dir)) { throw new Exception("没有配置图片文件夹"); } foreach (var gu in shoes) { if (this.isStop) { break; } if (gu.Source.UpdateEnabled == false) { continue; } if (gu.Source.VideoType != GoodsVideoType.VIDEO) { continue; } string state = null; try { string fullDir = System.IO.Path.Combine(dir, gu.Source.ImageDir); string[] videos = Directory.GetFiles(fullDir, "*.mp4"); if (videos.Length > 0) { FileInfo fileInfo = new FileInfo(videos[0]); string newPath = System.IO.Path.Combine(fullDir, gu.Source.Number + ".mp4"); File.Move(videos[0], newPath); state = "已处理"; } else { state = "已检查,未处理"; } } catch (Exception ex) { state = "错误:" + ex.Message; } finally { lock (this.shoes) { current++; } this.Dispatcher.BeginInvoke(new Action(() => { this.tbProgress.Text = "已经更新:" + current + "/" + this.shoes.Count; gu.State = state; })); WPFHelper.DoEvents(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.isRunning = false; this.isStop = true; this.Dispatcher.BeginInvoke(new Action(() => this.btnUpdate.Content = "更新商品")); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { try { var printOrderPage = (sender as Button).DataContext as PrintOrderPageViewModel; if (printOrderPage.IsRunning) { if (MessageBox.Show("是否停止打印", "提示", MessageBoxButton.YesNo, MessageBoxImage.Stop) == MessageBoxResult.Yes) { printOrderPage.Stop(); return; } } var orders = printOrderPage.OrderViewModels.ToArray(); var selectedOrders = orders.Where(obj => obj.IsChecked).Select(obj => obj.Source).ToArray(); var printTemplate = printOrderPage.WuliuPrintTemplate; Grid grid = ((sender as Button).Parent as StackPanel).Parent as Grid; DataGrid dg = grid.FindName("dgOrders") as DataGrid; DataGridColumn goodsCol = dg.Columns.FirstOrDefault(col => col.Header != null && col.Header.ToString() == "门牌编号"); if (printOrderPage.WuliuBranch == null) { throw new Exception("未选择发货网点"); } if (printTemplate == null) { throw new Exception("请选择相应的快递模板"); } if (selectedOrders.Count() < 1) { throw new Exception("没有选择需要打印的订单"); } if (selectedOrders.Select(obj => obj.PopPayType).Distinct().Count() != 1) { throw new Exception("不同支付类型的订单不能一起打印"); } if (goodsCol == null) { throw new Exception("无法找到列标题为: 门牌编号 的列"); } if (printTemplate.SourceType == WuliuPrintTemplateSourceType.PINDUODUO && selectedOrders.Any(obj => obj.PopType != PopType.PINGDUODUO)) { throw new Exception("拼多多电子面单只能打印拼多多的订单"); } //检查货到付款 if (selectedOrders[0].PopPayType == PopPayType.COD && printTemplate.Name.Contains("货到") == false) { throw new Exception("货到付款订单必须使用货到付款模板"); } if (selectedOrders[0].PopPayType == PopPayType.ONLINE && printTemplate.Name.Contains("货到")) { throw new Exception("在线支付订单不能使用货到付款模板"); } string printer = printOrderPage.Printer; if (string.IsNullOrWhiteSpace(printer)) { throw new Exception("没有选择打印机"); } string popMessage = string.Format("发货网点:{0}{1}打印模板:{2}{3}打印设备:{4}{5}打印数据:{6}", printOrderPage.WuliuBranch.Name, Environment.NewLine, printTemplate.Name, Environment.NewLine, printer, Environment.NewLine, selectedOrders.Count()); if (MessageBox.Show(popMessage, "确认打印", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { return; } //按照厂家门牌号,对数据进行排序 goodsCol.SortDirection = null; this.SortData(printOrderPage, dg, goodsCol); WPFHelper.DoEvents(); printOrderPage.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Start(string popOrderId, DateTime startTime, DateTime endTime) { try { if (this.isRunning) { this.isRunning = false; return; } this.isRunning = true; this.Dispatcher.BeginInvoke(new Action(() => this.btnUpdate.Content = "停止")); string htmlRet = this.wb1.GetTextAsync().Result; var allShops = ServiceContainer.GetService <ShopService>().GetByAll().Datas; var shop = allShops.FirstOrDefault(obj => htmlRet.Contains(obj.PopSellerId)); var ors = ServiceContainer.GetService <OrderUpdateService>().GetByAll(new long[] { shop.Id }, popOrderId, startTime, endTime, 0, 0); var orders = ors.Datas.Where(obj => string.IsNullOrWhiteSpace(obj.PopOrderId) == false).ToArray(); if (orders.Length < 1) { throw new Exception("订单不存在"); } int i = 0; foreach (var o in orders) { if (this.isRunning == false) { break; } this.Dispatcher.BeginInvoke(new Action(() => { if (this.tbMessage.LineCount > 10000) { this.tbMessage.Text = ""; } this.tbMessage.AppendText(DateTime.Now + ":正在下载订单:" + (++i) + "/" + orders.Count() + " " + o.PopOrderId + Environment.NewLine); this.tbMessage.ScrollToEnd(); })); var pos = this.ParseOrderState(shop, o.PopOrderId); string ret = ServiceContainer.GetService <OrderService>().UpdateOrderState(pos, o, shop).data; this.Dispatcher.BeginInvoke(new Action(() => { if (this.tbMessage.LineCount > 10000) { this.tbMessage.Text = ""; } this.tbMessage.AppendText(DateTime.Now + ":操作结果:" + o.PopOrderId + " " + ret + Environment.NewLine); this.tbMessage.ScrollToEnd(); })); WPFHelper.DoEvents(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.isRunning = false; this.Dispatcher.BeginInvoke(new Action(() => this.btnUpdate.Content = "开始同步")); } }
/// <summary> /// </summary> /// <returns></returns> public void Print() { try { this.orderVmToOrder = new Dictionary <Order, List <PrintOrderViewModel> >(); this.IsUserStop = false; this.IsRunning = true; this.PrintButtonString = "停止"; this.WuliuPrintTemplate.XOffset = this.XOffset; this.WuliuPrintTemplate.YOffset = this.YOffset; string senderName = ServiceContainer.GetService <SystemConfigService>().Get(-1, SystemNames.CONFIG_CAINIAO_SENDER_NAME, ""); string senderPhone = ServiceContainer.GetService <SystemConfigService>().Get(-1, SystemNames.CONFIG_CAINIAO_SENDER_PHONE, ""); if (string.IsNullOrWhiteSpace(senderName) || string.IsNullOrWhiteSpace(senderPhone)) { throw new Exception("系统中没有配置发货姓名和电话无法打印"); } var selectedOrderVMs = this.OrderViewModels.Where(obj => obj.IsChecked).ToArray(); var selectedOrders = selectedOrderVMs.Select(obj => obj.Source).ToArray(); if (selectedOrderVMs.Length < 1) { throw new Exception("没有需要打印的订单"); } this.WorkStateMessage = "第一步:正在检查是否打印过..."; WPFHelper.DoEvents(); foreach (var o in selectedOrderVMs) { if (printHistoryService.GetByAll(o.Source.Id, "", "", 0, DateTime.Now.AddDays(-30), DateTime.Now, 0, 0).Total > 0) { o.State = "已经打印过,请先删除打印历史"; o.Background = Brushes.Red; throw new Exception("订单编号:" + o.Source.Id + " 已经打印过,请先删除打印历史"); } WPFHelper.DoEvents(); } this.WorkStateMessage = "第二步:正在重置当前打印数据..."; WPFHelper.DoEvents(); foreach (var v in selectedOrderVMs) { v.WuliuNumber = null; v.DeliveryNumber = ""; v.DeliveryCompany = ""; v.State = ""; v.Background = null; WPFHelper.DoEvents(); } this.WorkStateMessage = "第三步:正在合并订单数据..."; WPFHelper.DoEvents(); //在线支付,需要合并订单 var mergedOrders = new List <Order>(); if (selectedOrders[0].PopPayType == PopPayType.ONLINE) { //合并相同订单 foreach (var or in selectedOrders) { if (this.IsUserStop) { throw new Exception("用户已停止打印"); } WPFHelper.DoEvents(); var first = mergedOrders.FirstOrDefault(obj => HasSameReceiverInfo(or, obj)); if (first == null) { mergedOrders.Add(or); List <PrintOrderViewModel> vms = new List <PrintOrderViewModel>(); vms.Add(this.OrderViewModels.First(obj => obj.Source.Id == or.Id)); orderVmToOrder.Add(or, vms); } else { //合并商品,订单可能被重复打印,以前合并过的,不再合并 foreach (var og in or.OrderGoodss) { if (first.OrderGoodss.Any(obj => obj.Id == og.Id) == false) { first.OrderGoodss.Add(og); } } orderVmToOrder[first].Add(this.OrderViewModels.First(obj => obj.Source.Id == or.Id)); } } } else { mergedOrders.AddRange(selectedOrders); foreach (var mo in mergedOrders) { orderVmToOrder.Add(mo, this.OrderViewModels.Where(obj => obj.Source.Id == mo.Id).ToList()); } } //生成快递单号 var wuliuNumbers = new WuliuNumber[mergedOrders.Count]; for (int i = 0; i < wuliuNumbers.Length; i++) { if (this.IsUserStop) { throw new Exception("用户已停止打印"); } try { this.WorkStateMessage = string.Format("第四步:正在获取快递单号{0}/{1}...", i + 1, wuliuNumbers.Length); WPFHelper.DoEvents(); wuliuNumbers[i] = ServiceContainer.GetService <WuliuNumberService>().GenWuliuNumber(this.Shop, this.WuliuPrintTemplate, mergedOrders[i], GetMatchOrderViewModelsWuliuId(mergedOrders[i]), this.PackageId > 0 ? this.PackageId.ToString() : "", senderName, senderPhone, this.WuliuBranch.SenderAddress).First; foreach (var ov in this.orderVmToOrder[mergedOrders[i]]) { ov.WuliuNumber = wuliuNumbers[i]; ov.DeliveryCompany = wuliuNumbers[i].DeliveryCompany; ov.DeliveryNumber = wuliuNumbers[i].DeliveryNumber; ov.State = ""; ov.PageNumber = i + 1; } } catch (Exception ex) { var vms = this.orderVmToOrder[mergedOrders[i]]; foreach (var v in vms) { v.State = ex.Message; v.Background = Brushes.Red; } throw; } } var allShops = ServiceContainer.GetService <ShopService>().GetByAll().Datas; var vs = ServiceContainer.GetService <VendorService>(); //生成自定义打印数据 var userDatas = new Dictionary <string, string> [mergedOrders.Count]; for (int i = 0; i < userDatas.Length; i++) { if (this.IsUserStop) { throw new Exception("用户已停止打印"); } this.WorkStateMessage = string.Format("第五步:正在生成自定义数据{0}/{1}...", i + 1, wuliuNumbers.Length); WPFHelper.DoEvents(); userDatas[i] = new Dictionary <string, string>(); StringBuilder goods_commment = new StringBuilder(); if (mergedOrders[i].Type == OrderType.NORMAL) { if (mergedOrders[i].OrderGoodss != null && mergedOrders[i].OrderGoodss.Count > 0) { foreach (var goods in mergedOrders[i].OrderGoodss.Where(obj => (int)obj.State <= (int)OrderState.SUCCESS)) { goods_commment.AppendLine(vs.GetVendorPingyingName(goods.Vendor).ToUpper() + " " + goods.Number + " " + goods.Edtion + " " + goods.Color + " " + goods.Size + " (" + goods.Count + ")"); } } if (mergedOrders[i].PopPayType != PopPayType.COD) { goods_commment.AppendLine(mergedOrders[i].PopSellerComment); } } userDatas[i].Add("goodsInfoSellerComment", goods_commment.ToString()); userDatas[i].Add("suminfo", string.Format("店:{0},数:{1},付:{2}", allShops.FirstOrDefault(obj => obj.Id == mergedOrders[i].ShopId).Mark, mergedOrders[i].OrderGoodss.Select(obj => obj.Count).Sum().ToString(), mergedOrders[i].PopPayTime.ToString("yyyy-MM-dd HH:mm:ss"))); } this.WorkStateMessage = string.Format("第六步:输出打印数据..."); WPFHelper.DoEvents(); this.printDoc = new CainiaoPrintDocument(mergedOrders.ToArray(), wuliuNumbers, userDatas, this.WuliuPrintTemplate); string file = printDoc.StartPrint(this.Printer, this.PrintServerAdd); this.WorkStateMessage = string.Format("第七步:保存打印记录..."); WPFHelper.DoEvents(); UploadPrintHistory(selectedOrderVMs); HandelPrintEnded(); if (this.WuliuPrintTemplate.SourceType == WuliuPrintTemplateSourceType.CAINIAO) { LocalConfigService.UpdateValue(SystemNames.CONFIG_PRINTSERVERADD_CAINIAO, this.PrintServerAdd); } else if (this.WuliuPrintTemplate.SourceType == WuliuPrintTemplateSourceType.PINDUODUO) { LocalConfigService.UpdateValue(SystemNames.CONFIG_PRINTSERVERADD_PDD, this.PrintServerAdd); } if (string.IsNullOrWhiteSpace(file) == false && file.StartsWith("http")) { //下载文件 byte[] content = MsHttpRestful.GetUrlEncodeBodyReturnBytes(file, null); Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.AddExtension = true; sfd.DefaultExt = "pdf"; sfd.Filter = "*.pdf|PDF 文件"; sfd.FileName = "快递单 " + this.WuliuPrintTemplate.DeliveryCompany + " " + DateTime.Now.ToString("MM-dd") + ".pdf"; sfd.InitialDirectory = LocalConfigService.GetValue("PrintFileSaveDir_" + this.shipper, ""); if (sfd.ShowDialog().Value == false) { return; } File.WriteAllBytes(sfd.FileName, content); LocalConfigService.UpdateValue("PrintFileSaveDir_" + this.shipper, new FileInfo(sfd.FileName).DirectoryName); } LocalConfigService.UpdateValue(SystemNames.CONFIG_PRINTER_DELIVERY_HOT, this.Printer); var offsets = LocalConfigService.GetValue(SystemNames.CONFIG_PRINT_OFFSETS, "").Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries).ToList(); string url = this.WuliuPrintTemplate.UserOrIsvTemplateAreaUrl ?? this.WuliuPrintTemplate.StandTemplateUrl; string urlOffset = url + "," + XOffset + "," + YOffset; offsets.RemoveAll(obj => obj.Contains(url)); offsets.Add(urlOffset); string strOffsets = string.Join("###", offsets); LocalConfigService.UpdateValue(SystemNames.CONFIG_PRINT_OFFSETS, strOffsets); } finally { HandelPrintEnded(); } }
private List <OrderDownload> GetOrders() { List <OrderDownload> allOrders = new List <OrderDownload>(); int totalCount = 0, currentCount = 0; int totalPage = 0, currentPage = 1; string htmlRet = this.wb1.GetTextAsync().Result; var allShops = ServiceContainer.GetService <ShopService>().GetByAll().Datas; var shop = allShops.FirstOrDefault(obj => htmlRet.Contains(obj.PopSellerId)); if (shop == null) { throw new Exception("系统中没有找到相应店铺"); } while (this.isRunning) { string script = ScriptManager.GetBody(jspath, "//TAOBAO_SEARCH_ORDER").Replace("###prePageNo", (currentPage - 1 >= 0 ? currentPage - 1 : 1).ToString()).Replace("###pageNum", currentPage.ToString()); var task = wb1.GetBrowser().MainFrame.EvaluateScriptAsync(script, "", 1, new TimeSpan(0, 0, 30)); var ret = task.Result; if (ret.Success == false || (ret.Result != null && ret.Result.ToString().StartsWith("ERROR"))) { throw new Exception("执行操作失败:" + ret.Message); } var or = Newtonsoft.Json.JsonConvert.DeserializeObject <TaobaoQueryOrderListResponse>(ret.Result.ToString()); if (or.page == null) { throw new Exception("执行操作失败:返回数据格式无法识别"); } if (or.mainOrders == null || or.mainOrders.Length < 1) { break; } totalCount = or.page.totalNumber; totalPage = or.page.totalPage; List <OrderDownload> orders = new List <OrderDownload>(1); foreach (var v in or.mainOrders) { OrderDownload od = new OrderDownload(); orders.Clear(); orders.Add(od); try { this.tbMsg.Text = string.Format("正在下载:{0}/{1} {2} ", currentCount, totalCount, v.id); WPFHelper.DoEvents(); var odInDb = ServiceContainer.GetService <OrderService>().GetByPopOrderId(v.id); if (odInDb.Total >= 1) { od.Order = odInDb.First; var state = ConvertState(v.statusInfo.text); //未发货订单,即使有退款商品,整个订单状态也是待发货不是退款中 if (state == OrderState.PAYED && v.subOrders.All(obj => obj.operations != null && (obj.operations.FirstOrDefault(op => op.text.Trim() == "退款成功" || op.text.Trim() == "请卖家处理" || op.text.Trim() == "请退款") != null))) { state = OrderState.RETURNING; } if (od.Order.State == state || od.Order.State == OrderState.CLOSED || od.Order.State == OrderState.CANCLED) { continue; } if (state == OrderState.RETURNING || state == OrderState.CLOSED || state == OrderState.CANCLED) { od.Order.State = state; od.Order.PopState = v.statusInfo.text; var resp = ServiceContainer.GetService <OrderService>().Update(od.Order); } } else { var order = ParseOrder(v, shop); od.Order = order; var resp = ServiceContainer.GetService <OrderService>().SaveOrUpdateOrdersByPopOrderId(shop, orders); od = resp.First; } if (this.isRunning == false) { break; } } catch (Exception ex) { od.Error = new OrderDownloadError(shop.Id, v.id, "", ex.Message, ex.StackTrace); } finally { currentCount++; allOrders.Add(od); } } currentPage++; } return(allOrders); }