增加线性工件校准 增加信号变化日志记录

This commit is contained in:
XingCheng3
2026-05-13 00:30:32 +08:00
parent 1e908cf72f
commit 14ff9fa4c3
10 changed files with 2182 additions and 2040 deletions

View File

@@ -13,7 +13,6 @@ namespace MesWork
private class CalibrationCache private class CalibrationCache
{ {
public string ToolName; public string ToolName;
public string CalibrationValue;
public string Formula; public string Formula;
public string Description; public string Description;
public DateTime LoadedAt; public DateTime LoadedAt;
@@ -29,10 +28,17 @@ namespace MesWork
formula = "x"; formula = "x";
message = ""; message = "";
if (!TryGetConfig(opName, out CalibrationCache config, out string queryMsg)) if (!TryGetConfig(opName, rawWeight, out CalibrationCache config, out string queryMsg))
{ {
message = string.IsNullOrWhiteSpace(queryMsg) ? "未找到工具标定配置" : queryMsg; if (!string.IsNullOrWhiteSpace(queryMsg))
return false; {
message = queryMsg;
return false;
}
formula = "x";
calibratedWeight = rawWeight;
return true;
} }
formula = NormalizeFormula(config.Formula); formula = NormalizeFormula(config.Formula);
@@ -94,11 +100,12 @@ namespace MesWork
} }
} }
private static bool TryGetConfig(string opName, out CalibrationCache config, out string message) private static bool TryGetConfig(string opName, decimal rawWeight, out CalibrationCache config, out string message)
{ {
config = null; config = null;
message = ""; message = "";
string key = string.IsNullOrWhiteSpace(opName) ? "" : opName.Trim(); string station = string.IsNullOrWhiteSpace(opName) ? "" : opName.Trim();
string key = station + "|" + rawWeight.ToString("F3", CultureInfo.InvariantCulture);
lock (CacheLock) lock (CacheLock)
{ {
@@ -108,7 +115,7 @@ namespace MesWork
} }
} }
if (!B_DB_Opera.QueryToolCalibration(key, out string toolName, out string calibrationValue, out string formula, out string description, out message)) if (!B_DB_Opera.QueryToolCalibration(station, rawWeight, out string toolName, out string formula, out string description, out message))
{ {
return false; return false;
} }
@@ -116,7 +123,6 @@ namespace MesWork
config = new CalibrationCache config = new CalibrationCache
{ {
ToolName = toolName, ToolName = toolName,
CalibrationValue = calibrationValue,
Formula = formula, Formula = formula,
Description = description, Description = description,
LoadedAt = DateTime.Now LoadedAt = DateTime.Now

View File

@@ -52,16 +52,14 @@ namespace MesWork
} }
public static void Event_Signal_Log(string opName, int tagTypeCodeID, string value, string tagID) public static void Event_Signal_Log(string opName, int tagTypeCodeID, string signalName, string value)
{ {
var ChangeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
var procedureName = "Event_Signal_Log"; var procedureName = "Event_Signal_Log";
var sqlParameter = new SqlParameter[] { var sqlParameter = new SqlParameter[] {
new SqlParameter("@OpName", opName), new SqlParameter("@OpName", opName),
new SqlParameter("@TagTypeCodeID", tagTypeCodeID), new SqlParameter("@TagTypeCodeID", tagTypeCodeID),
new SqlParameter("@Value", value), new SqlParameter("@SignalName", signalName),
new SqlParameter("@ChangeTime",ChangeTime), new SqlParameter("@TagValue", value)
new SqlParameter("@TagID", tagID)
}; };
SqlOperation.ExecuteStoredProcedure(procedureName, sqlParameter, out string errorMessage); SqlOperation.ExecuteStoredProcedure(procedureName, sqlParameter, out string errorMessage);
@@ -261,49 +259,37 @@ namespace MesWork
} }
/// <summary> /// <summary>
/// 查询指定工位的工具标定配置。 /// 查询指定工位和原始重量匹配的工具标定配置。
/// </summary> /// </summary>
public static bool QueryToolCalibration(string opName, out string toolName, out string calibrationValue, out string formula, out string description, out string msg) public static bool QueryToolCalibration(string opName, decimal rawWeight, out string toolName, out string formula, out string description, out string msg)
{ {
toolName = ""; toolName = "";
calibrationValue = "";
formula = ""; formula = "";
description = ""; description = "";
msg = ""; msg = "";
try var sqlParameter = new SqlParameter[] {
new SqlParameter("@工位号", opName ?? ""),
new SqlParameter("@重量", rawWeight)
};
SqlOperation.ExecuteStoredProcedure("工具管理_查询匹配标定", sqlParameter, out DataTable dt, out string err);
if (dt == null)
{ {
using (var conn = new SqlConnection(MesWorkForm.ConnectionString)) msg = string.IsNullOrWhiteSpace(err) ? $"查询[{opName}]工具标定配置失败" : err;
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = @"
SELECT TOP 1 [工具名称], [重量标定], [计算公式], [说明]
FROM [工具管理]
WHERE [工位号] = @工位号
ORDER BY [ID]";
cmd.Parameters.Add(new SqlParameter("@工位号", opName ?? ""));
conn.Open();
using (var reader = cmd.ExecuteReader())
{
if (!reader.Read())
{
msg = $"未找到[{opName}]工具标定配置";
return false;
}
toolName = reader["工具名称"]?.ToString() ?? "";
calibrationValue = reader["重量标定"]?.ToString() ?? "";
formula = reader["计算公式"]?.ToString() ?? "";
description = reader["说明"]?.ToString() ?? "";
return true;
}
}
}
catch (Exception err)
{
msg = $"查询[{opName}]工具标定配置失败:{err.Message}";
return false; return false;
} }
if (dt.Rows.Count == 0)
{
msg = "";
return false;
}
var row = dt.Rows[0];
toolName = row["工具名称"]?.ToString() ?? "";
formula = row["计算公式"]?.ToString() ?? "";
description = row["说明"]?.ToString() ?? "";
return true;
} }
/// <summary> /// <summary>

