FrmGateFrim1.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Tool;
  3. using Core.StlMes.Client.YdmBcPipeManage.Entity;
  4. using CoreFS.CA06;
  5. using Infragistics.Win;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Windows.Forms;
  17. namespace Core.StlMes.Client.YdmBcPipeManage
  18. {
  19. public partial class FrmGateFrim1 : FrmBase
  20. {
  21. public FrmGateFrim1()
  22. {
  23. InitializeComponent();
  24. try
  25. {
  26. string[] portnames = System.IO.Ports.SerialPort.GetPortNames(); //获取计算机串口数组
  27. if (portnames is Infragistics.Win.UltraWinGrid.Nullable || portnames.Length < 1)
  28. {
  29. portnames = new string[10] { "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10" };
  30. }
  31. txtCom.DataSource = portnames;
  32. }
  33. catch (Exception eex3)
  34. {
  35. MessageBox.Show(eex3.Message);
  36. }
  37. }
  38. private string[] arr = null;
  39. private TalentICTGXControl.TalentICTGXClass icClass;
  40. private void FrmGateFrim1_Load(object sender, EventArgs e)
  41. {
  42. DateTime now = DateTime.Now;
  43. DateTime dt1 = new DateTime(now.Year, now.Month, 1);//当月第一天
  44. DateTime dt2 = dt1.AddMonths(1).AddDays(-1);//当月最后一天
  45. this.RegStartTime.Value = DateTime.Parse(dt1.ToString("yyyy-MM-dd") + " 00:00:00");
  46. this.RegEndTime.Value = DateTime.Parse(dt2.ToString("yyyy-MM-dd") + " 23:59:59");
  47. //BaseMethod.InitCellPosition(ultraGrid1, new string[] { "ActWeight", "ActCount", "ActDimater", "ActHeight", "ActLenMin", "ActLenMax", "ActLen" });
  48. //BaseMethod.InitCellPosition(ultraGrid2, new string[] { "ActWeight", "ActCount", "ActDimater", "ActHeight", "ActLenMin", "ActLenMax", "ActLen" });
  49. EntityHelper.ShowGridCaption<CouplingMatDealEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  50. EntityHelper.ShowGridCaption<CouplingMatDealEntity>(ultraGrid2.DisplayLayout.Bands[0]);
  51. arr = this.ValidDataPurviewIds;
  52. this.txtCom.SelectedIndex = 0;
  53. }
  54. private void chkDk_CheckedChanged(object sender, EventArgs e)
  55. {
  56. this.txtOutList.Enabled = chkDk.Checked;
  57. }
  58. private void chkFurnace_CheckedChanged(object sender, EventArgs e)
  59. {
  60. this.txtFurnace.Enabled = chkFurnace.Checked;
  61. }
  62. public override void ToolBar_Click(object sender, string ToolbarKey)
  63. {
  64. switch (ToolbarKey)
  65. {
  66. case "ReadCard":
  67. ReadData();
  68. break;
  69. case "Query":
  70. Query();
  71. break;
  72. case "Confirm":
  73. Confirm();
  74. break;
  75. case "CancelConfirm":
  76. CancelConfirm();
  77. break;
  78. case "Close":
  79. Close();
  80. break;
  81. }
  82. }
  83. /// <summary>
  84. /// 读卡查询出库信息
  85. /// </summary>
  86. /// <param name="dealOrde"></param>
  87. public void doQueryOutList(string dealOrde){
  88. List<CouplingMatDealEntity> listSource = EntityHelper.GetData<CouplingMatDealEntity>(
  89. "com.steering.ydm.bc.FrmGateFrim1.doQueryOutList", new object[] { dealOrde }, this.ob);
  90. couplingMatDealEntityBindingSource.DataSource = listSource;
  91. }
  92. /// <summary>
  93. /// 读卡
  94. /// </summary>
  95. public void ReadData()
  96. {
  97. WaitingForm2 wf = new WaitingForm2("正在加载,请稍候....");
  98. try
  99. {
  100. string outdoc = "";
  101. if (!ConnectCard(wf))
  102. {
  103. disConnect();
  104. return;
  105. }
  106. icClass.PrepareReadTemp();
  107. //bool b = icClass.DoReadTemp(1, 39);
  108. if (icClass.DoReadTemp(1, 39))
  109. {
  110. int count = icClass.RecordCount;
  111. if (count == 0) //判断卡上的记录数
  112. {
  113. wf.Close();
  114. MessageUtil.ShowTips("IC卡无记录,请核实!");
  115. disConnect();
  116. return;
  117. }
  118. else
  119. {
  120. outdoc = icClass.taskid;
  121. }
  122. //disConnect();
  123. }
  124. else
  125. {
  126. wf.Close();
  127. MessageUtil.ShowTips("读取IC卡出现错误!");
  128. disConnect();
  129. return;
  130. }
  131. doQueryOutList(outdoc);
  132. }
  133. finally
  134. {
  135. disConnect();
  136. wf.Close();
  137. }
  138. }
  139. /// <summary>
  140. /// 查询
  141. /// </summary>
  142. public void Query()
  143. {
  144. string strRegStart = "";
  145. string strRegEnd = "";
  146. string judgeNo = "";
  147. string dealOrde = "";
  148. ArrayList parm = new ArrayList();
  149. if (chkRegTime.Checked)
  150. {
  151. strRegStart = RegStartTime.Value.ToString();
  152. strRegEnd = RegEndTime.Value.ToString();
  153. }
  154. if (chkFurnace.Checked)
  155. {
  156. judgeNo = this.txtFurnace.Text.Trim();
  157. }
  158. if (chkDk.Checked)
  159. {
  160. dealOrde = this.txtOutList.Text.Trim();
  161. }
  162. parm.Add(strRegStart);
  163. parm.Add(strRegEnd);
  164. parm.Add(judgeNo);
  165. parm.Add(dealOrde);
  166. if (ultraTabControl1.SelectedTab.Index == 0)
  167. {
  168. List<CouplingMatDealEntity> listSource = EntityHelper.GetData<CouplingMatDealEntity>(
  169. "com.steering.ydm.bc.FrmGateFrim1.QueryBefore", new object[] { parm }, this.ob);
  170. couplingMatDealEntityBindingSource.DataSource = listSource;
  171. }
  172. else
  173. {
  174. List<CouplingMatDealEntity> listSource = EntityHelper.GetData<CouplingMatDealEntity>(
  175. "com.steering.ydm.bc.FrmGateFrim1.QueryDone", new object[] { parm }, this.ob);
  176. couplingMatDealEntityBindingSource1.DataSource = listSource;
  177. }
  178. }
  179. /// <summary>
  180. /// 确认出厂
  181. /// </summary>
  182. public void Confirm()
  183. {
  184. this.ultraGrid1.UpdateData();
  185. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  186. if (uRow == null)
  187. {
  188. return;
  189. }
  190. string dealOrde = uRow.Cells["DealOrde"].Text.ToString();
  191. if (MessageUtil.ShowYesNoAndQuestion("是否确认出厂?") == DialogResult.No)
  192. {
  193. return;
  194. }
  195. CoreClientParam ccp = new CoreClientParam();
  196. ccp.ServerName = "com.steering.ydm.bc.FrmGateFrim1";
  197. ccp.MethodName = "Confirm";
  198. ccp.ServerParams = new object[] { dealOrde , UserInfo.GetUserName() };
  199. ccp = ob.ExecuteNonQuery(ccp,CoreInvokeType.Internal);
  200. if (ccp.ReturnCode != -1)
  201. {
  202. if (ccp.ReturnInfo.Equals("确认出厂成功!"))
  203. {
  204. Query();
  205. MessageUtil.ShowTips(ccp.ReturnInfo);
  206. }
  207. else
  208. {
  209. MessageUtil.ShowTips(ccp.ReturnInfo);
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// 撤销确认出厂
  215. /// </summary>
  216. public void CancelConfirm()
  217. {
  218. this.ultraGrid2.UpdateData();
  219. UltraGridRow uRow = this.ultraGrid2.ActiveRow;
  220. if (uRow == null)
  221. {
  222. return;
  223. }
  224. string dealOrde = uRow.Cells["DealOrde"].Text.ToString();
  225. if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销出厂?") == DialogResult.No)
  226. {
  227. return;
  228. }
  229. CoreClientParam ccp = new CoreClientParam();
  230. ccp.ServerName = "com.steering.ydm.bc.FrmGateFrim1";
  231. ccp.MethodName = "CancelConfirm";
  232. ccp.ServerParams = new object[] { dealOrde };
  233. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  234. if (ccp.ReturnCode != -1)
  235. {
  236. if (ccp.ReturnInfo.Equals("撤销确认出厂成功!"))
  237. {
  238. Query();
  239. MessageUtil.ShowTips(ccp.ReturnInfo);
  240. }
  241. else
  242. {
  243. MessageUtil.ShowTips(ccp.ReturnInfo);
  244. }
  245. }
  246. }
  247. ///<summary>
  248. /// 关闭连接
  249. /// </summary>
  250. /// <returns></returns>
  251. private bool disConnect()
  252. {
  253. if (icClass.Active)
  254. {
  255. icClass.AlarmBeep(1);
  256. //设置Active属性为false,则断开与读卡器的连接。
  257. icClass.ToFindCard = false;
  258. icClass.Active = false;
  259. return true;
  260. }
  261. else
  262. {
  263. return true;
  264. }
  265. }
  266. void icClass_OnFindCard()
  267. {
  268. icClass.OnFindCard -= new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
  269. icClass.OnDropCard += new TalentICTGXControl.ITalentICTGXEvents_OnDropCardEventHandler(icClass_OnDropCard);
  270. }
  271. void icClass_OnDropCard()
  272. {
  273. //将OnDropCard事件从委托链中删除,并加入OnFindCard事件到委托链中。
  274. //这样就实现了程序中自动寻卡的功能。
  275. icClass.OnDropCard -= new TalentICTGXControl.ITalentICTGXEvents_OnDropCardEventHandler(icClass_OnDropCard);
  276. icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
  277. }
  278. /// <summary>
  279. /// 连接读卡器
  280. /// </summary>
  281. /// <returns></returns>
  282. private bool ConnectCard(WaitingForm2 wf)
  283. {
  284. //if (icClass == null)
  285. //{
  286. // icClass = new TalentICTGXControl.TalentICTGXClass();
  287. // //委托OnFindCard事件,icClass_OnFindCard是该事件要执行的方法。
  288. // //此事件在当IC卡放到读卡器上时触发。
  289. // icClass.OnFindCard += new TalentICTGXControl.ITalentICTGXEvents_OnFindCardEventHandler(icClass_OnFindCard);
  290. //}
  291. icClass = IcReadWrite.getIcClass();
  292. int comNum = (short)(short.Parse(txtCom.Text.Replace("COM", "")) - 1);
  293. icClass.CommPort = comNum;
  294. if (!icClass.Active)
  295. {
  296. //利用ToFindCard属性连接读卡器,启动OnFindCard事件。
  297. icClass.ToFindCard = true;
  298. if (icClass.Active)
  299. {
  300. //AlarmBeep(int times)方法实现了让IC卡读卡器发出警示音,
  301. //参数为发出几次警示音。
  302. icClass.AlarmBeep(2);
  303. Thread.Sleep(500);
  304. return true;
  305. }
  306. else
  307. {
  308. wf.Close();
  309. MessageUtil.ShowTips("读卡器连接失败!或请切换端口尝试!");
  310. return false;
  311. }
  312. }
  313. return true;
  314. }
  315. /// <summary>
  316. /// 清卡
  317. /// </summary>
  318. private void clearCard()
  319. {
  320. WaitingForm2 wf = new WaitingForm2("正在加载,请稍候....");
  321. try
  322. {
  323. if (ConnectCard(wf) == false)
  324. {
  325. return;
  326. }
  327. icClass.ClearCard();
  328. icClass.AlarmBeep(1);
  329. }
  330. catch
  331. {
  332. }
  333. finally
  334. {
  335. disConnect();
  336. wf.Close();
  337. }
  338. }
  339. private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
  340. {
  341. if (toolMenu == null || toolMenu.Toolbars == null) return;
  342. if (toolMenu.Toolbars[0].Tools.Exists("ReadCard")) { toolMenu.Toolbars[0].Tools["ReadCard"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; }
  343. if (toolMenu.Toolbars[0].Tools.Exists("Confirm")) { toolMenu.Toolbars[0].Tools["Confirm"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; }
  344. if (toolMenu.Toolbars[0].Tools.Exists("CancelConfirm")) { toolMenu.Toolbars[0].Tools["CancelConfirm"].InstanceProps.Visible = this.ultraTabControl1.SelectedTab.Index == 1 ? DefaultableBoolean.True : DefaultableBoolean.False; }
  345. }
  346. }
  347. }