增加固体饮料批号初版

This commit is contained in:
2026-04-29 09:52:08 +08:00
parent 7f7eb32ca3
commit add4308b91
17 changed files with 354 additions and 90 deletions

View File

@@ -255,7 +255,7 @@ namespace FATrace.App
ListRawCtrInfo = new List<RawCtrInfo>()
{
new RawCtrInfo(){
RawName="瑞士乳杆菌GCL1815",
RawName="瑞士乳杆菌(固体饮料)",
RawCode="1121000265",
BtnControlName="btnRawName1",
RawSource=RawSource.Japan
@@ -463,6 +463,7 @@ namespace FATrace.App
txtWeight.Text = CurSelectedRawProInput.Weight.ToString();
txtBatch.Text = CurSelectedRawProInput.Batch!;
txtSolidBeveBatch.Text = CurSelectedRawProInput.SolidBeveBatch ?? "";
txtShelfLife.Text = CurSelectedRawProInput.ShelfLife.ToString();
txtRemainWeight.Text = CurSelectedRawProInput.RemainWeight.ToString();
@@ -572,6 +573,7 @@ namespace FATrace.App
// 2) 读取并校验输入框
var weightText = (txtWeight.Text ?? string.Empty).Trim();
var batchText = (txtBatch.Text ?? string.Empty).Trim();
var solidBeveBatchText = (txtSolidBeveBatch.Text ?? string.Empty).Trim();
var shelfLifeText = (txtShelfLife.Text ?? string.Empty).Trim();
if (string.IsNullOrWhiteSpace(weightText) ||
@@ -596,6 +598,19 @@ namespace FATrace.App
return;
}
if (string.IsNullOrWhiteSpace(solidBeveBatchText))
{
MessageBox.Show("请输入固体饮料批次。", "校验失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtSolidBeveBatch.Focus();
return;
}
if (solidBeveBatchText.Length > 20)
{
MessageBox.Show("固体饮料批次长度不能超过20个字符。", "校验失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtSolidBeveBatch.Focus();
return;
}
if (string.IsNullOrWhiteSpace(shelfLifeText) ||
!int.TryParse(shelfLifeText.Replace('', '.').Replace('。', '.'), out var shelfLife) || shelfLife <= 0)
{
@@ -612,6 +627,7 @@ namespace FATrace.App
RawCode = CurSelectedRawProInput.RawCode,
Weight = Math.Round(weight, 2), // 保留3位小数避免浮点抖动
Batch = batchText,
SolidBeveBatch = solidBeveBatchText,
ShelfLife = shelfLife,
RawSource = CurSelectedRawProInput.RawSource,
RemainWeight = Math.Round(weight, 2),
@@ -687,7 +703,7 @@ namespace FATrace.App
MessageBox.Show("请先选择要称重的产品", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(CurSelectedRawProInput.RawName) || string.IsNullOrEmpty(CurSelectedRawProInput.Batch) || string.IsNullOrEmpty(CurSelectedRawProInput.RawCode))
if (string.IsNullOrEmpty(CurSelectedRawProInput.RawName) || string.IsNullOrEmpty(CurSelectedRawProInput.Batch) || string.IsNullOrEmpty(CurSelectedRawProInput.SolidBeveBatch) || string.IsNullOrEmpty(CurSelectedRawProInput.RawCode))
{
MessageBox.Show("选择的产品信息无数据,请信息输入后再操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
@@ -736,15 +752,21 @@ namespace FATrace.App
txtRemainWeight.Text = NewRemainWeight.ToString();
//二维码
var Code = GenCode(CurSelectedRawProInput.RawCode!, CurWeight, CurSelectedRawProInput.Batch!, CurSelectedRawProInput.ShelfLife, CurSelectedRawProInput.RawSource, CurDayCount.Count);
var solidBeveBatchForCode = (txtSolidBeveBatch.Text ?? string.Empty).Trim();
if (string.IsNullOrWhiteSpace(solidBeveBatchForCode))
{
solidBeveBatchForCode = CurSelectedRawProInput.SolidBeveBatch ?? string.Empty;
}
var Code = GenCode(CurSelectedRawProInput.RawCode!, CurWeight, CurSelectedRawProInput.Batch!, solidBeveBatchForCode, CurSelectedRawProInput.ShelfLife, CurSelectedRawProInput.RawSource, CurDayCount.Count);
// 执行打印
try
{
UpdateStatusLabel(tslPrintState, "正在打印...", Color.Goldenrod, Color.White);
CurZebraPrint.PrintWeight(Code, CurSelectedRawProInput.RawName!,
CurZebraPrint.PrintWeight(Code, GetSimpleCode(Code), CurSelectedRawProInput.RawName!,
CurWeight,
CurSelectedRawProInput.Batch!,
solidBeveBatchForCode,
CurSelectedRawProInput.ShelfLife
);
SetPrinterStatusOk("打印成功");
@@ -765,6 +787,7 @@ namespace FATrace.App
var Result = FSqlContext.FDb.Insert<RawProUse>(new RawProUse()
{
Batch = CurSelectedRawProInput.Batch,
SolidBeveBatch = solidBeveBatchForCode,
InBagCode = Code,
BoxCode = Code + ",A",
OpUser = CurrentOpUserNo,
@@ -833,6 +856,34 @@ namespace FATrace.App
}
}
/// <summary>
/// 获取简单的条码
/// 只要原料编码,批次,序号
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
private string GetSimpleCode(string code)
{
if (string.IsNullOrWhiteSpace(code))
return string.Empty;
var normalized = code.Trim()
.Replace('', ',')
.Replace('', ',')
.Replace(';', ',');
var parts = normalized.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 7)
return string.Empty;
// 原料编码,批次,序号(最后一段为 DayCount
var rawCode = parts[0].Trim();
var batch = parts[1].Trim();
var seq = parts[6].Trim();
return $"{rawCode},{batch},{seq}";
}
/// <summary>
/// 格式化重量显示自动适配整数部分位数2-4位小数部分固定2位
/// </summary>
@@ -900,6 +951,7 @@ namespace FATrace.App
{
txtWeight.Text = "";
txtBatch.Text = "";
txtSolidBeveBatch.Text = "";
txtShelfLife.Text = "";
txtRemainWeight.Text = "";
}
@@ -924,7 +976,7 @@ namespace FATrace.App
/// 生成条码信息
/// </summary>
/// <returns></returns>
public string GenCode(string RawCode, double Weight, string Batch, int ShelfLife, RawSource Source, int DayCount)
public string GenCode(string RawCode, double Weight, string Batch, string SolidBeveBatch, int ShelfLife, RawSource Source, int DayCount)
{
//二维码数据
var Code = new StringBuilder();
@@ -932,6 +984,8 @@ namespace FATrace.App
Code.Append(',');
Code.Append(Batch);
Code.Append(',');
Code.Append(SolidBeveBatch);
Code.Append(',');
Code.Append(FormatWeight(Weight).ToString().Replace(".", ""));
Code.Append(',');
Code.Append(ShelfLife.ToString());
@@ -1351,9 +1405,10 @@ namespace FATrace.App
try
{
UpdateStatusLabel(tslPrintState, "正在打印...", Color.Goldenrod, Color.White);
CurZebraPrint.PrintWeight(LastData.InBagCode!, CurSelectedRawProInput.RawName!,
CurZebraPrint.PrintWeight(LastData.InBagCode!, GetSimpleCode(LastData.InBagCode!), CurSelectedRawProInput.RawName!,
CurWeight,
CurSelectedRawProInput.Batch!,
LastData.SolidBeveBatch ?? "",
CurSelectedRawProInput.ShelfLife
);
SetPrinterStatusOk("打印成功");