You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1497 lines
66 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using Newtonsoft.Json;
using ChipGlueDeviceManager.CommonFunctions;
using Module.Common;
using Module.DB.Model;
using Module.DB.SQLServerDAL;
using Module.Plc.Profinet.Tool;
namespace ChipGlueDeviceManager
{
public partial class FrmRecipeCOT : Form
{
private List<int> lstSeqNo = new List<int>();
private int selectedRowNo = -1; //已选择行号
private double COTzzzgsd = 0;
private bool bJgpb = false;
private int _trackNo = 0;
public FrmRecipeCOT(int trackNo)
{
InitializeComponent();
_trackNo = trackNo;
}
/// <summary>
/// 窗体启动加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmRecipeCOT_Load(object sender, EventArgs e)
{
if (_trackNo <= 1)
{
lblFormTitle.Text = "T1 匀 胶 配 方";
}
else if (_trackNo == 2)
{
lblFormTitle.Text = "T2 匀 胶 配 方";
}
dgViewCotRecipe.AutoGenerateColumns = false;
if (dgViewCotRecipe.Columns.Count <= 0)
{
GenerateBaseRepDataGridViewColumns(dgViewCotRecipe);
}
SRPCotInfo dalCotInfo = new SRPCotInfo();
cmbRepNo.DataSource = dalCotInfo.GetAllRecpieRepNo(_trackNo);
}
#region DataGridView初始化
/// <summary>
/// 生成基础执行配方信息
/// </summary>
/// <param name="srcGridView"></param>
private void GenerateBaseRepDataGridViewColumns(DataGridView srcGridView) // 生成DataGridView列
{
//生成DataGridView基础设置
GridViewStyleHelper.gridView_BaseStyle(srcGridView);
srcGridView.AllowUserToAddRows = false;
srcGridView.AllowUserToResizeRows = false;
srcGridView.AllowUserToOrderColumns = false;
srcGridView.AllowUserToResizeColumns = false;
// colID 序号
DataGridViewTextBoxColumn colID = new DataGridViewTextBoxColumn();
colID.DividerWidth = 2;
colID.HeaderText = "序号";
colID.Name = "colID";
colID.DataPropertyName = "f_id";
colID.Resizable = DataGridViewTriState.True;
colID.SortMode = DataGridViewColumnSortMode.NotSortable;
colID.Visible = false;
srcGridView.Columns.Add(colID);
// colRepNo 配方名称
DataGridViewTextBoxColumn colRepNo = new DataGridViewTextBoxColumn();
colRepNo.ReadOnly = true;
colRepNo.DividerWidth = 2;
colRepNo.HeaderText = "配方名称";
colRepNo.Name = "colRepNo";
colRepNo.DataPropertyName = "f_cot_rep_no";
colRepNo.Resizable = DataGridViewTriState.True;
colRepNo.SortMode = DataGridViewColumnSortMode.NotSortable;
colRepNo.Visible = false;
srcGridView.Columns.Add(colRepNo);
// colRepNo 配方名称
DataGridViewTextBoxColumn colPlcNo = new DataGridViewTextBoxColumn();
colPlcNo.ReadOnly = true;
colPlcNo.DividerWidth = 2;
colPlcNo.HeaderText = "PLC配方名称";
colPlcNo.Name = "colPlcNo";
colPlcNo.DataPropertyName = "f_cot_plc_no";
colPlcNo.SortMode = DataGridViewColumnSortMode.NotSortable;
colPlcNo.Visible = false;
srcGridView.Columns.Add(colPlcNo);
// colSeqID 步号
DataGridViewTextBoxColumn colSeqID = new DataGridViewTextBoxColumn();
colSeqID.ReadOnly = true;
colSeqID.DividerWidth = 2;
colSeqID.HeaderText = "步骤号";
colSeqID.Name = "colSeqID";
colSeqID.DataPropertyName = "f_seq_no";
colSeqID.SortMode = DataGridViewColumnSortMode.NotSortable;
colSeqID.Visible = true;
srcGridView.Columns.Add(colSeqID);
// colRotateSpeed 转速
DataGridViewTextBoxColumn colRotateSpeed = new DataGridViewTextBoxColumn();
colRotateSpeed.DividerWidth = 2;
colRotateSpeed.HeaderText = "转速";
colRotateSpeed.Name = "colRotateSpeed";
colRotateSpeed.DataPropertyName = "f_rotate_speed";
colRotateSpeed.SortMode = DataGridViewColumnSortMode.NotSortable;
srcGridView.Columns.Add(colRotateSpeed);
srcGridView.Columns["colRotateSpeed"].DefaultCellStyle.Format = "0.0";
// colTimeNum 时间
DataGridViewTextBoxColumn colTimeNum = new DataGridViewTextBoxColumn();
colTimeNum.DividerWidth = 2;
colTimeNum.HeaderText = "时间";
colTimeNum.Name = "colTimeNum";
colTimeNum.DataPropertyName = "f_time_num";
colTimeNum.SortMode = DataGridViewColumnSortMode.NotSortable;
srcGridView.Columns.Add(colTimeNum);
srcGridView.Columns["colTimeNum"].DefaultCellStyle.Format = "0.0";
// colAccSpeed 加减速
DataGridViewTextBoxColumn colAccSpeed = new DataGridViewTextBoxColumn();
colAccSpeed.DividerWidth = 2;
colAccSpeed.HeaderText = "加减速";
colAccSpeed.Name = "colAccSpeed";
colAccSpeed.DataPropertyName = "f_acc_speed";
colAccSpeed.SortMode = DataGridViewColumnSortMode.NotSortable;
srcGridView.Columns.Add(colAccSpeed);
srcGridView.Columns["colAccSpeed"].DefaultCellStyle.Format = "0.0";
// colGlueCover 胶盖
var colGlueCover = GetCheckBoxColumn("胶盖", "colGlueCover", "f_glue_cover");
colGlueCover.DividerWidth = 2;
srcGridView.Columns.Add(colGlueCover);
//colSideValveEBR 去边阀EBR
var colSideValveEBR = GetCheckBoxColumn("去边阀EBR", "colSideValveEBR", "f_side_valve_ebr");
colSideValveEBR.DividerWidth = 2;
srcGridView.Columns.Add(colSideValveEBR);
//colClearValveBSR 背清阀BSR
var colClearValveBSR = GetCheckBoxColumn("背清阀BSR", "colClearValveBSR", "f_clear_valve_bsr");
colClearValveBSR.DividerWidth = 2;
srcGridView.Columns.Add(colClearValveBSR);
//colClearValveBSGR 背气阀BSR
var colClearValveBSGR = GetCheckBoxColumn("背气阀BSGR", "colClearValveBSGR", "f_clear_valve_bsgr");
colClearValveBSGR.DividerWidth = 2;
srcGridView.Columns.Add(colClearValveBSGR);
//colClearValveCCR1 胶锅清洗阀CCR1
//var colClearValveCCR1 = GetCheckBoxColumn("胶锅清洗阀CCR1", "colClearValveCCR1", "f_clear_valve_ccr1");
//srcGridView.Columns.Add(colClearValveCCR1);
//colClearValveCCR1 胶锅清洗阀CCR2
//var colClearValveCCR2 = GetCheckBoxColumn("胶锅清洗阀CCR2", "colClearValveCCR2", "f_clear_valve_ccr2");
//srcGridView.Columns.Add(colClearValveCCR2);
// colCallRepNo 胶臂调用配方名称
var colCallRepNo = GetComboBoxColumn("胶臂调用配方名称", "colCallRepNo", "f_arm_rep_no");
colCallRepNo.DividerWidth = 2;
srcGridView.Columns.Add(colCallRepNo);
//colSelect 选中
var colSelect = GetCheckBoxColumn("选择", "btnSelect", "btnSelect");
colSelect.DividerWidth = 2;
srcGridView.Columns.Add(colSelect);
}
private DataGridViewCheckBoxColumn GetCheckBoxColumn(string title, string name, string propertyName)
{
DataGridViewCheckBoxColumn checkbox = new DataGridViewCheckBoxColumn();
checkbox.HeaderText = title;
checkbox.Name = name;
checkbox.TrueValue = 1;
checkbox.FalseValue = 0;
checkbox.DataPropertyName = propertyName;
checkbox.SortMode = DataGridViewColumnSortMode.NotSortable;
return checkbox;
}
DataGridViewComboBoxColumn combobox = new DataGridViewComboBoxColumn();
private DataGridViewComboBoxColumn GetComboBoxColumn(string title, string name, string propertyName)
{
SRPArmInfo dalRPArmInfo = new SRPArmInfo();
combobox.HeaderText = title;
combobox.Name = name;
combobox.DataSource = dalRPArmInfo.GetAllRecpieNo(_trackNo); ;
combobox.DisplayMember = propertyName;
combobox.DataPropertyName = propertyName;
combobox.ValueMember = propertyName;
combobox.SortMode = DataGridViewColumnSortMode.NotSortable;
return combobox;
}
#endregion DataGridView初始化
/// <summary>
/// 查询结果数据表
/// </summary>
DataTable dtResult = null;
/// <summary>
/// 查询结果
/// </summary>
private void CotSearch()
{
SRPCotInfo dalCotInfo = new SRPCotInfo();
string repNo = txtRepNo.Text.Trim();
if (string.IsNullOrEmpty(repNo))
{
MessageBox.Show("请选择配方或输入新名称!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (dtResult != null)
{
dtResult = dtResult.Clone();
lstSeqNo.Clear();
}
dtResult = dalCotInfo.GetRPCotInfoTableByRepNo(repNo, _trackNo);
if (dtResult != null)
{
selectedRowNo = -1;
int rowNum = dtResult.Rows.Count;
for (int i = 0; i < rowNum; i++)
{
object objSeqNo = dtResult.Rows[i]["f_seq_no"];
int seq_no = (objSeqNo == null || objSeqNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objSeqNo);
lstSeqNo.Add(seq_no);
}
if (rowNum > 0)
{
btnCotAddSeq.Enabled = true;
if (dtResult.Rows[0]["f_glue_time_num"] == null)
{
return;
}
object objGlueTimeNum = dtResult.Rows[0]["f_glue_time_num"];
decimal glueTimeNum = (objGlueTimeNum == null || objGlueTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objGlueTimeNum);
txtGlueTimeNum.Text = glueTimeNum.ToString("#0.0");
if (dtResult.Rows[0]["f_coating"] == null)
{
return;
}
int fCoating;
bool isNumber = Int32.TryParse(dtResult.Rows[0]["f_coating"].ToString(), out fCoating);
if (!isNumber)
{
return;
}
switch (fCoating)
{
case 1:
{
rdbIsCoating01.Checked = true;
break;
}
case 2:
{
rdbIsCoating02.Checked = true;
break;
}
case 3:
{
rdbIsCoating03.Checked = true;
break;
}
}
}
else
{
dtResult = CotDefaultInfo();
txtGlueTimeNum.Text = "0.0";
rdbIsCoating01.Checked = true;
rdbIsCoating02.Checked = false;
rdbIsCoating03.Checked = false;
}
}
dgViewCotRecipe.DataSource = dtResult;
}
private void CotAddSeqSearch()
{
SRPCotInfo dalCotInfo = new SRPCotInfo();
string repNo = txtRepNo.Text.Trim();
if (string.IsNullOrEmpty(repNo))
{
MessageBox.Show("请选择配方或输入新名称!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
DataTable dtAddSeqInfo = GetAddSeqDataTable();
dtResult.Clear();
dtResult = dtAddSeqInfo.Copy();
if (dtResult != null)
{
selectedRowNo = -1;
int rowNum = dtResult.Rows.Count;
if (rowNum > 0)
{
btnCotAddSeq.Enabled = true;
if (dtResult.Rows[0]["f_glue_time_num"] == null)
{
return;
}
object objGlueTimeNum = dtResult.Rows[0]["f_glue_time_num"];
decimal glueTimeNum = (objGlueTimeNum == null || objGlueTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objGlueTimeNum);
txtGlueTimeNum.Text = glueTimeNum.ToString("#0.0");
if (dtResult.Rows[0]["f_coating"] == null)
{
return;
}
int fCoating;
bool isNumber = Int32.TryParse(dtResult.Rows[0]["f_coating"].ToString(), out fCoating);
if (!isNumber)
{
return;
}
switch (fCoating)
{
case 1:
{
rdbIsCoating01.Checked = true;
break;
}
case 2:
{
rdbIsCoating02.Checked = true;
break;
}
case 3:
{
rdbIsCoating03.Checked = true;
break;
}
}
}
else
{
//dtResult = CotDefaultInfo();
txtGlueTimeNum.Text = "0.0";
rdbIsCoating01.Checked = false;
rdbIsCoating02.Checked = false;
rdbIsCoating03.Checked = false;
}
}
dgViewCotRecipe.DataSource = dtResult;
}
private void CotDelSeqSearch(DataTable dtRst)
{
SRPCotInfo dalCotInfo = new SRPCotInfo();
string repNo = txtRepNo.Text.Trim();
if (string.IsNullOrEmpty(repNo))
{
MessageBox.Show("请选择配方或输入新名称!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
//dtResult = dtRst;
if (dtRst != null)
{
selectedRowNo = -1;
int rowNum = dtRst.Rows.Count;
if (rowNum > 0)
{
btnCotAddSeq.Enabled = true;
if (dtResult.Rows[0]["f_glue_time_num"] == null)
{
return;
}
object objGlueTimeNum = dtResult.Rows[0]["f_glue_time_num"];
decimal glueTimeNum = (objGlueTimeNum == null || objGlueTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objGlueTimeNum);
txtGlueTimeNum.Text = glueTimeNum.ToString("#0.0");
if (dtRst.Rows[0]["f_coating"] == null)
{
return;
}
int fCoating;
bool isNumber = Int32.TryParse(dtRst.Rows[0]["f_coating"].ToString(), out fCoating);
if (!isNumber)
{
return;
}
switch (fCoating)
{
case 1:
{
rdbIsCoating01.Checked = true;
break;
}
case 2:
{
rdbIsCoating02.Checked = true;
break;
}
case 3:
{
rdbIsCoating03.Checked = true;
break;
}
}
}
else
{
//dtResult = CotDefaultInfo();
txtGlueTimeNum.Text = "0.0";
rdbIsCoating01.Checked = false;
rdbIsCoating02.Checked = false;
rdbIsCoating03.Checked = false;
}
}
dgViewCotRecipe.DataSource = dtRst;
dtResult.Clear();
dtResult = dtRst;
}
private DataTable CotDefaultInfo()
{
DataTable dtResult = new DataTable();
dtResult.Columns.Add("f_seq_no", typeof(int));
dtResult.Columns.Add("f_rotate_speed", typeof(decimal));
dtResult.Columns.Add("f_time_num", typeof(decimal));
dtResult.Columns.Add("f_acc_speed", typeof(decimal));
dtResult.Columns.Add("f_glue_cover", typeof(int));
dtResult.Columns.Add("f_side_valve_ebr", typeof(int));
dtResult.Columns.Add("f_clear_valve_bsr", typeof(int));
dtResult.Columns.Add("f_clear_valve_bsgr", typeof(int));
//dtResult.Columns.Add("f_clear_valve_ccr1", typeof(int));
//dtResult.Columns.Add("f_clear_valve_ccr2", typeof(int));
dtResult.Columns.Add("f_arm_rep_no", typeof(string));
dtResult.Columns.Add("f_coating", typeof(byte));
dtResult.Rows.Add(1, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(2, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(3, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(4, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(5, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(6, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(7, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(8, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
dtResult.Rows.Add(9, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0);
return dtResult;
}
/// <summary>
/// 删除配方
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDeleteAll_Click(object sender, EventArgs e)
{
if (!MessageUtil.ConfirmYesNo("确认删除全部数据吗?"))
{
return;
}
string repNo = txtRepNo.Text.Trim();
if (!cmbRepNo.Text.Trim().Equals("请选择"))
{
if (string.IsNullOrEmpty(repNo))
{
MessageBox.Show("配方名称不能为空,请选择后再删除!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
SRPCotInfo dalCotInfo = new SRPCotInfo();
dalCotInfo.DeleteRPCotInfoByRepNo(repNo, _trackNo);
cmbRepNo.DataSource = dalCotInfo.GetAllRecpieRepNo(_trackNo);
//txtRepNo.Text = "";
dtResult.Clear();
selectedRowNo = -1;
}
/// <summary>
/// 从DataGridView获取匀胶配方列表
/// </summary>
/// <returns></returns>
private List<MRPCotInfo> GetRPCotInfoListFromDataGridView()
{
List<MRPCotInfo> lstResult = null;
int rowNum = dgViewCotRecipe.Rows.Count;
if (rowNum > 0)
{
lstResult = new List<MRPCotInfo>();
for (int i = 0; i < rowNum; i++)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[i];
object objID = rowCol.Cells["colID"].Value;
rpCotInfo.f_id = (objID == null || objID.ToString().Trim() == "") ? 0 : Convert.ToInt32(objID);
rpCotInfo.f_cot_rep_no = rowCol.Cells["colRepNo"].Value == null ? "" : rowCol.Cells["colRepNo"].Value.ToString().Trim();
object objcotPlcNo = rowCol.Cells["colPlcNo"].Value;
rpCotInfo.f_cot_plc_no = (objcotPlcNo == null || objcotPlcNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objcotPlcNo);
object objSeqNo = rowCol.Cells["colSeqID"].Value;
rpCotInfo.f_seq_no = (objSeqNo == null || objSeqNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objSeqNo);
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
object objTimeNum = rowCol.Cells["colTimeNum"].Value;
rpCotInfo.f_time_num = (objTimeNum == null || objTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objTimeNum);
object objAccSpeed = rowCol.Cells["colAccSpeed"].Value;
rpCotInfo.f_acc_speed = (objAccSpeed == null || objAccSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objAccSpeed);
object objGlueCover = rowCol.Cells["colGlueCover"].Value;
rpCotInfo.f_glue_cover = (objGlueCover == null || objGlueCover.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objGlueCover);
object objSideValveEbr = rowCol.Cells["colSideValveEBR"].Value;
rpCotInfo.f_side_valve_ebr = (objSideValveEbr == null || objSideValveEbr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objSideValveEbr);
object objClearValveBsr = rowCol.Cells["colClearValveBSR"].Value;
rpCotInfo.f_clear_valve_bsr = (objClearValveBsr == null || objClearValveBsr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsr);
object objClearValveBsgr = rowCol.Cells["colClearValveBSGR"].Value;
rpCotInfo.f_clear_valve_bsgr = (objClearValveBsgr == null || objClearValveBsgr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsgr);
object objClearValveCcr1 = rowCol.Cells["colClearValveCCR1"].Value;
rpCotInfo.f_clear_valve_ccr1 = (objClearValveCcr1 == null || objClearValveCcr1.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr1);
object objClearValveCcr2 = rowCol.Cells["colClearValveCCR2"].Value;
rpCotInfo.f_clear_valve_ccr2 = (objClearValveCcr2 == null || objClearValveCcr2.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr2);
if (rdbIsCoating01.Checked)
{
rpCotInfo.f_coating = 1;
}
else if (rdbIsCoating02.Checked)
{
rpCotInfo.f_coating = 2;
}
else if (rdbIsCoating03.Checked)
{
rpCotInfo.f_coating = 3;
}
rpCotInfo.f_arm_rep_no = rowCol.Cells["colCallRepNo"].Value == null ? "" : rowCol.Cells["colCallRepNo"].Value.ToString().Trim();
rpCotInfo.f_track_no = 1;
rpCotInfo.f_creator = "管理员";
rpCotInfo.f_create_time = DateTime.Now;
rpCotInfo.f_modify_time = DateTime.Now;
lstResult.Add(rpCotInfo);
}
}
return lstResult;
}
/// <summary>
/// 新增步骤
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCotAddSeq_Click(object sender, EventArgs e)
{
var repNo = txtRepNo.Text.Trim();
if (String.IsNullOrEmpty(repNo))
{
MessageBox.Show("配方名称不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
SRPCotInfo dalCotInfo = new SRPCotInfo();
var count = dgViewCotRecipe.Rows.Count;
if (dalCotInfo.GetMaxSeqNoByReqNo(repNo, 1) >= 20 || count >= 20)
{
MessageBox.Show("配方步骤最多20步", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
CotAddSeqSearch();
cmbRepNo.DataSource = dalCotInfo.GetAllRecpieRepNo(_trackNo);
}
/// <summary>
/// 删除选中步骤
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCotDelSeq_Click(object sender, EventArgs e)
{
DialogResult dResult = MessageBox.Show("您确认要删除选中步骤吗?", "消息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (dResult == DialogResult.OK)
{
int iRowNum = dgViewCotRecipe.Rows.Count;
if (iRowNum > 0)
{
DataTable dtNewResult = dtResult.Copy();
for (int i = 0; i < iRowNum; i++)
{
DataGridViewRow rowCol = dgViewCotRecipe.Rows[i];
object objSelectValue = rowCol.Cells["btnSelect"].Value;
byte selectedValue = (objSelectValue == null || objSelectValue.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objSelectValue);
if (selectedValue == 1)
{
object objID = rowCol.Cells["colID"].Value;
int id = (objID == null || objID.ToString().Trim() == "") ? 0 : Convert.ToInt32(objID);
object objSeqNo = rowCol.Cells["colSeqID"].Value;
int seqNo = (objSeqNo == null || objSeqNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objSeqNo);
if (lstSeqNo.Contains(seqNo))
{
lstSeqNo.Remove(seqNo);
}
foreach (DataRow row in dtNewResult.Rows)
{
object objNo = row["f_seq_no"];
int cmpNo = (objNo == null || objNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objNo);
if (cmpNo == seqNo)
{
dtNewResult.Rows.Remove(row);
break;
}
}
}
}
dtNewResult.AcceptChanges(); //全部删除完必须执行这一步,否则结果不保存
//查询结果
CotDelSeqSearch(dtNewResult);
}
}
}
/// <summary>
/// 鼠标点击行编辑信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgViewCotRecipe_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dgViewCotRecipe.Columns[e.ColumnIndex].Name == "btnEdit")
{
int rowNum = e.RowIndex;
if (rowNum != -1)
{
DialogResult dResult = MessageBox.Show("您确认要编辑匀胶配方吗?", "消息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (dResult == DialogResult.OK)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[rowNum];
object objID = rowCol.Cells["colID"].Value;
rpCotInfo.f_id = (objID == null || objID.ToString().Trim() == "") ? 0 : Convert.ToInt32(objID);
rpCotInfo.f_cot_rep_no = rowCol.Cells["colRepNo"].Value == null ? "" : rowCol.Cells["colRepNo"].Value.ToString().Trim();
object objcotPlcNo = rowCol.Cells["colPlcNo"].Value;
rpCotInfo.f_cot_plc_no = (objcotPlcNo == null || objcotPlcNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objcotPlcNo);
object objSeqNo = rowCol.Cells["colSeqID"].Value;
rpCotInfo.f_seq_no = (objSeqNo == null || objSeqNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objSeqNo);
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToInt32(objRotateSpeed);
object objTimeNum = rowCol.Cells["colTimeNum"].Value;
rpCotInfo.f_time_num = (objTimeNum == null || objTimeNum.ToString().Trim() == "") ? 0 : Convert.ToInt32(objTimeNum);
object objAccSpeed = rowCol.Cells["colAccSpeed"].Value;
rpCotInfo.f_acc_speed = (objAccSpeed == null || objAccSpeed.ToString().Trim() == "") ? 0 : Convert.ToInt32(objAccSpeed);
object objGlueCover = rowCol.Cells["colGlueCover"].Value;
rpCotInfo.f_glue_cover = (objGlueCover == null || objGlueCover.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objGlueCover);
object objSideValveEbr = rowCol.Cells["colSideValveEBR"].Value;
rpCotInfo.f_side_valve_ebr = (objSideValveEbr == null || objSideValveEbr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objSideValveEbr);
object objClearValveBsr = rowCol.Cells["colClearValveBSR"].Value;
rpCotInfo.f_clear_valve_bsr = (objClearValveBsr == null || objClearValveBsr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsr);
object objClearValveBsgr = rowCol.Cells["colClearValveBSGR"].Value;
rpCotInfo.f_clear_valve_bsgr = (objClearValveBsgr == null || objClearValveBsgr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsgr);
object objClearValveCcr1 = rowCol.Cells["colClearValveCCR1"].Value;
rpCotInfo.f_clear_valve_ccr1 = (objClearValveCcr1 == null || objClearValveCcr1.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr1);
object objClearValveCcr2 = rowCol.Cells["colClearValveCCR2"].Value;
rpCotInfo.f_clear_valve_ccr2 = (objClearValveCcr2 == null || objClearValveCcr2.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr2);
if (rdbIsCoating01.Checked)
{
rpCotInfo.f_coating = 1;
}
else if (rdbIsCoating02.Checked)
{
rpCotInfo.f_coating = 2;
}
else if (rdbIsCoating03.Checked)
{
rpCotInfo.f_coating = 3;
}
rpCotInfo.f_arm_rep_no = rowCol.Cells["colCallRepNo"].Value == null ? "" : rowCol.Cells["colCallRepNo"].Value.ToString().Trim();
rpCotInfo.f_modify_time = DateTime.Now;
string strGlueTimeNum = txtGlueTimeNum.Text.Trim();
if (strGlueTimeNum != "")
{
rpCotInfo.f_glue_time_num = (strGlueTimeNum == "") ? Convert.ToDecimal(0.1) : Convert.ToDecimal(strGlueTimeNum);
}
SRPCotInfo dalCotInfo = new SRPCotInfo();
dalCotInfo.EditRPCotInfo(rpCotInfo);
}
}
}
}
/// <summary>
/// 保存已修改的数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSave_Click(object sender, EventArgs e)
{
if (!MessageUtil.ConfirmYesNo("确认要保存修改的数据吗?"))
{
return;
}
if (_trackNo <= 1)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.COTzzzgsd), 1);
}
else if (_trackNo == 2)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.t2COTzzzgsd), 1);
}
var nums = dgViewCotRecipe.Rows.Count;
if (nums > 0)
{
for (int i = 0; i < nums; i++)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[i];
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
decimal speed = FormValidate.NumberMinMaxValueResult(rpCotInfo.f_rotate_speed, Convert.ToDecimal(0.0), Convert.ToDecimal(COTzzzgsd));
rpCotInfo.f_rotate_speed = Convert.ToDecimal(Convert.ToInt32(speed).ToString("#0.0"));
rowCol.Cells["colRotateSpeed"].Value = rpCotInfo.f_rotate_speed.ToString("#0.0");
}
}
string repNo = txtRepNo.Text.Trim();
if (string.IsNullOrEmpty(repNo))
{
MessageBox.Show("配方名称不能为空,请选择后再保存!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (repNo.Length > 20)
{
MessageBox.Show("配方名称不能超过20个字符", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (_trackNo == 1)
{
if (!PlcRecipeUtils.T1CotRecipeCanEdit())
{
MessageBox.Show("当前工位正在工作中,请稍后!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
else if (_trackNo == 2)
{
if (!PlcRecipeUtils.T2CotRecipeCanEdit())
{
MessageBox.Show("当前工位正在工作中,请稍后!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
SRPCotInfo dalCotInfo = new SRPCotInfo();
dalCotInfo.DeleteRPCotInfoByRepNo(repNo, _trackNo);
var count = dgViewCotRecipe.Rows.Count;
for (int i = 0; i < count; i++)
{
EditSingleData(i);
}
CotSearch();
cmbRepNo.DataSource = dalCotInfo.GetAllRecpieRepNo(_trackNo);
#region 更新总配方
UpdateCotFileInfo(_trackNo, repNo);
#endregion 更新总配方
#region 更新当前配方并下发给PLC
UpdateCurrentCotFileInfo(_trackNo, repNo);
#endregion 更新当前配方并下发给PLC
}
#region 更新总配方
/// <summary>
/// 更新总配方
/// </summary>
/// <param name="trackNo">通道号</param>
/// <param name="repNo">配方号</param>
private void UpdateCotFileInfo(int trackNo, string repNo)
{
SRPCotFileInfo dalCotFileInfo = new SRPCotFileInfo();
bool bExistFile = dalCotFileInfo.ExistCotFileInfoByTrackNoRepNo(trackNo, repNo);
if (bExistFile)
{
List<MRPCotFileInfo> lstCotFileInfo = null;
lstCotFileInfo = dalCotFileInfo.GetRPCotFileInfoByTrackNoRepNo(trackNo, repNo);
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_cot_info != null)
{
jsonResult.f_rep_cot_info = GetJsonRPCotInfoList(trackNo, repNo);
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="repNo">匀胶配方号</param>
/// <returns>JSON字段列表</returns>
private List<MJsonRPCotInfo> GetJsonRPCotInfoList(int trackNo, string repNo)
{
try
{
List<MJsonRPCotInfo> lstResult = null;
SRPCotInfo dalCotInfo = new SRPCotInfo();
List<MRPCotInfo> lstCotInfo = dalCotInfo.GetRPCotInfoList(repNo, trackNo);
if (lstCotInfo != null)
{
int cotNum = lstCotInfo.Count;
if (cotNum > 0)
{
lstResult = new List<MJsonRPCotInfo>();
for (int i = 0; i < cotNum; i++)
{
MJsonRPCotInfo jsonCotInfo = new MJsonRPCotInfo();
jsonCotInfo.f_cot_rep_no = lstCotInfo[i].f_cot_rep_no;
jsonCotInfo.f_cot_plc_no = lstCotInfo[i].f_cot_plc_no;
jsonCotInfo.f_seq_no = lstCotInfo[i].f_seq_no;
jsonCotInfo.f_rotate_speed = lstCotInfo[i].f_rotate_speed;
jsonCotInfo.f_time_num = lstCotInfo[i].f_time_num;
jsonCotInfo.f_acc_speed = lstCotInfo[i].f_acc_speed;
jsonCotInfo.f_coating = lstCotInfo[i].f_coating;
jsonCotInfo.f_glue_cover = lstCotInfo[i].f_glue_cover;
jsonCotInfo.f_side_valve_ebr = lstCotInfo[i].f_side_valve_ebr;
jsonCotInfo.f_clear_valve_bsr = lstCotInfo[i].f_clear_valve_bsr;
jsonCotInfo.f_clear_valve_bsgr = lstCotInfo[i].f_clear_valve_bsgr;
jsonCotInfo.f_clear_valve_ccr1 = lstCotInfo[i].f_clear_valve_ccr1;
jsonCotInfo.f_clear_valve_ccr2 = lstCotInfo[i].f_clear_valve_ccr2;
jsonCotInfo.f_arm_rep_no = lstCotInfo[i].f_arm_rep_no;
jsonCotInfo.f_glue_time_num = lstCotInfo[i].f_glue_time_num;
lstResult.Add(jsonCotInfo);
}
}
}
return lstResult;
}
catch (Exception ex)
{
ex.ToString();
return null;
}
}
#endregion 更新总配方
#region 更新当前配方并下发给PLC
/// <summary>
/// 更新当前配方并下发配方到PLC
/// </summary>
/// <param name="trackNo">通道号</param>
/// <param name="repNo">匀胶配方号</param>
private void UpdateCurrentCotFileInfo(int trackNo, string repNo)
{
try
{
SRPCurrentCotFileInfo dalCurrentCotFileInfo = new SRPCurrentCotFileInfo();
bool bExistFile = dalCurrentCotFileInfo.ExistCotFileInfoByTrackNoRepNo(trackNo, repNo);
if (bExistFile)
{
MRPCotFileInfo cotFileInfo = null;
cotFileInfo = dalCurrentCotFileInfo.GetRPCotFileInfoByTrackNoRepNo(trackNo, repNo);
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_cot_info != null)
{
jsonResult.f_rep_cot_info.Clear();
jsonResult.f_rep_cot_info = GetJsonRPCotInfoList(trackNo, repNo);
JsonSerializerSettings jsetting = new JsonSerializerSettings();
string fileContentResult = JsonConvert.SerializeObject(jsonResult, Formatting.Indented, jsetting);
dalCurrentCotFileInfo.UpdateCotContentByFileId(cotFileInfo.f_id, fileContentResult);
}
}
}
}
SendCotInfoToPlc(trackNo, repNo);
}
}
catch (Exception ex)
{
ex.ToString();
}
}
/// <summary>
/// 发送匀胶配方到PLC
/// </summary>
/// <param name="trackNo">通道号</param>
/// <param name="repNo">匀胶配方号</param>
private void SendCotInfoToPlc(int trackNo, string repNo)
{
if (trackNo == 1)
{
if (PublicParams.T1ConnectPlc)
{
SRPCotInfo dalCotInfo = new SRPCotInfo();
List<MRPCotInfo> rpCotInfo = dalCotInfo.GetRPCotInfoList(repNo, trackNo);
PlcCotRecipeFunc.CotRecipeToPlc(trackNo, rpCotInfo);
}
}
else if (trackNo == 2)
{
if (PublicParams.T2ConnectPlc)
{
SRPCotInfo dalCotInfo = new SRPCotInfo();
List<MRPCotInfo> rpCotInfo = dalCotInfo.GetRPCotInfoList(repNo, trackNo);
PlcCotRecipeFunc.CotRecipeToPlc(trackNo, rpCotInfo);
}
}
}
#endregion 更新当前配方并下发给PLC
/// <summary>
/// 编辑单行数据
/// </summary>
/// <param name="rowNum"></param>
private void EditSingleData(int rowNum)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[rowNum];
object objID = rowCol.Cells["colID"].Value;
rpCotInfo.f_id = (objID == null || objID.ToString().Trim() == "") ? 0 : Convert.ToInt32(objID);
rpCotInfo.f_cot_rep_no = rowCol.Cells["colRepNo"].Value == null ? "" : rowCol.Cells["colRepNo"].Value.ToString().Trim();
object objcotPlcNo = rowCol.Cells["colPlcNo"].Value;
rpCotInfo.f_cot_plc_no = (objcotPlcNo == null || objcotPlcNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objcotPlcNo);
//object objSeqNo = rowCol.Cells["colSeqID"].Value;
//rpCotInfo.f_seq_no = (objSeqNo == null || objSeqNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objSeqNo);
rpCotInfo.f_seq_no = rowNum + 1;
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
object objTimeNum = rowCol.Cells["colTimeNum"].Value;
rpCotInfo.f_time_num = (objTimeNum == null || objTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objTimeNum);
object objAccSpeed = rowCol.Cells["colAccSpeed"].Value;
rpCotInfo.f_acc_speed = (objAccSpeed == null || objAccSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objAccSpeed);
object objGlueCover = rowCol.Cells["colGlueCover"].Value;
rpCotInfo.f_glue_cover = (objGlueCover == null || objGlueCover.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objGlueCover);
object objSideValveEbr = rowCol.Cells["colSideValveEBR"].Value;
rpCotInfo.f_side_valve_ebr = (objSideValveEbr == null || objSideValveEbr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objSideValveEbr);
object objClearValveBsr = rowCol.Cells["colClearValveBSR"].Value;
rpCotInfo.f_clear_valve_bsr = (objClearValveBsr == null || objClearValveBsr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsr);
object objClearValveBsgr = rowCol.Cells["colClearValveBSGR"].Value;
rpCotInfo.f_clear_valve_bsgr = (objClearValveBsgr == null || objClearValveBsgr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsgr);
//object objClearValveCcr1 = rowCol.Cells["colClearValveCCR1"].Value;
//rpCotInfo.f_clear_valve_ccr1 = (objClearValveCcr1 == null || objClearValveCcr1.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr1);
//object objClearValveCcr2 = rowCol.Cells["colClearValveCCR2"].Value;
//rpCotInfo.f_clear_valve_ccr2 = (objClearValveCcr2 == null || objClearValveCcr2.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr2);
string strGlueTimeNum = txtGlueTimeNum.Text.Trim();
if (strGlueTimeNum != "")
{
rpCotInfo.f_glue_time_num = (strGlueTimeNum == "") ? Convert.ToDecimal(0.1) : Convert.ToDecimal(strGlueTimeNum);
}
if (rdbIsCoating01.Checked)
{
rpCotInfo.f_coating = 1;
}
else if (rdbIsCoating02.Checked)
{
rpCotInfo.f_coating = 2;
}
else if (rdbIsCoating03.Checked)
{
rpCotInfo.f_coating = 3;
}
rpCotInfo.f_arm_rep_no = rowCol.Cells["colCallRepNo"].Value == null ? "" : rowCol.Cells["colCallRepNo"].Value.ToString().Trim();
rpCotInfo.f_modify_time = DateTime.Now;
rpCotInfo.f_coating = GetCoating();
rpCotInfo.f_track_no = _trackNo;
rpCotInfo.f_cot_rep_no = txtRepNo.Text.Trim();
rpCotInfo.f_creator = "管理员";
rpCotInfo.f_create_time = DateTime.Now;
SRPCotInfo dalCotInfo = new SRPCotInfo();
dalCotInfo.AddRPCotInfo(rpCotInfo);
}
private DataTable GetAddSeqDataTable()
{
DataTable dtAddSeqResult = new DataTable();
if (dtAddSeqResult != null)
{
dtAddSeqResult.Clear();
}
dtAddSeqResult = GetCurrentDgvDataTable();
var nwSeqNo = 0;
if (lstSeqNo.Count > 0)
{
nwSeqNo = lstSeqNo.Max() + 1;
}
lstSeqNo.Add(nwSeqNo);
dtAddSeqResult.Rows.Add(nwSeqNo, 0.0, 0.0, 0.0, 0, 0, 0, 0, "None", 0, 0);
return dtAddSeqResult;
}
/// <summary>
/// 初始化当前匀胶信息Table
/// </summary>
/// <param name="dtCurrentResult"></param>
private void InitCurrentCotDataTable(ref DataTable dtCurrentResult)
{
dtCurrentResult.Columns.Add("f_seq_no", typeof(int));
dtCurrentResult.Columns.Add("f_rotate_speed", typeof(float));
dtCurrentResult.Columns.Add("f_time_num", typeof(float));
dtCurrentResult.Columns.Add("f_acc_speed", typeof(float));
dtCurrentResult.Columns.Add("f_glue_cover", typeof(byte));
dtCurrentResult.Columns.Add("f_side_valve_ebr", typeof(byte));
dtCurrentResult.Columns.Add("f_clear_valve_bsr", typeof(byte));
dtCurrentResult.Columns.Add("f_clear_valve_bsgr", typeof(byte));
//dtCurrentResult.Columns.Add("f_clear_valve_ccr1", typeof(int));
//dtCurrentResult.Columns.Add("f_clear_valve_ccr2", typeof(int));
dtCurrentResult.Columns.Add("f_arm_rep_no", typeof(string));
dtCurrentResult.Columns.Add("f_coating", typeof(byte));
dtCurrentResult.Columns.Add("f_glue_time_num", typeof(int));
}
/// <summary>
/// 新增步骤时保留已经修改得数据行
/// </summary>
private DataTable GetCurrentDgvDataTable()
{
var count = dgViewCotRecipe.Rows.Count;
DataTable dtCurrentResult = new DataTable();
InitCurrentCotDataTable(ref dtCurrentResult);
lstSeqNo.Clear();
for (int i = 0; i < count; i++)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[i];
object objID = rowCol.Cells["colID"].Value;
rpCotInfo.f_id = (objID == null || objID.ToString().Trim() == "") ? 0 : Convert.ToInt32(objID);
rpCotInfo.f_cot_rep_no = rowCol.Cells["colRepNo"].Value == null ? "" : rowCol.Cells["colRepNo"].Value.ToString().Trim();
object objcotPlcNo = rowCol.Cells["colPlcNo"].Value;
rpCotInfo.f_cot_plc_no = (objcotPlcNo == null || objcotPlcNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objcotPlcNo);
object objSeqNo = rowCol.Cells["colSeqID"].Value;
rpCotInfo.f_seq_no = (objSeqNo == null || objSeqNo.ToString().Trim() == "") ? 0 : Convert.ToInt32(objSeqNo);
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
object objTimeNum = rowCol.Cells["colTimeNum"].Value;
rpCotInfo.f_time_num = (objTimeNum == null || objTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objTimeNum);
object objAccSpeed = rowCol.Cells["colAccSpeed"].Value;
rpCotInfo.f_acc_speed = (objAccSpeed == null || objAccSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objAccSpeed);
object objGlueCover = rowCol.Cells["colGlueCover"].Value;
rpCotInfo.f_glue_cover = (objGlueCover == null || objGlueCover.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objGlueCover);
object objSideValveEbr = rowCol.Cells["colSideValveEBR"].Value;
rpCotInfo.f_side_valve_ebr = (objSideValveEbr == null || objSideValveEbr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objSideValveEbr);
object objClearValveBsr = rowCol.Cells["colClearValveBSR"].Value;
rpCotInfo.f_clear_valve_bsr = (objClearValveBsr == null || objClearValveBsr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsr);
object objClearValveBsgr = rowCol.Cells["colClearValveBSGR"].Value;
rpCotInfo.f_clear_valve_bsgr = (objClearValveBsgr == null || objClearValveBsgr.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveBsgr);
if (rdbIsCoating01.Checked)
{
rpCotInfo.f_coating = 1;
}
else if (rdbIsCoating02.Checked)
{
rpCotInfo.f_coating = 2;
}
else if (rdbIsCoating03.Checked)
{
rpCotInfo.f_coating = 3;
}
string strGlueTimeNum = txtGlueTimeNum.Text.Trim();
if (strGlueTimeNum != "")
{
rpCotInfo.f_glue_time_num = (strGlueTimeNum == "") ? Convert.ToDecimal(0.1) : Convert.ToDecimal(strGlueTimeNum);
}
//object objClearValveCcr1 = rowCol.Cells["colClearValveCCR1"].Value;
//rpCotInfo.f_clear_valve_ccr1 = (objClearValveCcr1 == null || objClearValveCcr1.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr1);
//object objClearValveCcr2 = rowCol.Cells["colClearValveCCR2"].Value;
//rpCotInfo.f_clear_valve_ccr2 = (objClearValveCcr2 == null || objClearValveCcr2.ToString().Trim() == "") ? Convert.ToByte(0) : Convert.ToByte(objClearValveCcr2);
rpCotInfo.f_arm_rep_no = rowCol.Cells["colCallRepNo"].Value == null ? "" : rowCol.Cells["colCallRepNo"].Value.ToString().Trim();
if (!lstSeqNo.Contains(rpCotInfo.f_seq_no))
{
lstSeqNo.Add(rpCotInfo.f_seq_no);
dtCurrentResult.Rows.Add(rpCotInfo.f_seq_no, rpCotInfo.f_rotate_speed, rpCotInfo.f_time_num, rpCotInfo.f_acc_speed, rpCotInfo.f_glue_cover, rpCotInfo.f_side_valve_ebr, rpCotInfo.f_clear_valve_bsr, rpCotInfo.f_clear_valve_bsgr, rpCotInfo.f_arm_rep_no, rpCotInfo.f_coating, rpCotInfo.f_glue_time_num);
}
}
return dtCurrentResult;
}
private void CotSaveInfo(ref DataTable dtCurrentResult)
{
dtCurrentResult.Columns.Add("f_seq_no", typeof(int));
dtCurrentResult.Columns.Add("f_rotate_speed", typeof(float));
dtCurrentResult.Columns.Add("f_time_num", typeof(float));
dtCurrentResult.Columns.Add("f_acc_speed", typeof(float));
dtCurrentResult.Columns.Add("f_glue_cover", typeof(byte));
dtCurrentResult.Columns.Add("f_side_valve_ebr", typeof(byte));
dtCurrentResult.Columns.Add("f_clear_valve_bsr", typeof(byte));
dtCurrentResult.Columns.Add("f_clear_valve_bsgr", typeof(byte));
//dtCurrentResult.Columns.Add("f_clear_valve_ccr1", typeof(int));
//dtCurrentResult.Columns.Add("f_clear_valve_ccr2", typeof(int));
dtCurrentResult.Columns.Add("f_arm_rep_no", typeof(string));
dtCurrentResult.Columns.Add("f_coating", typeof(byte));
dtCurrentResult.Columns.Add("f_glue_time_num", typeof(int));
}
private byte GetCoating()
{
if (rdbIsCoating01.Checked)
{
return 1;
}
else if (rdbIsCoating02.Checked)
{
return 2;
}
else if (rdbIsCoating03.Checked)
{
return 3;
}
else
{
return 0;
}
}
private void tbNo_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode != Keys.Enter)
{
return;
}
CotSearch();
}
private void btnArm_Click(object sender, EventArgs e)
{
new FrmRecipeArm(_trackNo).ShowDialog();
}
private void btnDC_Click(object sender, EventArgs e)
{
}
/// <summary>
/// SelectedIndex属性发生改变时发生的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbRepNo_SelectedIndexChanged(object sender, EventArgs e)
{
string repNo = cmbRepNo.SelectedItem.ToString();
if (String.IsNullOrEmpty(repNo) || repNo.Equals("请选择"))
{
return;
}
txtRepNo.Text = repNo;
CotSearch();
}
/// <summary>
/// 单击单元格内容时发生事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgViewCotRecipe_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewTextBoxEditingControl)
{
var dgv = (DataGridView)sender;
var tb = (DataGridViewTextBoxEditingControl)e.Control;
//解除事件
tb.KeyPress -= dataGridViewTextBox_KeyPress;
tb.KeyPress -= dataGridViewTextBox1_KeyPress;
var col = dgv.CurrentCell.ColumnIndex;
if (_trackNo <= 1)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.COTzzzgsd), 1);
}
else if (_trackNo == 2)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.t2COTzzzgsd), 1);
}
// 转速、时间、加减速只能输入数字
if (dgv.CurrentCell.ColumnIndex == 4)
{
//事件追加
tb.KeyPress += dataGridViewTextBox_KeyPress;
if (selectedRowNo >= 0)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[selectedRowNo];
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
decimal speed = FormValidate.NumberMinMaxValueResult(rpCotInfo.f_rotate_speed, Convert.ToDecimal(0.0), Convert.ToDecimal(COTzzzgsd));
rpCotInfo.f_rotate_speed = Convert.ToDecimal(Convert.ToInt32(speed).ToString("#0.0"));
rowCol.Cells["colRotateSpeed"].Value = rpCotInfo.f_rotate_speed.ToString("#0.0");
}
}
else if (dgv.CurrentCell.ColumnIndex == 5 || dgv.CurrentCell.ColumnIndex == 6)
{
//事件追加
tb.KeyPress += dataGridViewTextBox1_KeyPress;
if (selectedRowNo >= 0)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[selectedRowNo];
object objTimeNum = rowCol.Cells["colTimeNum"].Value;
rpCotInfo.f_time_num = (objTimeNum == null || objTimeNum.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objTimeNum);
rowCol.Cells["colTimeNum"].Value = Convert.ToDecimal(rpCotInfo.f_time_num).ToString("#0.0");
object objAccSpeed = rowCol.Cells["colAccSpeed"].Value;
rpCotInfo.f_acc_speed = (objAccSpeed == null || objAccSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objAccSpeed);
rowCol.Cells["colAccSpeed"].Value = Convert.ToDecimal(rpCotInfo.f_acc_speed).ToString("#0.0");
}
}
}
if (e.Control is DataGridViewComboBoxEditingControl)
{
var dgv = (DataGridView)sender;
var cmb = (DataGridViewComboBoxEditingControl)e.Control;
var col = dgv.CurrentCell.ColumnIndex;
if (col == 11)
{
SRPArmInfo dalRPArmInfo = new SRPArmInfo();
combobox.DataSource = dalRPArmInfo.GetAllRecpieNo(_trackNo);
e.CellStyle.BackColor = System.Drawing.SystemColors.Control;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridViewTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyPositiveInteger(sender, e);
}
private void dataGridViewTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumber(sender, e);
}
/// <summary>
/// 在控件具有焦点并且用户按下并释放某个键后发生的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPlcNo_KeyPress(object sender, KeyPressEventArgs e)
{
FormValidate.OnlyNumbers(sender, e);
}
/// <summary>
/// 在单元格单击鼠标时发生事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgViewCotRecipe_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int rowNum = e.RowIndex;
if (rowNum >= 0)
{
var row = dgViewCotRecipe.Rows[rowNum];
if (row == dgViewCotRecipe.CurrentRow)
{
selectedRowNo = rowNum;
}
else
{
selectedRowNo = -1;
}
if (_trackNo <= 1)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.COTzzzgsd), 1);
}
else if (_trackNo == 2)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.t2COTzzzgsd), 1);
}
var nums = dgViewCotRecipe.Rows.Count;
if (nums > 0)
{
for (int i = 0; i < nums; i++)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[i];
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
decimal speed = FormValidate.NumberMinMaxValueResult(rpCotInfo.f_rotate_speed, Convert.ToDecimal(0.0), Convert.ToDecimal(COTzzzgsd));
rpCotInfo.f_rotate_speed = Convert.ToDecimal(Convert.ToInt32(speed).ToString("#0.0"));
rowCol.Cells["colRotateSpeed"].Value = rpCotInfo.f_rotate_speed.ToString("#0.0");
}
}
}
}
private void txtRepNo_TextChanged(object sender, EventArgs e)
{
CotSearch();
}
private void dgViewCotRecipe_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (_trackNo <= 1)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.COTzzzgsd), 1);
bJgpb = PublicParams.OemModelInfo.COTjgpb;
}
else if (_trackNo == 2)
{
COTzzzgsd = Math.Round(Convert.ToDouble(PublicParams.OemModelInfo.t2COTzzzgsd), 1);
bJgpb = PublicParams.OemModelInfo.t2COTjgpb;
}
if (selectedRowNo >= 0)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[selectedRowNo];
object objRotateSpeed = rowCol.Cells["colRotateSpeed"].Value;
rpCotInfo.f_rotate_speed = (objRotateSpeed == null || objRotateSpeed.ToString().Trim() == "") ? 0 : Convert.ToDecimal(objRotateSpeed);
decimal speed = FormValidate.NumberMinMaxValueResult(rpCotInfo.f_rotate_speed, Convert.ToDecimal(0.0), Convert.ToDecimal(COTzzzgsd));
rpCotInfo.f_rotate_speed = Convert.ToDecimal(Convert.ToInt32(speed).ToString("#0.0"));
rowCol.Cells["colRotateSpeed"].Value = rpCotInfo.f_rotate_speed.ToString("#0.0");
}
var nums = dgViewCotRecipe.Rows.Count;
if (nums > 0)
{
for (int i = 0; i < nums; i++)
{
MRPCotInfo rpCotInfo = new MRPCotInfo();
DataGridViewRow rowCol = dgViewCotRecipe.Rows[i];
if (bJgpb)
{
rowCol.Cells["colGlueCover"].ReadOnly = true;
}
else
{
rowCol.Cells["colGlueCover"].ReadOnly = false;
}
}
}
}
private void txtGlueTimeNum_KeyPress(object sender, KeyPressEventArgs e)
{
//FormValidate.OnlyNumber(sender, e);
}
private void txtGlueTimeNum_MouseLeave(object sender, EventArgs e)
{
string strGlueTimeNum = txtGlueTimeNum.Text.Trim();
if (strGlueTimeNum != "")
{
decimal value = Convert.ToDecimal(txtGlueTimeNum.Text.Trim());
decimal glueTime = FormValidate.NumberMinMaxValueResult(value, Convert.ToDecimal(0.1), Convert.ToDecimal(99.9));
txtGlueTimeNum.Text = glueTime.ToString();
}
}
}
}