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

595 lines
22 KiB

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