private void btnPrintNew_Click(object sender, RoutedEventArgs e) { var items = this.gcs.ToArray(); if (items == null || items.Length < 1) { MessageBox.Show("没有需要打印的数据"); return; } try { string printer = LocalConfigService.GetValue(SystemNames.CONFIG_PRINTER_A4, ""); if (string.IsNullOrWhiteSpace(printer)) { throw new Exception("请在系统配置里面,配置要使用的打印机"); } //数据数量过滤 int minCount = 1; int.TryParse(this.tbMinCount.Text.Trim(), out minCount); Dictionary <string, List <GoodsCount> > gcs = new Dictionary <string, List <GoodsCount> >(); foreach (var gc in items) { if (items.Where(obj => obj.Address == gc.Address).Select(o => o.Count).Sum() >= minCount) { if (gcs.ContainsKey(gc.Vendor) == false) { gcs[gc.Vendor] = new List <GoodsCount>(); } gcs[gc.Vendor].Add(gc); } } string message = string.Format("是否打印:\n打印机:{0}\n打印数量:{1}", printer, gcs.Select(obj => obj.Value.Count).Sum()); if (MessageBox.Show(message, "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } var pd = PrintUtil.GetPrinter(printer); GoodsCountPrintDocument2 goodsCountDoc = new GoodsCountPrintDocument2(); goodsCountDoc.PageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight); goodsCountDoc.SetGoodsCount(gcs, ServiceContainer.GetService <SystemConfigService>().Get(-1, "GOODS_NAME", ""), ServiceContainer.GetService <SystemConfigService>().Get(-1, "GOODS_PHONE", "")); pd.PrintDocument(goodsCountDoc, "拿货统计"); MessageBox.Show("打印完成"); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错"); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { var items = this.gcs.ToArray(); if (items == null || items.Length < 1) { MessageBox.Show("没有需要打印的数据"); return; } try { string printer = LocalConfigService.GetValue(SystemNames.CONFIG_PRINTER_A4, ""); if (string.IsNullOrWhiteSpace(printer)) { throw new Exception("请在系统配置里面,配置要使用的打印机"); } string message = string.Format("是否打印:\n打印机:{0}\n打印数量:{1}", printer, items.Select(obj => obj.Count).Sum()); if (MessageBox.Show(message, "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } var pd = PrintUtil.GetPrinter(printer); GoodsCountPrintDocument goodsCountDoc = new GoodsCountPrintDocument(); goodsCountDoc.PageSize = new Size(796.8, 1123.2); goodsCountDoc.SetGoodsCount(items); pd.PrintDocument(goodsCountDoc, "拿货统计"); SaveLastOrderInfo(); MessageBox.Show("打印完成"); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错"); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { if (this.OrderReturns.Count < 1) { MessageBox.Show("没有需要打印的数据"); return; } try { string printer = LocalConfigService.GetValue(SystemNames.CONFIG_PRINTER_A4, ""); if (string.IsNullOrWhiteSpace(printer)) { throw new Exception("请在系统配置里面,配置要使用的打印机"); } if (MessageBox.Show("是否使用打印机:" + printer + Environment.NewLine + "打印?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } var pd = PrintUtil.GetPrinter(printer); VendorService vs = ServiceContainer.GetService <VendorService>(); var goodsCountDoc = new OrderReturnOutPrintDocument(); List <GoodsCount> counts = new List <GoodsCount>(); foreach (var item in this.OrderReturns) { string[] infos = item.Source.GoodsInfo.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); if (infos.Length < 4) { MessageBox.Show("退货信息不正确,请检查:" + item.Source.Id); continue; } var vendor = vs.GetByAll(infos[0], "", "", "", 0, 0).First; if (vendor == null) { vendor = vs.GetByAll(infos[0] + infos[1], "", "", "", 0, 0).First; } if (vendor == null) { MessageBox.Show("退货信息厂家找不到,请检查:" + item.Source.Id); continue; } GoodsCount count = null; if (infos.Length >= 5) { count = counts.FirstOrDefault( obj => obj.Vendor == VendorService.FormatVendorName(infos[0]) && obj.Number == infos[1] && obj.Edtion == infos[2] && obj.Color == infos[3] && obj.Size == infos[4]); } else { count = counts.FirstOrDefault( obj => obj.Vendor == VendorService.FormatVendorName(infos[0]) && obj.Number == infos[1] && obj.Color == infos[2] && obj.Size == infos[3]); } if (count == null) { count = new GoodsCount { Vendor = infos[0].Trim(), Number = infos[1].Trim(), Money = (int)(item.Source.GoodsMoney / item.Source.Count), Count = 0, FirstPayTime = item.Source.ProcessTime, }; if (infos.Length >= 5) { count.Edtion = infos[2].Trim(); count.Color = infos[3].Trim(); count.Size = infos[4].Trim(); } else { count.Edtion = ""; count.Color = infos[2].Trim(); count.Size = infos[3].Trim(); } count.Address = vendor.MarketAddressShort; count.Vendor = VendorService.FormatVendorName(count.Vendor); counts.Add(count); } foreach (var c in counts.Where(obj => obj.Vendor == count.Vendor && obj.Number == count.Number && obj.Edtion == count.Edtion)) { //取消最大金额值 if (c.Money < count.Money) { c.Money = count.Money; } else { count.Money = c.Money; } } if (count.FirstPayTime >= item.Source.ProcessTime) { count.FirstPayTime = item.Source.ProcessTime; } count.Count += item.Source.Count; } IComparer <GoodsCount> comparer = new OrderGoodsCountSortByDoor(); counts.Sort(comparer); //拿货地址 counts.Sort(comparer); //货号 counts.Sort(comparer); //版本 counts.Sort(comparer); //颜色 counts.Sort(comparer); //尺码 goodsCountDoc.PageSize = new Size(793, 1122.24); goodsCountDoc.SetGoodsCount(counts.ToArray()); pd.PrintDocument(goodsCountDoc, "退货统计"); foreach (var item in this.OrderReturns) { this.OrderReturnService.Update(item.Source); } MessageBox.Show("打印完成"); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错"); } }