华恒Mes鼎捷代码
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.

1985 lines
89 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 Newtonsoft.Json;
  26. using System.Net;
  27. using System.Configuration;
  28. using ICSSoft.Entity.PU_AppVouch;
  29. using ICSSoft.Frame.Data.Entity.WWModel;
  30. using ICSSoft.Frame.Data.DAL;
  31. using ICSSoft.Frame.Data.Entity;
  32. using ICSSoft.Base.Lable.PrintTool;
  33. namespace ICSSoft.Frame.APP
  34. {
  35. public partial class FormICSMO : DevExpress.XtraEditors.XtraForm
  36. {
  37. private string sqltxt = "";
  38. private string sqlconn = "";
  39. String guid = AppConfig.GetGuid();
  40. private DataTable dataSource = null;
  41. static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
  42. static string DataCollectWW = APIURL + "APICreatePR";
  43. //static string DataCollectWW = "http://localhost:51182/api/"+ "APICreatePR";
  44. private DataSet ds = new DataSet();
  45. private DataTable body = null;
  46. #region 构造函数
  47. public FormICSMO()
  48. {
  49. InitializeComponent();
  50. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  51. this.WindowState = FormWindowState.Maximized;
  52. foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns)
  53. {
  54. if (col.Name == "picturesee")
  55. {
  56. col.OptionsColumn.ReadOnly = false;
  57. }
  58. else
  59. col.OptionsColumn.ReadOnly = true;
  60. col.OptionsColumn.AllowEdit = true;
  61. if (col.Name == "colisSelect")
  62. col.OptionsColumn.AllowEdit = false;
  63. // col.OptionsColumn.ReadOnly = true;
  64. }
  65. }
  66. #endregion
  67. #region 操作权限
  68. public DataTable RightOfExute()
  69. {
  70. DataTable rData = new DataTable();
  71. rData.Columns.Add("BtnName");
  72. rData.Columns.Add("ActionName");
  73. //查看权限(必须有)
  74. DataRow seeRow = rData.NewRow();
  75. seeRow["BtnName"] = "see";
  76. seeRow["ActionName"] = "查看";
  77. rData.Rows.Add(seeRow);
  78. List<Control> ControlList = new List<Control>();
  79. ControlList.Add(btnCreatePR);
  80. ControlList.Add(btnModify);
  81. ControlList.Add(btnDel);
  82. ControlList.Add(btnOutPut);
  83. ControlList.Add(BtnCancelCloseMO);
  84. ControlList.Add(btnCancelAll);
  85. ControlList.Add(btnRefresh);
  86. ControlList.Add(txtsend);
  87. ControlList.Add(txtcancelSend);
  88. ControlList.Add(btnBatch);
  89. ControlList.Add(btnExit);
  90. ControlList.Add(txtstop);
  91. ControlList.Add(txtcancelStop);
  92. ControlList.Add(txtcloseDan);
  93. ControlList.Add(btnLot1);
  94. ControlList.Add(btnprint);
  95. foreach (Control ctr in ControlList)
  96. {
  97. if (ctr.GetType() == typeof(SimpleButton))
  98. {
  99. DataRow dr = rData.NewRow();
  100. dr["BtnName"] = ctr.Name;
  101. dr["ActionName"] = ctr.Text;
  102. rData.Rows.Add(dr);
  103. }
  104. }
  105. rData.AcceptChanges();
  106. return rData;
  107. }
  108. public DataTable RightOfData()// 数据权限
  109. {
  110. DataTable rData = new DataTable();
  111. rData.Columns.Add("BodyName");
  112. rData.Columns.Add("ControlName");
  113. rData.Columns.Add("ControlCaption");
  114. rData.AcceptChanges();
  115. return rData;
  116. }
  117. #endregion
  118. #region 退出
  119. private void btnClose_Click(object sender, EventArgs e)
  120. {
  121. AppConfig.CloseFormShow(this.Text);
  122. this.Close();
  123. }
  124. private void btnExit_Click(object sender, EventArgs e)
  125. {
  126. AppConfig.CloseFormShow(this.Text);
  127. this.Close();
  128. }
  129. #endregion
  130. #region 移动窗体
  131. private const int WM_NCHITTEST = 0x84;
  132. private const int HTCLIENT = 0x1;
  133. private const int HTCAPTION = 0x2;
  134. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  135. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  136. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  137. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  138. //重写窗体,使窗体可以不通过自带标题栏实现移动
  139. protected override void WndProc(ref Message m)
  140. {
  141. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  142. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  143. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  144. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  145. switch (m.Msg)
  146. {
  147. case WM_NCHITTEST:
  148. base.WndProc(ref m);
  149. if ((int)m.Result == HTCLIENT)
  150. m.Result = (IntPtr)HTCAPTION;
  151. return;
  152. }
  153. //拦截双击标题栏、移动窗体的系统消息
  154. if (m.Msg != 0xA3)
  155. {
  156. base.WndProc(ref m);
  157. }
  158. }
  159. #endregion
  160. #region 列表
  161. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  162. {
  163. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  164. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  165. }
  166. #endregion
  167. #region 过滤
  168. private string tempTableName = "";
  169. private void btnFilter_Click(object sender, EventArgs e)
  170. {
  171. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  172. filter.OldTempTableName = tempTableName;
  173. if (filter.ShowDialog() == DialogResult.OK)
  174. {
  175. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  176. try
  177. {
  178. _wait.Show();
  179. tempTableName = filter.NewTempTableName;
  180. sqltxt = filter.SqlText;
  181. sqlconn = filter.FilterConnectString;
  182. dataSource = filter.FilterData.Tables[0];
  183. grdDetail.DataSource = dataSource;
  184. grvDetail.BestFitColumns();
  185. rptPage.RecordNum = dataSource.Rows.Count;
  186. rptPage.PageSize = 499;
  187. rptPage.PageIndex = 1;
  188. rptPage.ReLoad();
  189. rptPage.PageSize = 500;
  190. rptPage.PageIndex = 1;
  191. rptPage.ReLoad();
  192. _wait.Close();
  193. //_wait.Show();
  194. //ds.Reset();
  195. //dataSource = null;
  196. //body = null;
  197. //tempTableName = filter.NewTempTableName;
  198. //sqltxt = filter.SqlText;
  199. //sqlconn = filter.FilterConnectString;
  200. //dataSource = filter.FilterData.Tables[0].Copy();
  201. //dataSource.TableName = "Hand";
  202. //ds.Tables.Add(dataSource);
  203. //body = ICSMOBLL.GetMOBOM(sqltxt).Copy();
  204. //body.TableName = "Body";
  205. //ds.Tables.Add(body);
  206. //DataRelation dr = new DataRelation("子件资料", new DataColumn[] { ds.Tables["Hand"].Columns["MOCODE"], ds.Tables["Hand"].Columns["MOSEQ"] }, new DataColumn[] { ds.Tables["Body"].Columns["MOCODE"], ds.Tables["Body"].Columns["SEQ"] });
  207. //ds.Relations.Add(dr);
  208. //grdDetail.DataSource = ds.Tables["Hand"];
  209. //grvDetail.BestFitColumns();
  210. //rptPage.RecordNum = dataSource.Rows.Count;
  211. //rptPage.PageSize = 499;
  212. //rptPage.PageIndex = 1;
  213. //rptPage.ReLoad();
  214. //rptPage.PageSize = 500;
  215. //rptPage.PageIndex = 1;
  216. ////rptPage.ReLoad();
  217. //_wait.Close();
  218. }
  219. catch (Exception ex)
  220. {
  221. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  222. _wait.Close();
  223. }
  224. }
  225. }
  226. #endregion
  227. #region 绑定数据源
  228. private void btnConfig_Click(object sender, EventArgs e)
  229. {
  230. if (AppConfig.UserCode.ToLower() != "demo")
  231. {
  232. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  233. return;
  234. }
  235. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  236. fdata.ShowDialog();
  237. }
  238. #endregion
  239. #region 分页
  240. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  241. {
  242. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  243. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  244. grdDetail.DataSource = data;
  245. }
  246. #endregion
  247. #region 过滤方法
  248. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  249. {
  250. AppConfig.DropTemTable(tempTableName);
  251. }
  252. #endregion
  253. #region 全选
  254. private void btnSelectAll_Click(object sender, EventArgs e)
  255. {
  256. grvDetail.PostEditor();
  257. this.Validate();
  258. for (int i = 0; i < grvDetail.RowCount; i++)
  259. {
  260. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  261. }
  262. }
  263. #endregion
  264. #region 全消
  265. private void btnCancelAll_Click(object sender, EventArgs e)
  266. {
  267. grvDetail.PostEditor();
  268. this.Validate();
  269. for (int i = 0; i < grvDetail.RowCount; i++)
  270. {
  271. grvDetail.SetRowCellValue(i, colisSelect, "");
  272. }
  273. }
  274. #endregion
  275. #region 双击
  276. private void grvDetail_DoubleClick(object sender, EventArgs e)
  277. {
  278. if (grvDetail.FocusedRowHandle < 0)
  279. {
  280. return;
  281. }
  282. if (grvDetail.FocusedColumn == colisSelect)
  283. {
  284. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  285. {
  286. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  287. }
  288. else
  289. {
  290. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  291. }
  292. }
  293. }
  294. #endregion
  295. #region 批次删除
  296. private void btnDel_Click(object sender, EventArgs e)
  297. {
  298. #region
  299. //SimpleButton btntemp = (SimpleButton)sender;
  300. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  301. //{
  302. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  303. // return;
  304. //}
  305. //List<string> moidList = new List<string>();
  306. //for (int i = 0; i < grvDetail.RowCount; i++)
  307. //{
  308. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  309. // {
  310. // string moid;
  311. // if (grvDetail.GetRowCellValue(i, colMOTYPE).ToString() == "1")
  312. // {
  313. // moidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  314. // }
  315. // else
  316. // {
  317. // ICSBaseSimpleCode.AppshowMessageBox("非返程工单,不能删除!!!");
  318. // return;
  319. // }
  320. // }
  321. //}
  322. //if (moidList.Count == 0 || moidList == null)
  323. //{
  324. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  325. // return;
  326. //}
  327. //if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除工单吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  328. //{
  329. // btnCancelAll_Click(sender, e);
  330. // return;
  331. //}
  332. //try
  333. //{
  334. // ICSMOBLL.deleteInfo(moidList, AppConfig.AppConnectString);
  335. // ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  336. //}
  337. //catch (Exception ex)
  338. //{
  339. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  340. //}
  341. //btnRefresh_Click(null, null);
  342. #endregion
  343. //批次删除
  344. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确认删除批次信息吗?删除后无法恢复!")==DialogResult.OK) {
  345. int count = 0;
  346. List<ICSMO> list = new List<ICSMO>();
  347. for (int i = 0; i < grvDetail.RowCount; i++)
  348. {
  349. if (grvDetail.GetRowCellValue(i, colisSelect) == "Y") {
  350. count++;
  351. string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  352. string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  353. string status = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  354. if (ICSMO2LotBLL.IsKG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString()))
  355. {
  356. ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已开工,无法删除批次!");
  357. return;
  358. }
  359. if (ICSMO2LotBLL.IsPG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString()))
  360. {
  361. ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已派工,请先取消派工!");
  362. return;
  363. }
  364. ICSMO mo = new ICSMO();
  365. mo.MOCODE = mocode;
  366. mo.MOSEQ = moseq;
  367. list.Add(mo);
  368. }
  369. }
  370. if (count <= 0) {
  371. ICSBaseSimpleCode.AppshowMessageBox("请选择要删除批次信息的工单!");
  372. }
  373. try
  374. {
  375. ICSMOBLL.DeleteLotno(list);
  376. ICSBaseSimpleCode.AppshowMessageBox("删除成功!");
  377. }
  378. catch (Exception ex) {
  379. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  380. }
  381. }
  382. }
  383. #endregion
  384. #region 导出
  385. private void btnOutPut_Click(object sender, EventArgs e)
  386. {
  387. try
  388. {
  389. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  390. foe.ShowDialog();
  391. }
  392. catch (Exception ex)
  393. {
  394. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  395. }
  396. //FormOutExcel foe = new FormOutExcel();
  397. //if (foe.ShowDialog() == DialogResult.OK)
  398. //{
  399. // try
  400. // {
  401. // string outtype = foe._OutType;
  402. // string exceltype = foe._ExcelType;
  403. // string filename = foe._FileName;
  404. // string url = foe._Url;
  405. // string sheetname = foe._SheetName;
  406. // if (outtype.ToLower() == "excel")
  407. // {
  408. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  409. // op.SheetName = sheetname;
  410. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  411. // }
  412. // else
  413. // {
  414. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  415. // }
  416. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  417. // }
  418. // catch (Exception ex)
  419. // {
  420. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  421. // }
  422. //}
  423. }
  424. #endregion
  425. #region 刷新
  426. private void btnRefresh_Click(object sender, EventArgs e)
  427. {
  428. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  429. try
  430. {
  431. _wait.Show();
  432. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  433. filter.OldTempTableName = tempTableName;
  434. //tempTableName = filter.NewTempTableName;
  435. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  436. if (!string.IsNullOrWhiteSpace(sqlconn))
  437. {
  438. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  439. grdDetail.DataSource = dataSource;
  440. grvDetail.BestFitColumns();
  441. rptPage.RecordNum = dataSource.Rows.Count;
  442. rptPage.PageIndex = 1;
  443. rptPage.ReLoad();
  444. }
  445. _wait.Close();
  446. }
  447. catch (Exception ex)
  448. {
  449. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  450. _wait.Close();
  451. }
  452. }
  453. #endregion
  454. #region 新增
  455. private void btnCreate_Click(object sender, EventArgs e)
  456. {
  457. SimpleButton btntemp = (SimpleButton)sender;
  458. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  459. {
  460. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  461. return;
  462. }
  463. try
  464. {
  465. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定产生委外请购单吗?") != DialogResult.OK)
  466. {
  467. return;
  468. }
  469. else
  470. {
  471. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在创建...请稍等...");
  472. try
  473. {
  474. _wait.Show();
  475. bool isright = true;
  476. List<PU_AppVouch> listcontextWW = new List<PU_AppVouch>();
  477. List<PU_AppVouchs> contextsWWList = new List<PU_AppVouchs>();
  478. PU_AppVouch contextWW = new PU_AppVouch();
  479. contextWW.UserCode = AppConfig.UserCode;
  480. contextWW.UserName = AppConfig.UserName;
  481. //contextWW.TargetAccount =AppConfig.GetDataBaseNameByConnectString(AppConfig.GetDataBaseConnectStringByKey("[]"));
  482. contextWW.TargetAccount = ConfigurationManager.AppSettings["TargetAccountU8"];
  483. List<string> dept = new List<string>();
  484. string sqladdress = "select '['+DBIPADDRESS+']'+'.'+DBNAME as address from Sys_DataBase where dbsourcename='ERP'";
  485. string ipaddress = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqladdress).Tables[0].Rows[0]["address"].ToString();
  486. for (int i = 0; i < grvDetail.RowCount; i++)
  487. {
  488. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  489. {
  490. #region MyRegion
  491. //工单工号
  492. string MOCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  493. string MCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  494. string MOSEQ = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  495. string MOSTATUS = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  496. string ItemName = grvDetail.GetRowCellValue(i, colITEMNAME).ToString();
  497. string MOPLANQTY = grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString();
  498. string MOPLANENDDATE = grvDetail.GetRowCellValue(i, colMOPLANENDDATE).ToString();
  499. string deptname = grvDetail.GetRowCellValue(i, colcDepName).ToString();
  500. if (!dept.Contains(deptname)) {
  501. dept.Add(deptname);
  502. }
  503. if (dept.Count > 1) {
  504. ICSBaseSimpleCode.AppshowMessageBox("请选择相同部门的工单行!");
  505. return;
  506. }
  507. string U8Sql = @"SELECT COUNT( c.IssQty)
  508. FROM "+ipaddress+ @".dbo.mom_order a
  509. INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId
  510. INNER JOIN " + ipaddress + @".dbo.mom_moallocate c ON b.MoDId = c.MoDId
  511. WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "' and c.IssQty>0";
  512. DataTable U8Dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, U8Sql).Tables[0];
  513. if (U8Dt != null && U8Dt.Rows.Count > 0)
  514. {
  515. string IssQty = U8Dt.Rows[0][0].ToString();
  516. int _IssQty = 0;
  517. if (string.IsNullOrWhiteSpace(IssQty))
  518. {
  519. _IssQty = Int32.Parse(IssQty);
  520. if (_IssQty > 0)
  521. {
  522. _wait.Close();
  523. ICSBaseSimpleCode.AppshowMessageBox("工单:" + MOCode + ",行号:" + MOSEQ + "在U8中已经领料,不能创建请购单!!!");
  524. return;
  525. }
  526. }
  527. }
  528. string u8sql = "select cDefine22 from " + ipaddress + @".dbo.PU_AppVouchs where cDefine22='" + MOCode + "' and cDefine24='"+MOSEQ+"'";
  529. DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, u8sql).Tables[0];
  530. if (dt1.Rows.Count > 0) {
  531. _wait.Close();
  532. ICSBaseSimpleCode.AppshowMessageBox("工单:" + MOCode + ",行号:" + MOSEQ + "在U8中已创建请购单,请不要重复创建!!");
  533. return;
  534. }
  535. if (MOSTATUS != "初始")
  536. {
  537. _wait.Close();
  538. ICSBaseSimpleCode.AppshowMessageBox("工单:" + MOCode + ",行号:" + MOSEQ + "不是初始状态,不能创建请购单!!!");
  539. return;
  540. }
  541. string lotNO = string.Empty;
  542. string sqlCheck = @"SELECT bPurchase FROM ICSINVENTORY WHERE INVCODE='" + MCODE + "' ";
  543. DataTable dtCheck = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlCheck).Tables[0];
  544. string bPurchase = string.Empty;
  545. if (dtCheck != null && dtCheck.Rows.Count > 0)
  546. {
  547. bPurchase = dtCheck.Rows[0]["bPurchase"].ToString();
  548. }
  549. if (bPurchase != "1")
  550. {
  551. _wait.Close();
  552. //throw new Exception("料号:" + MCODE + "的外购标识是false,不允许请购!");
  553. ICSBaseSimpleCode.AppshowMessageBox("料号:" + MCODE + "的外购标识是false,不允许请购!!!");
  554. return;
  555. }
  556. string sql = @"SELECT DISTINCT MOSTATUS from ICSMO WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "' ";
  557. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  558. if (dt != null && dt.Rows.Count > 0)
  559. {
  560. foreach (DataRow dr1 in dt.Rows)
  561. {
  562. string PRLineID = dr1["MOSTATUS"].ToString();
  563. if (PRLineID == "关闭")
  564. {
  565. _wait.Close();
  566. ICSBaseSimpleCode.AppshowMessageBox("该工单已经关闭,不能生成请购单!!!");
  567. return;
  568. }
  569. }
  570. }
  571. #region
  572. // string sqlQty = @"
  573. //SELECT A.MOCODE, B.MCODE AS MCODE, C.INVNAME, A.OPCODE, D.OPDESC AS PRLineID, COUNT (B.LOTQTY) AS PRQty,
  574. //ISNULL(MIN(A.StartPlanDate), GETDATE()) StartPlanDate, ISNULL(MAX(A.EndPlanDate), GETDATE()) EndPlanDate
  575. //FROM ICSMO2User A LEFT JOIN ICSITEMLot B ON A.LOTNO = B.LotNO LEFT JOIN ICSOP D ON D.OPCODE = A.OPCODE
  576. //LEFT JOIN ICSINVENTORY C ON B.MCODE = C.INVCODE WHERE A.MOCODE = '" + MOCode + "' AND B.MCODE = '" + MCODE + @"'
  577. //AND A.MOSEQ = '" + MOSEQ + @"' AND A.EATTRIBUTE1 = 1 AND (A.PRLineID IS NULL OR A.PRLineID = '')
  578. //GROUP BY A.MOCODE, A.OPCODE, B.MCODE, C.INVNAME, D.OPDESC ";//UPDATE BY SUMMER 2020.06.17
  579. #endregion
  580. //DataTable dtQty = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlQty).Tables[0];
  581. string _EnumKey = "00010";
  582. string sqlcInvCCode = @"SELECT DISTINCT EnumText from Sys_EnumValues WHERE EnumKey='" + _EnumKey + "' ";
  583. DataTable dtcInvCCode = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlcInvCCode).Tables[0];
  584. string _cInvCCode = string.Empty;
  585. if (dtcInvCCode != null && dtcInvCCode.Rows.Count > 0)
  586. {
  587. _cInvCCode = dtcInvCCode.Rows[0][0].ToString();
  588. }
  589. string sqldepart = @"SELECT MDeptCode
  590. FROM " + ipaddress + @".dbo.mom_order a
  591. INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId
  592. WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "'";
  593. DataTable depart = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqldepart).Tables[0];
  594. if (depart.Rows.Count > 0)
  595. {
  596. contextWW.cDepCode = depart.Rows[0]["MDeptCode"].ToString();
  597. }
  598. else
  599. contextWW.cDepCode = "";
  600. PU_AppVouchs contextsWW = new PU_AppVouchs();
  601. contextsWW.cInvCCode = _cInvCCode;//物料大类
  602. contextsWW.cInvCode = MCODE;// _dr["MCODE"].ToString();//料号
  603. contextsWW.cInvName = ItemName;//_dr["INVNAME"].ToString();//料号名称
  604. contextsWW.OPCode = null;// _dr["OPCODE"].ToString();//工序
  605. contextsWW.iQuantity = Decimal.Parse(MOPLANQTY);// Decimal.Parse(_dr["PRQty"].ToString());
  606. contextsWW.iNum = Int32.Parse(MOSEQ);// lotinfo.LOTQTY * Convert.ToDecimal(lotinfo.EATTRIBUTE3);
  607. contextsWW.MOCode = MOCode;//工单号
  608. contextsWW.PRLine = "";//_dr["PRLineID"].ToString();//工序
  609. contextsWW.dArriveDate = null;// Convert.ToDateTime(_dr["StartPlanDate"].ToString()).ToShortDateString();
  610. if (string.IsNullOrWhiteSpace(MOPLANENDDATE))
  611. {
  612. contextsWW.dRequirDate = null; ;// Convert.ToDateTime(_dr["EndPlanDate"].ToString()).ToShortDateString();
  613. }
  614. else
  615. {
  616. contextsWW.dRequirDate = MOPLANENDDATE;
  617. }
  618. contextsWW.LotNo = "";//产品产品跟踪单号
  619. contextsWWList.Add(contextsWW);
  620. #endregion
  621. }
  622. }
  623. contextWW.list = contextsWWList;
  624. listcontextWW.Add(contextWW);
  625. string WWPR = JsonConvert.SerializeObject(listcontextWW);
  626. string iresultMO = HttpPost(DataCollectWW, WWPR);
  627. U8Result INVINResultMO = new U8Result();
  628. INVINResultMO = JsonConvert.DeserializeObject<U8Result>(iresultMO);
  629. StringBuilder str = new StringBuilder();
  630. str.AppendLine("创建U8请购单接口:" + WWPR);
  631. str.AppendLine("接口返回结果:" + INVINResultMO.code);
  632. str.AppendLine("接口返回数据:" + INVINResultMO.msg);
  633. ICSMO2UserDAL.WriteLogFile(str.ToString(), "创建U8请购单接口");
  634. if (INVINResultMO.code != "200")
  635. {
  636. _wait.Close();
  637. throw new Exception(INVINResultMO.msg);
  638. }
  639. List<PU_AppVouchs> _list = new List<PU_AppVouchs>();
  640. if (!string.IsNullOrWhiteSpace(INVINResultMO.msg))
  641. {
  642. _list = JsonConvert.DeserializeObject<List<PU_AppVouchs>>(INVINResultMO.msg.ToString());
  643. }
  644. else
  645. {
  646. _wait.Close();
  647. throw new Exception("未获取到请购单数据!");
  648. }
  649. //--MOBIOSVER
  650. string code = "";
  651. foreach (PU_AppVouchs vouch in _list)
  652. {
  653. string sqlUpdate = @"UPDATE ICSMO SET MOSTATUS='关闭',PRDate='"+ DateTime.Now + "' WHERE MOCODE='"+vouch.MOCode+"' AND MOSEQ='"+vouch.iNum+"' ";
  654. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sqlUpdate);
  655. code = vouch.Code;
  656. }
  657. _wait.Close();
  658. ICSBaseSimpleCode.AppshowMessageBox("产生请购单:"+code+"成功!");
  659. btnRefresh_Click(null, null);
  660. }
  661. catch (Exception _ex)
  662. {
  663. _wait.Close();
  664. throw new Exception(_ex.ToString());
  665. }
  666. }
  667. }
  668. catch (Exception ex)
  669. {
  670. throw new Exception(ex.ToString());
  671. }
  672. btnRefresh_Click(null, null);
  673. }
  674. #endregion
  675. public static string HttpPost(string url, string body)
  676. {
  677. try
  678. {
  679. Encoding encoding = Encoding.UTF8;
  680. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  681. request.Method = "POST";
  682. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  683. request.ContentType = "application/json; charset=utf-8";
  684. byte[] buffer = encoding.GetBytes(body);
  685. request.ContentLength = buffer.Length;
  686. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  687. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  688. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  689. {
  690. return reader.ReadToEnd();
  691. }
  692. }
  693. catch (WebException ex)
  694. {
  695. var res = (HttpWebResponse)ex.Response;
  696. StringBuilder sb = new StringBuilder();
  697. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  698. sb.Append(sr.ReadToEnd());
  699. throw new Exception(sb.ToString());
  700. }
  701. }
  702. #region 修改
  703. private void btnModify_Click(object sender, EventArgs e)
  704. {
  705. //已经分批的不能修改途程20190717ZM
  706. SimpleButton btntemp = (SimpleButton)sender;
  707. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  708. {
  709. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  710. return;
  711. }
  712. int count = 0;
  713. for (int i = 0; i < grvDetail.RowCount; i++)
  714. {
  715. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  716. {
  717. count++;
  718. }
  719. }
  720. if (count != 1)
  721. {
  722. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  723. return;
  724. }
  725. try
  726. {
  727. string moid;
  728. for (int i = 0; i < grvDetail.RowCount; i++)
  729. {
  730. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  731. {
  732. moid = grvDetail.GetRowCellValue(i, colID).ToString();
  733. bool issplit = ChechIsSplit(moid);
  734. if (issplit)
  735. {
  736. ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改");
  737. return;
  738. }
  739. else
  740. {
  741. FormICSMOAdd add = new FormICSMOAdd(moid);
  742. add.ShowDialog();
  743. }
  744. //}
  745. //else
  746. //{
  747. // ICSBaseSimpleCode.AppshowMessageBox("非返程工单,不能修改!!!");
  748. // return;
  749. //}
  750. }
  751. }
  752. btnRefresh_Click(null, null);
  753. }
  754. catch (Exception ex)
  755. {
  756. //throw ex;
  757. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  758. }
  759. }
  760. #endregion
  761. private bool ChechIsSplit(string moid)
  762. {
  763. bool isSplit = false;
  764. string mocode = string.Empty; ;
  765. string MOSEQ = string.Empty;
  766. string sql = @" SELECT MOCODE,MOSEQ FROM ICSMO WHERE ID='" + moid + "' ";
  767. sql = string.Format(sql);
  768. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  769. if (data != null && data.Rows.Count > 0)
  770. {
  771. mocode = data.Rows[0][0].ToString();
  772. MOSEQ = data.Rows[0][1].ToString();
  773. }
  774. string _sql = @"
  775. SELECT COUNT(*) AS num FROM
  776. ICSITEMLot b
  777. WHERE b.TransNO='" + mocode + "' AND B.TransLine='" + MOSEQ + "' ";
  778. _sql = string.Format(_sql);
  779. DataTable _data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, _sql).Tables[0];
  780. if (_data != null || _data.Rows.Count > 0)
  781. {
  782. int a = Int32.Parse(_data.Rows[0][0].ToString());
  783. if (a > 0)
  784. {
  785. isSplit = true;
  786. }
  787. }
  788. return isSplit;
  789. //if (isSplit)
  790. //{
  791. // ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改");
  792. // return;
  793. //}
  794. }
  795. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  796. {
  797. AppConfig.DropTemTable(tempTableName);
  798. }
  799. private void FormICSMO_Load(object sender, EventArgs e)
  800. {
  801. btnFilter_Click(sender, e);
  802. }
  803. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  804. {
  805. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  806. {
  807. //e.DisplayText = FormatHelper.
  808. e.CellValue = "cccc";
  809. }
  810. if (e.RowHandle > 0 && e.Column.FieldName == "isexpection" && e.CellValue.ToString() == "是")
  811. {
  812. e.Appearance.BackColor = Color.Red;
  813. }
  814. }
  815. //生成序列号
  816. private void newRcard_Click(object sender, EventArgs e)
  817. {
  818. //SimpleButton btntemp = (SimpleButton)sender;
  819. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  820. //{
  821. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  822. // return;
  823. //}
  824. //int count = 0;
  825. //for (int i = 0; i < grvDetail.RowCount; i++)
  826. //{
  827. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  828. // {
  829. // count++;
  830. // }
  831. //}
  832. //if (count != 1)
  833. //{
  834. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  835. // return;
  836. //}
  837. //try
  838. //{
  839. // string moID;
  840. // string moCode;
  841. // decimal qty = 0.00m;
  842. // for (int i = 0; i < grvDetail.RowCount; i++)
  843. // {
  844. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  845. // {
  846. // moID = grvDetail.GetRowCellValue(i, colID).ToString();
  847. // moCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  848. // qty = decimal.Parse(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
  849. // FormICSMO2RCARDAdd rec = new FormICSMO2RCARDAdd(moID, moCode, qty);
  850. // rec.ShowDialog();
  851. // }
  852. // }
  853. // btnRefresh_Click(null, null);
  854. //}
  855. //catch (Exception ex)
  856. //{
  857. // //throw ex;
  858. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  859. //}
  860. }
  861. private void repSerialButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  862. {
  863. }
  864. /// <summary>
  865. /// 下发
  866. /// </summary>
  867. /// <param name="sender"></param>
  868. /// <param name="e"></param>
  869. private void txtsend_Click(object sender, EventArgs e)
  870. {
  871. #region 工艺路线默认匹配 自控参考
  872. //SimpleButton btntemp = (SimpleButton)sender;
  873. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  874. //{
  875. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  876. // return;
  877. //}
  878. //int count = 0;
  879. //List<string> docNoList = new List<string>();
  880. //for (int i = 0; i < grvDetail.RowCount; i++)
  881. //{
  882. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  883. // {
  884. // string docNo = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  885. // docNoList.Add(docNo);
  886. // count++;
  887. // }
  888. //}
  889. //if (count <= 0)
  890. //{
  891. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据!!!");
  892. // return;
  893. //}
  894. //try
  895. //{
  896. // string msg = "";
  897. // List<string> mocodeList = new List<string>();
  898. // List<FormICSMORoute_IsRef> MORouteList = new List<FormICSMORoute_IsRef>();
  899. // for (int i = 0; i < grvDetail.RowCount; i++)
  900. // {
  901. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  902. // {
  903. // string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  904. // string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  905. // string itemCode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  906. // string state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  907. // bool IsHasRoute = ICSMOBLL.IshasROUTE(mocode, AppConfig.AppConnectString);//icsmo2route 是否有值
  908. // bool hasRoute = ICSMOBLL.hasROUTE(mocode, itemCode, AppConfig.AppConnectString);
  909. //
  910. // if (!IsHasRoute && !hasRoute)
  911. // {
  912. // msg += "工单代码:" + mocode + " 没有关联工艺路线,不能下发!\n";
  913. // }
  914. // ICSROUTE Route = ICSMOBLL.hasIsRefROUTE(itemCode, AppConfig.AppConnectString);
  915. // if (!IsHasRoute && Route == null)//判断是否无默认工艺路线
  916. // {
  917. // msg += "工单代码:" + mocode + " 无默认工艺路线,不能下发!\n";
  918. // }
  919. // if (string.IsNullOrEmpty(msg))
  920. // {
  921. // FormICSMORoute_IsRef item = new FormICSMORoute_IsRef();
  922. // item.MOCODE = mocode;
  923. // item.MOSEQ = moseq;
  924. // item.Route = Route;
  925. // item.isRef = "是";
  926. // mocodeList.Add(mocode);
  927. // if (!IsHasRoute)
  928. // {
  929. // MORouteList.Add(item);
  930. // }
  931. // }
  932. // }
  933. // }
  934. // if (msg != "")
  935. // {
  936. // ICSBaseSimpleCode.AppshowMessageBox(msg);
  937. // return;
  938. // }
  939. // //直接下发
  940. // foreach (string code in mocodeList)
  941. // {
  942. // ICSMOBLL.Sends(code, MOSEQ, AppConfig.AppConnectString);
  943. // }
  944. // if (MORouteList != null && MORouteList.Count > 0)
  945. // {
  946. // ICSMOBLL.ADDIsRefRoute(MORouteList, AppConfig.AppConnectString);
  947. // }
  948. // ICSBaseSimpleCode.AppshowMessageBox("下发成功");
  949. // btnRefresh_Click(null, null);
  950. //}
  951. //catch (Exception ex)
  952. //{
  953. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  954. //}
  955. #endregion 匹配默认
  956. #region 081 GJ 下发
  957. SimpleButton btntemp = (SimpleButton)sender;
  958. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  959. {
  960. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  961. return;
  962. }
  963. int count = 0;
  964. for (int i = 0; i < grvDetail.RowCount; i++)
  965. {
  966. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  967. {
  968. count++;
  969. }
  970. }
  971. if (count == 0)
  972. {
  973. ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行下发操作!!!");
  974. return;
  975. }
  976. try
  977. {
  978. string mocode = "";
  979. string moseq = "";
  980. string status = "";
  981. List<ICSMO> moinfolist = new List<ICSMO>();
  982. for (int i = 0; i < grvDetail.RowCount; i++)
  983. {
  984. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  985. {
  986. string id = grvDetail.GetRowCellValue(i, MOID1).ToString();
  987. mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  988. moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  989. status = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  990. string itemCode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  991. #region 判断工单是否是初始状态
  992. if (status != "初始")
  993. {
  994. ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行:" + moseq + "不是初始状态,无法下发!!!");
  995. return;
  996. }
  997. #endregion
  998. #region 0827
  999. string IsHasRoute = string.Empty;
  1000. if (string.IsNullOrWhiteSpace(id))
  1001. {
  1002. IsHasRoute = ICSMOBLL.IshasROUTE(id, AppConfig.AppConnectString);//icsmo2route 返回工单的工艺路线
  1003. }
  1004. if (string.IsNullOrWhiteSpace(IsHasRoute))
  1005. {
  1006. string Route = ICSMOBLL.hasIsRefROUTE(itemCode, AppConfig.AppConnectString);//存货是否有默认路线
  1007. FormICSMOUIModel mo = new FormICSMOUIModel();
  1008. mo.ID = grvDetail.GetRowCellValue(i, colID).ToString();
  1009. mo.MOCODE = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1010. // mo.MOMEMO = grvDetail.GetRowCellValue(i, colMOMEMO).ToString();
  1011. //mo.MOTYPE = txtMOTYPE.Text;
  1012. //mo.MODESC = grvDetail.GetRowCellValue(i, colMODESC).ToString();
  1013. mo.MOTYPE = "1";//工单类型默认为1
  1014. mo.MOPLANQTY = Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
  1015. mo.MOPLANSTARTDATE = Convert.ToDateTime(grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE).ToString());
  1016. mo.MOPLANENDDATE = Convert.ToDateTime(grvDetail.GetRowCellValue(i, colMOPLANENDDATE).ToString());
  1017. mo.FACTORY = grvDetail.GetRowCellValue(i, colFACTORY).ToString();
  1018. // mo.CUSORDERNO = grvDetail.GetRowCellValue(i, colCUSORDERNO).ToString();
  1019. // mo.MOUSER = grvDetail.GetRowCellValue(i, colMOUSER).ToString();
  1020. mo.MODOWNDATE = Convert.ToDateTime(grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE).ToString());
  1021. mo.MOSTATUS = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  1022. // GetRowCellValue(i, colMOMEMO).ToString(); grvDetail.GetRowCellValue(i, colMODESC).ToString();
  1023. //mo.ISCONINPUT = txtISCONINPUT.Text;
  1024. //if (txtISCONINPUT.Checked)
  1025. // mo.ISCONINPUT = "是";
  1026. //else
  1027. // mo.ISCONINPUT = "否";
  1028. //mo.
  1029. mo.ITEMCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  1030. mo.MOSEQ = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  1031. // mo.MOPENDINGCAUSE = grvDetail.GetRowCellValue(i, colMOPENDINGCAUSE).ToString();
  1032. // 9.1注释 mo.OFFMOQTY = Convert.ToDecimal(txtOFFMOQTY.Text.Equals("") ? "0" : txtOFFMOQTY.Text);
  1033. mo.MOBOM = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  1034. // mo.MORemark = grvDetail.GetRowCellValue(i, colMORemark).ToString();
  1035. // mo.MOVER =grvDetail.GetRowCellValue(i, colMODESC).ToString();
  1036. ICSMOBLL.Add(mo, Route, AppConfig.AppConnectString);
  1037. //if (flag == 0)
  1038. //{
  1039. //ICSBaseSimpleCode.AppshowMessageBox("匹配成功");
  1040. //this.Close();
  1041. // this.DialogResult = DialogResult.Yes;
  1042. //}
  1043. //else if (flag == 1)
  1044. //{
  1045. // ICSBaseSimpleCode.AppshowMessageBox("修改成功");
  1046. // this.Close();
  1047. // this.DialogResult = DialogResult.Yes;
  1048. //}
  1049. // add.ShowDialog();
  1050. // }
  1051. //}
  1052. //else
  1053. //{
  1054. // ICSBaseSimpleCode.AppshowMessageBox(" 没有默认工艺路线,不能下发!!!\n");
  1055. // return;
  1056. //}
  1057. }
  1058. #region 废弃的
  1059. //bool hasRoute = ICSMOBLL.hasROUTE(mocode, itemCode, AppConfig.AppConnectString);//工单号(mocode)是否有路线
  1060. //ICSROUTE Route = ICSMOBLL.hasIsRefROUTE(itemCode, AppConfig.AppConnectString);//存货是否有默认路线
  1061. //if (!IsHasRoute && !hasRoute)
  1062. //{
  1063. // ICSBaseSimpleCode.AppshowMessageBox("工单代码:" + mocode + " 没有关联工艺路线,不能下发!\n");
  1064. // return;
  1065. //}
  1066. //if (IsHasRoute && Route != null)//判断是否默认工艺路线
  1067. //{
  1068. // string moid = grvDetail.GetRowCellValue(i, colID).ToString();
  1069. // bool issplit = ChechIsSplit(moid);
  1070. // if (issplit)
  1071. // {
  1072. // ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改!!");
  1073. // return;
  1074. // }
  1075. // else
  1076. // {
  1077. // ICSBaseSimpleCode.AppshowMessageBox("有默认的工艺路线\n");
  1078. // FormICSMOAdd add = new FormICSMOAdd(moid);
  1079. // add.ShowDialog();
  1080. #endregion
  1081. #endregion
  1082. #region 下发前检验工单是否绑定工艺路线
  1083. ICSMO2ROUTE morouteinfo = ICSMOBLL.selectmo2routebyid(grvDetail.GetRowCellValue(i, colID).ToString(), AppConfig.AppConnectString);
  1084. if (morouteinfo == null)
  1085. {
  1086. ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行:" + moseq + "尚未绑定工艺路线,无法下发!!!");
  1087. return;
  1088. }
  1089. #endregion
  1090. ICSMO moinfo = new ICSMO();
  1091. moinfo.MOCODE = mocode;
  1092. moinfo.MOSEQ = moseq;
  1093. moinfolist.Add(moinfo);
  1094. }
  1095. }
  1096. ICSMOBLL.Send(moinfolist, AppConfig.AppConnectString);
  1097. ICSBaseSimpleCode.AppshowMessageBox("下发成功");
  1098. btnRefresh_Click(null, null);
  1099. }
  1100. catch (Exception ex)
  1101. {
  1102. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1103. }
  1104. #endregion
  1105. #region 注释的原版0819
  1106. // SimpleButton btntemp = (SimpleButton)sender;
  1107. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1108. // {
  1109. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1110. // return;
  1111. // }
  1112. // int count = 0;
  1113. // for (int i = 0; i < grvDetail.RowCount; i++)
  1114. // {
  1115. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1116. // {
  1117. // count++;
  1118. // }
  1119. // }
  1120. // if (count != 1)
  1121. // {
  1122. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  1123. // return;
  1124. // }
  1125. // try
  1126. // {
  1127. // string mocode = "";
  1128. // string moseq = "";
  1129. // string state = "";
  1130. // string moid = ""; //0819
  1131. // for (int i = 0; i < grvDetail.RowCount; i++)
  1132. // {
  1133. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1134. // {
  1135. // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1136. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  1137. // moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  1138. // moid = grvDetail.GetRowCellValue(i, colID).ToString(); //0819
  1139. // }
  1140. // }
  1141. // #region 20210804 下发之后才能分批,不是分批之后在下发。
  1142. // string sendSql = @"SELECT * FROM ICSITEMLot WHERE TransNO='" + mocode + "' ";
  1143. // sendSql = string.Format(sendSql);
  1144. // DataTable sendData = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sendSql).Tables[0];
  1145. // if (sendData == null || sendData.Rows.Count < 1)
  1146. // {
  1147. // ICSBaseSimpleCode.AppshowMessageBox("只有分完批次才能下发!");
  1148. // return;
  1149. // }
  1150. // #endregion
  1151. // --工艺路线,代码(途程代码)的sql语句
  1152. // string _sql = @"SELECT
  1153. // c.ROUTECODE --工艺路线,代码(途程代码)
  1154. // FROM
  1155. // ICSMO a
  1156. // LEFT JOIN ICSMO2ROUTE c ON a.ID = c.MOID
  1157. // LEFT JOIN (
  1158. // SELECT
  1159. // b.MOCODE,
  1160. // CONVERT (INT, b.MOSEQ) AS MOSEQ,
  1161. // b.ITEMCODE,
  1162. // COUNT (*) AS IsUse
  1163. // FROM
  1164. // ICSMOPickLog a
  1165. // INNER JOIN ICSMO b ON (
  1166. // a.MOCode = b.MOCODE
  1167. // AND b.MOSEQ = a.MOSEQ
  1168. // AND a.ITEMCODE = b.ITEMCODE
  1169. // )
  1170. // GROUP BY
  1171. // b.MOCODE,
  1172. // b.MOSEQ,
  1173. // b.ITEMCODE
  1174. // ) d ON (
  1175. // d.MOCODE = a.MOCODE
  1176. // AND d.MOSEQ = a.MOSEQ
  1177. // AND d.ITEMCODE = a.ITEMCODE
  1178. // )
  1179. // WHERE 1 = 1
  1180. // AND a.MOCODE = '" + mocode + "' AND a.MOSEQ =" + moseq + " ORDER BY a.MOCODE, CONVERT (INT, a.MOSEQ)";
  1181. // _sql = string.Format(_sql);
  1182. // DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, _sql).Tables[0];
  1183. // string _ROUTECODE = string.Empty;//--工艺路线,代码(途程代码)
  1184. // if (data != null && data.Rows.Count > 0)
  1185. // {
  1186. // _ROUTECODE = data.Rows[0][0].ToString();//--工艺路线,代码(途程代码)
  1187. // }
  1188. // else
  1189. // {
  1190. // ICSBaseSimpleCode.AppshowMessageBox("工单尚未绑定工艺路线不能下发!");
  1191. // return;
  1192. // }
  1193. // if (string.IsNullOrWhiteSpace(_ROUTECODE))//--工艺路线,代码(途程代码)
  1194. // {
  1195. // ICSBaseSimpleCode.AppshowMessageBox("工单尚未绑定工艺路线不能下发!!");
  1196. // return;
  1197. // }
  1198. // 判断是否是初始状态
  1199. // if (state.Equals("初始"))
  1200. // {
  1201. // //判断是否在工单首检记录表中
  1202. // if (ICSMOBLL.isInFirstCheck(mocode, AppConfig.AppConnectString))
  1203. // {
  1204. // //判断(最近的时间)是否合格
  1205. // if (ICSMOBLL.isQualified(mocode, AppConfig.AppConnectString))
  1206. // {
  1207. // ICSMOBLL.Send(mocode, moseq, AppConfig.AppConnectString);
  1208. // ICSBaseSimpleCode.AppshowMessageBox("下发成功");
  1209. // }
  1210. // else
  1211. // {
  1212. // ICSBaseSimpleCode.AppshowMessageBox("不合格,不能下发");
  1213. // return;
  1214. // //}
  1215. // }
  1216. // else
  1217. // {
  1218. // ICSBaseSimpleCode.AppshowMessageBox("不存在工单首检记录中");
  1219. // return;
  1220. // }
  1221. // }
  1222. // else
  1223. // {
  1224. // ICSBaseSimpleCode.AppshowMessageBox("不是初始状态,不能下发");
  1225. // return;
  1226. // }
  1227. // btnRefresh_Click(null, null);
  1228. // } //try
  1229. // catch (Exception ex)
  1230. // {
  1231. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1232. // }
  1233. #endregion
  1234. }
  1235. //取消下发
  1236. private void txtcancelSend_Click(object sender, EventArgs e)
  1237. {
  1238. SimpleButton btntemp = (SimpleButton)sender;
  1239. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1240. {
  1241. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1242. return;
  1243. }
  1244. for (int i = 0; i < grvDetail.RowCount; i++)
  1245. {
  1246. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1247. {
  1248. //if (!grvDetail.GetRowCellValue(i, colMOSTATUS).ToString().Equals("下发"))
  1249. //{
  1250. // ICSBaseSimpleCode.AppshowMessageBox("工单: "+grvDetail.GetRowCellValue(i, colMOCODE).ToString()+" 不是下发状态,不能取消下发");
  1251. // return;
  1252. //}
  1253. if (ICSMO2LotBLL.IsKG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString())) {
  1254. ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已开工,无法取消下发!");
  1255. return;
  1256. }
  1257. if (ICSMO2LotBLL.IsPG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString())) {
  1258. ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已派工,请先取消派工!");
  1259. return;
  1260. }
  1261. if (ICSMO2LotBLL.IsIncludingInMO2Lot(grvDetail.GetRowCellValue(i, colID).ToString())) {
  1262. ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已分批,请先删除分批再取消下发!");
  1263. return;
  1264. }
  1265. }
  1266. }
  1267. try
  1268. {
  1269. string mocode = "";
  1270. string state = "";
  1271. string moseq = "";
  1272. for (int i = 0; i < grvDetail.RowCount; i++)
  1273. {
  1274. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1275. {
  1276. mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1277. state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  1278. moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  1279. ICSMOBLL.cancelSend(mocode, moseq, AppConfig.AppConnectString);
  1280. }
  1281. }
  1282. ICSBaseSimpleCode.AppshowMessageBox("取消下发成功");
  1283. btnRefresh_Click(null, null);
  1284. }
  1285. catch (Exception ex)
  1286. {
  1287. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1288. }
  1289. }
  1290. //暂停
  1291. private void txtstop_Click(object sender, EventArgs e)
  1292. {
  1293. //SimpleButton btntemp = (SimpleButton)sender;
  1294. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1295. //{
  1296. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1297. // return;
  1298. //}
  1299. //int count = 0;
  1300. //for (int i = 0; i < grvDetail.RowCount; i++)
  1301. //{
  1302. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1303. // {
  1304. // count++;
  1305. // }
  1306. //}
  1307. //if (count != 1)
  1308. //{
  1309. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  1310. // return;
  1311. //}
  1312. //try
  1313. //{
  1314. // string mocode = "";
  1315. // string state = "";
  1316. // for (int i = 0; i < grvDetail.RowCount; i++)
  1317. // {
  1318. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1319. // {
  1320. // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1321. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  1322. // }
  1323. // }
  1324. // //判断是否是生产中状态
  1325. // if (state.Equals("生产中"))
  1326. // {
  1327. // ICSMOBLL.stop(mocode, AppConfig.AppConnectString);
  1328. // ICSBaseSimpleCode.AppshowMessageBox("暂停成功");
  1329. // }
  1330. // else
  1331. // {
  1332. // ICSBaseSimpleCode.AppshowMessageBox("不是生产中状态,不能暂停");
  1333. // return;
  1334. // }
  1335. // btnRefresh_Click(null, null);
  1336. //}
  1337. //catch (Exception ex)
  1338. //{
  1339. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1340. //}
  1341. }
  1342. //取消暂停
  1343. private void txtcancelStop_Click(object sender, EventArgs e)
  1344. {
  1345. SimpleButton btntemp = (SimpleButton)sender;
  1346. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1347. {
  1348. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1349. return;
  1350. }
  1351. int count = 0;
  1352. for (int i = 0; i < grvDetail.RowCount; i++)
  1353. {
  1354. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1355. {
  1356. count++;
  1357. }
  1358. }
  1359. if (count != 1)
  1360. {
  1361. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  1362. return;
  1363. }
  1364. try
  1365. {
  1366. string mocode = "";
  1367. string state = "";
  1368. for (int i = 0; i < grvDetail.RowCount; i++)
  1369. {
  1370. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1371. {
  1372. mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1373. state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  1374. }
  1375. }
  1376. //判断是否是暂停状态
  1377. if (state.Equals("暂停"))
  1378. {
  1379. ICSMOBLL.cancelStop(mocode, AppConfig.AppConnectString);
  1380. ICSBaseSimpleCode.AppshowMessageBox("取消暂停成功");
  1381. }
  1382. else
  1383. {
  1384. ICSBaseSimpleCode.AppshowMessageBox("不是暂停状态,不能取消暂停");
  1385. return;
  1386. }
  1387. btnRefresh_Click(null, null);
  1388. }
  1389. catch (Exception ex)
  1390. {
  1391. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1392. }
  1393. }
  1394. //关单
  1395. private void txtcloseDan_Click(object sender, EventArgs e)
  1396. {
  1397. SimpleButton btntemp = (SimpleButton)sender;
  1398. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1399. {
  1400. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1401. return;
  1402. }
  1403. for (int i = 0; i < grvDetail.RowCount; i++)
  1404. {
  1405. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1406. {
  1407. if (grvDetail.GetRowCellValue(i, colMOSTATUS).ToString().Equals("关单")) {
  1408. ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已经是关单状态,不能关单!");
  1409. return;
  1410. }
  1411. }
  1412. }
  1413. try
  1414. {
  1415. List<string> ID = new List<string>();
  1416. for (int i = 0; i < grvDetail.RowCount; i++)
  1417. {
  1418. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1419. {
  1420. string id = grvDetail.GetRowCellValue(i, colID).ToString();
  1421. ID.Add(id);
  1422. }
  1423. }
  1424. FormICSMOClose add = new FormICSMOClose(ID);
  1425. add.ShowDialog();
  1426. btnRefresh_Click(null, null);
  1427. }
  1428. catch (Exception ex)
  1429. {
  1430. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1431. }
  1432. }
  1433. //批次信息
  1434. private void btnBatch_Click(object sender, EventArgs e)
  1435. {
  1436. //SimpleButton btntemp = (SimpleButton)sender;
  1437. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1438. //{
  1439. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1440. // return;
  1441. //}
  1442. //FormICSMO2Lot add = new FormICSMO2Lot();
  1443. //add.ShowDialog();
  1444. //btnRefresh_Click(null, null);
  1445. SimpleButton btntemp = (SimpleButton)sender;
  1446. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1447. {
  1448. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1449. return;
  1450. }
  1451. int count = 0;
  1452. for (int i = 0; i < grvDetail.RowCount; i++)
  1453. {
  1454. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1455. {
  1456. count++;
  1457. }
  1458. }
  1459. if (count != 1)
  1460. {
  1461. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  1462. return;
  1463. }
  1464. try
  1465. {
  1466. string id;
  1467. string code;
  1468. int Qty = 0;
  1469. string itemcode;
  1470. string dept;//0816新增
  1471. DateTime MOPLANSTARTDATE;
  1472. DateTime MOPLANENDDATE;
  1473. for (int i = 0; i < grvDetail.RowCount; i++)
  1474. {
  1475. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1476. {
  1477. dept = grvDetail.GetRowCellValue(i, colcDepName).ToString();//0816新增字段
  1478. id = grvDetail.GetRowCellValue(i, colID).ToString();
  1479. code = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1480. Qty = (int)Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
  1481. itemcode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  1482. string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  1483. MOPLANSTARTDATE = Convert.ToDateTime((grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE)));
  1484. MOPLANENDDATE = Convert.ToDateTime((grvDetail.GetRowCellValue(i, colMOPLANENDDATE)));
  1485. FormICSMO2LOT1 add = new FormICSMO2LOT1(id, code, Qty, itemcode, moseq, dept, MOPLANSTARTDATE, MOPLANENDDATE);
  1486. add.ShowDialog();
  1487. btnRefresh_Click(null, null);
  1488. }
  1489. }
  1490. //判断是否是关单状态
  1491. //if (!(state.Equals("关单")))
  1492. //{
  1493. //}
  1494. //else
  1495. //{
  1496. // ICSBaseSimpleCode.AppshowMessageBox("已经是关单状态");
  1497. // return;
  1498. //}
  1499. btnRefresh_Click(null, null);
  1500. }
  1501. catch (Exception ex)
  1502. {
  1503. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1504. }
  1505. }
  1506. #region 取消关单
  1507. private void BtnCancelCloseMO_Click(object sender, EventArgs e)
  1508. {
  1509. SimpleButton btntemp = (SimpleButton)sender;
  1510. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1511. {
  1512. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1513. return;
  1514. }
  1515. int count = 0;
  1516. for (int i = 0; i < grvDetail.RowCount; i++)
  1517. {
  1518. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1519. {
  1520. count++;
  1521. }
  1522. }
  1523. if (count != 1)
  1524. {
  1525. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  1526. return;
  1527. }
  1528. try
  1529. {
  1530. string ID = "";
  1531. string state = "";
  1532. for (int i = 0; i < grvDetail.RowCount; i++)
  1533. {
  1534. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1535. {
  1536. ID = grvDetail.GetRowCellValue(i, colID).ToString();
  1537. state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  1538. }
  1539. }
  1540. if ((state.Equals("关单")))
  1541. {
  1542. //判断是否是关单状态
  1543. ICSMOBLL.CancleCloseDan(ID, AppConfig.AppConnectString);
  1544. ICSBaseSimpleCode.AppshowMessageBox("取消关单成功");
  1545. }
  1546. else
  1547. {
  1548. ICSBaseSimpleCode.AppshowMessageBox("非关单状态,不能取消关单");
  1549. return;
  1550. }
  1551. btnRefresh_Click(null, null);
  1552. }
  1553. catch (Exception ex)
  1554. {
  1555. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1556. }
  1557. }
  1558. #endregion
  1559. /// <summary>
  1560. /// 新增的 [一键分批按钮] 按钮0818
  1561. /// </summary>
  1562. /// <param name="sender"></param>
  1563. /// <param name="e"></param>
  1564. private void btnLot1_Click(object sender, EventArgs e)
  1565. {
  1566. try
  1567. {
  1568. //根据ICSMOPickLog窜起来查确定是否领料。工单:MOCODE、生产订单行号:MOSEQ、子料:ITEMCODE(根据工单母料看子料)
  1569. //限制:如果‘是否领料’字段为‘否’,那么无法进行分批操作;
  1570. SimpleButton btntemp = (SimpleButton)sender;
  1571. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1572. {
  1573. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1574. return;
  1575. }
  1576. int count = 0;
  1577. for (int i = 0; i < grvDetail.RowCount; i++)
  1578. {
  1579. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1580. // if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect).ToString()))
  1581. {
  1582. count++;
  1583. }
  1584. }
  1585. if (count == 0)
  1586. {
  1587. ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行分批!");
  1588. return;
  1589. }
  1590. else
  1591. {
  1592. List<ICSITEMLot> lotinfoList = new List<ICSITEMLot>();
  1593. List<ICSITEMROUTE2OPLot> oplotinfoList = new List<ICSITEMROUTE2OPLot>();
  1594. for (int i = 0; i < grvDetail.RowCount; i++)
  1595. {
  1596. //if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect).ToString()))
  1597. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1598. {
  1599. string ITEMCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  1600. string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  1601. string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  1602. string moplanstartdate= grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE).ToString();
  1603. string moplanenddate = grvDetail.GetRowCellValue(i, colMOPLANENDDATE).ToString();
  1604. ICSMO moinfo = ICSMOBLL.selectbyid(grvDetail.GetRowCellValue(i, colID).ToString(), AppConfig.AppConnectString);
  1605. if (moinfo.MOSTATUS != "下发")
  1606. {
  1607. ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行号:" + moseq + "尚未下发,不能分批!");
  1608. return;
  1609. }
  1610. string ItemCode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  1611. string RouteCode = grvDetail.GetRowCellValue(i, colMOROUTE).ToString();
  1612. bool b = ICSMO2LotBLL.IsIncludingInMO2Lot(grvDetail.GetRowCellValue(i, colID).ToString());
  1613. if (b)
  1614. {
  1615. ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行号:" + moseq + "已生成批次,若要重新生成,请先删除原批次信息!");
  1616. return;
  1617. }
  1618. #region ICSITEMLot表
  1619. ICSITEMLot lotinfo = new ICSITEMLot();
  1620. lotinfo.MCODE = ITEMCODE;//0827新增
  1621. lotinfo.ID = AppConfig.GetGuid();
  1622. lotinfo.LotNO = mocode + moseq + "0001";
  1623. lotinfo.TransNO = mocode;
  1624. lotinfo.TransLine = moseq;
  1625. // lotinfo.ItemCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  1626. lotinfo.VENDORITEMCODE = "";
  1627. lotinfo.VENDORCODE = "";
  1628. lotinfo.VenderLotNO = "";
  1629. lotinfo.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1630. lotinfo.LOTQTY = Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
  1631. lotinfo.ACTIVE = "Y";
  1632. lotinfo.Exdate = Convert.ToDateTime("2999-12-31 00:00:00.000");
  1633. lotinfo.WorkPoint = AppConfig.WorkPointCode;
  1634. lotinfo.MUSER = AppConfig.UserCode;
  1635. lotinfo.MUSERName = AppConfig.UserName;
  1636. lotinfo.MTIME = DateTime.Now;
  1637. lotinfo.EATTRIBUTE1 = "";
  1638. lotinfo.TYPE = "工单";
  1639. lotinfo.MOPLANSTARTDATE = moplanstartdate;
  1640. lotinfo.MOPLANENDDATE = moplanenddate;
  1641. lotinfoList.Add(lotinfo);
  1642. #endregion
  1643. #region 根据Code获取工艺路线信息
  1644. List<ICSITEMROUTE2OP> opinfolist = ICSITEMROUTE2OPBLL.selectinfobycode(ItemCode, RouteCode, AppConfig.AppConnectString);
  1645. #endregion
  1646. #region 写入ICSItemRoute2OPLot表
  1647. foreach (ICSITEMROUTE2OP opinfo in opinfolist)
  1648. {
  1649. ICSITEMROUTE2OPLot oplotinfo = new ICSITEMROUTE2OPLot();
  1650. oplotinfo.ITEMCODE = ItemCode;
  1651. oplotinfo.ROUTECODE = RouteCode;
  1652. oplotinfo.OPCODE = opinfo.OPCODE;
  1653. oplotinfo.OPSEQ = opinfo.OPSEQ;
  1654. oplotinfo.OPCONTROL = "";
  1655. oplotinfo.OPTIONALOP = "";
  1656. oplotinfo.IDMERGERULE = 0;
  1657. oplotinfo.IDMERGETYPE = "";
  1658. oplotinfo.MUSER = AppConfig.UserCode;
  1659. oplotinfo.MUSERName = AppConfig.UserName;
  1660. oplotinfo.MTIME = DateTime.Now;
  1661. oplotinfo.WorkPoint = AppConfig.WorkPointCode;
  1662. oplotinfo.EATTRIBUTE1 = "";
  1663. oplotinfo.LotNo = mocode + moseq + "0001";
  1664. oplotinfo.ID = AppConfig.GetGuid();
  1665. oplotinfoList.Add(oplotinfo);
  1666. }
  1667. #endregion
  1668. }
  1669. }
  1670. ICSMO2LotBLL.OP2LotAdd(lotinfoList, oplotinfoList, AppConfig.AppConnectString);
  1671. ICSBaseSimpleCode.AppshowMessageBox("分批成功");
  1672. btnRefresh_Click(null, null);
  1673. }
  1674. }
  1675. catch (Exception ex)
  1676. {
  1677. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1678. }
  1679. }
  1680. private void simpleButton1_Click(object sender, EventArgs e)
  1681. {
  1682. AppConfig.CloseFormShow(this.Text);
  1683. this.Close();
  1684. }
  1685. private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  1686. {
  1687. try
  1688. {
  1689. string url = @"http://172.16.12.155:8999/api/GetPLMToken";
  1690. //string url = @"http://localhost:51182/api/GetPLMToken";
  1691. FormICSProductionReport.SearchPart Bills = new FormICSProductionReport.SearchPart();
  1692. //Bills.ItemCode = "20100003035";
  1693. //Bills.ItemCode = "20100000670";
  1694. //Bills.ItemCode = "20800001904";
  1695. Bills.ItemCode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colITEMCODE).ToString();
  1696. Bills.size = 100;
  1697. Bills.extra = "DWGSW";
  1698. string JsonData = JsonConvert.SerializeObject(Bills);
  1699. //try
  1700. //{
  1701. // //Bills = JsonConvert.DeserializeObject<List<SearchPart>>(JsonData.ToString());
  1702. // Bills = JsonConvert.DeserializeObject<SearchPart>(JsonData.ToString());
  1703. //}
  1704. #region MyRegion
  1705. BaseModel rtn = PLM.PLMMap(url, JsonData);
  1706. if (rtn.code == "200")
  1707. {
  1708. #region MyRegion
  1709. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  1710. if (string.IsNullOrWhiteSpace(connectionString))
  1711. {
  1712. ICSBaseSimpleCode.AppshowMessageBox("没有获取到FTP链接,请在数据源中先配置FTP");
  1713. return;
  1714. }
  1715. string[] ftps = connectionString.Split(';');
  1716. string ftpServerIP = ftps[0].Split('=')[1];
  1717. //string ftpRemotePath = ftps[1].Split('=')[1];
  1718. string ftpRemotePath = "";
  1719. string ftpUserID = ftps[2].Split('=')[1];
  1720. string ftpPassword = ftps[3].Split('=')[1];
  1721. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  1722. //FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  1723. //string filePath = System.IO.Path.GetTempPath() + "\\Drawing";
  1724. string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\Drawing";
  1725. if (!Directory.Exists(filePath))
  1726. {
  1727. Directory.CreateDirectory(filePath);
  1728. }
  1729. string fileName = Bills.ItemCode + ".pdf";
  1730. ftpWeb.Download(filePath + "\\", fileName);
  1731. string filePathName = filePath + "\\" + fileName;
  1732. //string fileName = logAdress + Bills.ItemCode + ".pdf";
  1733. string ftpURL = "ftp://" + ftpServerIP + "/" + fileName;
  1734. //if (!string.IsNullOrEmpty(fileName))
  1735. if (!string.IsNullOrEmpty(filePathName))
  1736. {
  1737. FileDrawing.LoadPDF(filePathName);
  1738. }
  1739. #endregion
  1740. }
  1741. else
  1742. {
  1743. ICSBaseSimpleCode.AppshowMessageBox("调用PLM接口返回异常:" + rtn.code + ";" + rtn.msg);
  1744. return;
  1745. }
  1746. #endregion
  1747. }
  1748. catch (Exception ex)
  1749. {
  1750. MessageBox.Show(ex.Message);
  1751. }
  1752. }
  1753. private void grvDetail_Click(object sender, EventArgs e)
  1754. {
  1755. }
  1756. private void simpleButton2_Click(object sender, EventArgs e)
  1757. {
  1758. try {
  1759. SimpleButton btntemp = (SimpleButton)sender;
  1760. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  1761. {
  1762. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  1763. return;
  1764. }
  1765. string para1 = "1 and ";
  1766. for (int i = 0; i < grvDetail.RowCount; i++) {
  1767. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") {
  1768. para1 += " (a.mocode='" + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + "' and a.moseq='" + grvDetail.GetRowCellValue(i, colMOSEQ).ToString() + "') OR";
  1769. }
  1770. }
  1771. if (para1 == "1 and ") {
  1772. ICSBaseSimpleCode.AppshowMessageBox("请选择要打印的数据!");
  1773. return;
  1774. }
  1775. para1=para1.TrimEnd("OR".ToCharArray());
  1776. List<PrintPara> parasList = new List<PrintPara>();
  1777. PrintPara para = new PrintPara();
  1778. para.PrintKey = "1=1";
  1779. para.PrintValues = new object[] { para1 };
  1780. parasList.Add(para);
  1781. FormPrintDialog f = new FormPrintDialog("099", this.Text, parasList, false, null);
  1782. f.ShowDialog();
  1783. }
  1784. catch (Exception ex) {
  1785. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1786. }
  1787. }
  1788. }
  1789. }