using Core.Mes.Client.Comm.Control; 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 FrmGateFrim1 : FrmBase { public FrmGateFrim1() { 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 FrmGateFrim1_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]); arr = this.ValidDataPurviewIds; this.txtCom.SelectedIndex = 0; } private void chkDk_CheckedChanged(object sender, EventArgs e) { this.txtOutList.Enabled = chkDk.Checked; } private void chkFurnace_CheckedChanged(object sender, EventArgs e) { this.txtFurnace.Enabled = chkFurnace.Checked; } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "ReadCard": ReadData(); break; case "Query": Query(); break; case "Confirm": Confirm(); break; case "CancelConfirm": CancelConfirm(); break; case "Close": Close(); break; } } /// /// 读卡查询出库信息 /// /// public void doQueryOutList(string dealOrde){ List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim1.doQueryOutList", new object[] { dealOrde }, this.ob); couplingMatDealEntityBindingSource.DataSource = listSource; } /// /// 读卡 /// public 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; } doQueryOutList(outdoc); } finally { disConnect(); wf.Close(); } } /// /// 查询 /// public void Query() { string strRegStart = ""; string strRegEnd = ""; string judgeNo = ""; string dealOrde = ""; ArrayList parm = new ArrayList(); if (chkRegTime.Checked) { strRegStart = RegStartTime.Value.ToString(); strRegEnd = RegEndTime.Value.ToString(); } if (chkFurnace.Checked) { judgeNo = this.txtFurnace.Text.Trim(); } if (chkDk.Checked) { dealOrde = this.txtOutList.Text.Trim(); } parm.Add(strRegStart); parm.Add(strRegEnd); parm.Add(judgeNo); parm.Add(dealOrde); if (ultraTabControl1.SelectedTab.Index == 0) { List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim1.QueryBefore", new object[] { parm }, this.ob); couplingMatDealEntityBindingSource.DataSource = listSource; } else { List listSource = EntityHelper.GetData( "com.steering.ydm.bc.FrmGateFrim1.QueryDone", new object[] { parm }, this.ob); couplingMatDealEntityBindingSource1.DataSource = listSource; } } /// /// 确认出厂 /// public void Confirm() { this.ultraGrid1.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) { return; } string dealOrde = uRow.Cells["DealOrde"].Text.ToString(); if (MessageUtil.ShowYesNoAndQuestion("是否确认出厂?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.ydm.bc.FrmGateFrim1"; ccp.MethodName = "Confirm"; ccp.ServerParams = new object[] { dealOrde , UserInfo.GetUserName() }; ccp = ob.ExecuteNonQuery(ccp,CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("确认出厂成功!")) { Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 撤销确认出厂 /// public void CancelConfirm() { this.ultraGrid2.UpdateData(); UltraGridRow uRow = this.ultraGrid2.ActiveRow; if (uRow == null) { return; } string dealOrde = uRow.Cells["DealOrde"].Text.ToString(); if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销出厂?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.ydm.bc.FrmGateFrim1"; ccp.MethodName = "CancelConfirm"; ccp.ServerParams = new object[] { dealOrde }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("撤销确认出厂成功!")) { Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 关闭连接 /// /// 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 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("Confirm")) { toolMenu.Toolbars[0].Tools["Confirm"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("CancelConfirm")) { toolMenu.Toolbars[0].Tools["CancelConfirm"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 1 ? DefaultableBoolean.True : DefaultableBoolean.False; } } } }