using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.YdmBcPipeManage.Entity; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace Core.StlMes.Client.YdmBcPipeManage { public partial class FrmGateFrim : FrmBase { public FrmGateFrim() { InitializeComponent(); try { string[] portnames = System.IO.Ports.SerialPort.GetPortNames(); //获取计算机串口数组 if (portnames is Infragistics.Win.UltraWinGrid.Nullable || portnames.Length < 1) { portnames = new string[10] { "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10" }; } txtCom.DataSource = portnames; } catch (Exception eex3) { MessageBox.Show(eex3.Message); } } private string[] arr = null; private TalentICTGXControl.TalentICTGXClass icClass; private void FrmGateFrim_Load(object sender, EventArgs e) { DateTime now = DateTime.Now; DateTime dt1 = new DateTime(now.Year, now.Month, 1);//当月第一天 DateTime dt2 = dt1.AddMonths(1).AddDays(-1);//当月最后一天 this.RegStartTime.Value = DateTime.Parse(dt1.ToString("yyyy-MM-dd") + " 00:00:00"); this.RegEndTime.Value = DateTime.Parse(dt2.ToString("yyyy-MM-dd") + " 23:59:59"); BaseMethod.InitCellPosition(ultraGrid1, new string[] { "ActWeight", "ActCount", "ActDimater", "ActHeight", "ActLenMin", "ActLenMax", "ActLen" }); BaseMethod.InitCellPosition(ultraGrid2, new string[] { "ActWeight", "ActCount", "ActDimater", "ActHeight", "ActLenMin", "ActLenMax", "ActLen" }); EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid3.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid4.DisplayLayout.Bands[0]); arr = this.ValidDataPurviewIds; this.txtCom.SelectedIndex = 0; } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "ReadCard": readData(); break; case "Query": //if (!CheckQuery()) return; doQueryData(); break; case"QueryFrim": doQueryFrim(); break; case "Comfrim": doComfrim(); break; case"CancelComfrim": cancelComfrim(); break; case "Close": close(); break; } } /// /// 查询已出厂确认 /// private void doQueryFrim() { string strRegStart = ""; string strRegEnd = ""; string heatNo = ""; string outDoc = ""; ArrayList parm = new ArrayList(); if (chkRegTime.Checked) { strRegStart = RegStartTime.Value.ToString(); strRegEnd = RegEndTime.Value.ToString(); } if (chkFurnace.Checked) { heatNo = this.txtFurnace.Text.Trim(); } if (chkDk.Checked) { outDoc = this.txtOutList.Text.Trim(); } parm.Add(strRegStart); parm.Add(strRegEnd); parm.Add(heatNo); parm.Add(outDoc); List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim.doQueryBcOutList2", new object[] { parm,arr }, this.ob); ydmBcOutlistEntityBindingSource1.DataSource = listSource; List listSource1 = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim.doQueryGpOutList2", new object[] { parm,arr }, this.ob); ydmGpOutlistEntityBindingSource1.DataSource = listSource1; } private bool CheckQuery() { if (DataTimeUtil.JudgeTime(DateTime.Parse(RegStartTime.Value.ToString()), DateTime.Parse(RegEndTime.Value.ToString())) == 0) { MessageUtil.ShowTips("开始时间不能大于结束时间!"); return false; } if (chkFurnace.Checked && string.IsNullOrEmpty(txtFurnace.Text.Trim())) { MessageBox.Show("请输入炉号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (chkDk.Checked && string.IsNullOrEmpty(txtOutList.Text.Trim())) { MessageUtil.ShowTips("请输入倒库单号!"); return false; } if (string.IsNullOrEmpty(txtFurnace.Text.Trim()) && string.IsNullOrEmpty(txtOutList.Text.Trim())) { MessageUtil.ShowTips("不读卡时,请输入炉号或者倒库单号!"); return false; } return true; } /// /// 查询倒库信息 /// private void doQueryData() { string strRegStart = ""; string strRegEnd = ""; string heatNo = ""; string outDoc = ""; ArrayList parm = new ArrayList(); if (chkRegTime.Checked) { strRegStart = RegStartTime.Value.ToString(); strRegEnd = RegEndTime.Value.ToString(); } if (chkFurnace.Checked) { heatNo = this.txtFurnace.Text.Trim(); } if (chkDk.Checked) { outDoc = this.txtOutList.Text.Trim(); } parm.Add(strRegStart); parm.Add(strRegEnd); parm.Add(heatNo); parm.Add(outDoc); List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim.doQueryBcOutList1", new object[] { parm }, this.ob); ydmBcOutlistEntityBindingSource.DataSource = listSource; List listSource1 = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim.doQueryGpOutList1", new object[] { parm }, this.ob); ydmGpOutlistEntityBindingSource.DataSource = listSource1; foreach (UltraGridRow ugr in ultraGrid1.Rows) { if (!ugr.Cells["ProductFlag"].Value.ToString().Equals("在制品") && (ugr.Cells["PonderGrossWt"].Value == null || String.IsNullOrEmpty(ugr.Cells["PonderGrossWt"].Value.ToString())) && ugr.Cells["MeterWeight"].Value == null && (ugr.Cells["PlineCode"].Value.ToString().Equals("C008") || ugr.Cells["PlineCode"].Value.ToString().Equals("C009") || ugr.Cells["PlineCode"].Value.ToString().Equals("C017"))) { ugr.Appearance.BackColor = Color.Red; } } } /// /// 出厂确认 /// private void doComfrim() { this.ultraGrid1.UpdateData(); this.ultraGrid2.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; UltraGridRow uRow1 = this.ultraGrid2.ActiveRow; if (uRow == null && uRow1 == null) { return; } YdmGpOutlistEntity ydmGpEntity = new YdmGpOutlistEntity(); string ydmGpTity = ""; YdmBcOutlistEntity ydmBcEntity = new YdmBcOutlistEntity(); string ydmBcTity = ""; if (uRow != null) { ydmBcEntity = (YdmBcOutlistEntity)uRow.ListObject; ydmBcTity = JSONFormat.Format(ydmBcEntity); } if (uRow1 != null) { ydmGpEntity = (YdmGpOutlistEntity)uRow1.ListObject; ydmGpTity = JSONFormat.Format(ydmGpEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否确认出厂?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.ydm.bc.FrmGateFrim"; ccp.MethodName = "doComfrim"; ccp.ServerParams = new object[] { ydmBcTity, ydmGpTity,UserInfo.GetUserName(),UserInfo.GetDeptid(),UserInfo.GetDepartment() }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("确认出厂成功!")) { ydmBcOutlistEntityBindingSource.Clear(); ydmGpOutlistEntityBindingSource.Clear(); //readData(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 撤销出厂确认 /// private void cancelComfrim() { this.ultraGrid3.UpdateData(); this.ultraGrid4.UpdateData(); UltraGridRow uRow = this.ultraGrid3.ActiveRow; UltraGridRow uRow1 = this.ultraGrid4.ActiveRow; if (uRow == null && uRow1 == null) { return; } YdmGpOutlistEntity ydmGpEntity = new YdmGpOutlistEntity(); string ydmGpTity = ""; YdmBcOutlistEntity ydmBcEntity = new YdmBcOutlistEntity(); string ydmBcTity = ""; if (uRow != null) { ydmBcEntity = (YdmBcOutlistEntity)uRow.ListObject; ydmBcTity = JSONFormat.Format(ydmBcEntity); } if (uRow1 != null) { ydmGpEntity = (YdmGpOutlistEntity)uRow1.ListObject; ydmGpTity = JSONFormat.Format(ydmGpEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销出厂?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.ydm.bc.FrmGateFrim"; ccp.MethodName = "cancelComfrim"; ccp.ServerParams = new object[] { ydmBcTity, ydmGpTity }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("撤销确认成功!")) { doQueryFrim(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } private void close() { this.Close(); } /// /// 读卡 /// private void readData() { WaitingForm2 wf = new WaitingForm2("正在加载,请稍候...."); try { string outDoc = ""; if (!ConnectCard(wf)) { disConnect(); return; } icClass.PrepareReadTemp(); //bool b = icClass.DoReadTemp(1, 39); if (icClass.DoReadTemp(1, 39)) { int count = icClass.RecordCount; if (count == 0) //判断卡上的记录数 { wf.Close(); MessageUtil.ShowTips("IC卡无记录,请核实!"); disConnect(); return; } else { outDoc = icClass.taskid; } //disConnect(); } else { wf.Close(); MessageUtil.ShowTips("读取IC卡出现错误!"); disConnect(); return; } doQueryBcOutList(outDoc); doQueryGpOutList(outDoc); } finally { disConnect(); wf.Close(); } } /// /// 读卡查询管坯倒库信息 /// /// private void doQueryGpOutList(string outDoc) { List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim.doQueryGpOutList", new object[] { outDoc }, this.ob); ydmGpOutlistEntityBindingSource.DataSource = listSource; } /// /// 读卡查询钢管倒库信息 /// /// private void doQueryBcOutList(string outDoc) { List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim.doQueryBcOutList", new object[] { outDoc }, this.ob); ydmBcOutlistEntityBindingSource.DataSource = listSource; foreach (UltraGridRow ugr in ultraGrid1.Rows) { if (!ugr.Cells["ProductFlag"].Value.ToString().Equals("在制品") && (ugr.Cells["PonderGrossWt"].Value == null || String.IsNullOrEmpty(ugr.Cells["PonderGrossWt"].Value.ToString())) && ugr.Cells["MeterWeight"].Value == null && (ugr.Cells["PlineCode"].Value.ToString().Equals("C008") || ugr.Cells["PlineCode"].Value.ToString().Equals("C009") || ugr.Cells["PlineCode"].Value.ToString().Equals("C017"))) { ugr.Appearance.BackColor = Color.Red; } } } /// /// 关闭连接 /// /// private bool disConnect() { if (icClass.Active) { icClass.AlarmBeep(1); //设置Active属性为false,则断开与读卡器的连接。 icClass.ToFindCard = false; icClass.Active = false; return true; } else { return true; } } void icClass_OnFindCard() { icClass.OnFindCard -= new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard); icClass.OnDropCard += new TalentICTGXControl.ITalentICTGXEvents_OnDropCardEventHandler(icClass_OnDropCard); } void icClass_OnDropCard() { //将OnDropCard事件从委托链中删除,并加入OnFindCard事件到委托链中。 //这样就实现了程序中自动寻卡的功能。 icClass.OnDropCard -= new TalentICTGXControl.ITalentICTGXEvents_OnDropCardEventHandler(icClass_OnDropCard); icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard); } /// /// 连接读卡器 /// /// private bool ConnectCard(WaitingForm2 wf) { //if (icClass == null) //{ // icClass = new TalentICTGXControl.TalentICTGXClass(); // //委托OnFindCard事件,icClass_OnFindCard是该事件要执行的方法。 // //此事件在当IC卡放到读卡器上时触发。 // icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard); //} icClass = IcReadWrite.getIcClass(); int comNum = (short)(short.Parse(txtCom.Text.Replace("COM", "")) - 1); icClass.CommPort = comNum; if (!icClass.Active) { //利用ToFindCard属性连接读卡器,启动OnFindCard事件。 icClass.ToFindCard = true; if (icClass.Active) { //AlarmBeep(int times)方法实现了让IC卡读卡器发出警示音, //参数为发出几次警示音。 icClass.AlarmBeep(2); Thread.Sleep(500); return true; } else { wf.Close(); MessageUtil.ShowTips("读卡器连接失败!或请切换端口尝试!"); return false; } } return true; } /// /// 清卡 /// private void clearCard() { WaitingForm2 wf = new WaitingForm2("正在加载,请稍候...."); try { if (ConnectCard(wf) == false) { return; } icClass.ClearCard(); icClass.AlarmBeep(1); } catch { } finally { disConnect(); wf.Close(); } } private void chkRegTime_CheckedChanged(object sender, EventArgs e) { this.RegStartTime.Enabled = this.chkRegTime.Checked; this.RegEndTime.Enabled = this.chkRegTime.Checked; } private void chkDk_CheckedChanged(object sender, EventArgs e) { this.txtOutList.Enabled = this.chkDk.Checked; } private void chkFurnace_CheckedChanged(object sender, EventArgs e) { txtFurnace.Enabled = this.chkFurnace.Checked; } private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e) { if (toolMenu == null || toolMenu.Toolbars == null) return; if (toolMenu.Toolbars[0].Tools.Exists("ReadCard")) { toolMenu.Toolbars[0].Tools["ReadCard"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("Query")) { toolMenu.Toolbars[0].Tools["Query"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("Comfrim")) { toolMenu.Toolbars[0].Tools["Comfrim"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("QueryFrim")) { toolMenu.Toolbars[0].Tools["QueryFrim"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 1 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("CancelComfrim")) { toolMenu.Toolbars[0].Tools["CancelComfrim"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 1 ? DefaultableBoolean.True : DefaultableBoolean.False; } } private void FrmGateFrim_Shown(object sender, EventArgs e) { if (toolMenu == null) return; if (toolMenu.Toolbars[0].Tools.Exists("QueryFrim")) { toolMenu.Toolbars[0].Tools["QueryFrim"].InstanceProps.Visible = DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("CancelComfrim")) { toolMenu.Toolbars[0].Tools["CancelComfrim"].InstanceProps.Visible = DefaultableBoolean.False; } } } }