View File

@@ -39,6 +39,12 @@ namespace MesWork
tagValue = msgEvent.TagValue.ToString(); tagValue = msgEvent.TagValue.ToString();
break; break;
} }
// ── 监控变量变化记录(首次值除外,不影响主流程)──
if (!ValueT(isFirstValue))
{
var signalName = string.IsNullOrWhiteSpace(alarmMsg) ? tagID : alarmMsg;
SaveSignalChangeLog(opName, tagTypeCodeID, signalName, tagValue);
}
// ── 报警处理编码900~2000── // ── 报警处理编码900~2000──
if (tagTypeCodeID >= 900 & tagTypeCodeID < 2000) if (tagTypeCodeID >= 900 & tagTypeCodeID < 2000)
{ {
@@ -61,7 +67,8 @@ namespace MesWork
switch (tagTypeCodeID) switch (tagTypeCodeID)
{ {
case 2: // 工件到位/离开 case 2: // 工件到位/离开
WritePLC_IF(112, opName, 0); // 报警代码清空 // WritePLC_IF(112, opName, 0); // 报警代码清空
ClearStationDisplay(opName);
break; break;
case 14: // PLC心跳 → 回写PC心跳 case 14: // PLC心跳 → 回写PC心跳
WritePLC_IF(15, opName, tagValue); WritePLC_IF(15, opName, tagValue);
@@ -108,6 +115,22 @@ namespace MesWork
WeighingPage?.AppendLog(errMsg); WeighingPage?.AppendLog(errMsg);
} }
} }
/// <summary>
/// 记录监控变量变化异常不影响PLC主流程。
/// </summary>
private void SaveSignalChangeLog(string opName, int tagTypeCodeID, string signalName, string tagValue)
{
try
{
B_DB_Opera.Event_Signal_Log(opName, tagTypeCodeID, signalName, tagValue);
}
catch
{
// 变化记录失败不干涉PLC信号主流程
}
}
// ==================================================================== // ====================================================================
// 称重交互核心方法 // 称重交互核心方法
// ==================================================================== // ====================================================================
@@ -123,6 +146,35 @@ namespace MesWork
// Hanging模式 // Hanging模式
return opName == "OP10" ? "放油前" : "放油后"; return opName == "OP10" ? "放油前" : "放油后";
} }
/// <summary>
/// 清除工位显示信息(工件离开时调用)
/// </summary>
private void ClearStationDisplay(string opName)
{
try
{
int stIdx = WeighingPage?.GetStationIndex(opName) ?? 1;
// 清除工件信息
WeighingPage?.UpdateStationInfo(stIdx, "", "", "");
// 清除油量参数信息
WeighingPage?.UpdateOilInfo(stIdx, 0, 0, 0, 0, 0);
// 清除结果信息
WeighingPage?.UpdateOilResult(stIdx, 0, 0);
WeighingPage?.ClearSaveResult(stIdx);
}
catch (Exception err)
{
WeighingPage?.AppendLog($"[{opName}] 清除显示异常:{err.Message}");
}
}
/// <summary> /// <summary>
/// 码块数据转换:将产品编号统一转大写,并拆分出订货号与产品编号 /// 码块数据转换:将产品编号统一转大写,并拆分出订货号与产品编号
/// 支持格式: /// 支持格式:
@@ -192,7 +244,7 @@ namespace MesWork
if (!B_DB_Opera.QueryWorkpieceByOrderNo(orderNo, out string matchedModelNo, out decimal addOilQty, out decimal extractOilQty, out decimal density, if (!B_DB_Opera.QueryWorkpieceByOrderNo(orderNo, out string matchedModelNo, out decimal addOilQty, out decimal extractOilQty, out decimal density,
out decimal residualOilUpperLimit, out decimal residualOilLowerLimit)) // 根据订货号 查询基本参数 out decimal residualOilUpperLimit, out decimal residualOilLowerLimit)) // 根据订货号 查询基本参数
{ {
WritePLC_IF(112, opName, 3); // 报警代码=3机型错误 // WritePLC_IF(112, opName, 3); // 报警代码=3机型错误
LogWeighingFallback(opName, engineNo, "请求工作", $"订货号[{orderNo}]未匹配到工件参数使用PLC机型[{modelNo}]继续允许工作", AID); LogWeighingFallback(opName, engineNo, "请求工作", $"订货号[{orderNo}]未匹配到工件参数使用PLC机型[{modelNo}]继续允许工作", AID);
// 兜底机制参数资料缺失不再卡PLC请求保存时若无法正常更新记录会生成异常完成记录。 // 兜底机制参数资料缺失不再卡PLC请求保存时若无法正常更新记录会生成异常完成记录。
WritePLC_IF(66, opName, true); WritePLC_IF(66, opName, true);
@@ -213,7 +265,7 @@ namespace MesWork
// 空中放油后:查找最新放油前记录(无论是否完成,支持多次测量) // 空中放油后:查找最新放油前记录(无论是否完成,支持多次测量)
if (!B_DB_Opera.QueryWeighingBeforeOil(engineNo, out _, out decimal preWeight, out _, out _, out _)) if (!B_DB_Opera.QueryWeighingBeforeOil(engineNo, out _, out decimal preWeight, out _, out _, out _))
{ {
WritePLC_IF(112, opName, 3); // WritePLC_IF(112, opName, 3);
LogWeighingFallback(opName, engineNo, "请求工作-放油后", "未找到放油前记录,继续允许工作,保存时按异常放油后记录处理", AID); LogWeighingFallback(opName, engineNo, "请求工作-放油后", "未找到放油前记录,继续允许工作,保存时按异常放油后记录处理", AID);
} }
else else
@@ -235,7 +287,7 @@ namespace MesWork
} }
else else
{ {
WritePLC_IF(112, opName, 1); // 报警代码=1获取数据失败 // WritePLC_IF(112, opName, 1); // 报警代码=1获取数据失败
engineNo = string.IsNullOrWhiteSpace(rawCodeBlock) ? $"未知产品_{opName}_{DateTime.Now:yyyyMMddHHmmss}" : rawCodeBlock.Trim(); engineNo = string.IsNullOrWhiteSpace(rawCodeBlock) ? $"未知产品_{opName}_{DateTime.Now:yyyyMMddHHmmss}" : rawCodeBlock.Trim();
LogWeighingFallback(opName, engineNo, "请求工作", $"码块数据转换失败,原始码值=[{rawCodeBlock}],仍允许工作", AID); LogWeighingFallback(opName, engineNo, "请求工作", $"码块数据转换失败,原始码值=[{rawCodeBlock}],仍允许工作", AID);
// 兜底机制:产品解析失败时仍给允许工作,后续保存阶段会按异常产品记录并判不合格。 // 兜底机制:产品解析失败时仍给允许工作,后续保存阶段会按异常产品记录并判不合格。
@@ -245,7 +297,7 @@ namespace MesWork
} }
catch (Exception err) catch (Exception err)
{ {
WritePLC_IF(112, opName, 1); // 报警代码=1获取数据失败 //WritePLC_IF(112, opName, 1); // 报警代码=1获取数据失败
B_DB_Opera.SaveLog_Response($"【{opName}】请求工作处理失败:{err.Message}", AID); B_DB_Opera.SaveLog_Response($"【{opName}】请求工作处理失败:{err.Message}", AID);
} }
} }
@@ -295,6 +347,7 @@ namespace MesWork
long curveWeighingRecordId = 0; long curveWeighingRecordId = 0;
B_DB_Opera.UpdateStationComplete(engineNo, opName, weight); // 过站记录保存最终采用重量 B_DB_Opera.UpdateStationComplete(engineNo, opName, weight); // 过站记录保存最终采用重量
WeighingPage?.UpdateFinalWeight(WeighingPage?.GetStationIndex(opName) ?? 1, weight);
string weighType = GetWeighingType(opName); string weighType = GetWeighingType(opName);
decimal oilReleaseQty = 0; decimal oilReleaseQty = 0;
decimal residualOilQty = 0; decimal residualOilQty = 0;
@@ -393,7 +446,7 @@ namespace MesWork
catch (Exception err) catch (Exception err)
{ {
CurveCollector_EndSegment(opName, 0); CurveCollector_EndSegment(opName, 0);
WritePLC_IF(112, opName, 2); // 报警代码=2保存失败 // WritePLC_IF(112, opName, 2); // 报警代码=2保存失败
B_DB_Opera.SaveLog_Response($"【{opName}】保存处理失败:{err.Message}", AID); B_DB_Opera.SaveLog_Response($"【{opName}】保存处理失败:{err.Message}", AID);
WeighingPage?.AppendLog($"[{opName}] ❌ 保存异常:{err.Message}"); WeighingPage?.AppendLog($"[{opName}] ❌ 保存异常:{err.Message}");
} }

