华恒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.

998 lines
40 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. namespace ICSSoft.Frame.APP
  26. {
  27. public partial class FormICSMONew : DevExpress.XtraEditors.XtraForm
  28. {
  29. private string sqltxt = "";
  30. private string sqlconn = "";
  31. String guid = AppConfig.GetGuid();
  32. private DataTable dataSource = null;
  33. private DataTable body = null;
  34. private DataSet ds = new DataSet();
  35. #region 构造函数
  36. public FormICSMONew()
  37. {
  38. InitializeComponent();
  39. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  40. this.WindowState = FormWindowState.Maximized;
  41. foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns)
  42. {
  43. col.OptionsColumn.AllowEdit = col.Name == colSerial.Name;
  44. // col.OptionsColumn.ReadOnly = true;
  45. }
  46. }
  47. #endregion
  48. #region 操作权限
  49. public DataTable RightOfExute()
  50. {
  51. DataTable rData = new DataTable();
  52. rData.Columns.Add("BtnName");
  53. rData.Columns.Add("ActionName");
  54. //查看权限(必须有)
  55. DataRow seeRow = rData.NewRow();
  56. seeRow["BtnName"] = "see";
  57. seeRow["ActionName"] = "查看";
  58. rData.Rows.Add(seeRow);
  59. List<Control> ControlList = new List<Control>();
  60. //ControlList.Add(btnCreate);
  61. //ControlList.Add(btnModify);
  62. //ControlList.Add(btnDel);
  63. ControlList.Add(btnCancelAll);
  64. ControlList.Add(btnRefresh);
  65. ControlList.Add(btnExit);
  66. ControlList.Add(btnGetInfo);
  67. ControlList.Add(btnOutPut);
  68. foreach (Control ctr in ControlList)
  69. {
  70. if (ctr.GetType() == typeof(SimpleButton))
  71. {
  72. DataRow dr = rData.NewRow();
  73. dr["BtnName"] = ctr.Name;
  74. dr["ActionName"] = ctr.Text;
  75. rData.Rows.Add(dr);
  76. }
  77. }
  78. rData.AcceptChanges();
  79. return rData;
  80. }
  81. public DataTable RightOfData()// 数据权限
  82. {
  83. DataTable rData = new DataTable();
  84. rData.Columns.Add("BodyName");
  85. rData.Columns.Add("ControlName");
  86. rData.Columns.Add("ControlCaption");
  87. rData.AcceptChanges();
  88. return rData;
  89. }
  90. #endregion
  91. #region 退出
  92. private void btnClose_Click(object sender, EventArgs e)
  93. {
  94. AppConfig.CloseFormShow(this.Text);
  95. this.Close();
  96. }
  97. private void btnExit_Click(object sender, EventArgs e)
  98. {
  99. AppConfig.CloseFormShow(this.Text);
  100. this.Close();
  101. }
  102. #endregion
  103. #region 移动窗体
  104. private const int WM_NCHITTEST = 0x84;
  105. private const int HTCLIENT = 0x1;
  106. private const int HTCAPTION = 0x2;
  107. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  108. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  109. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  110. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  111. //重写窗体,使窗体可以不通过自带标题栏实现移动
  112. protected override void WndProc(ref Message m)
  113. {
  114. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  115. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  116. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  117. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  118. switch (m.Msg)
  119. {
  120. case WM_NCHITTEST:
  121. base.WndProc(ref m);
  122. if ((int)m.Result == HTCLIENT)
  123. m.Result = (IntPtr)HTCAPTION;
  124. return;
  125. }
  126. //拦截双击标题栏、移动窗体的系统消息
  127. if (m.Msg != 0xA3)
  128. {
  129. base.WndProc(ref m);
  130. }
  131. }
  132. #endregion
  133. #region 列表
  134. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  135. {
  136. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  137. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  138. }
  139. #endregion
  140. #region 过滤
  141. private string tempTableName = "";
  142. private void btnFilter_Click(object sender, EventArgs e)
  143. {
  144. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  145. filter.OldTempTableName = tempTableName;
  146. if (filter.ShowDialog() == DialogResult.OK)
  147. {
  148. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  149. try
  150. {
  151. _wait.Show();
  152. ds.Reset();
  153. dataSource = null;
  154. body = null;
  155. tempTableName = filter.NewTempTableName;
  156. sqltxt = filter.SqlText;
  157. sqlconn = filter.FilterConnectString;
  158. dataSource = filter.FilterData.Tables[0].Copy();
  159. dataSource.TableName = "Hand";
  160. ds.Tables.Add(dataSource);
  161. body = ICSMOBLL.GetMOBOM(sqltxt).Copy();
  162. body.TableName = "Body";
  163. ds.Tables.Add(body);
  164. 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"] });
  165. ds.Relations.Add(dr);
  166. grdDetail.DataSource = ds.Tables["Hand"];
  167. grvDetail.BestFitColumns();
  168. rptPage.RecordNum = dataSource.Rows.Count;
  169. rptPage.PageSize = 499;
  170. rptPage.PageIndex = 1;
  171. rptPage.ReLoad();
  172. rptPage.PageSize = 500;
  173. rptPage.PageIndex = 1;
  174. //rptPage.ReLoad();
  175. _wait.Close();
  176. }
  177. catch (Exception ex)
  178. {
  179. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  180. _wait.Close();
  181. }
  182. }
  183. }
  184. #endregion
  185. #region 绑定数据源
  186. private void btnConfig_Click(object sender, EventArgs e)
  187. {
  188. if (AppConfig.UserCode.ToLower() != "demo")
  189. {
  190. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  191. return;
  192. }
  193. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  194. fdata.ShowDialog();
  195. }
  196. #endregion
  197. #region 分页
  198. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  199. {
  200. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  201. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  202. grdDetail.DataSource = data;
  203. }
  204. #endregion
  205. #region 过滤方法
  206. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  207. {
  208. AppConfig.DropTemTable(tempTableName);
  209. }
  210. #endregion
  211. #region 全选
  212. private void btnSelectAll_Click(object sender, EventArgs e)
  213. {
  214. grvDetail.PostEditor();
  215. this.Validate();
  216. for (int i = 0; i < grvDetail.RowCount; i++)
  217. {
  218. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  219. }
  220. }
  221. #endregion
  222. #region 全消
  223. private void btnCancelAll_Click(object sender, EventArgs e)
  224. {
  225. grvDetail.PostEditor();
  226. this.Validate();
  227. for (int i = 0; i < grvDetail.RowCount; i++)
  228. {
  229. grvDetail.SetRowCellValue(i, colisSelect, "");
  230. }
  231. }
  232. #endregion
  233. #region 双击
  234. private void grvDetail_DoubleClick(object sender, EventArgs e)
  235. {
  236. if (grvDetail.FocusedRowHandle < 0)
  237. {
  238. return;
  239. }
  240. if (grvDetail.FocusedColumn == colisSelect)
  241. {
  242. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  243. {
  244. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  245. }
  246. else
  247. {
  248. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  249. }
  250. }
  251. }
  252. #endregion
  253. #region 导出
  254. private void btnOutPut_Click(object sender, EventArgs e)
  255. {
  256. try
  257. {
  258. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  259. foe.ShowDialog();
  260. }
  261. catch (Exception ex)
  262. {
  263. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  264. }
  265. //SimpleButton btntemp = (SimpleButton)sender;
  266. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  267. //{
  268. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  269. // return;
  270. //}
  271. //FormOutExcel foe = new FormOutExcel();
  272. //if (foe.ShowDialog() == DialogResult.OK)
  273. //{
  274. // try
  275. // {
  276. // string outtype = foe._OutType;
  277. // string exceltype = foe._ExcelType;
  278. // string filename = foe._FileName;
  279. // string url = foe._Url;
  280. // string sheetname = foe._SheetName;
  281. // if (outtype.ToLower() == "excel")
  282. // {
  283. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  284. // op.SheetName = sheetname;
  285. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  286. // }
  287. // else
  288. // {
  289. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  290. // }
  291. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  292. // }
  293. // catch (Exception ex)
  294. // {
  295. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  296. // }
  297. //}
  298. }
  299. #endregion
  300. #region 刷新
  301. private void btnRefresh_Click(object sender, EventArgs e)
  302. {
  303. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  304. try
  305. {
  306. _wait.Show();
  307. ds.Reset();
  308. dataSource = null;
  309. body = null;
  310. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  311. filter.OldTempTableName = tempTableName;
  312. //tempTableName = filter.NewTempTableName;
  313. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  314. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0].Copy();
  315. dataSource.TableName = "Hand";
  316. ds.Tables.Add(dataSource);
  317. body = ICSMOBLL.GetMOBOM(sqltxt).Copy();
  318. body.TableName = "Body";
  319. ds.Tables.Add(body);
  320. 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"] });
  321. ds.Relations.Add(dr);
  322. grdDetail.DataSource = ds.Tables["Hand"];
  323. grvDetail.BestFitColumns();
  324. rptPage.RecordNum = dataSource.Rows.Count;
  325. rptPage.PageIndex = 1;
  326. //rptPage.ReLoad();
  327. _wait.Close();
  328. }
  329. catch (Exception ex)
  330. {
  331. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  332. _wait.Close();
  333. }
  334. }
  335. #endregion
  336. //#region 新增
  337. //private void btnCreate_Click(object sender, EventArgs e)
  338. //{
  339. // SimpleButton btntemp = (SimpleButton)sender;
  340. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  341. // {
  342. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  343. // return;
  344. // }
  345. // FormICSMOAdd add = new FormICSMOAdd();
  346. // add.ShowDialog();
  347. // btnRefresh_Click(null, null);
  348. //}
  349. //#endregion
  350. //#region 修改
  351. //private void btnModify_Click(object sender, EventArgs e)
  352. //{
  353. // SimpleButton btntemp = (SimpleButton)sender;
  354. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  355. // {
  356. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  357. // return;
  358. // }
  359. // int count = 0;
  360. // for (int i = 0; i < grvDetail.RowCount; i++)
  361. // {
  362. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  363. // {
  364. // count++;
  365. // }
  366. // }
  367. // if (count != 1)
  368. // {
  369. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  370. // return;
  371. // }
  372. // try
  373. // {
  374. // string moid;
  375. // for (int i = 0; i < grvDetail.RowCount; i++)
  376. // {
  377. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  378. // {
  379. // moid = grvDetail.GetRowCellValue(i, colID).ToString();
  380. // FormICSMOAdd add = new FormICSMOAdd(moid);
  381. // add.ShowDialog();
  382. // }
  383. // }
  384. // btnRefresh_Click(null, null);
  385. // }
  386. // catch (Exception ex)
  387. // {
  388. // //throw ex;
  389. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  390. // }
  391. //}
  392. //#endregion
  393. //#region 删除
  394. //private void btnDel_Click(object sender, EventArgs e)
  395. //{
  396. // SimpleButton btntemp = (SimpleButton)sender;
  397. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  398. // {
  399. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  400. // return;
  401. // }
  402. // List<string> moidList = new List<string>();
  403. // for (int i = 0; i < grvDetail.RowCount; i++)
  404. // {
  405. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  406. // {
  407. // moidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  408. // }
  409. // }
  410. // if (moidList.Count == 0 || moidList == null)
  411. // {
  412. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  413. // return;
  414. // }
  415. // if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除工单吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  416. // {
  417. // btnCancelAll_Click(sender, e);
  418. // return;
  419. // }
  420. // try
  421. // {
  422. // ICSMOBLL.deleteInfo(moidList, AppConfig.AppConnectString);
  423. // ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  424. // }
  425. // catch (Exception ex)
  426. // {
  427. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  428. // }
  429. // btnRefresh_Click(null, null);
  430. //}
  431. //#endregion
  432. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  433. {
  434. AppConfig.DropTemTable(tempTableName);
  435. }
  436. private void FormICSMO_Load(object sender, EventArgs e)
  437. {
  438. btnFilter_Click(sender, e);
  439. }
  440. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  441. {
  442. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  443. {
  444. //e.DisplayText = FormatHelper.
  445. e.CellValue = "cccc";
  446. }
  447. }
  448. //生成序列号
  449. private void newRcard_Click(object sender, EventArgs e)
  450. {
  451. //SimpleButton btntemp = (SimpleButton)sender;
  452. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  453. //{
  454. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  455. // return;
  456. //}
  457. //int count = 0;
  458. //for (int i = 0; i < grvDetail.RowCount; i++)
  459. //{
  460. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  461. // {
  462. // count++;
  463. // }
  464. //}
  465. //if (count != 1)
  466. //{
  467. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  468. // return;
  469. //}
  470. //try
  471. //{
  472. // string moID;
  473. // string moCode;
  474. // decimal qty = 0.00m;
  475. // for (int i = 0; i < grvDetail.RowCount; i++)
  476. // {
  477. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  478. // {
  479. // moID = grvDetail.GetRowCellValue(i, colID).ToString();
  480. // moCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  481. // qty = decimal.Parse(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString());
  482. // FormICSMO2RCARDAdd rec = new FormICSMO2RCARDAdd(moID, moCode, qty);
  483. // rec.ShowDialog();
  484. // }
  485. // }
  486. // btnRefresh_Click(null, null);
  487. //}
  488. //catch (Exception ex)
  489. //{
  490. // //throw ex;
  491. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  492. //}
  493. }
  494. private void repSerialButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  495. {
  496. try
  497. {
  498. string moID;
  499. string moCode;
  500. decimal qty = 0.00m;
  501. moID = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString();
  502. moCode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colMOCODE).ToString();
  503. qty = Convert.ToDecimal(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colMOPLANQTY).ToString());
  504. FormICSMO2RCARDAdd rec = new FormICSMO2RCARDAdd(moID, moCode, qty);
  505. rec.ShowDialog();
  506. btnRefresh_Click(null, null);
  507. }
  508. catch (Exception ex)
  509. {
  510. throw ex;
  511. }
  512. }
  513. //下发
  514. //private void txtsend_Click(object sender, EventArgs e)
  515. //{
  516. // SimpleButton btntemp = (SimpleButton)sender;
  517. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  518. // {
  519. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  520. // return;
  521. // }
  522. // int count = 0;
  523. // for (int i = 0; i < grvDetail.RowCount; i++)
  524. // {
  525. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  526. // {
  527. // count++;
  528. // }
  529. // }
  530. // if (count != 1)
  531. // {
  532. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  533. // return;
  534. // }
  535. // try
  536. // {
  537. // string mocode="";
  538. // string state = "";
  539. // for (int i = 0; i < grvDetail.RowCount; i++)
  540. // {
  541. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  542. // {
  543. // mocode = grvDetail.GetRowCellValue(i,colMOCODE).ToString();
  544. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  545. // }
  546. // }
  547. // //判断是否是初始状态
  548. // if (state.Equals("初始"))
  549. // {
  550. // //判断是否在工单首检记录表中
  551. // if (ICSMOBLL.isInFirstCheck(mocode, AppConfig.AppConnectString))
  552. // {
  553. // //判断(最近的时间)是否合格
  554. // if (ICSMOBLL.isQualified(mocode, AppConfig.AppConnectString))
  555. // {
  556. // ICSMOBLL.Send(mocode,AppConfig.AppConnectString);
  557. // ICSBaseSimpleCode.AppshowMessageBox("下发成功");
  558. // }
  559. // else
  560. // {
  561. // ICSBaseSimpleCode.AppshowMessageBox("不合格,不能下发");
  562. // return;
  563. // }
  564. // }
  565. // else
  566. // {
  567. // ICSBaseSimpleCode.AppshowMessageBox("不存在工单首检记录中");
  568. // return;
  569. // }
  570. // }
  571. // else
  572. // {
  573. // ICSBaseSimpleCode.AppshowMessageBox("不是初始状态,不能下发");
  574. // return;
  575. // }
  576. // btnRefresh_Click(null, null);
  577. // }
  578. // catch (Exception ex)
  579. // {
  580. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  581. // }
  582. //}
  583. ////取消下发
  584. //private void txtcancelSend_Click(object sender, EventArgs e)
  585. //{
  586. // SimpleButton btntemp = (SimpleButton)sender;
  587. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  588. // {
  589. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  590. // return;
  591. // }
  592. // int count = 0;
  593. // for (int i = 0; i < grvDetail.RowCount; i++)
  594. // {
  595. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  596. // {
  597. // count++;
  598. // }
  599. // }
  600. // if (count != 1)
  601. // {
  602. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  603. // return;
  604. // }
  605. // try
  606. // {
  607. // string mocode = "";
  608. // string state = "";
  609. // for (int i = 0; i < grvDetail.RowCount; i++)
  610. // {
  611. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  612. // {
  613. // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  614. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  615. // }
  616. // }
  617. // //判断是否是下发状态
  618. // if (state.Equals("下发"))
  619. // {
  620. // ICSMOBLL.cancelSend(mocode,AppConfig.AppConnectString);
  621. // ICSBaseSimpleCode.AppshowMessageBox("取消下发成功");
  622. // }
  623. // else
  624. // {
  625. // ICSBaseSimpleCode.AppshowMessageBox("不是下发状态,不能取消下发");
  626. // return;
  627. // }
  628. // btnRefresh_Click(null, null);
  629. // }
  630. // catch (Exception ex)
  631. // {
  632. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  633. // }
  634. //}
  635. ////暂停
  636. //private void txtstop_Click(object sender, EventArgs e)
  637. //{
  638. // SimpleButton btntemp = (SimpleButton)sender;
  639. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  640. // {
  641. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  642. // return;
  643. // }
  644. // int count = 0;
  645. // for (int i = 0; i < grvDetail.RowCount; i++)
  646. // {
  647. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  648. // {
  649. // count++;
  650. // }
  651. // }
  652. // if (count != 1)
  653. // {
  654. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  655. // return;
  656. // }
  657. // try
  658. // {
  659. // string mocode = "";
  660. // string state = "";
  661. // for (int i = 0; i < grvDetail.RowCount; i++)
  662. // {
  663. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  664. // {
  665. // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  666. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  667. // }
  668. // }
  669. // //判断是否是生产中状态
  670. // if (state.Equals("生产中"))
  671. // {
  672. // ICSMOBLL.stop(mocode, AppConfig.AppConnectString);
  673. // ICSBaseSimpleCode.AppshowMessageBox("暂停成功");
  674. // }
  675. // else
  676. // {
  677. // ICSBaseSimpleCode.AppshowMessageBox("不是生产中状态,不能暂停");
  678. // return;
  679. // }
  680. // btnRefresh_Click(null, null);
  681. // }
  682. // catch (Exception ex)
  683. // {
  684. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  685. // }
  686. //}
  687. ////取消暂停
  688. //private void txtcancelStop_Click(object sender, EventArgs e)
  689. //{
  690. // SimpleButton btntemp = (SimpleButton)sender;
  691. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  692. // {
  693. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  694. // return;
  695. // }
  696. // int count = 0;
  697. // for (int i = 0; i < grvDetail.RowCount; i++)
  698. // {
  699. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  700. // {
  701. // count++;
  702. // }
  703. // }
  704. // if (count != 1)
  705. // {
  706. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  707. // return;
  708. // }
  709. // try
  710. // {
  711. // string mocode = "";
  712. // string state = "";
  713. // for (int i = 0; i < grvDetail.RowCount; i++)
  714. // {
  715. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  716. // {
  717. // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  718. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  719. // }
  720. // }
  721. // //判断是否是暂停状态
  722. // if (state.Equals("暂停"))
  723. // {
  724. // ICSMOBLL.cancelStop(mocode, AppConfig.AppConnectString);
  725. // ICSBaseSimpleCode.AppshowMessageBox("取消暂停成功");
  726. // }
  727. // else
  728. // {
  729. // ICSBaseSimpleCode.AppshowMessageBox("不是暂停状态,不能取消暂停");
  730. // return;
  731. // }
  732. // btnRefresh_Click(null, null);
  733. // }
  734. // catch (Exception ex)
  735. // {
  736. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  737. // }
  738. //}
  739. ////关单
  740. //private void txtcloseDan_Click(object sender, EventArgs e)
  741. //{
  742. // SimpleButton btntemp = (SimpleButton)sender;
  743. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  744. // {
  745. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  746. // return;
  747. // }
  748. // int count = 0;
  749. // for (int i = 0; i < grvDetail.RowCount; i++)
  750. // {
  751. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  752. // {
  753. // count++;
  754. // }
  755. // }
  756. // if (count != 1)
  757. // {
  758. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  759. // return;
  760. // }
  761. // try
  762. // {
  763. // string mocode = "";
  764. // string state = "";
  765. // for (int i = 0; i < grvDetail.RowCount; i++)
  766. // {
  767. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  768. // {
  769. // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  770. // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString();
  771. // }
  772. // }
  773. // //判断是否是关单状态
  774. // if (!(state.Equals("关单")))
  775. // {
  776. // ICSMOBLL.closeDan(mocode, AppConfig.AppConnectString);
  777. // ICSBaseSimpleCode.AppshowMessageBox("关单成功");
  778. // }
  779. // else
  780. // {
  781. // ICSBaseSimpleCode.AppshowMessageBox("已经是关单状态");
  782. // return;
  783. // }
  784. // btnRefresh_Click(null, null);
  785. // }
  786. // catch (Exception ex)
  787. // {
  788. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  789. // }
  790. //}
  791. //同步
  792. private void btnGetInfo_Click(object sender, EventArgs e)
  793. {
  794. SimpleButton btntemp = (SimpleButton)sender;
  795. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  796. {
  797. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  798. return;
  799. }
  800. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在同步请稍等...");
  801. try
  802. {
  803. string sql = @"delete ICSMO
  804. where MOCODE in
  805. (SELECT a.MoCode
  806. FROM {1}.dbo.mom_order a
  807. INNER JOIN {1}.dbo.mom_orderdetail b ON a.MoId = b.MoId
  808. LEFT JOIN [ICSMES_WLSys].[dbo].ICSMO d ON b.MoDId = d.EATTRIBUTE1
  809. and isnull(a.ModifyTime,'') = isnull(d.EATTRIBUTE2,'')
  810. WHERE (b.RelsUser IS NOT NULL OR b.RelsUser <> '')
  811. AND b.CloseUser IS NULL AND ISNULL(b.QualifiedInQty,0) = 0
  812. AND d.EATTRIBUTE1 IS NULL and a.CreateDate >= '2018-01-01 00:00:00.000')
  813. delete ICSMO
  814. where MOCODE in
  815. (select b.MOCODE from {1}.dbo.mom_order a
  816. right join ICSMO b on a.MoCode = b.MOCODE where a.MoCode is null)
  817. delete ICSMOBOM
  818. where MOBITEMECN in
  819. (SELECT c.AllocateId
  820. FROM {1}.dbo.mom_order a
  821. INNER JOIN {1}.dbo.mom_orderdetail b ON a.MoId = b.MoId
  822. INNER JOIN {1}.dbo.mom_moallocate c ON b.MoDId = c.MoDId
  823. LEFT JOIN [dbo].ICSMO g
  824. ON b.MoDId = g.EATTRIBUTE1 and isnull(a.ModifyTime,'') = isnull(g.EATTRIBUTE2,'')
  825. LEFT JOIN [dbo].ICSMOBOM bom ON c.AllocateId = bom.MOBITEMECN
  826. WHERE (b.RelsUser IS NOT NULL OR b.RelsUser <> '')
  827. AND b.CloseUser IS NULL AND ISNULL(b.QualifiedInQty,0) = 0
  828. AND bom.MOBITEMECN IS NULL and a.CreateDate >= '2018-01-01 00:00:00.000')
  829. delete ICSMOBOM
  830. where MOBITEMECN in
  831. (select b.MOBITEMECN from {1}.dbo.mom_moallocate a
  832. right join ICSMOBOM b on a.AllocateId = b.MOBITEMECN where a.AllocateId is null)
  833. INSERT INTO [ICSMES_WLSys].[dbo].[ICSMO] (
  834. [ID],[MOCODE],[MOMEMO],[MOTYPE],[MODESC],[MOBIOSVER]
  835. ,[MOPCBAVER],[MOPLANQTY],[MOINPUTQTY],[MOSCRAPQTY],[MOACTQTY]
  836. ,[MOPLANSTARTDATE],[MOPLANENDDATE],[MOACTSTARTDATE],[MOACTENDDATE]
  837. ,[FACTORY],[CUSCODE],[CUSNAME],[CUSORDERNO] ,[CUSITEMCODE],[ORDERNO]
  838. ,[ORDERSEQ],[MOUSER],[MODOWNDATE],[MOSTATUS],[MOVER],[ISCONINPUT]
  839. ,[ISBOMPASS],[IDMERGERULE],[WorkPoint],[MUSER],[MUSERName]
  840. ,[MTIME],[EATTRIBUTE1],[ITEMCODE],[MORELEASETIME],[MOPENDINGCAUSE]
  841. ,[MOIMPORTTIME],[OFFMOQTY],[ISCOMPARESOFT],[RMABILLCODE],[MOSEQ]
  842. ,[REMOCODE],[REMOITEMCODE],[REMOITEMDESC],[REMOLOTNO],[REMOENABLED]
  843. ,[MOBOM],[MOOP],[ITEMDESC],[MOPLANENDTIME],[MOPLANLINE],[BackflushStorage]
  844. ,[WarningStopLine],[MORemark],[EATTRIBUTE2],[EATTRIBUTE3],[EATTRIBUTE4])
  845. SELECT NEWID(), a.MoCode,'','','','','',b.Qty,'0','0','0',
  846. c.StartDate,c.DueDate,c.StartDate,c.DueDate,'',b.CustCode,cus.cCusName,b.OrderCode,cusInv.cCusInvCode,
  847. b.OrderCode,ISNULL(so.iRowNo,''),'',a.CreateDate,'','','','','0.00','{0}',
  848. '','',GETDATE(),b.MoDId,b.InvCode,
  849. NULL,'',GETDATE(),'0.00','0','',b.SortSeq,'','','','','',b.PartId,'','',NULL,
  850. '','','',ISNULL(b.Remark,''),CONVERT(NVARCHAR(50),a.ModifyTime,21),NULL,NULL
  851. FROM {1}.dbo.mom_order a
  852. INNER JOIN {1}.dbo.mom_orderdetail b ON a.MoId = b.MoId
  853. INNER JOIN {1}.dbo.mom_morder c ON b.MoDId = c.MoDId
  854. LEFT JOIN {1}.dbo.Customer cus ON b.CustCode = cus.cCusCode
  855. LEFT JOIN {1}.dbo.SO_SODetails so ON b.OrderDId = so.iSOsID
  856. LEFT JOIN {1}.dbo.CusInvContrapose cusInv
  857. ON cusinv.cCusCode = b.CustCode AND b.InvCode = cusInv.cInvCode
  858. LEFT JOIN [ICSMES_WLSys].[dbo].ICSMO d
  859. ON b.MoDId = d.EATTRIBUTE1 and isnull(a.ModifyTime,'') = isnull(d.EATTRIBUTE2,'')
  860. WHERE (b.RelsUser IS NOT NULL OR b.RelsUser <> '')
  861. AND b.CloseUser IS NULL AND ISNULL(b.QualifiedInQty,0) = 0
  862. AND d.EATTRIBUTE1 IS NULL and a.CreateDate >= '2018-01-01 00:00:00.000'
  863. INSERT INTO [ICSMES_WLSys].[dbo].ICSMOBOM
  864. SELECT a.MoCode,b.InvCode,b.SortSeq,c.InvCode,c.AllocateId,d.cInvName,d.cInvStd,
  865. '1','',GETDATE(),DATEADD(YEAR,100,GETDATE()),BaseQtyN,'','',
  866. '','','',GETDATE(),'{0}','',
  867. unit.cComUnitName,CONVERT(INT,SUBSTRING(c.Ufts,0,18)),f.Version,c.SortSeq,'',''
  868. FROM {1}.dbo.mom_order a
  869. INNER JOIN {1}.dbo.mom_orderdetail b ON a.MoId = b.MoId
  870. INNER JOIN {1}.dbo.mom_moallocate c ON b.MoDId = c.MoDId
  871. INNER JOIN {1}.dbo.Inventory d ON c.InvCode = d.cInvCode
  872. LEFT JOIN {1}.dbo.bom_parent e ON b.BomId = e.ParentId
  873. LEFT JOIN {1}.dbo.bom_bom f ON e.BomId = f.BomId
  874. LEFT JOIN [dbo].ICSMO g
  875. ON b.MoDId = g.EATTRIBUTE1 and isnull(a.ModifyTime,'') = isnull(g.EATTRIBUTE2,'')
  876. LEFT JOIN [dbo].ICSMOBOM bom ON c.AllocateId = bom.MOBITEMECN
  877. LEFT JOIN {1}.dbo.ComputationUnit unit
  878. ON d.cComUnitCode = unit.cComunitCode
  879. WHERE (b.RelsUser IS NOT NULL OR b.RelsUser <> '')
  880. AND b.CloseUser IS NULL AND ISNULL(b.QualifiedInQty,0) = 0
  881. AND bom.MOBITEMECN IS NULL and a.CreateDate >= '2018-01-01 00:00:00.000'
  882. UPDATE a SET a.MOBITEMQTY = b.BaseQtyN
  883. FROM dbo.ICSMOBOM a
  884. INNER JOIN {1}.dbo.mom_moallocate b
  885. ON a.MOBITEMECN = b.AllocateId
  886. WHERE CONVERT(INT,SUBSTRING(b.Ufts,0,18)) <> a.OPCODE";
  887. sql = string.Format(sql, AppConfig.WorkPointCode, ICSBaseSimpleCode.GetWorkPointErpData());
  888. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  889. _wait.Close();
  890. ICSBaseSimpleCode.AppshowMessageBox("同步成功");
  891. }
  892. catch (Exception ex)
  893. {
  894. _wait.Close();
  895. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  896. }
  897. }
  898. }
  899. }