|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
using Newtonsoft.Json;
|
|
|
using Module.DB.Model;
|
|
|
using Module.DB.SQLServerDAL;
|
|
|
using Module.Common;
|
|
|
using Module.Plc.Profinet.Tool;
|
|
|
using ChipGlueDeviceManager.CommonFunctions;
|
|
|
|
|
|
namespace ChipGlueDeviceManager
|
|
|
{
|
|
|
public partial class FrmRecipeCP : Form
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 已查询的胶臂配方索引ID
|
|
|
/// </summary>
|
|
|
private int fid = 0;
|
|
|
private int _trackNo = 0;
|
|
|
|
|
|
public FrmRecipeCP(int trackNo)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
_trackNo = trackNo;
|
|
|
}
|
|
|
|
|
|
private void FrmRecipeCP_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
if (_trackNo <= 1)
|
|
|
{
|
|
|
lblFormTitle.Text = "T1 冷 板 配 方";
|
|
|
}
|
|
|
else if (_trackNo == 2)
|
|
|
{
|
|
|
lblFormTitle.Text = "T2 冷 板 配 方";
|
|
|
}
|
|
|
|
|
|
SRPCpInfo dalRPCpInfo = new SRPCpInfo();
|
|
|
cbRepNo.DataSource = dalRPCpInfo.GetAllRecpieRepNo(_trackNo);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 文本框只读设定
|
|
|
/// </summary>
|
|
|
private void TextIsReadOnly(bool bReadOnly)
|
|
|
{
|
|
|
if (bReadOnly)
|
|
|
{
|
|
|
txtCPTimeNum.ReadOnly = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
txtCPTimeNum.ReadOnly = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 按钮事件
|
|
|
|
|
|
|
|
|
private void CPSearch()
|
|
|
{
|
|
|
SRPCpInfo dalRPCpInfo = new SRPCpInfo();
|
|
|
string repNo = txtCPRepNo.Text.Trim();
|
|
|
if (!cbRepNo.Text.Trim().Equals("请选择"))
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(repNo))
|
|
|
{
|
|
|
MessageBox.Show("配方号不能为空,请填写后再查询!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MRPCpInfo cpInfo = null;
|
|
|
cpInfo = dalRPCpInfo.GetRPCPInfoByRepNo(repNo, _trackNo);
|
|
|
if (cpInfo != null)
|
|
|
{
|
|
|
fid = cpInfo.f_id;
|
|
|
//txtPlcNo.Text = cpInfo.f_cp_plc_no.ToString();
|
|
|
txtCPTimeNum.Text = cpInfo.f_cp_time_num.ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
txtCPTimeNum.Text = "0.0";
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 信息编辑
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnCPEdit_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
string strRepNo = txtCPRepNo.Text.Trim();
|
|
|
string strTimeNum = txtCPTimeNum.Text.Trim();
|
|
|
//string strPlcNo = txtPlcNo.Text.Trim();
|
|
|
|
|
|
#region 填写异常处理
|
|
|
if (String.IsNullOrEmpty(strRepNo))
|
|
|
{
|
|
|
MessageBox.Show("下发配方号不能为空,请填写后再编辑!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
if (String.IsNullOrEmpty(strTimeNum))
|
|
|
{
|
|
|
MessageBox.Show("烘烤时间不能为空,请填写后再编辑!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
#endregion 填写异常处理
|
|
|
|
|
|
|
|
|
if (_trackNo == 1)
|
|
|
{
|
|
|
if (!PlcRecipeUtils.T1CpRecipeCanEdit())
|
|
|
{
|
|
|
MessageBox.Show("当前工位正在工作中,请稍后!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
else if (_trackNo == 2)
|
|
|
{
|
|
|
if (!PlcRecipeUtils.T2CpRecipeCanEdit())
|
|
|
{
|
|
|
MessageBox.Show("当前工位正在工作中,请稍后!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (strRepNo.Length > 20)
|
|
|
{
|
|
|
MessageBox.Show("配方名称不能超过20个字符!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
SRPCpInfo dalRPCpInfo = new SRPCpInfo();
|
|
|
bool bSearchRepNo = dalRPCpInfo.ExistCPRepNo(strRepNo, _trackNo);
|
|
|
DialogResult dResult = MessageBox.Show("您确定要保存冷板配方吗?", "消息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
|
|
|
if (dResult == DialogResult.OK)
|
|
|
{
|
|
|
//if(String.IsNullOrEmpty(strPlcNo))
|
|
|
//{
|
|
|
// strPlcNo = "0";
|
|
|
//}
|
|
|
|
|
|
MRPCpInfo newCpInfo = new MRPCpInfo();
|
|
|
newCpInfo.f_cp_rep_no = strRepNo;
|
|
|
newCpInfo.f_id = fid;
|
|
|
//newCpInfo.f_cp_plc_no = Convert.ToInt32(strPlcNo);
|
|
|
newCpInfo.f_cp_plc_no = Convert.ToInt32(0);
|
|
|
newCpInfo.f_cp_time_num = Convert.ToDecimal(txtCPTimeNum.Text.Trim());
|
|
|
|
|
|
newCpInfo.f_track_no = _trackNo;
|
|
|
newCpInfo.f_creator = "管理员";
|
|
|
newCpInfo.f_create_time = DateTime.Now;
|
|
|
newCpInfo.f_modify_time = DateTime.Now;
|
|
|
|
|
|
if (bSearchRepNo)
|
|
|
{
|
|
|
dalRPCpInfo.EditRPCPInfo(newCpInfo);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dalRPCpInfo.AddRPCPInfo(newCpInfo);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
CPSearch();
|
|
|
cbRepNo.DataSource = dalRPCpInfo.GetAllRecpieRepNo(_trackNo);
|
|
|
cbRepNo.Text = txtCPRepNo.Text.Trim();
|
|
|
|
|
|
#region 更新总配方
|
|
|
UpdateCotFileInfo(_trackNo, strRepNo);
|
|
|
#endregion 更新总配方
|
|
|
|
|
|
#region 更新当前配方并下发给PLC
|
|
|
UpdateCurrentCotFileInfo(_trackNo, strRepNo);
|
|
|
#endregion 更新当前配方并下发给PLC
|
|
|
|
|
|
}
|
|
|
|
|
|
#region 更新总配方
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新总配方
|
|
|
/// </summary>
|
|
|
/// <param name="trackNo">通道号</param>
|
|
|
/// <param name="cpNo">冷板配方号</param>
|
|
|
private void UpdateCotFileInfo(int trackNo, string cpNo)
|
|
|
{
|
|
|
SRPCotFileInfo dalCotFileInfo = new SRPCotFileInfo();
|
|
|
bool bExistFile = dalCotFileInfo.ExistCotFileInfoByTrackNoCpNo(trackNo, cpNo);
|
|
|
if (bExistFile)
|
|
|
{
|
|
|
List<MRPCotFileInfo> lstCotFileInfo = null;
|
|
|
lstCotFileInfo = dalCotFileInfo.GetRPCotFileInfoByTrackNoCpNo(trackNo, cpNo);
|
|
|
if (lstCotFileInfo != null)
|
|
|
{
|
|
|
int fileNum = lstCotFileInfo.Count;
|
|
|
if (fileNum > 0)
|
|
|
{
|
|
|
for (int i = 0; i < fileNum; i++)
|
|
|
{
|
|
|
string strJson = lstCotFileInfo[i].f_rep_content;
|
|
|
if (strJson != null)
|
|
|
{
|
|
|
MJsonRPCotFileInfo jsonResult = JsonConvert.DeserializeObject<MJsonRPCotFileInfo>(strJson);
|
|
|
if (jsonResult != null)
|
|
|
{
|
|
|
if (jsonResult.f_rep_cp_info != null)
|
|
|
{
|
|
|
jsonResult.f_rep_cp_info = GetJsonRPCpInfo(trackNo, cpNo);
|
|
|
|
|
|
JsonSerializerSettings jsetting = new JsonSerializerSettings();
|
|
|
string fileContentResult = JsonConvert.SerializeObject(jsonResult, Formatting.Indented, jsetting);
|
|
|
dalCotFileInfo.UpdateCotContentByFileId(lstCotFileInfo[i].f_id, fileContentResult);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据通道号与冷板配方号查询JSON字段
|
|
|
/// </summary>
|
|
|
/// <param name="trackNo">通道号</param>
|
|
|
/// <param name="cpNo">冷板配方号</param>
|
|
|
/// <returns>JSON字段</returns>
|
|
|
private MJsonRpCpInfo GetJsonRPCpInfo(int trackNo, string cpNo)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
MJsonRpCpInfo jsonCpInfo = null;
|
|
|
SRPCpInfo dalCpInfo = new SRPCpInfo();
|
|
|
MRPCpInfo cpInfo = dalCpInfo.GetRPCPInfoByRepNo(cpNo, trackNo);
|
|
|
if (cpInfo != null)
|
|
|
{
|
|
|
jsonCpInfo = new MJsonRpCpInfo();
|
|
|
jsonCpInfo.f_cp_rep_no = cpInfo.f_cp_rep_no;
|
|
|
jsonCpInfo.f_cp_plc_no = cpInfo.f_cp_plc_no;
|
|
|
jsonCpInfo.f_cp_time_num = cpInfo.f_cp_time_num;
|
|
|
}
|
|
|
return jsonCpInfo;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ex.ToString();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion 更新总配方
|
|
|
|
|
|
#region 更新当前配方并下发给PLC
|
|
|
/// <summary>
|
|
|
/// 更新当前配方并下发配方到PLC
|
|
|
/// </summary>
|
|
|
/// <param name="trackNo">通道号</param>
|
|
|
/// <param name="cpNo">冷板配方号</param>
|
|
|
private void UpdateCurrentCotFileInfo(int trackNo, string cpNo)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
SRPCurrentCotFileInfo dalCurrentCotFileInfo = new SRPCurrentCotFileInfo();
|
|
|
bool bExistFile = dalCurrentCotFileInfo.ExistCotFileInfoByTrackNoCpNo(trackNo, cpNo);
|
|
|
if (bExistFile)
|
|
|
{
|
|
|
MRPCotFileInfo cotFileInfo = null;
|
|
|
cotFileInfo = dalCurrentCotFileInfo.GetRPCotFileInfoByTrackNoCpNo(trackNo, cpNo);
|
|
|
if (cotFileInfo != null)
|
|
|
{
|
|
|
string strJson = cotFileInfo.f_rep_content;
|
|
|
if (!string.IsNullOrEmpty(strJson))
|
|
|
{
|
|
|
MJsonRPCotFileInfo jsonResult = JsonConvert.DeserializeObject<MJsonRPCotFileInfo>(strJson);
|
|
|
if (jsonResult != null)
|
|
|
{
|
|
|
if (jsonResult.f_rep_cp_info != null)
|
|
|
{
|
|
|
jsonResult.f_rep_cp_info = GetJsonRPCpInfo(trackNo, cpNo);
|
|
|
|
|
|
JsonSerializerSettings jsetting = new JsonSerializerSettings();
|
|
|
string fileContentResult = JsonConvert.SerializeObject(jsonResult, Formatting.Indented, jsetting);
|
|
|
dalCurrentCotFileInfo.UpdateCotContentByFileId(cotFileInfo.f_id, fileContentResult);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
SendCpInfoToPlc(trackNo, cpNo);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ex.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送冷板配方到PLC
|
|
|
/// </summary>
|
|
|
/// <param name="trackNo">通道号</param>
|
|
|
/// <param name="cpNo">冷板配方号</param>
|
|
|
private void SendCpInfoToPlc(int trackNo, string cpNo)
|
|
|
{
|
|
|
if (trackNo == 1)
|
|
|
{
|
|
|
if (PublicParams.T1ConnectPlc)
|
|
|
{
|
|
|
//if (PublicParams.t1IsRecipe)
|
|
|
//{
|
|
|
SRPCpInfo dalCpInfo = new SRPCpInfo();
|
|
|
MRPCpInfo rpCpInfo = dalCpInfo.GetRPCPInfoByRepNo(cpNo, trackNo);
|
|
|
|
|
|
PlcCpRecipeFunc.CpRecipe(trackNo, rpCpInfo);
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
else if (trackNo == 2)
|
|
|
{
|
|
|
if (PublicParams.T2ConnectPlc)
|
|
|
{
|
|
|
//if (PublicParams.t2IsRecipe)
|
|
|
//{
|
|
|
SRPCpInfo dalCpInfo = new SRPCpInfo();
|
|
|
MRPCpInfo rpCpInfo = dalCpInfo.GetRPCPInfoByRepNo(cpNo, trackNo);
|
|
|
|
|
|
PlcCpRecipeFunc.CpRecipe(trackNo, rpCpInfo);
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion 更新当前配方并下发给PLC
|
|
|
|
|
|
|
|
|
#endregion 按钮事件
|
|
|
|
|
|
|
|
|
private bool checkIsEnterCode(KeyEventArgs e)
|
|
|
{
|
|
|
return Keys.Enter == e.KeyCode;
|
|
|
}
|
|
|
|
|
|
private void txtCPRepNo_KeyDown(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
if (!checkIsEnterCode(e))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
CPSearch();
|
|
|
}
|
|
|
|
|
|
private void cbRepNo_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
string repNo = cbRepNo.SelectedItem.ToString();
|
|
|
|
|
|
if (String.IsNullOrEmpty(repNo) || repNo.Equals("请选择"))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
txtCPRepNo.Text = repNo;
|
|
|
|
|
|
CPSearch();
|
|
|
}
|
|
|
|
|
|
private void txtCPTimeNum_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
{
|
|
|
FormValidate.OnlyNumbers(sender, e);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除冷板配方
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnDelCpRepInfo_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (!MessageUtil.ConfirmYesNo("确认删除冷板配方数据吗?"))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
SRPCpInfo dalCpInfo = new SRPCpInfo();
|
|
|
dalCpInfo.DeleteRPCpInfo(txtCPRepNo.Text.Trim(), _trackNo);
|
|
|
cbRepNo.DataSource = dalCpInfo.GetAllRecpieRepNo(_trackNo);
|
|
|
|
|
|
#region 界面所有填充初始化
|
|
|
fid = 0;
|
|
|
txtCPRepNo.Text = "";
|
|
|
//txtPlcNo.Text = "0";
|
|
|
txtCPTimeNum.Text = "0.0";
|
|
|
#endregion 界面所有填充初始化
|
|
|
}
|
|
|
|
|
|
private void txtCPRepNo_TextChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
CPSearch();
|
|
|
}
|
|
|
}
|
|
|
}
|