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); } } } }