diff --git a/ButcherFactory.Form/ButcherFactory.Form.csproj b/ButcherFactory.Form/ButcherFactory.Form.csproj index 6252cbb..d36ab4a 100644 --- a/ButcherFactory.Form/ButcherFactory.Form.csproj +++ b/ButcherFactory.Form/ButcherFactory.Form.csproj @@ -34,6 +34,10 @@ + + False + ..\..\..\tsref\Debug\BwpClientPrint.dll + @@ -118,6 +122,7 @@ SegmentProductionForm.cs + Form diff --git a/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs b/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs index 4043ccb..eb8600b 100644 --- a/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs +++ b/ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs @@ -159,6 +159,8 @@ namespace ButcherFactory.SegmentProduction_ historyList.RemoveAt(100); historyDataGrid.FirstDisplayedScrollingRowIndex = 0; historyDataGrid.Refresh(); + if (barPrintCheck.Checked) + SegmentProductionPrint.Print(entity, batchDate); } void BindGrid() @@ -217,9 +219,7 @@ namespace ButcherFactory.SegmentProduction_ item.GroupID = groupID; Start(false); if (barPrintCheck.Checked) - { - - } + SegmentProductionPrint.PrintEnd(arr); } else throw new Exception("本次开始之后未生产任何商品"); @@ -267,7 +267,13 @@ namespace ButcherFactory.SegmentProduction_ private void rePrintBtn_Click(object sender, EventArgs e) { - + if (barPrintCheck.Checked) + { + if (historyDataGrid.CurrentRow == null) + throw new Exception("请先选择要补打的记录"); + var item = historyDataGrid.CurrentRow.DataBoundItem as SegmentProduction; + SegmentProductionPrint.Print(item, batchDate); + } } private void deleteBtn_Click(object sender, EventArgs e) diff --git a/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs b/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs new file mode 100644 index 0000000..f6737b7 --- /dev/null +++ b/ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs @@ -0,0 +1,74 @@ +using ButcherFactory.BO; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ButcherFactory.SegmentProduction_ +{ + public static class SegmentProductionPrint + { + static int id = 1; + public static void Print(SegmentProduction entity, DateTime? dt) + { + if (dt == null) + dt = DateTime.Today; + var dic = new Dictionary(); + dic.Add("$Goods_Name", entity.Goods_Name); + dic.Add("$Date", dt.Value.ToString("yyyy/MM/dd")); + var imgUrl = string.Format("TempImg\\_img{0}.png", id); + BwpClientPrint.BwpClientWebPrint.Create2DPic(entity.BarCode, imgUrl, 120); + dic.Add("$ImageUrl", imgUrl); + BwpClientPrint.BwpClientWebPrint.Print("SegmentationWeightPrint.html", dic); + AfterPrint(); + } + + public static void PrintEnd(IEnumerable list) + { + string firstRow = "{0}:{1}{2}"; + string template = "{0}:{1}{2}"; + var builder = new StringBuilder(); + bool first = true; + var count = list.GroupBy(x => x.Goods_Name).Count(); + foreach (var item in list.GroupBy(x => x.Goods_Name)) + { + var weight = item.Sum(x => x.Weight); + var num = item.Count(); + if (first) + { + builder.Append(string.Format(firstRow, item.Key, num, weight, count)); + first = false; + } + else + builder.Append(string.Format(template, item.Key, num, weight)); + } + var dic = new Dictionary(); + dic.Add("$tableContent", builder.ToString()); + var groupID = list.First().GroupID.ToString(); + var imgUrl = string.Format("TempImg\\_img{0}.png", id); + BwpClientPrint.BwpClientWebPrint.Create2DPic(groupID, imgUrl, 120); + dic.Add("$ImageUrl", imgUrl); + dic.Add("$DateTime", DateTime.Now.ToString("yyyy/MM/dd HH:ss")); + BwpClientPrint.BwpClientWebPrint.Print("SegmentationWeightPrintEnd.html", dic); + AfterPrint(); + } + + static DirectoryInfo TempImage = null; + private static void AfterPrint() + { + if (id == 20) + id = 0; + id++; + if (TempImage == null) + TempImage = new DirectoryInfo("TempImg"); + var files = TempImage.GetFiles(); + if (files.Length > 10) + { + var last = files.OrderBy(x => x.CreationTime).First().FullName; + File.Delete(last); + } + } + } +}