View File

@@ -37,7 +37,7 @@ namespace MesWork.Pages
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "发动机号", HeaderText = "发动机号", DataPropertyName = "发动机号", FillWeight = 100 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "发动机号", HeaderText = "发动机号", DataPropertyName = "发动机号", FillWeight = 100 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "机型号", HeaderText = "机型号", DataPropertyName = "机型号", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "机型号", HeaderText = "机型号", DataPropertyName = "机型号", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "订单号", HeaderText = "订号", DataPropertyName = "订单号", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "订单号", HeaderText = "订号", DataPropertyName = "订单号", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "进站重量", HeaderText = "进站重量(KG)", DataPropertyName = "进站重量", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "进站重量", HeaderText = "进站重量(KG)", DataPropertyName = "进站重量", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "离站重量", HeaderText = "离站重量(KG)", DataPropertyName = "离站重量", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "离站重量", HeaderText = "离站重量(KG)", DataPropertyName = "离站重量", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "加油量", HeaderText = "加油量", DataPropertyName = "加油量", FillWeight = 60 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "加油量", HeaderText = "加油量", DataPropertyName = "加油量", FillWeight = 60 });

View File

@@ -33,7 +33,7 @@ namespace MesWork.Pages
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "发动机号", HeaderText = "发动机号", DataPropertyName = "发动机号", FillWeight = 100 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "发动机号", HeaderText = "发动机号", DataPropertyName = "发动机号", FillWeight = 100 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "机型号", HeaderText = "机型号", DataPropertyName = "机型号", FillWeight = 70 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "机型号", HeaderText = "机型号", DataPropertyName = "机型号", FillWeight = 70 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工单号", HeaderText = "订号", DataPropertyName = "工单号", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工单号", HeaderText = "订号", DataPropertyName = "工单号", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工位号", HeaderText = "工位号", DataPropertyName = "工位号", FillWeight = 60 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工位号", HeaderText = "工位号", DataPropertyName = "工位号", FillWeight = 60 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工位名称", HeaderText = "工位名称", DataPropertyName = "工位名称", FillWeight = 70 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工位名称", HeaderText = "工位名称", DataPropertyName = "工位名称", FillWeight = 70 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "到站时间", HeaderText = "到达时间", DataPropertyName = "到站时间", FillWeight = 110, dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "到站时间", HeaderText = "到达时间", DataPropertyName = "到站时间", FillWeight = 110,

