using com.steering.mes.mcp.entity; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Mcp.CollarMaterial; using Core.StlMes.Client.Mcp.Common; using Core.StlMes.Client.Mcp.Control; using Core.StlMes.Client.Mcp.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.Mcp.CollarLibrary { public partial class FrmCollarInBound : FrmBase { private string strOutbound = "800703";//入库类型编码 private string strOutname = "";//入库类型名称 private TalentICTGXControl.TalentICTGXClass icClass; public FrmCollarInBound() { this.IsLoadUserView = true; 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 void FrmCollarInBound_Load(object sender, EventArgs e) { StorInfo(); getStoreAll(); RegStartTime.Value = DateTime.Parse(DateTime.Today.ToString("yyyy-MM-dd") + " 00:00:00"); RegEndTime.Value = DateTime.Parse(DateTime.Today.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd") + " 23:59:59"); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.WarehousePermissions.getKepNo", null, this.ob); cmbMaterial.DataSource = dt; cmbMaterial.DisplayMember = "KEP_NO"; PipeManageClass.SetComboItemHeight(cmbMaterial); PipeManageClass.setUltraGridColumnInput(ultraGrid2, new string[] { "DealNum" });//支数 PipeManageClass.setUltraGridColumnMaxInput(ultraGrid2, new string[] { "DealWt" });//重量 } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQuery(); break; case "Add": doAdd(); break; case "Delete": doDelete(); break; //case "Refresh": // doRefresh(); // break; case "Export": GridHelper.ulGridToExcel(ultraGrid2, "交易实绩表"); break; case "ReadCard": readData(); break; case "Close": this.Close(); break; case "clearCard": clearCard(); break; } } 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 void readData() { WaitingForm2 wf = new WaitingForm2("正在加载,请稍候...."); try { string outdoc = ""; if (!ConnectCard(wf)) { disConnect(); wf.Close(); 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.ToString2(); } //disConnect(); } else { wf.Close(); MessageUtil.ShowTips("读取IC卡出现错误!"); disConnect(); return; } doQueryOutList(outdoc); } catch (Exception e) { MessageUtil.ShowTips(e.Message); } finally { disConnect(); wf.Close(); } } /// /// 关闭连接 /// /// private bool disConnect() { try { if (icClass.Active) { icClass.AlarmBeep(1); //设置Active属性为false,则断开与读卡器的连接。 icClass.ToFindCard = false; icClass.Active = false; return true; } else { return true; } } catch (Exception e) { return true; } } /// /// 连接读卡器 /// /// private bool ConnectCard(WaitingForm2 wf) { try { //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; } } } catch (Exception e) { wf.Close(); MessageUtil.ShowTips("读卡器连接失败!或请切换端口尝试!"); return false; } finally { wf.Close(); } return true; } /// /// 清卡 /// private void clearCard() { string dealOrde = ""; WaitingForm2 wf = new WaitingForm2("正在加载,请稍候...."); try { if (ConnectCard(wf) == false) { return; } else { icClass.PrepareReadTemp(); if (icClass.DoReadTemp(1, 39)) { dealOrde = icClass.taskid.ToString2(); if (dealOrde != "") { //DataTable ds = ServerHelper.GetData("com.steering.ydm.bc.FrmFilpOutStorage.doQueryCount", new object[] { outDoc }, ob); DataTable ds = ServerHelper.GetData("com.steering.mes.mcp.CollarLibrary.FrmCollarInBound.doQueryCount", new object[] { dealOrde }, ob); if (int.Parse(ds.Rows[0][0].ToString2()) > 0) { MessageUtil.ShowTips("此卡有未接收倒运记录,不允许清卡!"); return; } } } else { wf.Close(); MessageUtil.ShowTips("读取IC卡出现错误,请联系相关部门!"); } } icClass.ClearCard(); icClass.AlarmBeep(1); } catch { } finally { disConnect(); wf.Close(); } } public void doQueryOutList(string dealOrde) { List listSource = EntityHelper.GetData ("com.steering.mes.mcp.CollarLibrary.FrmCollarInBound.queryOutPerfo", new object[] { dealOrde }, this.ob); couplingMatDealEntityBindingSource.DataSource = listSource; } private void doQuery() { string strRegStart = ""; string strRegEnd = ""; string strWare = "";//仓库号 string strMat = "";//框号 string strFurnace = ""; if (!CheckQuery()) return; ArrayList pram = new ArrayList(); if (chkWarehous.Checked) { strWare = cmbWarehous.Value.ToString(); } if (chkMaterial.Checked) { strMat = cmbMaterial.Value.ToString(); } if (chkRegTime.Checked) { strRegStart = RegStartTime.Value.ToString(); strRegEnd = RegEndTime.Value.ToString(); } if (chkFurnace.Checked) { strFurnace = txtFurnace.Text.Trim(); } pram.Clear(); pram.Add(strWare); pram.Add(strMat); pram.Add(strFurnace); pram.Add(strRegStart); pram.Add(strRegStart); pram.Add(strRegStart); pram.Add(strRegEnd); pram.Add(strRegEnd); string[] str = this.ValidDataPurviewIds; //获取用户对应科室ID string User = this.UserInfo.GetDeptid(); string StorageType = "";//根据传递的参数获取仓库类别 string StorageAttr = "";////根据传递的参数获取仓库类型 if (CustomInfo != "") { string[] strflg = CustomInfo.ToString().Split(new char[] { ',' }); StorageType = strflg[0]; StorageAttr = strflg[1]; } string[] arr = null; DataTable ds = ServerHelper.GetData("com.steering.mes.mcp.common.WarehousePermissions.getStoreNo", new object[] { StorageType, StorageAttr, str }, this.ob); if (ds.Rows.Count > 0) { arr = new string[ds.Rows.Count]; for (int i = 0; i < ds.Rows.Count; i++) { arr[i] = ds.Rows[i][0].ToString(); } } if (arr == null) { MessageUtil.ShowTips("无仓库权限!"); return; } if (arr.Length < 1) { return; } if (ChkOut.Checked) { List listSource = EntityHelper.GetData ("com.steering.mes.mcp.CollarLibrary.FrmCollarInBound.queryOutPerfo", new object[] { pram, arr }, this.ob); couplingMatDealEntityBindingSource.DataSource = listSource; //GridHelper.RefreshAndAutoSize(ultraGrid2); } else { List listSource = EntityHelper.GetData ("com.steering.mes.mcp.CollarLibrary.FrmCollarInBound.queryInPerfo", new object[] { pram, arr }, this.ob); couplingMatDealEntityBindingSource.DataSource = listSource; //GridHelper.RefreshAndAutoSize(ultraGrid2); } } /// /// 获取仓库 /// private void StorInfo() { string[] str = this.ValidDataPurviewIds; ArrayList arList = new ArrayList(); //获取用户对应科室ID string User = this.UserInfo.GetDeptid(); string StorageType = "";//根据传递的参数获取仓库类别 string StorageAttr = "";////根据传递的参数获取仓库类型 if (CustomInfo != "") { string[] strflg = CustomInfo.ToString().Split(new char[] { ',' }); StorageType = strflg[0]; StorageAttr = strflg[1]; } DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.WarehousePermissions.getStoreNo", new object[] { StorageType, StorageAttr, str }, this.ob); mbStorage.DataSource = dt; mbStorage.DisplayMember = "STORAGE_NAME"; mbStorage.ValueMember = "STORAGE_NO"; PipeManageClass.SetComboItemHeight(mbStorage); cmbWarehous.DataSource = dt; cmbWarehous.DisplayMember = "STORAGE_NAME"; cmbWarehous.ValueMember = "STORAGE_NO"; PipeManageClass.SetComboItemHeight(cmbWarehous); } /// /// 获取所有的目标库 /// private void getStoreAll() { string StorageType = "";//根据传递的参数获取仓库类别 string StorageAttr = "";////根据传递的参数获取仓库类型 //if (CustomInfo != "") //{ // string[] strflg = CustomInfo.ToString().Split(new char[] { ',' }); // StorageType = strflg[0]; // StorageAttr = strflg[1]; //} string[] arr = McpBaseHelper.WarehousePermissions(this.CustomInfo, this.ValidDataPurviewIds, this.ob); DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.common.WarehousePermissions.getStoreAll", new object[] { "800206", arr }, this.ob); //cmbWarehous.DataSource = dt; //cmbWarehous.DisplayMember = "STORAGE_NAME"; //cmbWarehous.ValueMember = "STORAGE_NO"; //PipeManageClass.SetComboItemHeight(cmbWarehous); CKstorage.DataSource = dt; CKstorage.DisplayMember = "STORAGE_NAME"; CKstorage.ValueMember = "STORAGE_NO"; PipeManageClass.SetComboItemHeight(CKstorage); } ///查询时验证必填项 private bool CheckQuery() { if (DataTimeUtil.JudgeTime(DateTime.Parse(RegStartTime.Value.ToString()), DateTime.Parse(RegEndTime.Value.ToString())) == 0) { MessageUtil.ShowTips("开始时间不能大于结束时间!"); return false; } if (chkWarehous.Checked && string.IsNullOrEmpty(cmbWarehous.Text.Trim())) { MessageBox.Show("请选择仓库号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } //if (chkMaterial.Checked && string.IsNullOrEmpty(cmbMaterial.Text.Trim())) //{ // MessageBox.Show("请选择料位号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; //} if (chkFurnace.Checked && string.IsNullOrEmpty(txtFurnace.Text.Trim())) { MessageBox.Show("请输入炉号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; } /// /// 验证Checked是否勾选,显示控件可编辑 打勾表示可编辑,不打勾表示不可编辑 /// /// /// private void chk_CheckedChanged(object sender, EventArgs e) { if (chkWarehous.Checked) { cmbWarehous.Enabled = true; } else { cmbWarehous.Enabled = false; } if (chkMaterial.Checked) { cmbMaterial.Enabled = true; } else { cmbMaterial.Enabled = false; } if (chkFurnace.Checked) { txtFurnace.Enabled = true; } else { txtFurnace.Enabled = false; } if (chkRegTime.Checked) { RegStartTime.Enabled = true; RegEndTime.Enabled = true; } else { RegStartTime.Enabled = false; RegEndTime.Enabled = false; } } private void FrmCollarInBound_Shown(object sender, EventArgs e) { toolMenu.Toolbars[0].Tools["Delete"].InstanceProps.Visible = DefaultableBoolean.False; } /// /// 回车键查询 /// /// /// private void txtFurnace_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { doQuery(); } } /// /// 新增 /// private void doAdd() { this.ultraGrid2.UpdateData(); ArrayList list = new ArrayList(); //查询入库类型 DataTable dt = PipeManageClass.getComTypeInfo(strOutbound, ob); if (dt.Rows.Count >= 1) { strOutname = dt.Rows[0]["BASENAME"].ToString(); } else { MessageUtil.ShowTips("入库类型不能为空,请确认基础信息是否有对应出库类型信息!"); return; } int num = 0; ArrayList List = new ArrayList(); foreach (Infragistics.Win.UltraWinGrid.UltraGridRow uRow in ultraGrid2.Rows) { if (Convert.ToBoolean(uRow.Cells["CHOOSE"].Text) == true) { num++; ArrayList pram = new ArrayList(); pram.Add(uRow.Cells["resultNo"].Text.ToString()); pram.Add(uRow.Cells["zyPlanId"].Text.ToString()); pram.Add(uRow.Cells["matNo"].Text.ToString()); pram.Add(uRow.Cells["tarKepNo"].Text.ToString()); pram.Add(uRow.Cells["tarStorageNo"].Value.ToString()); pram.Add(uRow.Cells["DealOrde"].Text.ToString()); pram.Add(this.UserInfo.GetUserName()); pram.Add(strOutbound); pram.Add(strOutname); pram.Add(uRow.Cells["WoId"].Text.ToString()); List.Add(pram); } } if (num == 0) { MessageUtil.ShowTips("请选择需要操作的数据!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认收料?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); try { this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待 if (Constant.WaitingForm == null) { Constant.WaitingForm = new WaitingForm(); } Constant.WaitingForm.ShowToUser = true; Constant.WaitingForm.Show(); Constant.WaitingForm.Update(); ccp.ServerName = "com.steering.mes.mcp.CollarLibrary.FrmCollarInBound"; ccp.MethodName = "addOutLibResult"; ccp.ServerParams = new object[] { List }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } catch (Exception ex) { this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } if (ccp.ReturnCode == -1) return; MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("收料成功!")) { clearCard(); doQuery(); } } /// /// 作废 /// private void doDelete() { UltraGridRow ugr = this.ultraGrid2.ActiveRow; int count = 0; if (ugr == null) return; ArrayList list = new ArrayList(); foreach (Infragistics.Win.UltraWinGrid.UltraGridRow uRow in ultraGrid2.Rows) { if (Convert.ToBoolean(uRow.Cells["CHOOSE"].Text) == true) { count += 1; ArrayList pram = new ArrayList(); pram.Add(uRow.Cells["resultNo"].Text.Trim()); pram.Add(uRow.Cells["zyPlanId"].Text.Trim()); pram.Add(uRow.Cells["matNo"].Text.Trim()); pram.Add(uRow.Cells["tarKepNo"].Value.ToString()); pram.Add(uRow.Cells["tarStorageNo"].Value.ToString()); pram.Add(this.UserInfo.GetUserName()); pram.Add(uRow.Cells["dealOrde"].Text.ToString()); list.Add(pram); } } if (count == 0) { MessageUtil.ShowTips("请选择要撤销的数据"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); try { this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待 if (Constant.WaitingForm == null) { Constant.WaitingForm = new WaitingForm(); } Constant.WaitingForm.ShowToUser = true; Constant.WaitingForm.Show(); Constant.WaitingForm.Update(); ccp.ServerName = "com.steering.mes.mcp.CollarLibrary.FrmCollarInBound"; ccp.MethodName = "deleteOutLibResult"; ccp.ServerParams = new object[] { list }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } catch (Exception ex) { this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } if (ccp.ReturnCode == -1) return; MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("撤销收料成功!")) { doQuery(); } } private void ultraGrid2_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { foreach (UltraGridRow uRow in ultraGrid2.Selected.Rows) { if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow)) { uRow.Cells["CHOOSE"].Value = true; } } } private void ChkOut_CheckedChanged(object sender, EventArgs e) { if (ChkOut.Checked) { ChkIn.Checked = false; ultraTabControl1.Tabs[0].Text = "倒库实绩"; //this.ultraGrid2.DisplayLayout.Bands[0].Columns["TarRecFlag"].Hidden = false; toolMenu.Toolbars[0].Tools["Delete"].InstanceProps.Visible = DefaultableBoolean.False; toolMenu.Toolbars[0].Tools["Add"].InstanceProps.Visible = DefaultableBoolean.True; toolMenu.Toolbars[0].Tools["ReadCard"].InstanceProps.Visible = DefaultableBoolean.True; } else { ultraTabControl1.Tabs[0].Text = "收料实绩"; //this.ultraGrid2.DisplayLayout.Bands[0].Columns["TarRecFlag"].Hidden = true; toolMenu.Toolbars[0].Tools["Add"].InstanceProps.Visible = DefaultableBoolean.False; toolMenu.Toolbars[0].Tools["Delete"].InstanceProps.Visible = DefaultableBoolean.True; toolMenu.Toolbars[0].Tools["ReadCard"].InstanceProps.Visible = DefaultableBoolean.False; } } private void ChkIn_CheckedChanged(object sender, EventArgs e) { if (ChkIn.Checked) { ChkOut.Checked = false; } } } }