Browse Source

分割品称重加打印功能。

master
yibo 7 years ago
parent
commit
7b6e09c52e
3 changed files with 89 additions and 4 deletions
  1. +5
    -0
      ButcherFactory.Form/ButcherFactory.Form.csproj
  2. +10
    -4
      ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs
  3. +74
    -0
      ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs

+ 5
- 0
ButcherFactory.Form/ButcherFactory.Form.csproj View File

@ -34,6 +34,10 @@
</ApplicationIcon> </ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="BwpClientPrint, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tsref\Debug\BwpClientPrint.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
@ -118,6 +122,7 @@
<DependentUpon>SegmentProductionForm.cs</DependentUpon> <DependentUpon>SegmentProductionForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="SegmentProduction_\SegmentProductionFormConfig.cs" /> <Compile Include="SegmentProduction_\SegmentProductionFormConfig.cs" />
<Compile Include="SegmentProduction_\SegmentProductionPrint.cs" />
<Compile Include="SegmentProduction_\TrunOutDialog.cs"> <Compile Include="SegmentProduction_\TrunOutDialog.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>


+ 10
- 4
ButcherFactory.Form/SegmentProduction_/SegmentProductionForm.cs View File

@ -159,6 +159,8 @@ namespace ButcherFactory.SegmentProduction_
historyList.RemoveAt(100); historyList.RemoveAt(100);
historyDataGrid.FirstDisplayedScrollingRowIndex = 0; historyDataGrid.FirstDisplayedScrollingRowIndex = 0;
historyDataGrid.Refresh(); historyDataGrid.Refresh();
if (barPrintCheck.Checked)
SegmentProductionPrint.Print(entity, batchDate);
} }
void BindGrid() void BindGrid()
@ -217,9 +219,7 @@ namespace ButcherFactory.SegmentProduction_
item.GroupID = groupID; item.GroupID = groupID;
Start(false); Start(false);
if (barPrintCheck.Checked) if (barPrintCheck.Checked)
{
}
SegmentProductionPrint.PrintEnd(arr);
} }
else else
throw new Exception("本次开始之后未生产任何商品"); throw new Exception("本次开始之后未生产任何商品");
@ -267,7 +267,13 @@ namespace ButcherFactory.SegmentProduction_
private void rePrintBtn_Click(object sender, EventArgs e) 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) private void deleteBtn_Click(object sender, EventArgs e)


+ 74
- 0
ButcherFactory.Form/SegmentProduction_/SegmentProductionPrint.cs View File

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

Loading…
Cancel
Save