View File

@@ -103,7 +103,7 @@ namespace MesWork.Pages
this.txt_ModelNo.Name = "txt_ModelNo"; this.txt_ModelNo.Name = "txt_ModelNo";
this.txt_ModelNo.Size = new System.Drawing.Size(140, 27); this.txt_ModelNo.Size = new System.Drawing.Size(140, 27);
// //
// txt_OrderNo — 订号筛选 // txt_OrderNo — 订号筛选
// //
this.txt_OrderNo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txt_OrderNo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txt_OrderNo.Font = new System.Drawing.Font("微软雅黑", 10F); this.txt_OrderNo.Font = new System.Drawing.Font("微软雅黑", 10F);

View File

@@ -42,7 +42,7 @@ namespace MesWork.Pages
// 为筛选框加占位提示 // 为筛选框加占位提示
SetHint(txt_ModelNo, "机型号筛选..."); SetHint(txt_ModelNo, "机型号筛选...");
SetHint(txt_OrderNo, "订号筛选..."); SetHint(txt_OrderNo, "订号筛选...");
} }
private void SetHint(TextBox txt, string hint) private void SetHint(TextBox txt, string hint)
@@ -70,7 +70,7 @@ namespace MesWork.Pages
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "测试时间", HeaderText = "检测时间", DataPropertyName = "测试时间", FillWeight = 100 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "测试时间", HeaderText = "检测时间", DataPropertyName = "测试时间", FillWeight = 100 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "发动机号", HeaderText = "工件编号", DataPropertyName = "发动机号", FillWeight = 100 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "发动机号", HeaderText = "工件编号", DataPropertyName = "发动机号", FillWeight = 100 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "订单号", HeaderText = "订号", DataPropertyName = "订单号", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "订单号", HeaderText = "订号", DataPropertyName = "订单号", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "机型号", HeaderText = "机型号", DataPropertyName = "机型号", FillWeight = 70 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "机型号", HeaderText = "机型号", DataPropertyName = "机型号", FillWeight = 70 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "残留量", HeaderText = "机油残留(mg)", DataPropertyName = "残留量", FillWeight = 80 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "残留量", HeaderText = "机油残留(mg)", DataPropertyName = "残留量", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "设备编号", HeaderText = "设备编号", DataPropertyName = "设备编号", FillWeight = 60 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "设备编号", HeaderText = "设备编号", DataPropertyName = "设备编号", FillWeight = 60 });

View File

