387 lines
15 KiB
C#
387 lines
15 KiB
C#
using JinYuan.ControlCenters;
|
|||
|
|
using JinYuan.DAL.Models;
|
||
|
|
using JinYuan.DAL.Service;
|
||
|
|
using JinYuan.MES.Models;
|
||
|
|
using JinYuan.Models;
|
||
|
|
using JinYuan.VirtualDataLibrary;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.ComponentModel;
|
||
|
|
using System.Data;
|
||
|
|
using System.Drawing;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows.Forms;
|
||
|
|
|
||
|
|
namespace LargeSquareOne
|
||
|
|
{
|
||
|
|
public partial class FrmInterCfg : Form
|
||
|
|
{
|
||
|
|
public FrmInterCfg()
|
||
|
|
{
|
||
|
|
InitializeComponent();
|
||
|
|
|
||
|
|
InitDgv();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void InitDgv()
|
||
|
|
{
|
||
|
|
#region 料框码与车间
|
||
|
|
DataGridViewTextBoxColumn column_ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
column_ID.HeaderText = "ID";
|
||
|
|
column_ID.MinimumWidth = 6;
|
||
|
|
column_ID.Name = "Column_ID";
|
||
|
|
column_ID.Visible = false;
|
||
|
|
column_ID.Width = 125;
|
||
|
|
column_ID.DataPropertyName = "ID";
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn column_StartCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
column_StartCode.HeaderText = "料框码匹配编码(第4-7位)";
|
||
|
|
column_StartCode.MinimumWidth = 6;
|
||
|
|
column_StartCode.Name = "Column_StartCode";
|
||
|
|
column_StartCode.Width = 225;
|
||
|
|
column_StartCode.DataPropertyName = "start_code";
|
||
|
|
column_StartCode.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
|
||
|
|
column_StartCode.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn column_WorkshopCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
column_WorkshopCode.HeaderText = "车间";
|
||
|
|
column_WorkshopCode.MinimumWidth = 6;
|
||
|
|
column_WorkshopCode.Name = "Column_WorkshopCode";
|
||
|
|
column_WorkshopCode.Width = 225;
|
||
|
|
column_WorkshopCode.DataPropertyName = "workshop_code";
|
||
|
|
column_WorkshopCode.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
|
||
|
|
column_WorkshopCode.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn column_IsDeleted = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
column_IsDeleted.HeaderText = "是否删除";
|
||
|
|
column_IsDeleted.MinimumWidth = 6;
|
||
|
|
column_IsDeleted.Name = "Column_IsDeleted";
|
||
|
|
column_IsDeleted.Visible = false;
|
||
|
|
column_IsDeleted.Width = 125;
|
||
|
|
column_IsDeleted.DataPropertyName = "is_deleted";
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn column_updateTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
column_updateTime.HeaderText = "更新时间";
|
||
|
|
column_updateTime.MinimumWidth = 6;
|
||
|
|
column_updateTime.Name = "Column_updateTime";
|
||
|
|
column_updateTime.Visible = false;
|
||
|
|
column_updateTime.Width = 125;
|
||
|
|
column_updateTime.DataPropertyName = "update_time";
|
||
|
|
|
||
|
|
dgv_materialRul.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||
|
|
column_ID,
|
||
|
|
column_StartCode,
|
||
|
|
column_WorkshopCode,
|
||
|
|
column_IsDeleted,
|
||
|
|
column_updateTime
|
||
|
|
});
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region 车间与接口
|
||
|
|
DataGridViewTextBoxColumn colInter_ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_ID.HeaderText = "ID";
|
||
|
|
colInter_ID.MinimumWidth = 6;
|
||
|
|
colInter_ID.Name = "colInter_ID";
|
||
|
|
colInter_ID.Visible = false;
|
||
|
|
colInter_ID.Width = 125;
|
||
|
|
colInter_ID.DataPropertyName = "ID";
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn colInter_workShopCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_workShopCode.HeaderText = "车间编码";
|
||
|
|
colInter_workShopCode.MinimumWidth = 6;
|
||
|
|
colInter_workShopCode.Name = "colInter_workShopCode";
|
||
|
|
colInter_workShopCode.Width = 225;
|
||
|
|
colInter_workShopCode.DataPropertyName = "workshop_code";
|
||
|
|
colInter_workShopCode.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
|
||
|
|
colInter_workShopCode.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn colInter_interFlag = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_interFlag.HeaderText = "接口标识";
|
||
|
|
colInter_interFlag.MinimumWidth = 6;
|
||
|
|
colInter_interFlag.Name = "colInter_interFlag";
|
||
|
|
colInter_interFlag.Width = 225;
|
||
|
|
colInter_interFlag.DataPropertyName = "interface_flag";
|
||
|
|
colInter_interFlag.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
|
||
|
|
colInter_interFlag.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn colInter_interName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_interName.HeaderText = "接口名称";
|
||
|
|
colInter_interName.MinimumWidth = 6;
|
||
|
|
colInter_interName.Name = "colInter_interName";
|
||
|
|
colInter_interName.Width = 225;
|
||
|
|
colInter_interName.DataPropertyName = "interface_name";
|
||
|
|
colInter_interName.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
|
||
|
|
colInter_interName.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn colInter_interUrl = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_interUrl.HeaderText = "接口URL地址";
|
||
|
|
colInter_interUrl.MinimumWidth = 6;
|
||
|
|
colInter_interUrl.Name = "colInter_interUrl";
|
||
|
|
colInter_interUrl.Width = 225;
|
||
|
|
colInter_interUrl.DataPropertyName = "interface_url";
|
||
|
|
colInter_interUrl.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
||
|
|
colInter_interUrl.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn colInter_IsDeleted = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_IsDeleted.HeaderText = "是否删除";
|
||
|
|
colInter_IsDeleted.MinimumWidth = 6;
|
||
|
|
colInter_IsDeleted.Name = "colInter_IsDeleted";
|
||
|
|
colInter_IsDeleted.Visible = false;
|
||
|
|
colInter_IsDeleted.Width = 125;
|
||
|
|
colInter_IsDeleted.DataPropertyName = "is_deleted";
|
||
|
|
|
||
|
|
DataGridViewTextBoxColumn colInter_updateTime = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||
|
|
colInter_updateTime.HeaderText = "更新时间";
|
||
|
|
colInter_updateTime.MinimumWidth = 6;
|
||
|
|
colInter_updateTime.Name = "colInter_updateTime";
|
||
|
|
colInter_updateTime.Visible = false;
|
||
|
|
colInter_updateTime.Width = 125;
|
||
|
|
colInter_updateTime.DataPropertyName = "update_time";
|
||
|
|
|
||
|
|
dgv_workInterface.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||
|
|
colInter_ID,
|
||
|
|
colInter_workShopCode,
|
||
|
|
colInter_interFlag,
|
||
|
|
colInter_interName,
|
||
|
|
colInter_interUrl,
|
||
|
|
colInter_IsDeleted,
|
||
|
|
colInter_updateTime
|
||
|
|
});
|
||
|
|
#endregion
|
||
|
|
}
|
||
|
|
|
||
|
|
private MaterialFrameRuleService ruleService;
|
||
|
|
private WorkshopInterCfgService interService;
|
||
|
|
|
||
|
|
private void InitDgvData()
|
||
|
|
{
|
||
|
|
ruleService = new MaterialFrameRuleService(CommonMethods.db.Db);
|
||
|
|
DataTable ruleDt = ruleService.GetDataTable();
|
||
|
|
|
||
|
|
bindingSource_frameRule.DataSource = ruleDt;
|
||
|
|
dgv_materialRul.DataSource = bindingSource_frameRule;
|
||
|
|
dgv_materialRul.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
|
||
|
|
|
||
|
|
interService = new WorkshopInterCfgService(CommonMethods.db.Db);
|
||
|
|
DataTable interDt = interService.GetDataTable();
|
||
|
|
|
||
|
|
bindingSource_workInterface.DataSource = interDt;
|
||
|
|
dgv_workInterface.DataSource = bindingSource_workInterface;
|
||
|
|
dgv_workInterface.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void FrmInterCfg_Load(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
InitDgvData();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void btn_exit_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
this.Close();
|
||
|
|
}
|
||
|
|
|
||
|
|
#region 料框码与车间
|
||
|
|
private void btn_codeAdd_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
bindingSource_frameRule.AddNew();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void btn_codeSave_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
DataTable dt = bindingSource_frameRule.DataSource as DataTable;
|
||
|
|
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
MaterialFrameRule model = null;
|
||
|
|
foreach (DataRow row in dt.Rows)
|
||
|
|
{
|
||
|
|
if (row.RowState == DataRowState.Deleted)
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
model = row.ToModel<MaterialFrameRule>();
|
||
|
|
|
||
|
|
switch (row.RowState)
|
||
|
|
{
|
||
|
|
case DataRowState.Added:
|
||
|
|
// 调用新增方法
|
||
|
|
ruleService.Add(model);
|
||
|
|
break;
|
||
|
|
case DataRowState.Modified:
|
||
|
|
// 调用修改方法
|
||
|
|
ruleService.Update(model);
|
||
|
|
break;
|
||
|
|
//case DataRowState.Deleted:
|
||
|
|
// // 调用删除方法
|
||
|
|
// ruleService.SoftDelete(model.Id);
|
||
|
|
// break;
|
||
|
|
case DataRowState.Unchanged:
|
||
|
|
// 未更改,不处理
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
// 收集错误信息
|
||
|
|
sb.AppendLine($"处理行时发生错误: {ex.Message}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 如果有错误信息,一起展示
|
||
|
|
if (sb.Length > 0)
|
||
|
|
{
|
||
|
|
MessageBox.Show(sb.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
|
|
}
|
||
|
|
|
||
|
|
DataTable ruleDt = ruleService.GetDataTable();
|
||
|
|
bindingSource_frameRule.DataSource = ruleDt;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void btn_codeDelete_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
// 获取选中的行删除
|
||
|
|
foreach (DataGridViewRow row in dgv_materialRul.SelectedRows)
|
||
|
|
{
|
||
|
|
object colVal = row.Cells["Column_ID"].Value;
|
||
|
|
|
||
|
|
if (colVal == null)
|
||
|
|
{
|
||
|
|
bindingSource_frameRule.RemoveAt(row.Index);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
int id = Convert.ToInt32(colVal);
|
||
|
|
bindingSource_frameRule.RemoveAt(row.Index);
|
||
|
|
ruleService.SoftDelete(id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region 车间与接口
|
||
|
|
private void btn_interAdd_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
bindingSource_workInterface.AddNew();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void btn_interDelete_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
// 获取选中的行删除
|
||
|
|
foreach (DataGridViewRow row in dgv_workInterface.SelectedRows)
|
||
|
|
{
|
||
|
|
object colVal = row.Cells["colInter_ID"].Value;
|
||
|
|
|
||
|
|
if (colVal == null)
|
||
|
|
{
|
||
|
|
bindingSource_workInterface.RemoveAt(row.Index);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
int id = Convert.ToInt32(colVal);
|
||
|
|
bindingSource_workInterface.RemoveAt(row.Index);
|
||
|
|
interService.SoftDelete(id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void btn_interSave_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
DataTable dt = bindingSource_workInterface.DataSource as DataTable;
|
||
|
|
|
||
|
|
StringBuilder sb = new StringBuilder();
|
||
|
|
WorkshopInterfaceConfig model = null;
|
||
|
|
foreach (DataRow row in dt.Rows)
|
||
|
|
{
|
||
|
|
if (row.RowState == DataRowState.Deleted)
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
model = row.ToModel<WorkshopInterfaceConfig>();
|
||
|
|
|
||
|
|
switch (row.RowState)
|
||
|
|
{
|
||
|
|
case DataRowState.Added:
|
||
|
|
// 调用新增方法
|
||
|
|
interService.Add(model);
|
||
|
|
break;
|
||
|
|
case DataRowState.Modified:
|
||
|
|
// 调用修改方法
|
||
|
|
interService.Update(model);
|
||
|
|
break;
|
||
|
|
//case DataRowState.Deleted:
|
||
|
|
// // 调用删除方法
|
||
|
|
// ruleService.SoftDelete(model.Id);
|
||
|
|
// break;
|
||
|
|
case DataRowState.Unchanged:
|
||
|
|
// 未更改,不处理
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
// 收集错误信息
|
||
|
|
sb.AppendLine($"处理行时发生错误: {ex.Message}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 如果有错误信息,一起展示
|
||
|
|
if (sb.Length > 0)
|
||
|
|
{
|
||
|
|
MessageBox.Show(sb.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
|
|
}
|
||
|
|
|
||
|
|
DataTable ruleDt = ruleService.GetDataTable();
|
||
|
|
bindingSource_frameRule.DataSource = ruleDt;
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
private void btn_test_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
string trayId = "PLT60I10032567";
|
||
|
|
string modelName = "LF350S";
|
||
|
|
//UnbindTrayInfo(trayId).ConfigureAwait(false);
|
||
|
|
|
||
|
|
MaterialFrameRuleService service = new MaterialFrameRuleService(CommonMethods.db.Db);
|
||
|
|
MaterialFrameRule rule = service.GetRuleByCode(trayId);
|
||
|
|
|
||
|
|
short model = CommonMethods.mesConfig.GetModelNum(modelName, rule?.Workshop_Code ?? string.Empty);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task<(bool success, string mesMessage)> UnbindTrayInfo(string trayID)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
MesUrlService service = new MesUrlService(CommonMethods.db.Db);
|
||
|
|
string url = service.GetMesUrl(trayID, ConstValue.INTER_UnBindTray);
|
||
|
|
if (string.IsNullOrEmpty(url))
|
||
|
|
{
|
||
|
|
throw new ArgumentException($"未找到{ConstValue.INTER_UnBindTray}对应的MES接口地址");
|
||
|
|
}
|
||
|
|
|
||
|
|
var (success, mesMessage) = await CommonMethods.hbgMes.UnbindTrayInfosAsync(
|
||
|
|
url,
|
||
|
|
CommonMethods.mesConfig.equipNum,
|
||
|
|
trayID
|
||
|
|
).ConfigureAwait(false);
|
||
|
|
|
||
|
|
return (success, mesMessage);
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
return (false, $"MES解绑失败{ex.Message}");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|