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

613 lines
24 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 FormIcsEqpWithLocation : 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 FormIcsEqpWithLocation()
  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(simpleButton2);
  55. ControlList.Add(simpleButton1);
  56. ControlList.Add(simpleButton3);
  57. ControlList.Add(btnOutPut);
  58. foreach (Control ctr in ControlList)
  59. {
  60. if (ctr.GetType() == typeof(SimpleButton))
  61. {
  62. DataRow dr = rData.NewRow();
  63. dr["BtnName"] = ctr.Name;
  64. dr["ActionName"] = ctr.Text;
  65. rData.Rows.Add(dr);
  66. }
  67. }
  68. rData.AcceptChanges();
  69. return rData;
  70. }
  71. public DataTable RightOfData()// 数据权限
  72. {
  73. DataTable rData = new DataTable();
  74. rData.Columns.Add("BodyName");
  75. rData.Columns.Add("ControlName");
  76. rData.Columns.Add("ControlCaption");
  77. rData.AcceptChanges();
  78. return rData;
  79. }
  80. #endregion
  81. #region 退出
  82. private void btnClose_Click(object sender, EventArgs e)
  83. {
  84. AppConfig.CloseFormShow(this.Text);
  85. this.Close();
  86. }
  87. private void btnExit_Click(object sender, EventArgs e)
  88. {
  89. AppConfig.CloseFormShow(this.Text);
  90. this.Close();
  91. }
  92. #endregion
  93. #region 移动窗体
  94. private const int WM_NCHITTEST = 0x84;
  95. private const int HTCLIENT = 0x1;
  96. private const int HTCAPTION = 0x2;
  97. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  98. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  99. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  100. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  101. //重写窗体,使窗体可以不通过自带标题栏实现移动
  102. protected override void WndProc(ref Message m)
  103. {
  104. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  105. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  106. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  107. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  108. switch (m.Msg)
  109. {
  110. case WM_NCHITTEST:
  111. base.WndProc(ref m);
  112. if ((int)m.Result == HTCLIENT)
  113. m.Result = (IntPtr)HTCAPTION;
  114. return;
  115. }
  116. //拦截双击标题栏、移动窗体的系统消息
  117. if (m.Msg != 0xA3)
  118. {
  119. base.WndProc(ref m);
  120. }
  121. }
  122. #endregion
  123. #region 列表
  124. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  125. {
  126. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  127. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  128. }
  129. #endregion
  130. #region 过滤
  131. private string tempTableName = "";
  132. private void btnFilter_Click(object sender, EventArgs e)
  133. {
  134. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  135. filter.OldTempTableName = tempTableName;
  136. if (filter.ShowDialog() == DialogResult.OK)
  137. {
  138. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  139. try
  140. {
  141. _wait.Show();
  142. tempTableName = filter.NewTempTableName;
  143. sqltxt = filter.SqlText;
  144. sqlconn = filter.FilterConnectString;
  145. dataSource = filter.FilterData.Tables[0];
  146. grdDetail.DataSource = dataSource;
  147. grvDetail.BestFitColumns();
  148. rptPage.RecordNum = dataSource.Rows.Count;
  149. rptPage.PageSize = 499;
  150. rptPage.PageIndex = 1;
  151. rptPage.ReLoad();
  152. rptPage.PageSize = 500;
  153. rptPage.PageIndex = 1;
  154. rptPage.ReLoad();
  155. _wait.Close();
  156. }
  157. catch (Exception ex)
  158. {
  159. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  160. _wait.Close();
  161. }
  162. }
  163. }
  164. #endregion
  165. #region 绑定数据源
  166. private void btnConfig_Click(object sender, EventArgs e)
  167. {
  168. //if (AppConfig.UserCode.ToLower() != "demo")
  169. //{
  170. // ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  171. // return;
  172. //}
  173. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  174. fdata.ShowDialog();
  175. }
  176. #endregion
  177. #region 分页
  178. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  179. {
  180. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  181. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  182. grdDetail.DataSource = data;
  183. }
  184. #endregion
  185. #region 过滤方法
  186. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  187. {
  188. AppConfig.DropTemTable(tempTableName);
  189. }
  190. #endregion
  191. #region 全选
  192. private void btnSelectAll_Click(object sender, EventArgs e)
  193. {
  194. grvDetail.PostEditor();
  195. this.Validate();
  196. for (int i = 0; i < grvDetail.RowCount; i++)
  197. {
  198. grvDetail.SetRowCellValue(i, coSelect, "Y");
  199. }
  200. }
  201. #endregion
  202. #region 全消
  203. private void btnCancelAll_Click(object sender, EventArgs e)
  204. {
  205. grvDetail.PostEditor();
  206. this.Validate();
  207. for (int i = 0; i < grvDetail.RowCount; i++)
  208. {
  209. grvDetail.SetRowCellValue(i, coSelect, "");
  210. }
  211. }
  212. #endregion
  213. #region 双击
  214. private void grvDetail_DoubleClick(object sender, EventArgs e)
  215. {
  216. if (grvDetail.FocusedRowHandle < 0)
  217. {
  218. return;
  219. }
  220. if (grvDetail.FocusedColumn == coSelect)
  221. {
  222. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coSelect).ToString() == "")
  223. {
  224. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, coSelect, "Y");
  225. }
  226. else
  227. {
  228. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, coSelect, "");
  229. }
  230. }
  231. }
  232. #endregion
  233. #region 删除
  234. private void btnDel_Click(object sender, EventArgs e)
  235. {
  236. grvDetail.PostEditor();
  237. this.Validate();
  238. if (grvDetail.RowCount == 0)
  239. return;
  240. SimpleButton btntemp = (SimpleButton)sender;
  241. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  242. {
  243. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  244. }
  245. List<string> guidList = new List<string>();
  246. for (int i = 0; i < grvDetail.RowCount; i++)
  247. {
  248. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y")
  249. {
  250. guidList.Add(grvDetail.GetRowCellValue(i, ID).ToString());
  251. }
  252. }
  253. if (guidList.Count == 0)
  254. {
  255. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  256. return;
  257. }
  258. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该数据吗?数据删除后无法恢复!!") != DialogResult.OK)
  259. return;
  260. try
  261. {
  262. ICSEqpWithLocationBLL.deleteInfo(guidList,AppConfig.AppConnectString);
  263. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  264. btnRefresh_Click(null, null);
  265. }
  266. catch (Exception ex)
  267. {
  268. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  269. }
  270. }
  271. #endregion
  272. #region 导出
  273. private void btnOutPut_Click(object sender, EventArgs e)
  274. {
  275. }
  276. #endregion
  277. #region 刷新
  278. private void btnRefresh_Click(object sender, EventArgs e)
  279. {
  280. if (sqlconn == null || sqlconn == "")
  281. {
  282. return;
  283. }
  284. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  285. try
  286. {
  287. _wait.Show();
  288. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  289. filter.OldTempTableName = tempTableName;
  290. //tempTableName = filter.NewTempTableName;
  291. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  292. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  293. grdDetail.DataSource = dataSource;
  294. grvDetail.BestFitColumns();
  295. rptPage.RecordNum = dataSource.Rows.Count;
  296. rptPage.PageIndex = 1;
  297. rptPage.ReLoad();
  298. _wait.Close();
  299. }
  300. catch (Exception ex)
  301. {
  302. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  303. _wait.Close();
  304. }
  305. }
  306. #endregion
  307. #region 新增
  308. private void btnCreate_Click(object sender, EventArgs e)
  309. {
  310. SimpleButton btntemp = (SimpleButton)sender;
  311. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  312. {
  313. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  314. return;
  315. }
  316. FormICSEqpWithLocationAdd add = new FormICSEqpWithLocationAdd();
  317. add.ShowDialog();
  318. btnRefresh_Click(null, null);
  319. }
  320. #endregion
  321. #region 页面加载
  322. private void grdDetail_Load(object sender, EventArgs e)
  323. {
  324. btnFilter_Click(null, null);
  325. }
  326. #endregion
  327. #region 修改
  328. private void btnModify_Click(object sender, EventArgs e)
  329. {
  330. String id = "";
  331. SimpleButton btntemp = (SimpleButton)sender;
  332. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  333. {
  334. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  335. }
  336. List<string> editList = new List<string>();
  337. for (int i = 0; i < grvDetail.RowCount; i++)
  338. {
  339. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y")
  340. {
  341. id = grvDetail.GetRowCellValue(i, ID).ToString();
  342. editList.Add(id);
  343. }
  344. }
  345. if (editList.Count != 1)
  346. {
  347. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  348. return;
  349. }
  350. try
  351. {
  352. FormICSEqpWithLocationAdd add = new FormICSEqpWithLocationAdd(id);
  353. add.ShowDialog();
  354. btnRefresh_Click(null, null);
  355. }
  356. catch (Exception ex)
  357. {
  358. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  359. }
  360. }
  361. #endregion
  362. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  363. {
  364. AppConfig.DropTemTable(tempTableName);
  365. }
  366. private void FormICSCREW_Load(object sender, EventArgs e)
  367. {
  368. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  369. filter.OldTempTableName = tempTableName;
  370. if (filter.ShowDialog() == DialogResult.OK)
  371. {
  372. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  373. try
  374. {
  375. _wait.Show();
  376. tempTableName = filter.NewTempTableName;
  377. sqltxt = filter.SqlText;
  378. sqlconn = filter.FilterConnectString;
  379. dataSource = filter.FilterData.Tables[0];
  380. grdDetail.DataSource = dataSource;
  381. grvDetail.BestFitColumns();
  382. rptPage.RecordNum = dataSource.Rows.Count;
  383. rptPage.PageSize = 499;
  384. rptPage.PageIndex = 1;
  385. rptPage.ReLoad();
  386. rptPage.PageSize = 500;
  387. rptPage.PageIndex = 1;
  388. rptPage.ReLoad();
  389. _wait.Close();
  390. }
  391. catch (Exception ex)
  392. {
  393. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  394. _wait.Close();
  395. }
  396. }
  397. }
  398. private void btnOutPut_Click_1(object sender, EventArgs e)
  399. {
  400. try
  401. {
  402. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  403. foe.ShowDialog();
  404. }
  405. catch (Exception ex)
  406. {
  407. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  408. }
  409. //FormOutExcel foe = new FormOutExcel();
  410. //if (foe.ShowDialog() == DialogResult.OK)
  411. //{
  412. // try
  413. // {
  414. // string outtype = foe._OutType;
  415. // string exceltype = foe._ExcelType;
  416. // string filename = foe._FileName;
  417. // string url = foe._Url;
  418. // string sheetname = foe._SheetName;
  419. // if (outtype.ToLower() == "excel")
  420. // {
  421. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  422. // op.SheetName = sheetname;
  423. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  424. // }
  425. // else
  426. // {
  427. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  428. // }
  429. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  430. // }
  431. // catch (Exception ex)
  432. // {
  433. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  434. // }
  435. //}
  436. }
  437. private void btnImportMould_Click(object sender, EventArgs e)
  438. {
  439. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  440. _wait.Hide();
  441. string anjianExcelFileName = Environment.CommandLine.Substring(1, Environment.CommandLine.LastIndexOf("\\")) + "Output\\";
  442. try
  443. {
  444. _wait.Show();
  445. _wait.Caption = "模板下载中......";
  446. SaveFileDialog dlgSaveFileDialog = new SaveFileDialog(); //弹框提示保存
  447. dlgSaveFileDialog.InitialDirectory = anjianExcelFileName; //默认打开目录
  448. dlgSaveFileDialog.FilterIndex = 1;
  449. dlgSaveFileDialog.RestoreDirectory = true;
  450. dlgSaveFileDialog.FileName = "设备与点位关联维护导入模板.xlsx"; //默认保存名称
  451. dlgSaveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  452. if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK)
  453. {
  454. string fileName = dlgSaveFileDialog.FileName; //获取弹出框选择或填写的文件名称
  455. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  456. colNameList.Add(new FormReadExcelUIModelColumns("设备编码", true));
  457. colNameList.Add(new FormReadExcelUIModelColumns("点位编码", true));
  458. //colNameList.Add(new FormReadExcelUIModelColumns("工序代码", true));
  459. //colNameList.Add(new FormReadExcelUIModelColumns("工序次序", true));
  460. FileUtil.exportToExcelFile(fileName, colNameList);
  461. _wait.Close();
  462. ICSBaseSimpleCode.AppshowMessageBox("模板下载成功!");
  463. }
  464. _wait.Close();
  465. }
  466. catch (Exception ex)
  467. {
  468. _wait.Close();
  469. ICSBaseSimpleCode.AppshowMessageBox("模板下载失败:" + ex.Message);
  470. }
  471. }
  472. private void btnImportData_Click(object sender, EventArgs e)
  473. {
  474. SimpleButton btntemp = (SimpleButton)sender;
  475. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  476. {
  477. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  478. return;
  479. }
  480. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  481. _wait.Hide();
  482. try
  483. {
  484. FormReadExcel fre = new FormReadExcel();
  485. if (fre.ShowDialog() != DialogResult.OK)
  486. {
  487. return;
  488. }
  489. DataTable dataSource = fre._excelData;
  490. if (dataSource == null)
  491. {
  492. throw new Exception("excel数据取得失败");
  493. }
  494. _wait.Show();
  495. _wait.Caption = "判断模版是否正确......";
  496. #region 判断模版是否正确
  497. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  498. colNameList.Add(new FormReadExcelUIModelColumns("设备编码", true));
  499. colNameList.Add(new FormReadExcelUIModelColumns("点位编码", true));
  500. //colNameList.Add(new FormReadExcelUIModelColumns("工序代码", true));
  501. //colNameList.Add(new FormReadExcelUIModelColumns("工序次序", true));
  502. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  503. {
  504. if (!dataSource.Columns.Contains(columnsName.columnsName))
  505. {
  506. throw new Exception("模版不正确,缺少列" + columnsName.columnsName);
  507. }
  508. }
  509. #endregion
  510. _wait.Caption = "数据整理中......";
  511. List<IcsEqpWithLocation> InitInvInfoList = new List<IcsEqpWithLocation>();
  512. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  513. db.Connection.Open();
  514. foreach (DataRow dr in dataSource.Rows)
  515. {
  516. ///判断必输项目是否为空
  517. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  518. {
  519. if (string.IsNullOrWhiteSpace(dr[columnsName.columnsName].ToString()) == true && columnsName.NotNull == true)
  520. {
  521. throw new Exception("列" + columnsName.columnsName + "没有输入值");
  522. }
  523. }
  524. IcsEqpWithLocation Info = new IcsEqpWithLocation();
  525. Info.ID = AppConfig.GetGuid();
  526. if (db.IcsAGVLocation.Where(a => a.LocationCode == dr["点位编码"].ToString()).FirstOrDefault() == null)
  527. throw new Exception("点位编码;"+ dr["点位编码"].ToString()+"不存在!");
  528. Info.LocationCode = dr["点位编码"].ToString();
  529. if (db.ICSEquipment.Where(a => a.EQPCode == dr["设备编码"].ToString()).FirstOrDefault() == null)
  530. throw new Exception("设备编码;" + dr["设备编码"].ToString() + "不存在!");
  531. Info.EqpCode = dr["设备编码"].ToString();
  532. Info.Muser = AppConfig.UserCode;
  533. Info.MuserName = AppConfig.UserName;
  534. Info.Mtime = DateTime.Now;
  535. InitInvInfoList.Add(Info);
  536. }
  537. _wait.Caption = "导入数据......";
  538. ICSEqpWithLocationBLL.AddList(InitInvInfoList, AppConfig.AppConnectString);
  539. _wait.Close();
  540. ICSBaseSimpleCode.AppshowMessageBox("导入成功");
  541. btnRefresh_Click(null, null);
  542. }
  543. catch (Exception ex)
  544. {
  545. _wait.Close();
  546. ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message);
  547. }
  548. }
  549. }
  550. }