| @ -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<string, string>(); | |||
| 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<SegmentProduction> list) | |||
| { | |||
| string firstRow = "<tr><td><span>{0}:</span></td><td>{1}</td><td>{2}</td><td rowspan='{3}' style='width:120px'><img src='$ImageUrl' style='width:120px;height:120px;margin-top:-5px;'/></td></tr>"; | |||
| string template = "<tr><td><span>{0}:</span></td><td>{1}</td><td>{2}</td></tr>"; | |||
| 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<string, string>(); | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| } | |||