锐腾搅拌上料功能
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.

1092 lines
45 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.Linq;
  6. using System.Linq;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.BandedGrid;
  12. using DevExpress.XtraGrid.Columns;
  13. using DevExpress.XtraGrid;
  14. using System.IO;
  15. using System.Threading;
  16. using ICSSoft.Base.Language.Tool;
  17. using ICSSoft.Base.Config.AppConfig;
  18. using ICSSoft.Base.UserControl.MessageControl;
  19. using ICSSoft.Base.Config.DBHelper;
  20. using ICSSoft.Base.Report.Filter;
  21. using ICSSoft.Base.UserControl.FormControl;
  22. using ICSSoft.Base.Report.GridReport;
  23. using ICSSoft.Base.ReferForm.AppReferForm;
  24. using ICSSoft.Frame.Data.BLL;
  25. using ICSSoft.Frame.Data.Entity;
  26. using System.Collections;
  27. using ICSSoft.Frame.DataConnect;
  28. using ICSSoft.Frame.DataConnect.Action;
  29. using ICSSoft.Frame.DataCollect;
  30. namespace ICSSoft.Frame.APP
  31. {
  32. public partial class FormMaterialColect : DevExpress.XtraEditors.XtraForm
  33. {
  34. private ActionCheckStatus actionCheckStatus = new ActionCheckStatus();
  35. private Hashtable listActionCheckStatus = new Hashtable();
  36. private DataSet ds;
  37. private DataTable dtzhu;
  38. private DataTable dtone;
  39. //资源
  40. public string res = "";
  41. string checkGroup = "";
  42. string _RuningCard = "";
  43. private ICSRES Resource;
  44. String guid = AppConfig.GetGuid();
  45. FormDataShow datashow = new FormDataShow();
  46. private bool _NeedInputLotPart;
  47. private ICSBaseModel _ICSBaseModel = null;
  48. private ProductInfo productInfo = null;
  49. private Hashtable listOpBomKeyParts = new Hashtable();
  50. private string _inno;
  51. private string INNO
  52. {
  53. get
  54. {
  55. return _inno;
  56. }
  57. set
  58. {
  59. _inno = value.Trim();
  60. }
  61. }
  62. private const string opCollectAutoCollectLotPart = "0";
  63. private const string opCollectNeedInputLotPart = "1";
  64. private int _CollectedCount = 0;
  65. private List<ICSOPBOMDETAIL> _OPBOMDetailList;
  66. private ArrayList _OPBOMDetailArrayList = new ArrayList();
  67. private List<ICSOPBOMDETAIL> _OPBOMDetailKeyPartList;
  68. private ArrayList _OPBOMDetailKeyPartArrayList = new ArrayList();
  69. private List<ICSMINNO> _PreparedLotPartList;
  70. private ArrayList _PreparedLotPartArrayList = new ArrayList();
  71. private List<ICSOPBOMDETAIL> _objBomDetailNotFilter;
  72. ArrayList _InputPartList = new ArrayList();
  73. private FramDataContext _domainDataProvider = null;
  74. private FramDataContext DataProvider
  75. {
  76. get
  77. {
  78. return _domainDataProvider;
  79. }
  80. }
  81. private DataCollectFacade _DataCollectFacade;
  82. private ICSMINNOBLL _MinnoBll = null;
  83. private bool _HaveCollectMaterial = false;
  84. private int _FlowControl = -1;
  85. private int FlowControl
  86. {
  87. get
  88. {
  89. return _FlowControl;
  90. }
  91. set
  92. {
  93. _FlowControl = value;
  94. }
  95. }
  96. #region 构造函数
  97. public FormMaterialColect()
  98. {
  99. InitializeComponent();
  100. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  101. this.WindowState = FormWindowState.Maximized;
  102. _domainDataProvider = new FramDataContext(AppConfig.AppConnectString);
  103. _DataCollectFacade = new DataCollectFacade(this._domainDataProvider);
  104. _ICSBaseModel = new ICSBaseModel(this._domainDataProvider);
  105. }
  106. public FormMaterialColect(string resource)
  107. {
  108. InitializeComponent();
  109. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  110. this.WindowState = FormWindowState.Maximized;
  111. ds = new DataSet();
  112. res = resource;
  113. _domainDataProvider = new FramDataContext(AppConfig.AppConnectString);
  114. _DataCollectFacade = new DataCollectFacade(this._domainDataProvider);
  115. _ICSBaseModel = new ICSBaseModel(this._domainDataProvider);
  116. }
  117. #endregion
  118. private void FormICSONWIPITEM_Load(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. FormResourceLogin formResourceLogin = new FormResourceLogin(this);
  123. formResourceLogin.ShowDialog();
  124. txtInfo.Text = "当前登陆资源是:" + res;
  125. Resource = this._domainDataProvider.ICSRES.SingleOrDefault(a => a.RESCODE == this.res && a.WorkPoint == AppConfig.WorkPointCode);
  126. string sql = @"select OPCODE
  127. from ICSOP2RES
  128. where RESCODE='" + res + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
  129. sql = string.Format(sql);
  130. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  131. string op = data.Rows[0]["OPCODE"].ToString();
  132. txtOP.Text = "工序:" + op;
  133. }
  134. catch (Exception ex)
  135. {
  136. throw ex;
  137. }
  138. }
  139. #region 退出关闭
  140. private void btnClose_Click(object sender, EventArgs e)
  141. {
  142. datashow.Close();
  143. AppConfig.CloseFormShow(this.Text);
  144. this.Close();
  145. }
  146. private void btnExit_Click(object sender, EventArgs e)
  147. {
  148. datashow.Close();
  149. AppConfig.CloseFormShow(this.Text);
  150. this.Close();
  151. }
  152. #endregion
  153. #region 移动窗体
  154. private const int WM_NCHITTEST = 0x84;
  155. private const int HTCLIENT = 0x1;
  156. private const int HTCAPTION = 0x2;
  157. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  158. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  159. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  160. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  161. //重写窗体,使窗体可以不通过自带标题栏实现移动
  162. protected override void WndProc(ref System.Windows.Forms.Message m)
  163. {
  164. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  165. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  166. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  167. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  168. switch (m.Msg)
  169. {
  170. case WM_NCHITTEST:
  171. base.WndProc(ref m);
  172. if ((int)m.Result == HTCLIENT)
  173. m.Result = (IntPtr)HTCAPTION;
  174. return;
  175. }
  176. //拦截双击标题栏、移动窗体的系统消息
  177. if (m.Msg != 0xA3)
  178. {
  179. base.WndProc(ref m);
  180. }
  181. }
  182. #endregion
  183. #region 列表
  184. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  185. {
  186. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  187. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  188. }
  189. #endregion
  190. private void btnModify_Click(object sender, EventArgs e)
  191. {
  192. }
  193. private void txtRcard_KeyPress(object sender, KeyPressEventArgs e)
  194. {
  195. try
  196. {
  197. if (e.KeyChar == '\r')
  198. {
  199. if (txtInput.Text.Trim() == string.Empty)
  200. {
  201. if (string.IsNullOrEmpty(this.txtMo.Text.Trim()))
  202. {
  203. txtMessage.Text = "请输入序列号";
  204. this.txtInput.Focus();
  205. return;
  206. }
  207. else
  208. {
  209. txtMessage.Text += " \r\n请输入物料条码";
  210. this.txtInput.Focus();
  211. return;
  212. }
  213. }
  214. Collect();
  215. }
  216. }
  217. catch (Exception ex)
  218. {
  219. txtMessage.Text += "\r\n"+ex.Message;
  220. }
  221. }
  222. private void txtRcard_Validated(object sender, EventArgs e)
  223. {
  224. string sql = @"select b.MOCODE as mocode,b.ITEMCODE as itemcode,a.RCARD
  225. from ICSMO2RCARD a
  226. left join ICSMO b on a.MOCODE=b.MOCODE
  227. where RCARD='"+txtInput.Text.Trim()+"' ";
  228. sql = string.Format(sql);
  229. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString,CommandType.Text,sql).Tables[0];
  230. txtMo.Text = dt.Rows[0]["mocode"].ToString();
  231. txtItemCode.Text = dt.Rows[0]["itemcode"].ToString();
  232. Blind();
  233. }
  234. private void Blind()
  235. {
  236. //绑定
  237. ds.Reset();
  238. dtzhu = null;
  239. dtone = null;
  240. dtzhu = MainTable().Copy();
  241. dtone = OneTable().Copy();
  242. dtzhu.TableName = "one";
  243. dtone.TableName = "two";
  244. ds.Tables.Add(dtzhu);
  245. ds.Tables.Add(dtone);
  246. DataRelation dr = new DataRelation("Level1", new DataColumn[] { ds.Tables[0].Columns["CKGROUP"] }, new DataColumn[] { ds.Tables[1].Columns["ziCKGROUP"] });
  247. ds.Relations.Add(dr);
  248. }
  249. public DataTable MainTable()
  250. {
  251. string sql=@"select a.CKGROUP,b.CKGROUPDESC
  252. from ICSMODELOP2CKGROUP a
  253. left join ICSOQCCKGROUP b on a.CKGROUP=b.CKGROUP
  254. where a.ITEMCODE='{0}' and a.OPCODE in(select OPCODE from ICSOP2RES where RESCODE='{1}')";
  255. sql = string.Format(sql,txtItemCode.Text,res);
  256. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  257. checkGroup = data.Rows[0]["CKGROUP"].ToString();
  258. return data;
  259. }
  260. public DataTable OneTable()
  261. {
  262. string sql = @"select a.CKITEMCODE,a.CKITEMDESC,a.SetValueMin,a.SetValueMax,b.CKGROUP as ziCKGROUP
  263. from ICSOQCCKLIST a
  264. left join ICSOQCCKGROUP2LIST b on a.CKITEMCODE=b.CKITEMCODE
  265. where b.CKGROUP in(select a.CKGROUP
  266. from ICSMODELOP2CKGROUP a
  267. left join ICSOQCCKGROUP b on a.CKGROUP=b.CKGROUP
  268. where a.ITEMCODE='{0}' and a.OPCODE in(select OPCODE from ICSOP2RES where RESCODE='{1}'))";
  269. sql = string.Format(sql, txtItemCode.Text, this.res);
  270. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  271. return data;
  272. }
  273. private void lblTitle_Click(object sender, EventArgs e)
  274. {
  275. }
  276. private void txtMo_EditValueChanged(object sender, EventArgs e)
  277. {
  278. }
  279. private void btnSave_Click(object sender, EventArgs e)
  280. {
  281. }
  282. private void txtMo_KeyPress(object sender, KeyPressEventArgs e)
  283. {
  284. }
  285. private bool GetOPBOMKeyparts()
  286. {
  287. OPBomKeyparts opBOMKeyparts = null;
  288. Messages msgMo = new Messages();
  289. try
  290. {
  291. //为改善性能
  292. string strMoCode = this.txtMo.Text.Trim();
  293. object[] objKeyParts = (object[])listOpBomKeyParts[strMoCode];
  294. if (objKeyParts != null)
  295. {
  296. opBOMKeyparts = new OPBomKeyparts((List<ICSOPBOMDETAIL>)objKeyParts[0], Convert.ToInt32(objKeyParts[1]), this.DataProvider);
  297. if (opBOMKeyparts != null && opBOMKeyparts.Count == 0)
  298. {
  299. throw new Exception(objKeyParts[2].ToString());
  300. }
  301. }
  302. if (opBOMKeyparts == null)
  303. {
  304. DataCollect.ActionOnLineHelper onLine = new DataCollect.ActionOnLineHelper(this.DataProvider);
  305. #region 先推途程,然后找OPBOM
  306. ProductInfo product=null;
  307. ICSMO mo = null;
  308. Messages messages1 = onLine.GetIDInfoByMoCodeAndId(strMoCode, _RuningCard);
  309. if (messages1.IsSuccess())
  310. {
  311. product = (ProductInfo)messages1.GetData().Values[0];
  312. //如果归属工单,则做归属工单检查,否则做序列号途程检查
  313. if (msgMo.GetData() != null) // 需要归属工单,做归属工单检查
  314. {
  315. ICSSoft.Frame.DataConnect.Message msgMoData = msgMo.GetData();
  316. mo = (ICSMO)msgMoData.Values[0];
  317. ActionGoToMO goToMO = new ActionGoToMO(this.DataProvider);
  318. GoToMOActionEventArgs MOActionEventArgs = new GoToMOActionEventArgs(ActionType.DataCollectAction_GoMO, _RuningCard, AppConfig.UserCode,
  319. this.res, product, mo.MOCODE);
  320. messages1 = goToMO.CheckIn(MOActionEventArgs);
  321. if (!MOActionEventArgs.PassCheck)
  322. {
  323. messages1 = onLine.CheckID(new CKeypartsActionEventArgs(ActionType.DataCollectAction_CollectINNO, _RuningCard, AppConfig.UserCode,
  324. this.res, product, null));
  325. }
  326. }
  327. else // 不需要归属工单,检查序列号途程
  328. {
  329. messages1 = onLine.CheckID(new CKeypartsActionEventArgs(ActionType.DataCollectAction_CollectINNO, _RuningCard, AppConfig.UserCode,
  330. this.res, product, null));
  331. }
  332. if (messages1.IsSuccess() == false)
  333. {
  334. throw new Exception(" 产品序列号: " + this.txtInput.Text.Trim());
  335. }
  336. }
  337. ICSMO moNew = (ICSMO)this.DataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == this.txtMo.Text.Trim());
  338. ICSOPBOMDETAILBLL opBOMFacade = new ICSOPBOMDETAILBLL(this.DataProvider);
  339. _OPBOMDetailList = opBOMFacade.QueryOPBOMDetail(product.NowSimulation.ITEMCODE, string.Empty, string.Empty, moNew.MOBOM,
  340. product.NowSimulation.ROUTECODE, product.NowSimulation.OPCODE, (int)MaterialType.CollectMaterial, true);
  341. if (_OPBOMDetailList == null || _OPBOMDetailList.Count <= 0)
  342. {
  343. throw new Exception("产品序列号: " + this.txtInput.Text+",对应的工序BOM不存在");
  344. }
  345. _objBomDetailNotFilter = _OPBOMDetailList;
  346. //过滤备选料
  347. _OPBOMDetailList = FilterOPBOMDetail(_OPBOMDetailList);
  348. if (_OPBOMDetailList == null || _OPBOMDetailList.Count <= 0)
  349. {
  350. throw new Exception("产品序列号: " + this.txtInput.Text + ",对应的工序BOM不存在");
  351. }
  352. //获取批控管上料资料
  353. //注意:检查icsminno中的数据是否能对应到icsopbomdetail中
  354. object[] tempMinNo = null;
  355. _MinnoBll.QueryMINNO(strMoCode, product.NowSimulation.ROUTECODE,
  356. product.NowSimulation.OPCODE, this.res, moNew.MOBIOSVER);
  357. if (tempMinNo == null)
  358. {
  359. _PreparedLotPartList = null;
  360. }
  361. else
  362. {
  363. List<ICSMINNO> minnoList = new List<ICSMINNO>();
  364. foreach (ICSMINNO minno in tempMinNo)
  365. {
  366. bool found = false;
  367. if (_OPBOMDetailList != null)
  368. {
  369. foreach (ICSOPBOMDETAIL opBOMDetail in _objBomDetailNotFilter)
  370. {
  371. if ((minno.MITEMCODE == opBOMDetail.OBSITEMCODE || minno.MITEMCODE == opBOMDetail.OBITEMCODE)
  372. && opBOMDetail.OBITEMCONTYPE == BOMItemControlType.ITEM_CONTROL_LOT
  373. )
  374. {
  375. found = true;
  376. break;
  377. }
  378. }
  379. }
  380. if (found)
  381. minnoList.Add(minno);
  382. }
  383. _PreparedLotPartList = minnoList;
  384. }
  385. _OPBOMDetailKeyPartList = opBOMFacade.GetOPBOMDetails(strMoCode,
  386. product.NowSimulation.ROUTECODE, product.NowSimulation.OPCODE, true, true);
  387. //过滤备选料
  388. if (_OPBOMDetailKeyPartList != null)
  389. {
  390. _OPBOMDetailKeyPartList = FilterOPBOMDetail(_OPBOMDetailKeyPartList);
  391. }
  392. opBOMKeyparts = new OPBomKeyparts(_OPBOMDetailList, Convert.ToInt32(mo.IDMERGERULE), this.DataProvider);
  393. if (_OPBOMDetailList != null && _OPBOMDetailList.Count > 0)
  394. {
  395. this.GetOPBOMDetailCount();
  396. }
  397. int _OPBOMDetailLotPartCount = 0;
  398. if (_PreparedLotPartList != null)
  399. _OPBOMDetailLotPartCount = _PreparedLotPartList.Count;
  400. if (_OPBOMDetailKeyPartList != null && _NeedInputLotPart == false && _OPBOMDetailList.Count > (_OPBOMDetailKeyPartList.Count + _OPBOMDetailLotPartCount))
  401. {
  402. throw new Exception("产品序列号: " + this.txtInput.Text);
  403. }
  404. if (_OPBOMDetailKeyPartList == null && _NeedInputLotPart == false && _OPBOMDetailList.Count > _OPBOMDetailLotPartCount)
  405. {
  406. throw new Exception("产品序列号: " + this.txtInput.Text);
  407. }
  408. if (!listOpBomKeyParts.ContainsKey(mo.MOCODE))
  409. {
  410. string strMsg = "$CS_NOOPBomInfo $CS_Param_MOCode=" + product.NowSimulation.MOCODE + " $CS_Param_RouteCode=" + product.NowSimulation.ROUTECODE + " $CS_Param_OPCode =" + product.NowSimulation.OPCODE;
  411. listOpBomKeyParts.Add(mo.MOCODE, new object[] { _OPBOMDetailList, Convert.ToInt32(mo.IDMERGERULE), strMsg });
  412. }
  413. #endregion
  414. }
  415. //输出提示信息
  416. if (!_NeedInputLotPart && _OPBOMDetailKeyPartList == null)
  417. {
  418. }
  419. string materialCode = "";
  420. string materialDesc = "";
  421. if (_NeedInputLotPart == true && _OPBOMDetailList != null)
  422. {
  423. materialCode = ((ICSOPBOMDETAIL)_OPBOMDetailList[0]).OBSITEMCODE;
  424. object objMaterial = this.DataProvider.ICSINVENTORY.SingleOrDefault() ;//获取料号信息
  425. if (objMaterial != null)
  426. {
  427. materialDesc = ((ICSINVENTORY)objMaterial).INVDESC;
  428. }
  429. if (((ICSOPBOMDETAIL)_OPBOMDetailList[0]).OBITEMCONTYPE == "item_control_lot")
  430. {
  431. throw new Exception(">>$CS_PleaseInputLot>>$CS_Param_Lot=" + materialCode);
  432. }
  433. }
  434. else if (_NeedInputLotPart == false && _OPBOMDetailKeyPartList != null)
  435. {
  436. materialCode = ((ICSOPBOMDETAIL)_OPBOMDetailKeyPartList[0]).OBSITEMCODE;
  437. object objMaterial = this.DataProvider.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == materialCode && a.WorkPoint == AppConfig.WorkPointCode);//获取料号信息
  438. if (objMaterial != null)
  439. {
  440. materialDesc = ((ICSINVENTORY)objMaterial).INVDESC;
  441. }
  442. }
  443. else if (_NeedInputLotPart == false && _PreparedLotPartList == null && _OPBOMDetailKeyPartList == null)
  444. {
  445. throw new Exception("产品序列号: " + this.txtInput.Text.Trim());
  446. }
  447. return true;
  448. }
  449. catch (Exception ex)
  450. {
  451. throw new Exception("产品序列号: " + this.txtInput.Text.Trim()+ex.Message);
  452. }
  453. }
  454. //自动采集所有Lot物料
  455. private bool AutoCollectAllLotPart()
  456. {
  457. if (_PreparedLotPartList != null)
  458. {
  459. for (int i = 0; i < _PreparedLotPartList.Count; i++)
  460. {
  461. try
  462. {
  463. string moCode = ((ICSMINNO)_PreparedLotPartList[i]).MOCODE;
  464. string mItemCode = ((ICSMINNO)_PreparedLotPartList[i]).MITEMCODE;
  465. string barcode = ((ICSMINNO)_PreparedLotPartList[i]).MITEMPACKEDNO;
  466. object opBomDetailNew = _objBomDetailNotFilter[0];
  467. if (_objBomDetailNotFilter != null && _objBomDetailNotFilter.Count > 0)
  468. {
  469. for (int j = 0; j < _objBomDetailNotFilter.Count; j++)
  470. {
  471. if (((ICSOPBOMDETAIL)_objBomDetailNotFilter[j]).OBITEMCODE == mItemCode
  472. || ((ICSOPBOMDETAIL)_objBomDetailNotFilter[j]).OBSITEMCODE == ((ICSMINNO)_PreparedLotPartList[i]).MOBSITEMCODE)
  473. {
  474. opBomDetailNew = _objBomDetailNotFilter[j];
  475. break;
  476. }
  477. }
  478. }
  479. if (!CollectPart((ICSOPBOMDETAIL)opBomDetailNew, barcode))
  480. {
  481. return false;
  482. }
  483. }
  484. catch (Exception e)
  485. {
  486. throw new Exception( "产品序列号: " + this.txtInput.Text.Trim());
  487. }
  488. }
  489. }
  490. return true;
  491. }
  492. //获取ArrayList与Count
  493. private void GetOPBOMDetailCount()
  494. {
  495. if (_OPBOMDetailList != null)
  496. {
  497. for (int i = 0; i < _OPBOMDetailList.Count; i++)
  498. {
  499. if (((ICSOPBOMDETAIL)_OPBOMDetailList[i]).OBITEMCONTYPE == "item_control_lot")
  500. {
  501. _OPBOMDetailArrayList.Add(_OPBOMDetailList[i]);
  502. }
  503. else
  504. {
  505. int number = Convert.ToInt32(((ICSOPBOMDETAIL)_OPBOMDetailList[i]).OBITEMQTY);
  506. for (int j = 0; j < number; j++)
  507. {
  508. _OPBOMDetailArrayList.Add(_OPBOMDetailList[i]);
  509. }
  510. }
  511. }
  512. }
  513. if (_OPBOMDetailKeyPartList != null)
  514. {
  515. for (int i = 0; i < _OPBOMDetailKeyPartList.Count; i++)
  516. {
  517. int number = Convert.ToInt32(((ICSOPBOMDETAIL)_OPBOMDetailKeyPartList[i]).OBITEMQTY);
  518. for (int j = 0; j < number; j++)
  519. {
  520. _OPBOMDetailKeyPartArrayList.Add(_OPBOMDetailKeyPartList[i]);
  521. }
  522. }
  523. }
  524. if (_PreparedLotPartList != null)
  525. {
  526. for (int i = 0; i < _PreparedLotPartList.Count; i++)
  527. {
  528. int number = Convert.ToInt32(((ICSMINNO)_PreparedLotPartList[i]).QTY);
  529. for (int j = 0; j < number; j++)
  530. {
  531. _PreparedLotPartArrayList.Add(_PreparedLotPartList[i]);
  532. }
  533. }
  534. }
  535. }
  536. //采集手工输入的物料
  537. private bool CollectPart(ICSOPBOMDETAIL opBOMDetail, string materialSerialNo)
  538. {
  539. bool returnValue = false;
  540. Messages msg = new Messages();
  541. try
  542. {
  543. //获取MOCode
  544. string moCode = this.txtMo.Text.ToString().Trim();
  545. if (moCode.Length <= 0)
  546. {
  547. ICSSimulation sim = (ICSSimulation)_DataCollectFacade.GetSimulation(_RuningCard);
  548. if (sim != null)
  549. {
  550. moCode = sim.MOCODE;
  551. }
  552. }
  553. //解析获得MINNO
  554. ICSMINNO newMINNO = new ICSMINNO();
  555. opBOMDetail.MUSER = AppConfig.UserCode;
  556. msg = _DataCollectFacade.GetMINNOByBarcode(opBOMDetail, materialSerialNo, moCode, _InputPartList, true, false, "collection", out newMINNO);
  557. if (msg.IsSuccess())
  558. {
  559. if (newMINNO != null)
  560. {
  561. _InputPartList.Add((object)newMINNO);
  562. }
  563. _CollectedCount++;
  564. returnValue = true;
  565. }
  566. else
  567. {
  568. throw new Exception("物料序列号: " + materialSerialNo);
  569. }
  570. }
  571. catch (Exception e)
  572. {
  573. throw new Exception("物料序列号: " + materialSerialNo+","+e.Message);
  574. }
  575. return returnValue;
  576. }
  577. //采集
  578. private void Collect()
  579. {
  580. Messages messages = new Messages();
  581. string RCard = txtInput.Text.ToUpper().Trim();
  582. try
  583. {
  584. #region 输入产品序列号后
  585. if (FlowControl == -1)
  586. {
  587. if (GetMoItem())
  588. {
  589. _RuningCard = _DataCollectFacade.GetRuningCard(RCard, this.txtMo.Text.Trim());
  590. _NeedInputLotPart = true;
  591. if (!GetOPBOMKeyparts())
  592. {
  593. return;
  594. }
  595. //如果BOM中没有Keypart,并且自动采集Lot料的方式,则整个采集工作可自动完成
  596. if (!_NeedInputLotPart && _OPBOMDetailKeyPartList == null)
  597. {
  598. if (AutoCollectAllLotPart())
  599. {
  600. //Save();
  601. return;
  602. }
  603. else
  604. {
  605. return;
  606. }
  607. }
  608. }
  609. }
  610. #endregion
  611. #region 输入物料后
  612. if (FlowControl >= 1)
  613. {
  614. //采集料号
  615. ArrayList opBOMDetailToCollect = null;
  616. opBOMDetailToCollect = _OPBOMDetailArrayList;
  617. if (opBOMDetailToCollect != null)
  618. {
  619. if (_CollectedCount < opBOMDetailToCollect.Count)
  620. {
  621. try
  622. {
  623. CollectPart((ICSOPBOMDETAIL)opBOMDetailToCollect[_CollectedCount], RCard);
  624. if (_CollectedCount < opBOMDetailToCollect.Count)
  625. {
  626. string materialDesc = "";
  627. var objMaterial = this._domainDataProvider.ICSINVENTORY.SingleOrDefault( a=> a.INVCODE== ((ICSOPBOMDETAIL)opBOMDetailToCollect[_CollectedCount]).OBSITEMCODE && a.WorkPoint == AppConfig.WorkPointCode );
  628. if (objMaterial != null)
  629. {
  630. materialDesc = ((ICSINVENTORY)objMaterial).INVDESC;
  631. }
  632. if (((ICSOPBOMDETAIL)opBOMDetailToCollect[_CollectedCount]).OBITEMCONTYPE == "item_control_keyparts")
  633. {
  634. throw new Exception(">>$CS_PleaseInputKeypart >>$CS_Param_KeypartItem=" + ((ICSOPBOMDETAIL)opBOMDetailToCollect[_CollectedCount]).OBSITEMCODE + "[" + materialDesc + "]");
  635. }
  636. else if (((ICSOPBOMDETAIL)opBOMDetailToCollect[_CollectedCount]).OBITEMCONTYPE == "item_control_lot")
  637. {
  638. throw new Exception(">>$CS_PleaseInputLot>>$CS_Param_Lot=" + ((ICSOPBOMDETAIL)opBOMDetailToCollect[_CollectedCount]).OBSITEMCODE + "[" + materialDesc + "]");
  639. }
  640. }
  641. }
  642. catch (Exception e)
  643. {
  644. throw new Exception(" 产品序列号: " + this.txtInput.Text.Trim() +" , "+ e.Message);
  645. }
  646. }
  647. }
  648. else
  649. {
  650. return;
  651. }
  652. }
  653. #endregion
  654. this.txtInput.Focus();
  655. this.txtInput.Text = "";
  656. FlowControl++;
  657. }
  658. catch (Exception e)
  659. {
  660. throw new Exception(e.Message);
  661. }
  662. }
  663. private Messages CheckInfo()
  664. {
  665. Messages messages = new Messages();
  666. //判断是否是第一道工序,如果是则做归属工单 如果不是则做过站操作
  667. ICSITEMROUTE2OP itemRoute2Op = _DataCollectFacade.GetMORouteFirstOperation(this.txtMo.Text.Trim());
  668. //根据资源找到对应的工序
  669. ICSOP2RES op2res = _ICSBaseModel.GetOperationByResource(res);
  670. if (itemRoute2Op.OPCODE == op2res.OPCODE)
  671. {
  672. //先判断是不良品回流,如果是,则不走GOMO,如果不是则走GOMO
  673. ICSTS icsts = CheckIsExistInICSTS(txtInput.Text.Trim());
  674. if (icsts== null)
  675. {
  676. messages.AddMessages(RunGOMO(actionCheckStatus, this.txtInput.Text.Trim()));
  677. if (!messages.IsSuccess())
  678. {
  679. listActionCheckStatus.Clear();
  680. }
  681. }
  682. else if (icsts.TSSTATUS != "tsstatus_reflow")
  683. {
  684. messages.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Success, string.Format("当前工序未完成维修")));
  685. }
  686. }
  687. else
  688. {
  689. ICSSimulation sim = GetSimulationByRCard(txtInput.Text.Trim());
  690. if (sim == null)
  691. {
  692. messages.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Success, string.Format("该序列号未归属工单")));
  693. }
  694. //当前工序如果不是第一站工序
  695. //判断是否有不良品回流
  696. ICSTS icsts = CheckIsExistInICSTS(txtInput.Text.Trim());
  697. if (icsts != null)
  698. {
  699. if (op2res.OPCODE == icsts.FRMOPCODE)
  700. {
  701. if (icsts.TSSTATUS != "tsstatus_reflow")
  702. messages.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Success, string.Format("当前工序未完成维修")));
  703. }
  704. if (sim.OPCODE != op2res.OPCODE && icsts.FRMOPCODE ==
  705. sim.OPCODE && icsts.TSSTATUS != "tsstatus_reflow")
  706. {
  707. messages.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Success, string.Format("工序" + icsts.FRMOPCODE + "未完成维修")));
  708. }
  709. }
  710. }
  711. return messages;
  712. }
  713. public ICSSimulation GetSimulationByRCard(string rCard)
  714. {
  715. string sql = @"select * from ICSSimulation
  716. where RCARD = '" + rCard + "' order by MTIME desc";
  717. var objs = this._domainDataProvider.ExecuteQuery<ICSSimulation>(sql).ToList();
  718. if (objs == null || objs.Count < 1)
  719. return null;
  720. else
  721. return (ICSSimulation)objs[0];
  722. }
  723. public ICSTS CheckIsExistInICSTS(string rcard)
  724. {
  725. string sql2 = @"select *
  726. from ICSTS
  727. where RCARD='" + rcard + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
  728. var objs = this._domainDataProvider.ExecuteQuery<ICSTS>(sql2).ToList();
  729. if (objs == null || objs.Count < 1)
  730. return null;
  731. else
  732. return (ICSTS)objs[0];
  733. }
  734. //工单归属采集
  735. private Messages RunGOMO(ActionCheckStatus actionCheckStatus, string rCard)
  736. {
  737. Messages messages = new Messages();
  738. ActionOnLineHelper onLine = new ActionOnLineHelper(this._domainDataProvider);
  739. actionCheckStatus.ProductInfo = productInfo;
  740. //参数定义
  741. GoToMOActionEventArgs args = new GoToMOActionEventArgs(ActionType.DataCollectAction_GoMO, rCard.Trim(),
  742. AppConfig.UserCode,
  743. this.res, productInfo, this.txtMo.Text.Trim());
  744. //Laws Lu,执行工单采集并收集返回信息
  745. if (messages.IsSuccess())
  746. {
  747. messages.AddMessages(onLine.Action(args, actionCheckStatus));
  748. }
  749. if (messages.IsSuccess())
  750. {
  751. messages.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Success, "$CS_GOMOSUCCESS $CS_Param_ID:" + rCard.Trim().ToString()));
  752. this.txtInput.SelectAll();
  753. this.txtInput.Focus();
  754. }
  755. return messages;
  756. }
  757. private bool GetMoItem()
  758. {
  759. string sql = @"select b.MOCODE as mocode,b.ITEMCODE as itemcode,c.INVNAME as itemdesc,a.RCARD
  760. from ICSMO2RCARD a
  761. left join ICSMO b on a.MOCODE=b.MOCODE
  762. left join ICSINVENTORY c on b.ITEMCODE=c.INVCODE
  763. where RCARD='" + this.txtInput.Text.Trim() + "' ";
  764. sql = string.Format(sql);
  765. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  766. if (dt != null && dt.Rows.Count > 0)
  767. {
  768. if (dt.Rows[0]["mocode"].ToString() != "")
  769. {
  770. txtMo.Text = dt.Rows[0]["mocode"].ToString();
  771. }
  772. if (dt.Rows[0]["itemcode"].ToString() != "")
  773. {
  774. txtItemCode.Text = dt.Rows[0]["itemcode"].ToString();
  775. }
  776. if (dt.Rows[0]["itemdesc"].ToString() != "")
  777. {
  778. txtItemName.Text = dt.Rows[0]["itemdesc"].ToString();
  779. }
  780. string sql2 = @"select ROUTECODE from ICSMO2ROUTE
  781. where MOCODE='" + txtMo.Text + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
  782. sql2 = string.Format(sql2);
  783. DataTable data2 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql2).Tables[0];
  784. string route = data2.Rows[0]["ROUTECODE"].ToString();
  785. txtRoute.Text = "途程:" + route;
  786. SetMsg(Color.White, "");
  787. return true;
  788. }
  789. else
  790. {
  791. SetMsg(Color.Red, "序列号不存在,请重新输入!");
  792. this.txtInput.Text = "";
  793. this.txtInput.Focus();
  794. return false;
  795. }
  796. }
  797. private void SetMsg(Color color, string Msg)
  798. {
  799. txtMessage.Text = Msg;
  800. txtMessage.ForeColor = color;
  801. }
  802. private void ClearPageData()
  803. {
  804. txtMo.Text = String.Empty;
  805. txtItemCode.Text = String.Empty;
  806. txtItemName.Text = String.Empty;
  807. }
  808. private void panelControl1_Paint(object sender, PaintEventArgs e)
  809. {
  810. }
  811. private List<ICSOPBOMDETAIL> FilterOPBOMDetail(List<ICSOPBOMDETAIL> bomDetailList)
  812. {
  813. List<ICSOPBOMDETAIL> filterList = new List<ICSOPBOMDETAIL>();
  814. for (int i = 0; i < bomDetailList.Count; i++)
  815. {
  816. if (((ICSOPBOMDETAIL)bomDetailList[i]).OBITEMCONTYPE != BOMItemControlType.ITEM_CONTROL_KEYPARTS
  817. && ((ICSOPBOMDETAIL)bomDetailList[i]).OBITEMCONTYPE != BOMItemControlType.ITEM_CONTROL_LOT)
  818. {
  819. continue;
  820. }
  821. bool found = false;
  822. for (int j = 0; j < filterList.Count; j++)
  823. {
  824. if (((ICSOPBOMDETAIL)bomDetailList[i]).OBITEMCONTYPE == ((ICSOPBOMDETAIL)filterList[j]).OBSITEMCODE)
  825. {
  826. found = true;
  827. break;
  828. }
  829. }
  830. if (!found)
  831. {
  832. filterList.Add(bomDetailList[i]);
  833. }
  834. }
  835. return filterList;
  836. }
  837. public void Save()
  838. {
  839. Messages _Messages = new Messages();
  840. ExtendSimulation lastSimulation = null;
  841. this._domainDataProvider.Connection.Open();
  842. this._domainDataProvider.Transaction = this._domainDataProvider.Connection.BeginTransaction();
  843. ActionOnLineHelper onLine = new ActionOnLineHelper(this._domainDataProvider);
  844. string rCard = this.txtInput.Text.Trim();
  845. _Messages.AddMessages(CheckProduct(rCard));
  846. actionCheckStatus = new ActionCheckStatus();
  847. actionCheckStatus.ProductInfo = productInfo;
  848. if (actionCheckStatus.ProductInfo != null)
  849. {
  850. actionCheckStatus.ProductInfo.Resource = Resource;
  851. }
  852. string strMoCode = this.txtMo.Text.Trim();
  853. actionCheckStatus.MO = this._domainDataProvider.ICSMO.SingleOrDefault(a => a.MOCODE == strMoCode && a.WorkPoint == AppConfig.WorkPointCode);
  854. if (listActionCheckStatus.ContainsKey(strMoCode))
  855. {
  856. actionCheckStatus = (ActionCheckStatus)listActionCheckStatus[strMoCode];
  857. actionCheckStatus.ProductInfo = productInfo;
  858. actionCheckStatus.ActionList = new ArrayList();
  859. }
  860. else
  861. {
  862. actionCheckStatus.NeedUpdateSimulation = false;
  863. actionCheckStatus.NeedFillReport = false;
  864. listActionCheckStatus.Add(strMoCode, actionCheckStatus);
  865. }
  866. #region 上料采集
  867. //建议在上料采集界面和良品/不良品界面增加计数功能,当用户成功采集一个产品序列号后,
  868. //计数器加一,同时该计数功能允许用户归零。每次打开界面时,计数器基数都是零,系统不需要保存计数器值
  869. //bool flag = true;//标示是否采集成功
  870. Messages messages1 = new Messages();
  871. if (actionCheckStatus.ProductInfo == null)
  872. {
  873. messages1 = onLine.GetIDInfo(_RuningCard);
  874. actionCheckStatus.ProductInfo = (ProductInfo)messages1.GetData().Values[0];
  875. actionCheckStatus.ProductInfo.Resource = Resource;
  876. lastSimulation = actionCheckStatus.ProductInfo.LastSimulation;
  877. _Messages.AddMessages(messages1);
  878. }
  879. else //将上一个Action的NowSimulation设置为本Action的LastSimulation
  880. {
  881. if (actionCheckStatus.ActionList.Count > 0)
  882. {
  883. actionCheckStatus.ProductInfo = new ProductInfo();
  884. actionCheckStatus.ProductInfo.NowSimulation = new ICSSimulation();
  885. actionCheckStatus.ProductInfo.Resource = Resource;
  886. actionCheckStatus.ProductInfo.LastSimulation =
  887. new ExtendSimulation(((ActionEventArgs)actionCheckStatus.ActionList[actionCheckStatus.ActionList.Count - 1]).ProductInfo.NowSimulation);
  888. }
  889. }
  890. if (_Messages.IsSuccess())
  891. {
  892. #region Check if key part was used
  893. if (_InputPartList != null)
  894. {
  895. foreach (ICSMINNO minno in _InputPartList)
  896. {
  897. if (minno.EATTRIBUTE1 == MCardType.MCardType_Keyparts)
  898. {
  899. if (_DataCollectFacade.KeyPartUsed(minno.MITEMPACKEDNO, minno.MITEMCODE, false, _InputPartList))
  900. {
  901. messages1.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Error,"$CS_Error_KeyPartUsed"));
  902. break;
  903. }
  904. }
  905. }
  906. }
  907. #endregion
  908. if (messages1.IsSuccess())
  909. {
  910. ProductInfo product = actionCheckStatus.ProductInfo;
  911. object[] objBomDetailLot = new object[_InputPartList.Count];
  912. _InputPartList.CopyTo(objBomDetailLot);
  913. if (objBomDetailLot != null)
  914. {
  915. messages1.AddMessages(onLine.ActionWithTransaction(new CINNOActionEventArgs(ActionType.DataCollectAction_CollectINNO, _RuningCard,
  916. AppConfig.UserCode, this.res,
  917. product, INNO
  918. ), actionCheckStatus, objBomDetailLot));
  919. }
  920. }
  921. }
  922. if (messages1.IsSuccess())
  923. messages1.Add(new ICSSoft.Frame.DataConnect.Message(MessageType.Success, "$CS_CollectSuccess:" + _RuningCard));
  924. _Messages.AddMessages(messages1);
  925. #endregion
  926. }
  927. // 获得产品信息
  928. private Messages GetProduct(string rcard)
  929. {
  930. Messages productmessages = new Messages();
  931. ActionOnLineHelper dataCollect = new ActionOnLineHelper(this._domainDataProvider);
  932. productmessages.AddMessages(dataCollect.GetIDInfo(rcard));
  933. if (productmessages.IsSuccess())
  934. {
  935. productInfo = (ProductInfo)productmessages.GetData().Values[0];
  936. }
  937. else
  938. {
  939. productInfo = new ProductInfo();
  940. }
  941. return productmessages;
  942. }
  943. // 根据产品信息,决定部分控件的状态
  944. private Messages CheckProduct(string rcard)
  945. {
  946. Messages messages = new Messages();
  947. try
  948. {
  949. messages.AddMessages(GetProduct(rcard));
  950. if (productInfo.LastSimulation != null)
  951. {
  952. }
  953. }
  954. catch (Exception e)
  955. {
  956. messages.Add( new ICSSoft.Frame.DataConnect.Message(MessageType.Error, e.Message));
  957. }
  958. return messages;
  959. }
  960. // 清空数据
  961. private void ClearVariables()
  962. {
  963. FlowControl = -1;
  964. _OPBOMDetailArrayList = new ArrayList();
  965. _OPBOMDetailKeyPartArrayList = new ArrayList();
  966. _PreparedLotPartArrayList = new ArrayList();
  967. _CollectedCount = 0;
  968. _HaveCollectMaterial = false;
  969. _RuningCard = string.Empty;
  970. _InputPartList = new ArrayList();
  971. listOpBomKeyParts = new Hashtable();
  972. }
  973. }
  974. }