增加线性工件校准 增加信号变化日志记录
This commit is contained in:
@@ -7,8 +7,8 @@ using System.Windows.Forms;
|
||||
namespace MesWork.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// 工具标定页面 — 固定维护OP10/OP20重量标定公式。
|
||||
/// 对应存储过程:工具管理_分页查询、工具管理_编辑
|
||||
/// 工具标定页面 — 按工位和重量范围维护分段标定公式。
|
||||
/// 对应存储过程:工具管理_分页查询、工具管理_增加、工具管理_编辑、工具管理_删除
|
||||
/// </summary>
|
||||
public partial class UC_ToolMgmt : UserControl
|
||||
{
|
||||
@@ -24,9 +24,6 @@ namespace MesWork.Pages
|
||||
this.Controls.Remove(pnl_StatusBar);
|
||||
this.Controls.Add(_pager);
|
||||
this.Controls.SetChildIndex(_pager, this.Controls.Count - 2);
|
||||
btn_Add.Visible = false;
|
||||
btn_Delete.Visible = false;
|
||||
btn_Edit.Location = btn_Delete.Location;
|
||||
}
|
||||
|
||||
/// <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 = "工位号", HeaderText = "工位号", DataPropertyName = "工位号", FillWeight = 70 });
|
||||
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 = 180 });
|
||||
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_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)
|
||||
{
|
||||
if (dgv_Data.CurrentRow != null) ShowEditDialog(dgv_Data.CurrentRow);
|
||||
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 dgv_Data_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) btn_Edit_Click(sender, e); }
|
||||
|
||||
@@ -89,38 +105,63 @@ namespace MesWork.Pages
|
||||
/// </summary>
|
||||
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;
|
||||
var txtStation = CrudHelper.AddTextField(dlg, "工位号:", ref y, row.Cells["工位号"]?.Value?.ToString(), inputWidth: 320);
|
||||
txtStation.ReadOnly = true;
|
||||
txtStation.BackColor = Color.FromArgb(245, 247, 250);
|
||||
var txtName = CrudHelper.AddTextField(dlg, "工具名称:", ref y, row.Cells["工具名称"]?.Value?.ToString(), inputWidth: 320);
|
||||
var txtFormula = CrudHelper.AddTextField(dlg, "计算公式:", ref y, row.Cells["计算公式"]?.Value?.ToString(), inputWidth: 320);
|
||||
var txtDesc = CrudHelper.AddTextField(dlg, "说明:", ref y, row.Cells["说明"]?.Value?.ToString(), inputWidth: 320);
|
||||
var cmbStation = AddStationComboField(dlg, "工位号:", ref y, isEdit ? row.Cells["工位号"]?.Value?.ToString() : "");
|
||||
var txtName = CrudHelper.AddTextField(dlg, "工具名称:", ref y, isEdit ? row.Cells["工具名称"]?.Value?.ToString() : "", inputWidth: 360);
|
||||
var txtMinWeight = CrudHelper.AddTextField(dlg, "最小重量:", ref y, isEdit ? row.Cells["最小重量"]?.Value?.ToString() : "0", inputWidth: 360);
|
||||
var txtMaxWeight = CrudHelper.AddTextField(dlg, "最大重量:", ref y, isEdit ? row.Cells["最大重量"]?.Value?.ToString() : "", inputWidth: 360);
|
||||
var txtFormula = CrudHelper.AddTextField(dlg, "计算公式:", ref y, isEdit ? row.Cells["计算公式"]?.Value?.ToString() : "x", inputWidth: 360);
|
||||
var txtDesc = CrudHelper.AddTextField(dlg, "说明:", ref y, isEdit ? row.Cells["说明"]?.Value?.ToString() : "X为重量结果值,可对重量进行科学标定", inputWidth: 360);
|
||||
CrudHelper.AddDialogButtons(dlg, ref y);
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
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))
|
||||
{
|
||||
MessageBox.Show(formulaMsg, "公式错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
string sp = isEdit ? "工具管理_编辑" : "工具管理_增加";
|
||||
var pList = new System.Collections.Generic.List<SqlParameter>
|
||||
{
|
||||
new SqlParameter("@ID", int.Parse(row.Cells["ID"]?.Value?.ToString() ?? "0")),
|
||||
new SqlParameter("@工位号", txtStation.Text.Trim()),
|
||||
new SqlParameter("@工位号", station),
|
||||
new SqlParameter("@工具名称", txtName.Text.Trim()),
|
||||
new SqlParameter("@最小重量", minWeight),
|
||||
new SqlParameter("@最大重量", maxWeight),
|
||||
new SqlParameter("@计算公式", txtFormula.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();
|
||||
LoadData();
|
||||
}
|
||||
@@ -148,5 +189,27 @@ namespace MesWork.Pages
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user