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

673 lines
28 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.Linq;
  6. using System.Linq;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.BandedGrid;
  12. using DevExpress.XtraGrid.Columns;
  13. using DevExpress.XtraGrid;
  14. using System.IO;
  15. using System.Threading;
  16. using ICSSoft.Base.Language.Tool;
  17. using ICSSoft.Base.Config.AppConfig;
  18. using ICSSoft.Base.UserControl.MessageControl;
  19. using ICSSoft.Base.Config.DBHelper;
  20. using ICSSoft.Base.Report.Filter;
  21. using ICSSoft.Base.UserControl.FormControl;
  22. using ICSSoft.Base.Report.GridReport;
  23. using ICSSoft.Base.ReferForm.AppReferForm;
  24. using ICSSoft.Frame.Data.BLL;
  25. using ICSSoft.Frame.Data.Entity;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSROUTE : DevExpress.XtraEditors.XtraForm
  29. {
  30. private string sqltxt = "";
  31. private string sqlconn = "";
  32. String guid = AppConfig.GetGuid();
  33. private DataTable dataSource = null;
  34. #region 构造函数
  35. public FormICSROUTE()
  36. {
  37. InitializeComponent();
  38. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  39. this.WindowState = FormWindowState.Maximized;
  40. }
  41. #endregion
  42. #region 操作权限
  43. public DataTable RightOfExute()
  44. {
  45. DataTable rData = new DataTable();
  46. rData.Columns.Add("BtnName");
  47. rData.Columns.Add("ActionName");
  48. //查看权限(必须有)
  49. DataRow seeRow = rData.NewRow();
  50. seeRow["BtnName"] = "see";
  51. seeRow["ActionName"] = "查看";
  52. rData.Rows.Add(seeRow);
  53. List<Control> ControlList = new List<Control>();
  54. ControlList.Add(btnCreate);
  55. ControlList.Add(btnOutPut);
  56. ControlList.Add(btnModify);
  57. ControlList.Add(btnDel);
  58. ControlList.Add(btnTBLOP);
  59. foreach (Control ctr in ControlList)
  60. {
  61. if (ctr.GetType() == typeof(SimpleButton))
  62. {
  63. if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name || ctr.Name == btnClose.Name)
  64. continue;
  65. DataRow dr = rData.NewRow();
  66. dr["BtnName"] = ctr.Name;
  67. dr["ActionName"] = ctr.Text;
  68. rData.Rows.Add(dr);
  69. }
  70. }
  71. rData.AcceptChanges();
  72. return rData;
  73. }
  74. public DataTable RightOfData()// 数据权限
  75. {
  76. DataTable rData = new DataTable();
  77. rData.Columns.Add("BodyName");
  78. rData.Columns.Add("ControlName");
  79. rData.Columns.Add("ControlCaption");
  80. rData.AcceptChanges();
  81. return rData;
  82. }
  83. #endregion
  84. #region 退出
  85. private void btnClose_Click(object sender, EventArgs e)
  86. {
  87. AppConfig.CloseFormShow(this.Text);
  88. this.Close();
  89. }
  90. private void btnExit_Click(object sender, EventArgs e)
  91. {
  92. AppConfig.CloseFormShow(this.Text);
  93. this.Close();
  94. }
  95. #endregion
  96. #region 移动窗体
  97. private const int WM_NCHITTEST = 0x84;
  98. private const int HTCLIENT = 0x1;
  99. private const int HTCAPTION = 0x2;
  100. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  101. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  102. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  103. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  104. //重写窗体,使窗体可以不通过自带标题栏实现移动
  105. protected override void WndProc(ref Message m)
  106. {
  107. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  108. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  109. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  110. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  111. switch (m.Msg)
  112. {
  113. case WM_NCHITTEST:
  114. base.WndProc(ref m);
  115. if ((int)m.Result == HTCLIENT)
  116. m.Result = (IntPtr)HTCAPTION;
  117. return;
  118. }
  119. //拦截双击标题栏、移动窗体的系统消息
  120. if (m.Msg != 0xA3)
  121. {
  122. base.WndProc(ref m);
  123. }
  124. }
  125. #endregion
  126. #region 列表
  127. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  128. {
  129. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  130. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  131. }
  132. #endregion
  133. #region 过滤
  134. private string tempTableName = "";
  135. private void btnFilter_Click(object sender, EventArgs e)
  136. {
  137. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  138. filter.OldTempTableName = tempTableName;
  139. if (filter.ShowDialog() == DialogResult.OK)
  140. {
  141. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  142. try
  143. {
  144. _wait.Show();
  145. tempTableName = filter.NewTempTableName;
  146. sqltxt = filter.SqlText;
  147. sqlconn = filter.FilterConnectString;
  148. dataSource = filter.FilterData.Tables[0];
  149. grdDetail.DataSource = dataSource;
  150. grvDetail.BestFitColumns();
  151. rptPage.RecordNum = dataSource.Rows.Count;
  152. rptPage.PageSize = 499;
  153. rptPage.PageIndex = 1;
  154. rptPage.ReLoad();
  155. rptPage.PageSize = 500;
  156. rptPage.PageIndex = 1;
  157. rptPage.ReLoad();
  158. _wait.Close();
  159. }
  160. catch (Exception ex)
  161. {
  162. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  163. _wait.Close();
  164. }
  165. }
  166. }
  167. #endregion
  168. #region 绑定数据源
  169. private void btnConfig_Click(object sender, EventArgs e)
  170. {
  171. if (AppConfig.UserCode.ToLower() != "demo")
  172. {
  173. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  174. return;
  175. }
  176. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  177. fdata.ShowDialog();
  178. }
  179. #endregion
  180. #region 分页
  181. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  182. {
  183. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  184. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  185. grdDetail.DataSource = data;
  186. }
  187. #endregion
  188. #region 过滤方法
  189. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  190. {
  191. AppConfig.DropTemTable(tempTableName);
  192. }
  193. #endregion
  194. #region 全选
  195. private void btnSelectAll_Click(object sender, EventArgs e)
  196. {
  197. grvDetail.PostEditor();
  198. this.Validate();
  199. for (int i = 0; i < grvDetail.RowCount; i++)
  200. {
  201. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  202. }
  203. }
  204. #endregion
  205. #region 全消
  206. private void btnCancelAll_Click(object sender, EventArgs e)
  207. {
  208. grvDetail.PostEditor();
  209. this.Validate();
  210. for (int i = 0; i < grvDetail.RowCount; i++)
  211. {
  212. grvDetail.SetRowCellValue(i, colisSelect, "");
  213. }
  214. }
  215. #endregion
  216. #region 双击
  217. private void grvDetail_DoubleClick(object sender, EventArgs e)
  218. {
  219. if (grvDetail.FocusedRowHandle < 0)
  220. {
  221. return;
  222. }
  223. if (grvDetail.FocusedColumn == colisSelect)
  224. {
  225. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  226. {
  227. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  228. }
  229. else
  230. {
  231. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  232. }
  233. }
  234. }
  235. #endregion
  236. #region 删除
  237. private void btnDel_Click(object sender, EventArgs e)
  238. {
  239. grvDetail.PostEditor();
  240. this.Validate();
  241. if (grvDetail.RowCount == 0)
  242. return;
  243. SimpleButton btntemp = (SimpleButton)sender;
  244. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  245. {
  246. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  247. }
  248. List<string> guidList = new List<string>();
  249. List<string> codeList = new List<string>();
  250. for (int i = 0; i < grvDetail.RowCount; i++)
  251. {
  252. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  253. {
  254. guidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  255. codeList.Add(grvDetail.GetRowCellValue(i, colROUTECODE).ToString());
  256. }
  257. }
  258. if (guidList.Count == 0)
  259. {
  260. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  261. return;
  262. }
  263. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该途程吗?途程删除后无法恢复,确定吗?") != DialogResult.OK)
  264. return;
  265. try
  266. {
  267. if (ICSROUTEBLL.isIncludingInICSROUTE2OP(guidList, AppConfig.AppConnectString))
  268. {
  269. ICSBaseSimpleCode.AppshowMessageBox("途程和工序的关系维护中已使用该途程,暂时无法删除");
  270. return;
  271. }
  272. if (ICSROUTEBLL.isIncludingInICSITEM2ROUTE(guidList, AppConfig.AppConnectString))
  273. {
  274. ICSBaseSimpleCode.AppshowMessageBox("产品和途程的关系维护中已使用该途程,暂时无法删除");
  275. return;
  276. }
  277. if (ICSROUTEBLL.isIncludingInICSITEMROUTE2OP(guidList, AppConfig.AppConnectString))
  278. {
  279. ICSBaseSimpleCode.AppshowMessageBox("产品、途程和工序的关系维护中已使用该途程,暂时无法删除");
  280. return;
  281. }
  282. else
  283. {
  284. ICSROUTEBLL.delete(guidList, codeList);
  285. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  286. }
  287. }
  288. catch (Exception ex)
  289. {
  290. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  291. }
  292. btnRefresh_Click(null, null);
  293. }
  294. #endregion
  295. #region 导出
  296. private void btnOutPut_Click(object sender, EventArgs e)
  297. {
  298. try
  299. {
  300. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  301. foe.ShowDialog();
  302. }
  303. catch (Exception ex)
  304. {
  305. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  306. }
  307. //FormOutExcel foe = new FormOutExcel();
  308. //if (foe.ShowDialog() == DialogResult.OK)
  309. //{
  310. // try
  311. // {
  312. // string outtype = foe._OutType;
  313. // string exceltype = foe._ExcelType;
  314. // string filename = foe._FileName;
  315. // string url = foe._Url;
  316. // string sheetname = foe._SheetName;
  317. // if (outtype.ToLower() == "excel")
  318. // {
  319. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  320. // op.SheetName = sheetname;
  321. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  322. // }
  323. // else
  324. // {
  325. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  326. // }
  327. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  328. // }
  329. // catch (Exception ex)
  330. // {
  331. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  332. // }
  333. //}
  334. }
  335. #endregion
  336. #region 刷新
  337. private void btnRefresh_Click(object sender, EventArgs e)
  338. {
  339. if (sqlconn == null || sqlconn == "")
  340. {
  341. return;
  342. }
  343. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  344. try
  345. {
  346. _wait.Show();
  347. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  348. filter.OldTempTableName = tempTableName;
  349. //tempTableName = filter.NewTempTableName;
  350. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  351. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  352. grdDetail.DataSource = dataSource;
  353. grvDetail.BestFitColumns();
  354. rptPage.RecordNum = dataSource.Rows.Count;
  355. rptPage.PageIndex = 1;
  356. rptPage.ReLoad();
  357. _wait.Close();
  358. }
  359. catch (Exception ex)
  360. {
  361. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  362. _wait.Close();
  363. }
  364. }
  365. #endregion
  366. #region 新增
  367. private void btnCreate_Click(object sender, EventArgs e)
  368. {
  369. SimpleButton btntemp = (SimpleButton)sender;
  370. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  371. {
  372. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  373. return;
  374. }
  375. FormICSROUTAdd add = new FormICSROUTAdd();
  376. add.ShowDialog();
  377. btnRefresh_Click(null, null);
  378. }
  379. #endregion
  380. #region 修改
  381. private void btnModify_Click(object sender, EventArgs e)
  382. {
  383. String id = "";
  384. SimpleButton btntemp = (SimpleButton)sender;
  385. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  386. {
  387. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  388. }
  389. List<string> editList = new List<string>();
  390. List<string> guidList1 = new List<string>();
  391. for (int i = 0; i < grvDetail.RowCount; i++)
  392. {
  393. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  394. {
  395. id = grvDetail.GetRowCellValue(i, colID).ToString();
  396. editList.Add(id);
  397. }
  398. }
  399. if (editList.Count != 1)
  400. {
  401. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  402. return;
  403. }
  404. try
  405. {
  406. ICSROUTEBLL.select(id, AppConfig.AppConnectString);
  407. FormICSROUTAdd add = new FormICSROUTAdd(id);
  408. add.ShowDialog();
  409. btnRefresh_Click(null, null);
  410. }
  411. catch (Exception ex)
  412. {
  413. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  414. }
  415. }
  416. #endregion
  417. //private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  418. //{
  419. // AppConfig.DropTemTable(tempTableName);
  420. //}
  421. #region 窗体加载
  422. private void FormTBLROUTE_Load(object sender, EventArgs e)
  423. {
  424. btnFilter_Click(sender, e);
  425. }
  426. #endregion
  427. #region 关联工序
  428. private void btnTBLOP_Click(object sender, EventArgs e)
  429. {
  430. String id = "";
  431. SimpleButton btntemp = (SimpleButton)sender;
  432. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  433. {
  434. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  435. }
  436. List<string> editList = new List<string>();
  437. List<string> guidList1 = new List<string>();
  438. for (int i = 0; i < grvDetail.RowCount; i++)
  439. {
  440. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  441. {
  442. id = grvDetail.GetRowCellValue(i, colID).ToString();
  443. editList.Add(id);
  444. }
  445. }
  446. if (editList.Count != 1)
  447. {
  448. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  449. return;
  450. }
  451. try
  452. {
  453. FormTBLROUTE2OP TBLROUTE2OP = new FormTBLROUTE2OP(id);
  454. TBLROUTE2OP.ShowDialog();
  455. btnRefresh_Click(null, null);
  456. }
  457. catch (Exception ex)
  458. {
  459. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  460. }
  461. //btnRefresh_Click(null, null);
  462. }
  463. #endregion
  464. #region 导入模板下载
  465. private void btnImportMould_Click(object sender, EventArgs e)
  466. {
  467. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  468. _wait.Hide();
  469. string anjianExcelFileName = Environment.CommandLine.Substring(1, Environment.CommandLine.LastIndexOf("\\")) + "Output\\";
  470. try
  471. {
  472. _wait.Show();
  473. _wait.Caption = "模板下载中......";
  474. SaveFileDialog dlgSaveFileDialog = new SaveFileDialog(); //弹框提示保存
  475. dlgSaveFileDialog.InitialDirectory = anjianExcelFileName; //默认打开目录
  476. dlgSaveFileDialog.FilterIndex = 1;
  477. dlgSaveFileDialog.RestoreDirectory = true;
  478. dlgSaveFileDialog.FileName = "途程工序导入模板.xlsx"; //默认保存名称
  479. dlgSaveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  480. if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK)
  481. {
  482. string fileName = dlgSaveFileDialog.FileName; //获取弹出框选择或填写的文件名称
  483. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  484. colNameList.Add(new FormReadExcelUIModelColumns("途程代码", true));
  485. colNameList.Add(new FormReadExcelUIModelColumns("途程描述", true));
  486. colNameList.Add(new FormReadExcelUIModelColumns("途程类别", true));
  487. colNameList.Add(new FormReadExcelUIModelColumns("生效/失效", true));
  488. //colNameList.Add(new FormReadExcelUIModelColumns("生效日期", true));
  489. //colNameList.Add(new FormReadExcelUIModelColumns("失效日期", true));
  490. colNameList.Add(new FormReadExcelUIModelColumns("工序代码", true));
  491. colNameList.Add(new FormReadExcelUIModelColumns("工序次序", true));
  492. FileUtil.exportToExcelFile(fileName, colNameList);
  493. _wait.Close();
  494. ICSBaseSimpleCode.AppshowMessageBox("模板下载成功!");
  495. }
  496. _wait.Close();
  497. }
  498. catch (Exception ex)
  499. {
  500. _wait.Close();
  501. ICSBaseSimpleCode.AppshowMessageBox("模板下载失败:" + ex.Message);
  502. }
  503. }
  504. #endregion
  505. #region 导入
  506. private void btnImportData_Click(object sender, EventArgs e)
  507. {
  508. SimpleButton btntemp = (SimpleButton)sender;
  509. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  510. {
  511. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  512. return;
  513. }
  514. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  515. _wait.Hide();
  516. try
  517. {
  518. FormReadExcel fre = new FormReadExcel();
  519. if (fre.ShowDialog() != DialogResult.OK)
  520. {
  521. return;
  522. }
  523. DataTable dataSource = fre._excelData;
  524. if (dataSource == null)
  525. {
  526. throw new Exception("excel数据取得失败");
  527. }
  528. _wait.Show();
  529. _wait.Caption = "判断模版是否正确......";
  530. #region 判断模版是否正确
  531. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  532. colNameList.Add(new FormReadExcelUIModelColumns("途程代码", true));
  533. colNameList.Add(new FormReadExcelUIModelColumns("途程描述", true));
  534. colNameList.Add(new FormReadExcelUIModelColumns("途程类别", true));
  535. colNameList.Add(new FormReadExcelUIModelColumns("生效/失效", true));
  536. //colNameList.Add(new FormReadExcelUIModelColumns("生效日期", true));
  537. //colNameList.Add(new FormReadExcelUIModelColumns("失效日期", true));
  538. colNameList.Add(new FormReadExcelUIModelColumns("工序代码", true));
  539. colNameList.Add(new FormReadExcelUIModelColumns("工序次序", true));
  540. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  541. {
  542. if (!dataSource.Columns.Contains(columnsName.columnsName))
  543. {
  544. throw new Exception("模版不正确,缺少列" + columnsName.columnsName);
  545. }
  546. }
  547. #endregion
  548. _wait.Caption = "数据整理中......";
  549. List<ICSROUTE> RouteLists = new List<ICSROUTE>();
  550. List<ICSROUTE2OP> OPLists = new List<ICSROUTE2OP>();
  551. string ROUTECODE = "";
  552. string ID = "";
  553. foreach (DataRow dr in dataSource.Rows)
  554. {
  555. ///判断必输项目是否为空
  556. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  557. {
  558. if (string.IsNullOrWhiteSpace(dr[columnsName.columnsName].ToString()) == true && columnsName.NotNull == true)
  559. {
  560. throw new Exception("列" + columnsName.columnsName + "没有输入值");
  561. }
  562. }
  563. if (ROUTECODE != dr["途程代码"].ToString().Trim())
  564. {
  565. ID = AppConfig.GetGuid().ToString();
  566. ROUTECODE = dr["途程代码"].ToString().Trim();
  567. ICSROUTE line = ICSROUTEBLL.search(ROUTECODE, AppConfig.AppConnectString);
  568. if (line == null)
  569. {
  570. ICSROUTE RouteList = new ICSROUTE();
  571. RouteList.ID = ID;
  572. RouteList.ROUTECODE = dr["途程代码"].ToString();
  573. RouteList.ROUTEDESC = dr["途程描述"].ToString();
  574. RouteList.ROUTETYPE = dr["途程类别"].ToString();
  575. RouteList.ENABLED = dr["生效/失效"].ToString();
  576. RouteList.MUSER = AppConfig.UserId;
  577. RouteList.MUSERName = AppConfig.UserName;
  578. RouteList.MTIME = DateTime.Now;
  579. RouteList.WorkPoint = AppConfig.WorkPointCode;
  580. RouteLists.Add(RouteList);
  581. }
  582. else
  583. {
  584. _wait.Close();
  585. ICSBaseSimpleCode.AppshowMessageBox("途程代码:" + ROUTECODE + "已经存在");
  586. return;
  587. }
  588. }
  589. DataTable dt = ICSROUTEBLL.GetOPCODE(dr["工序代码"].ToString().Trim(), AppConfig.WorkPointCode, AppConfig.AppConnectString);
  590. if (dt.Rows.Count > 0 && dt != null)
  591. {
  592. ICSROUTE2OP OPList = new ICSROUTE2OP();
  593. OPList.ROUTEID = ID;
  594. OPList.OPID = dt.Rows[0]["ID"].ToString();
  595. OPList.ROUTECODE = dr["途程代码"].ToString();
  596. OPList.OPCODE = dr["工序代码"].ToString();
  597. OPList.OPSEQ = Convert.ToInt32(dr["工序次序"].ToString());
  598. OPList.OPCONTROL = dt.Rows[0]["OPCONTROL"].ToString();
  599. OPList.MUSER = AppConfig.UserCode;
  600. OPList.MUSERName = AppConfig.UserName;
  601. OPList.MTIME = DateTime.Now;
  602. OPList.WORKPOINT = AppConfig.WorkPointCode;
  603. OPLists.Add(OPList);
  604. }
  605. else
  606. {
  607. _wait.Close();
  608. ICSBaseSimpleCode.AppshowMessageBox("工序代码:" + dr["工序代码"].ToString().Trim() + "不存在!");
  609. return;
  610. }
  611. }
  612. _wait.Caption = "导入数据......";
  613. string mes = ICSROUTEBLL.AddList(RouteLists, OPLists, AppConfig.AppConnectString);
  614. if (mes == "OK")
  615. {
  616. ICSBaseSimpleCode.AppshowMessageBox("数据导入成功!");
  617. }
  618. else
  619. {
  620. ICSBaseSimpleCode.AppshowMessageBox(mes);
  621. }
  622. _wait.Close();
  623. btnRefresh_Click(null, null);
  624. }
  625. catch (Exception ex)
  626. {
  627. _wait.Close();
  628. ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message);
  629. }
  630. }
  631. #endregion
  632. }
  633. }