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

576 lines
20 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.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Base.Report.Filter;
  15. using ICSSoft.Base.Config.DBHelper;
  16. using ICSSoft.Base.UserControl.FormControl;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Base.Lable.PrintTool;
  19. using ICSSoft.Frame.Data.Entity;
  20. using ICSSoft.Frame.Data.BLL;
  21. using System.Linq;
  22. //using ZHCSoft.AntiwearValveExpanded.DAL;
  23. //using ZHCSoft.AntiwearValveExpanded.BLL;
  24. //using ZHCSoft.AntiwearValveExpanded.Entity;
  25. namespace ICSSoft.Frame.APP
  26. {
  27. public partial class FormICSOP2UserAdds : 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 dataSource1 = null;
  34. Dictionary<string, string> UserList = new Dictionary<string, string>();
  35. Dictionary<string, string> OPList = new Dictionary<string, string>();
  36. Dictionary<string, string> OPIDList = new Dictionary<string, string>();
  37. #region 构造函数
  38. public FormICSOP2UserAdds()
  39. {
  40. InitializeComponent();
  41. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  42. this.WindowState = FormWindowState.Maximized;
  43. BlindUsersource("");
  44. BlindOPsource("");
  45. }
  46. #endregion
  47. #region 退出
  48. private void btnClose_Click(object sender, EventArgs e)
  49. {
  50. AppConfig.CloseFormShow(this.Text);
  51. this.Close();
  52. }
  53. private void btnExit_Click(object sender, EventArgs e)
  54. {
  55. AppConfig.CloseFormShow(this.Text);
  56. this.Close();
  57. }
  58. #endregion
  59. #region 移动窗体
  60. private const int WM_NCHITTEST = 0x84;
  61. private const int HTCLIENT = 0x1;
  62. private const int HTCAPTION = 0x2;
  63. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  64. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  65. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  66. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  67. //重写窗体,使窗体可以不通过自带标题栏实现移动
  68. protected override void WndProc(ref Message m)
  69. {
  70. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  71. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  72. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  73. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  74. switch (m.Msg)
  75. {
  76. case WM_NCHITTEST:
  77. base.WndProc(ref m);
  78. if ((int)m.Result == HTCLIENT)
  79. m.Result = (IntPtr)HTCAPTION;
  80. return;
  81. }
  82. //拦截双击标题栏、移动窗体的系统消息
  83. if (m.Msg != 0xA3)
  84. {
  85. base.WndProc(ref m);
  86. }
  87. }
  88. #endregion
  89. #region 列表
  90. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  91. {
  92. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  93. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  94. }
  95. #endregion
  96. #region 过滤
  97. private string tempTableName = "";
  98. private void btnFilter_Click(object sender, EventArgs e)
  99. {
  100. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  101. try
  102. {
  103. grvDetail.BestFitColumns();
  104. rptPage.RecordNum = dataSource.Rows.Count;
  105. rptPage.PageSize = 500;
  106. rptPage.PageIndex = 1;
  107. rptPage.ReLoad();
  108. _wait.Close();
  109. }
  110. catch (Exception ex)
  111. {
  112. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  113. _wait.Close();
  114. }
  115. }
  116. #endregion
  117. #region 分页
  118. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  119. {
  120. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  121. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  122. grdDetail.DataSource = data;
  123. }
  124. #endregion
  125. #region 全选
  126. private void btnSelectAll_Click(object sender, EventArgs e)
  127. {
  128. grvDetail.PostEditor();
  129. this.Validate();
  130. for (int i = 0; i < grvDetail.RowCount; i++)
  131. {
  132. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  133. }
  134. }
  135. #endregion
  136. #region 全消
  137. private void btnCancelAll_Click(object sender, EventArgs e)
  138. {
  139. UserList.Clear();
  140. OPList.Clear();
  141. OPIDList.Clear();
  142. BlindUsersource("");
  143. BlindOPsource("");
  144. usertextlist.Clear();
  145. optextlist.Clear();
  146. }
  147. #endregion
  148. #region 导出
  149. private void btnOutPut_Click(object sender, EventArgs e)
  150. {
  151. try
  152. {
  153. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  154. foe.ShowDialog();
  155. }
  156. catch (Exception ex)
  157. {
  158. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  159. }
  160. //FormOutExcel foe = new FormOutExcel();
  161. //if (foe.ShowDialog() == DialogResult.OK)
  162. //{
  163. // try
  164. // {
  165. // string outtype = foe._OutType;
  166. // string exceltype = foe._ExcelType;
  167. // string filename = foe._FileName;
  168. // string url = foe._Url;
  169. // string sheetname = foe._SheetName;
  170. // if (outtype.ToLower() == "excel")
  171. // {
  172. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  173. // op.SheetName = sheetname;
  174. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  175. // }
  176. // else
  177. // {
  178. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  179. // }
  180. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  181. // }
  182. // catch (Exception ex)
  183. // {
  184. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  185. // }
  186. //}
  187. }
  188. #endregion
  189. #region 刷新
  190. private void btnRefresh_Click(object sender, EventArgs e)
  191. {
  192. if (string.IsNullOrEmpty(sqlconn))
  193. return;
  194. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  195. try
  196. {
  197. //_wait.Show();
  198. //FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  199. //filter.OldTempTableName = tempTableName;
  200. ////tempTableName = filter.NewTempTableName;
  201. ////DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  202. //dataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqltxt).Tables[0];
  203. //grdDetail.DataSource = dataSource;
  204. //grvDetail.BestFitColumns();
  205. rptPage.RecordNum = dataSource.Rows.Count;
  206. rptPage.PageIndex = 1;
  207. rptPage.ReLoad();
  208. _wait.Close();
  209. }
  210. catch (Exception ex)
  211. {
  212. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  213. _wait.Close();
  214. }
  215. }
  216. #endregion
  217. #region 新增
  218. private void btnCreate_Click(object sender, EventArgs e)
  219. {
  220. SimpleButton btntemp = (SimpleButton)sender;
  221. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  222. {
  223. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  224. return;
  225. }
  226. //FormICSOP2UserAdd add = new FormICSOP2UserAdd();
  227. //add.ShowDialog();
  228. //btnRefresh_Click(null, null);
  229. }
  230. #endregion
  231. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  232. {
  233. AppConfig.DropTemTable(tempTableName);
  234. }
  235. private void FormICSITEM2ROUTE_Load(object sender, EventArgs e)
  236. {
  237. btnFilter_Click(sender, e);
  238. }
  239. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  240. {
  241. //if (e.RowHandle >= 0 && e.Column.FieldName == "isSelect" && UserList.Contains(grvDetail.GetFocusedRowCellValue(colUSERCODE).ToString()))
  242. //{
  243. // e.CellValue = "Y";
  244. // e.Handled = true;
  245. //}
  246. }
  247. private void btnLinkOP_Click(object sender, EventArgs e)
  248. {
  249. SimpleButton btntemp = (SimpleButton)sender;
  250. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  251. {
  252. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  253. return;
  254. }
  255. int count = 0;
  256. for (int i = 0; i < grvDetail.RowCount; i++)
  257. {
  258. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  259. {
  260. count++;
  261. }
  262. }
  263. if (count != 1)
  264. {
  265. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  266. return;
  267. }
  268. try
  269. {
  270. string itemCode;
  271. string routeCode;
  272. for (int i = 0; i < grvDetail.RowCount; i++)
  273. {
  274. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  275. {
  276. itemCode = grvDetail.GetRowCellValue(i, COLOPCODE).ToString();
  277. routeCode = grvDetail.GetRowCellValue(i, colUSERCODE).ToString();
  278. FormICSITEMROUTE2OP linkop = new FormICSITEMROUTE2OP(itemCode, routeCode);
  279. linkop.ShowDialog();
  280. }
  281. }
  282. btnRefresh_Click(null, null);
  283. }
  284. catch (Exception ex)
  285. {
  286. //throw ex;
  287. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  288. }
  289. }
  290. private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  291. {
  292. //if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  293. // e.Info.DisplayText = (e.RowHandle + 1).ToString();
  294. }
  295. private void grvDetail_Click(object sender, EventArgs e)
  296. {
  297. if (grvDetail.FocusedRowHandle < 0)
  298. {
  299. return;
  300. }
  301. if (grvDetail.FocusedColumn == colisSelect)
  302. {
  303. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  304. {
  305. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  306. string usercode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString();
  307. if (!UserList.Keys.Contains(usercode))
  308. UserList.Add(usercode, grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERName).ToString());
  309. }
  310. else
  311. {
  312. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  313. string usercode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString();
  314. if (UserList.Keys.Contains(usercode))
  315. UserList.Remove(usercode);
  316. }
  317. usertextlist.Clear();
  318. foreach (string a in UserList.Keys)
  319. {
  320. usertextlist.AppendText(a + "-" + UserList[a].ToString() + "" + "\r\n");
  321. }
  322. }
  323. }
  324. private void gridView1_Click(object sender, EventArgs e)
  325. {
  326. if (gridView1.FocusedRowHandle < 0)
  327. {
  328. return;
  329. }
  330. if (gridView1.FocusedColumn == isselect)
  331. {
  332. if (gridView1.GetRowCellValue(gridView1.FocusedRowHandle, isselect).ToString() == "")
  333. {
  334. gridView1.SetRowCellValue(gridView1.FocusedRowHandle, isselect, "Y");
  335. string opcode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPCODE).ToString();
  336. if (!OPList.Keys.Contains(opcode))
  337. {
  338. OPList.Add(opcode, gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPDESC).ToString());
  339. OPIDList.Add(opcode, gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPID).ToString());
  340. }
  341. }
  342. else
  343. {
  344. gridView1.SetRowCellValue(gridView1.FocusedRowHandle, isselect, "");
  345. string opcode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPCODE).ToString();
  346. if (OPList.Keys.Contains(opcode))
  347. {
  348. OPList.Remove(opcode);
  349. OPIDList.Remove(opcode);
  350. }
  351. }
  352. optextlist.Clear();
  353. foreach (string a in OPList.Keys)
  354. {
  355. optextlist.AppendText(a + "-" + OPList[a].ToString() + "" + "\r\n");
  356. }
  357. }
  358. }
  359. private void richTextBox1_TextChanged(object sender, EventArgs e)
  360. {
  361. }
  362. private void BlindUsersource(string UserName)
  363. {
  364. string sql = "select distinct '' as isSelect,USERCODE,USERNAME FROM Sys_User where STARTFLAG='1' AND 1=1";
  365. if (!string.IsNullOrEmpty(UserName))
  366. {
  367. sql += " and UserName like '%" + UserName + "%'";
  368. }
  369. DataTable table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  370. foreach (DataRow row in table.AsEnumerable().Where(a => UserList.Keys.Contains(a["USERCODE"].ToString())).ToList())
  371. {
  372. row["isSelect"] = "Y";
  373. }
  374. table.AcceptChanges();
  375. grdDetail.DataSource = table;
  376. grvDetail.BestFitColumns();
  377. dataSource = table;
  378. rptPage.RecordNum = table.Rows.Count;
  379. rptPage.PageIndex = 1;
  380. rptPage.ReLoad();
  381. }
  382. private void BlindOPsource(string Opname)
  383. {
  384. string sql = "select distinct '' as isSelect, OPCODE,OPDESC,ID AS OPID FROM ICSOP where 1=1";
  385. if (!string.IsNullOrEmpty(Opname))
  386. {
  387. sql += " and OPDESC like '%" + Opname + "%'";
  388. }
  389. DataTable table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  390. foreach (DataRow row in table.AsEnumerable().Where(a => OPList.Keys.Contains(a["OPCODE"].ToString())).ToList())
  391. {
  392. row["isSelect"] = "Y";
  393. }
  394. table.AcceptChanges();
  395. gridControl1.DataSource = table;
  396. gridView1.BestFitColumns();
  397. dataSource1 = table;
  398. rptPage1.RecordNum = table.Rows.Count;
  399. rptPage1.PageIndex = 1;
  400. rptPage1.ReLoad();
  401. }
  402. private void simpleButton1_Click(object sender, EventArgs e)
  403. {
  404. BlindUsersource(txtuser.Text);
  405. }
  406. private void simpleButton2_Click(object sender, EventArgs e)
  407. {
  408. BlindOPsource(textop.Text);
  409. }
  410. private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  411. {
  412. //if (e.RowHandle >= 0 && e.Column.FieldName == "isSelect" && OPList.Contains(gridView1.GetFocusedRowCellValue(COLOPCODE).ToString()))
  413. //{
  414. // e.CellValue = "Y";
  415. //}
  416. }
  417. private void rptPage_PageIndexChanged_1(object Sender, EventArgs e)
  418. {
  419. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  420. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  421. grdDetail.DataSource = data;
  422. }
  423. private void rptPage1_PageIndexChanged(object Sender, EventArgs e)
  424. {
  425. DataTable data = AppConfig.GetPageData(dataSource1, rptPage1.PageIndex, rptPage1.PageSize).Copy();
  426. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  427. gridControl1.DataSource = data;
  428. }
  429. private void btnCreate_Click_1(object sender, EventArgs e)
  430. {
  431. try
  432. {
  433. if (UserList.Count <= 0 || OPList.Count <= 0)
  434. throw new Exception("请选择要绑定的人员或者工序!");
  435. List<FormICSOP2UserUIModel> list = new List<FormICSOP2UserUIModel>();
  436. foreach (String usercode in UserList.Keys) {
  437. foreach (string opcode in OPList.Keys) {
  438. FormICSOP2UserUIModel test = new FormICSOP2UserUIModel();
  439. test.OPCODE = opcode;
  440. test.op = new FormICSOPUIModel();
  441. test.op.ID =OPIDList[opcode].ToString() ;
  442. test.op.OPCODE = opcode;
  443. test.user = new FormICSUserUIModel();
  444. test.USERCODE = usercode;;
  445. test.user.UserCode = usercode;
  446. test.user.UserName = UserList[usercode].ToString() ;
  447. test.MUSER = AppConfig.UserId;
  448. test.MUSERName = AppConfig.UserName;
  449. test.MTIME = DateTime.Now;
  450. test.WorkPoint = AppConfig.WorkPointCode;
  451. test.EATTRIBUTE1 = "";
  452. test.Level = "";
  453. list.Add(test);
  454. }
  455. }
  456. string mes=ICSOP2UserBLL.AddList(list,AppConfig.AppConnectString);
  457. if (string.IsNullOrEmpty(mes))
  458. ICSBaseSimpleCode.AppshowMessageBox("操作成功!");
  459. else
  460. throw new Exception(mes);
  461. btnCancelAll_Click(null,null);
  462. }
  463. catch (Exception ex) {
  464. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  465. //btnCancelAll_Click(null, null);
  466. }
  467. }
  468. }
  469. }