|
|
using ButcherFactory.BO;
|
|
|
using ButcherFactory.BO.Utils;
|
|
|
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;
|
|
|
const string PRINTFILE = @"PrintTemplate\SegmentProductionPrint.html";
|
|
|
const string ENDFILE = @"PrintTemplate\SegmentProductionPrintEnd.html";
|
|
|
const string IMGFILE = @"TempImg\_img{0}.png";
|
|
|
public static void Print(SegmentProduction entity, DateTime? dt)
|
|
|
{
|
|
|
if (AppContext.ConnectInfo.TraceBackUrl == "default")
|
|
|
throw new Exception("请先配置追溯服务器地址");
|
|
|
if (dt == null)
|
|
|
dt = DateTime.Today;
|
|
|
var dic = new Dictionary<string, string>();
|
|
|
dic.Add("$Goods_Name", entity.Goods_Name);
|
|
|
dic.Add("$Goods_Spec", entity.Goods_Spec);
|
|
|
dic.Add("$Date", dt.Value.ToString("yyyy/MM/dd"));
|
|
|
var imgUrl = string.Format(IMGFILE, id);
|
|
|
var url = string.Format(AppContext.ConnectInfo.TraceBackUrl + "?code={0}", entity.BarCode);
|
|
|
BwpClientPrint.BwpClientWebPrint.Create2DPic(url, imgUrl, 80);
|
|
|
dic.Add("$ImageUrl", imgUrl);
|
|
|
BwpClientPrint.BwpClientWebPrint.Print(PRINTFILE, dic);
|
|
|
AfterPrint();
|
|
|
}
|
|
|
|
|
|
public static void PrintEnd(List<SegmentProduction> list)
|
|
|
{
|
|
|
string firstRow = "<tr><td><span>{0}:</span></td><td>{1}</td><td>{2:#0.######}</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:#0.######}</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(IMGFILE, 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(ENDFILE, 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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|