@@ -7,8 +7,8 @@ using System.Windows.Forms;
namespace MesWork.Pages namespace MesWork.Pages
{ {
/// <summary> /// <summary>
/// 工具标定页面 — 固定维护OP10/OP20重量标定公式。 /// 工具标定页面 — 按工位和重量范围维护分段标定公式。
/// 对应存储过程工具管理_分页查询、工具管理_编辑 /// 对应存储过程工具管理_分页查询、工具管理_增加、工具管理_编辑、工具管理_删除
/// </summary> /// </summary>
public partial class UC_ToolMgmt : UserControl public partial class UC_ToolMgmt : UserControl
{ {
@@ -24,9 +24,6 @@ namespace MesWork.Pages
this.Controls.Remove(pnl_StatusBar); this.Controls.Remove(pnl_StatusBar);
this.Controls.Add(_pager); this.Controls.Add(_pager);
this.Controls.SetChildIndex(_pager, this.Controls.Count - 2); this.Controls.SetChildIndex(_pager, this.Controls.Count - 2);
btn_Add.Visible = false;
btn_Delete.Visible = false;
btn_Edit.Location = btn_Delete.Location;
} }
/// <summary> /// <summary>
@@ -39,8 +36,11 @@ namespace MesWork.Pages
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "ID", HeaderText = "ID", DataPropertyName = "ID", Visible = false });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工位号", HeaderText = "工位号", DataPropertyName = "工位号", FillWeight = 70 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工位号", HeaderText = "工位号", DataPropertyName = "工位号", FillWeight = 70 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工具名称", HeaderText = "工具名称", DataPropertyName = "工具名称", FillWeight = 120 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "工具名称", HeaderText = "工具名称", DataPropertyName = "工具名称", FillWeight = 120 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "最小重量", HeaderText = "最小重量(KG)", DataPropertyName = "最小重量", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "最大重量", HeaderText = "最大重量(KG)", DataPropertyName = "最大重量", FillWeight = 80 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "计算公式", HeaderText = "计算公式", DataPropertyName = "计算公式", FillWeight = 150 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "计算公式", HeaderText = "计算公式", DataPropertyName = "计算公式", FillWeight = 150 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "说明", HeaderText = "说明", DataPropertyName = "说明", FillWeight = 180 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "说明", HeaderText = "说明", DataPropertyName = "说明", FillWeight = 180 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "创建时间", HeaderText = "创建时间", DataPropertyName = "创建时间", FillWeight = 100 });
dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "修改时间", HeaderText = "修改时间", DataPropertyName = "修改时间", FillWeight = 100 }); dgv_Data.Columns.Add(new DataGridViewTextBoxColumn { Name = "修改时间", HeaderText = "修改时间", DataPropertyName = "修改时间", FillWeight = 100 });
} }
@@ -74,13 +74,29 @@ namespace MesWork.Pages
// ── 按钮事件 ── // ── 按钮事件 ──
private void btn_Search_Click(object sender, EventArgs e) { _pager.ResetPage(); LoadData(txt_Search.Text == SEARCH_HINT ? "" : txt_Search.Text.Trim()); } private void btn_Search_Click(object sender, EventArgs e) { _pager.ResetPage(); LoadData(txt_Search.Text == SEARCH_HINT ? "" : txt_Search.Text.Trim()); }
private void btn_Add_Click(object sender, EventArgs e) { } private void btn_Add_Click(object sender, EventArgs e) => ShowEditDialog(null);
private void btn_Edit_Click(object sender, EventArgs e) private void btn_Edit_Click(object sender, EventArgs e)
{ {
if (dgv_Data.CurrentRow != null) ShowEditDialog(dgv_Data.CurrentRow); if (dgv_Data.CurrentRow != null) ShowEditDialog(dgv_Data.CurrentRow);
else MessageBox.Show("请先选择一条记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("请先选择一条记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void btn_Delete_Click(object sender, EventArgs e) { } private void btn_Delete_Click(object sender, EventArgs e)
{
if (dgv_Data.CurrentRow == null) { MessageBox.Show("请先选择一条记录", "提示"); return; }
string station = dgv_Data.CurrentRow.Cells["工位号"]?.Value?.ToString() ?? "";
string range = $"{dgv_Data.CurrentRow.Cells[""]?.Value}-{dgv_Data.CurrentRow.Cells[""]?.Value}";
if (MessageBox.Show($"确认删除「{station}」重量范围 {range} 的标定公式?", "确认删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
try
{
var parms = new SqlParameter[] { new SqlParameter("@ID", int.Parse(dgv_Data.CurrentRow.Cells["ID"]?.Value?.ToString() ?? "0")) };
SqlOperation.ExecuteStoredProcedure("工具管理_删除", parms, out string err);
WeightCalibrationHelper.ClearCache();
LoadData();
}
catch (Exception ex) { MessageBox.Show($"删除失败:{ex.Message}"); }
}
}
private void btn_Refresh_Click(object sender, EventArgs e) { _pager.ResetPage(); LoadData(""); } private void btn_Refresh_Click(object sender, EventArgs e) { _pager.ResetPage(); LoadData(""); }
private void dgv_Data_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) btn_Edit_Click(sender, e); } private void dgv_Data_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) btn_Edit_Click(sender, e); }
@@ -89,38 +105,63 @@ namespace MesWork.Pages
/// </summary> /// </summary>
private void ShowEditDialog(DataGridViewRow row) private void ShowEditDialog(DataGridViewRow row)
{ {
if (row == null) return; bool isEdit = row != null;
using (var dlg = CrudHelper.CreateEditDialog("修改工具标定", 520, 360)) using (var dlg = CrudHelper.CreateEditDialog(isEdit ? "修改分段标定" : "新增分段标定", 560, 430))
{ {
int y = 20; int y = 20;
var txtStation = CrudHelper.AddTextField(dlg, "工位号:", ref y, row.Cells["工位号"]?.Value?.ToString(), inputWidth: 320); var cmbStation = AddStationComboField(dlg, "工位号:", ref y, isEdit ? row.Cells["工位号"]?.Value?.ToString() : "");
txtStation.ReadOnly = true; var txtName = CrudHelper.AddTextField(dlg, "工具名称:", ref y, isEdit ? row.Cells["工具名称"]?.Value?.ToString() : "", inputWidth: 360);
txtStation.BackColor = Color.FromArgb(245, 247, 250); var txtMinWeight = CrudHelper.AddTextField(dlg, "最小重量:", ref y, isEdit ? row.Cells["最小重量"]?.Value?.ToString() : "0", inputWidth: 360);
var txtName = CrudHelper.AddTextField(dlg, "工具名称", ref y, row.Cells["工具名称"]?.Value?.ToString(), inputWidth: 320); var txtMaxWeight = CrudHelper.AddTextField(dlg, "最大重量", ref y, isEdit ? row.Cells["最大重量"]?.Value?.ToString() : "", inputWidth: 360);
var txtFormula = CrudHelper.AddTextField(dlg, "计算公式:", ref y, row.Cells["计算公式"]?.Value?.ToString(), inputWidth: 320); var txtFormula = CrudHelper.AddTextField(dlg, "计算公式:", ref y, isEdit ? row.Cells["计算公式"]?.Value?.ToString() : "x", inputWidth: 360);
var txtDesc = CrudHelper.AddTextField(dlg, "说明:", ref y, row.Cells["说明"]?.Value?.ToString(), inputWidth: 320); var txtDesc = CrudHelper.AddTextField(dlg, "说明:", ref y, isEdit ? row.Cells["说明"]?.Value?.ToString() : "X为重量结果值可对重量进行科学标定", inputWidth: 360);
CrudHelper.AddDialogButtons(dlg, ref y); CrudHelper.AddDialogButtons(dlg, ref y);
if (dlg.ShowDialog() == DialogResult.OK) if (dlg.ShowDialog() == DialogResult.OK)
{ {
try try
{ {
string station = cmbStation.Text.Trim();
if (string.IsNullOrWhiteSpace(station))
{
MessageBox.Show("工位号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (!decimal.TryParse(txtMinWeight.Text.Trim(), out decimal minWeight) ||
!decimal.TryParse(txtMaxWeight.Text.Trim(), out decimal maxWeight))
{
MessageBox.Show("最小重量和最大重量必须是数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (minWeight >= maxWeight)
{
MessageBox.Show("最小重量必须小于最大重量", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (!WeightCalibrationHelper.ValidateFormula(txtFormula.Text.Trim(), out string formulaMsg)) if (!WeightCalibrationHelper.ValidateFormula(txtFormula.Text.Trim(), out string formulaMsg))
{ {
MessageBox.Show(formulaMsg, "公式错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show(formulaMsg, "公式错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
string sp = isEdit ? "工具管理_编辑" : "工具管理_增加";
var pList = new System.Collections.Generic.List<SqlParameter> var pList = new System.Collections.Generic.List<SqlParameter>
{ {
new SqlParameter("@ID", int.Parse(row.Cells["ID"]?.Value?.ToString() ?? "0")), new SqlParameter("@工位号", station),
new SqlParameter("@工位号", txtStation.Text.Trim()),
new SqlParameter("@工具名称", txtName.Text.Trim()), new SqlParameter("@工具名称", txtName.Text.Trim()),
new SqlParameter("@最小重量", minWeight),
new SqlParameter("@最大重量", maxWeight),
new SqlParameter("@计算公式", txtFormula.Text.Trim()), new SqlParameter("@计算公式", txtFormula.Text.Trim()),
new SqlParameter("@说明", txtDesc.Text.Trim()), new SqlParameter("@说明", txtDesc.Text.Trim()),
}; };
SqlOperation.ExecuteStoredProcedure("工具管理_编辑", pList.ToArray(), out string err); if (isEdit) pList.Insert(0, new SqlParameter("@ID", int.Parse(row.Cells["ID"]?.Value?.ToString() ?? "0")));
SqlOperation.ExecuteStoredProcedure(sp, pList.ToArray(), out DataTable dt, out string err);
if (dt != null && dt.Rows.Count > 0 && dt.Rows[0]["result"].ToString() != "1")
{
MessageBox.Show(dt.Rows[0]["msg"].ToString(), "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
WeightCalibrationHelper.ClearCache(); WeightCalibrationHelper.ClearCache();
LoadData(); LoadData();
} }
@@ -148,5 +189,27 @@ namespace MesWork.Pages
} }
protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); if (Visible && dgv_Data.DataSource == null) LoadData(); } protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); if (Visible && dgv_Data.DataSource == null) LoadData(); }
private ComboBox AddStationComboField(Form dlg, string label, ref int y, string selected)
{
dlg.Controls.Add(new Label { Text = label, Location = new Point(30, y + 4), AutoSize = true });
var cmb = new ComboBox
{
Location = new Point(130, y),
Size = new Size(360, 28),
DropDownStyle = ComboBoxStyle.DropDown
};
foreach (string opName in MesWorkForm.StationOpNames)
{
if (!string.IsNullOrWhiteSpace(opName) && !cmb.Items.Contains(opName))
cmb.Items.Add(opName);
}
cmb.Text = selected ?? "";
dlg.Controls.Add(cmb);
y += 42;
return cmb;
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -253,7 +253,9 @@ namespace MesWork.Pages
ConfigureWeightCard(weightBox, weightTitle, weightValue, weightUnit, topCardWidth, 128, 41F); ConfigureWeightCard(weightBox, weightTitle, weightValue, weightUnit, topCardWidth, 128, 41F);
weightBox.Location = new Point(margin, weightY); weightBox.Location = new Point(margin, weightY);
ConfigureMetricCard(station, waterBox, waterTitle, waterValue, waterUnit, "水含量", "ppm", margin + topCardWidth + gap, weightY, topCardWidth, 128, 28F); ConfigureMetricCard(station, waterBox, waterTitle, waterValue, waterUnit, "最终重量", "KG", margin + topCardWidth + gap, weightY, topCardWidth, 128, 28F);
if (string.IsNullOrWhiteSpace(waterValue.Text) || waterValue.Text == "0.00")
waterValue.Text = "0.000";
metricBox.BackColor = Color.White; metricBox.BackColor = Color.White;
metricBox.Location = new Point(margin, metricY); metricBox.Location = new Point(margin, metricY);
@@ -266,7 +268,9 @@ namespace MesWork.Pages
ConfigureMetricCard(metricBox, extractOilBox, extractOilTitle, extractOilValue, extractOilUnit, "抽油量", "L", (metricCardWidth + gap) * 2, 0, metricCardWidth, 74, 18F); ConfigureMetricCard(metricBox, extractOilBox, extractOilTitle, extractOilValue, extractOilUnit, "抽油量", "L", (metricCardWidth + gap) * 2, 0, metricCardWidth, 74, 18F);
ConfigureMetricCard(metricBox, oilReleaseBox, oilReleaseTitle, oilReleaseValue, oilReleaseUnit, "放油量", "L", 0, 74 + metricRowGap, metricCardWidth, 74, 18F); ConfigureMetricCard(metricBox, oilReleaseBox, oilReleaseTitle, oilReleaseValue, oilReleaseUnit, "放油量", "L", 0, 74 + metricRowGap, metricCardWidth, 74, 18F);
ConfigureMetricCard(metricBox, residualOilBox, residualOilTitle, residualOilValue, residualOilUnit, "残油量", "L", metricCardWidth + gap, 74 + metricRowGap, metricCardWidth, 74, 18F); ConfigureMetricCard(metricBox, residualOilBox, residualOilTitle, residualOilValue, residualOilUnit, "残油量", "L", metricCardWidth + gap, 74 + metricRowGap, metricCardWidth, 74, 18F);
ConfigureMetricCard(metricBox, qualityBox, qualityTitle, qualityValue, null, "合格结果", "", (metricCardWidth + gap) * 2, 74 + metricRowGap, metricCardWidth, 74, 18F); ConfigureMetricCard(metricBox, qualityBox, qualityTitle, qualityValue, null, "水含量", "", (metricCardWidth + gap) * 2, 74 + metricRowGap, metricCardWidth, 74, 18F);
if (string.IsNullOrWhiteSpace(qualityValue.Text) || qualityValue.Text == "--" || qualityValue.Text == "0.00")
qualityValue.Text = "0.00 ppm";
} }
private void LayoutStationHeaderSection( private void LayoutStationHeaderSection(
@@ -597,7 +601,7 @@ namespace MesWork.Pages
waterValue.Font = new Font("微软雅黑", 18F, FontStyle.Bold); waterValue.Font = new Font("微软雅黑", 18F, FontStyle.Bold);
waterValue.Location = new Point(660, 401); waterValue.Location = new Point(660, 401);
waterValue.Size = new Size(599, 164); waterValue.Size = new Size(599, 164);
waterValue.Text = "水含0.00 ppm"; waterValue.Text = "最终重0.000 KG";
waterValue.TextAlign = ContentAlignment.MiddleCenter; waterValue.TextAlign = ContentAlignment.MiddleCenter;
waterValue.AutoSize = false; waterValue.AutoSize = false;
@@ -610,7 +614,7 @@ namespace MesWork.Pages
ConfigureDesignerMetricLabel(extractOilValue, "抽油量0.00", 840, 0); ConfigureDesignerMetricLabel(extractOilValue, "抽油量0.00", 840, 0);
ConfigureDesignerMetricLabel(oilReleaseValue, "放油量0.00", 0, 93); ConfigureDesignerMetricLabel(oilReleaseValue, "放油量0.00", 0, 93);
ConfigureDesignerMetricLabel(residualOilValue, "残油量0.00", 420, 93); ConfigureDesignerMetricLabel(residualOilValue, "残油量0.00", 420, 93);
ConfigureDesignerMetricLabel(qualityValue, "合格结果:--", 840, 93); ConfigureDesignerMetricLabel(qualityValue, "水含量0.00 ppm", 840, 93);
alarmLabel.Font = new Font("微软雅黑", 13F, FontStyle.Bold); alarmLabel.Font = new Font("微软雅黑", 13F, FontStyle.Bold);
alarmLabel.Location = new Point(30, 792); alarmLabel.Location = new Point(30, 792);
@@ -679,12 +683,12 @@ namespace MesWork.Pages
{ {
if (!string.IsNullOrEmpty(_op1)) if (!string.IsNullOrEmpty(_op1))
PollStation(1, _op1, _s1Signals, PollStation(1, _op1, _s1Signals,
lbl_S1_Weight, lbl_S1_Info1, lbl_S1_Info2, lbl_S1_Weight, lbl_S1_QualityVal, lbl_S1_Info2,
lbl_S1_PalletVal, lbl_S1_AlarmVal); lbl_S1_PalletVal, lbl_S1_AlarmVal);
if (!string.IsNullOrEmpty(_op2)) if (!string.IsNullOrEmpty(_op2))
PollStation(2, _op2, _s2Signals, PollStation(2, _op2, _s2Signals,
lbl_S2_Weight, lbl_S2_Info1, lbl_S2_Info2, lbl_S2_Weight, lbl_S2_QualityVal, lbl_S2_Info2,
lbl_S2_PalletVal, lbl_S2_AlarmVal); lbl_S2_PalletVal, lbl_S2_AlarmVal);
} }
catch { } catch { }
@@ -728,9 +732,6 @@ namespace MesWork.Pages
signals[11].BackColor = qColor; signals[11].BackColor = qColor;
signals[11].Invalidate(); signals[11].Invalidate();
} }
var lblQuality = station == 1 ? lbl_S1_QualityVal : lbl_S2_QualityVal;
lblQuality.Text = qFlag == 1 ? "合格" : (qFlag == 2 ? "不合格" : "--");
lblQuality.ForeColor = qFlag == 2 ? C_SignalBad : Color.FromArgb(30, 58, 95);
} }
catch { } catch { }
@@ -756,7 +757,7 @@ namespace MesWork.Pages
{ {
var sv = PlcLinkForm.ReadPLC(100180, opName); var sv = PlcLinkForm.ReadPLC(100180, opName);
if (sv != null) if (sv != null)
lblWater.Text = Convert.ToDouble(sv).ToString("F2"); lblWater.Text = $"{Convert.ToDouble(sv):F2} ppm";
} }
catch { } catch { }
@@ -812,6 +813,39 @@ namespace MesWork.Pages
lbl.Text = weight.ToString("F3"); lbl.Text = weight.ToString("F3");
} }
/// <summary>
/// 更新保存时采用的最终重量显示。
/// </summary>
public void UpdateFinalWeight(int station, decimal weight)
{
var lbl = station == 1 ? lbl_S1_Info1 : lbl_S2_Info1;
Action act = () => lbl.Text = weight.ToString("F3");
if (lbl.InvokeRequired) lbl.Invoke(act); else act();
}
/// <summary>
/// 清空保存结果相关显示。
/// </summary>
public void ClearSaveResult(int station)
{
Action act = () =>
{
if (station == 1)
{
lbl_S1_Info1.Text = "0.000";
lbl_S1_QualityVal.Text = "0.00 ppm";
lbl_S1_QualityVal.ForeColor = Color.FromArgb(30, 58, 95);
}
else
{
lbl_S2_Info1.Text = "0.000";
lbl_S2_QualityVal.Text = "0.00 ppm";
lbl_S2_QualityVal.ForeColor = Color.FromArgb(30, 58, 95);
}
};
if (InvokeRequired) Invoke(act); else act();
}
public void UpdateStationInfo(int station, string engineNo, string modelNo, string orderNo) public void UpdateStationInfo(int station, string engineNo, string modelNo, string orderNo)
{ {
Action act = () => Action act = () =>