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

511 lines
18 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.UserControl.MessageControl;
  11. using System.Data.SqlClient;
  12. using ICSSoft.Base.Config.AppConfig;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Frame.Data.BLL;
  18. namespace ICSSoft.Frame.APP
  19. {
  20. public partial class FormICSEQPMaintainReport : DevExpress.XtraEditors.XtraForm
  21. {
  22. private string sqltxt = "";
  23. private string sqlconn = "";
  24. String guid = AppConfig.GetGuid();
  25. private DataTable dataSource = null;
  26. #region 构造函数
  27. public FormICSEQPMaintainReport()
  28. {
  29. InitializeComponent();
  30. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  31. this.WindowState = FormWindowState.Maximized;
  32. //FormICSEQPMaintainPlan_Load(null,null);
  33. }
  34. #endregion
  35. #region 移动窗体
  36. private const int WM_NCHITTEST = 0x84;
  37. private const int HTCLIENT = 0x1;
  38. private const int HTCAPTION = 0x2;
  39. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  40. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  41. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  42. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  43. //重写窗体,使窗体可以不通过自带标题栏实现移动
  44. protected override void WndProc(ref Message m)
  45. {
  46. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  47. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  48. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  49. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  50. switch (m.Msg)
  51. {
  52. case WM_NCHITTEST:
  53. base.WndProc(ref m);
  54. if ((int)m.Result == HTCLIENT)
  55. m.Result = (IntPtr)HTCAPTION;
  56. return;
  57. }
  58. //拦截双击标题栏、移动窗体的系统消息
  59. if (m.Msg != 0xA3)
  60. {
  61. base.WndProc(ref m);
  62. }
  63. }
  64. #endregion
  65. #region SystemOptition
  66. /// <summary>
  67. /// 操作权限
  68. /// </summary>
  69. /// <returns></returns>
  70. public DataTable RightOfExute()
  71. {
  72. DataTable rData = new DataTable();
  73. rData.Columns.Add("BtnName");
  74. rData.Columns.Add("ActionName");
  75. //查看权限(必须有)
  76. DataRow seeRow = rData.NewRow();
  77. seeRow["BtnName"] = "see";
  78. seeRow["ActionName"] = "查看";
  79. rData.Rows.Add(seeRow);
  80. List<Control> ControlList = new List<Control>();
  81. ControlList.Add(btnConfig);
  82. //ControlList.Add(btnAdd);
  83. //ControlList.Add(btnEdit);
  84. //ControlList.Add(btnDelLable);
  85. foreach (Control ctr in ControlList)
  86. {
  87. if (ctr.GetType() == typeof(SimpleButton))
  88. {
  89. DataRow dr = rData.NewRow();
  90. dr["BtnName"] = ctr.Name;
  91. dr["ActionName"] = ctr.Text;
  92. rData.Rows.Add(dr);
  93. }
  94. }
  95. rData.AcceptChanges();
  96. return rData;
  97. }
  98. /// <summary>
  99. /// 数据权限
  100. /// </summary>
  101. /// <returns></returns>
  102. public DataTable RightOfData()
  103. {
  104. DataTable rData = new DataTable();
  105. rData.Columns.Add("BodyName");
  106. rData.Columns.Add("ControlName");
  107. rData.Columns.Add("ControlCaption");
  108. rData.AcceptChanges();
  109. return rData;
  110. }
  111. #endregion
  112. #region 退出
  113. private void btnClose_Click(object sender, EventArgs e)
  114. {
  115. AppConfig.CloseFormShow(this.Text);
  116. this.Close();
  117. }
  118. private void btnExit_Click(object sender, EventArgs e)
  119. {
  120. AppConfig.CloseFormShow(this.Text);
  121. this.Close();
  122. }
  123. #endregion
  124. #region 过滤
  125. private string tempTableName = "";
  126. private void btnFilter_Click(object sender, EventArgs e)
  127. {
  128. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  129. filter.OldTempTableName = tempTableName;
  130. if (filter.ShowDialog() == DialogResult.OK)
  131. {
  132. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  133. try
  134. {
  135. _wait.Show();
  136. tempTableName = filter.NewTempTableName;
  137. sqltxt = filter.SqlText;
  138. sqlconn = filter.FilterConnectString;
  139. dataSource = filter.FilterData.Tables[0];
  140. grdDetail.DataSource = dataSource;
  141. grvDetail.BestFitColumns();
  142. rptPage.RecordNum = dataSource.Rows.Count;
  143. rptPage.PageSize = 499;
  144. rptPage.PageIndex = 1;
  145. rptPage.ReLoad();
  146. rptPage.PageSize = 500;
  147. rptPage.PageIndex = 1;
  148. rptPage.ReLoad();
  149. _wait.Close();
  150. }
  151. catch (Exception ex)
  152. {
  153. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  154. _wait.Close();
  155. }
  156. }
  157. }
  158. #endregion
  159. #region 分页
  160. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  161. {
  162. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  163. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  164. grdDetail.DataSource = data;
  165. }
  166. #endregion
  167. #region 全选
  168. private void btnSelect_Click(object sender, EventArgs e)
  169. {
  170. for (int i = 0; i < grvDetail.RowCount; i++)
  171. {
  172. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  173. }
  174. }
  175. #endregion
  176. #region 全消
  177. private void btnCanSelect_Click(object sender, EventArgs e)
  178. {
  179. for (int i = 0; i < grvDetail.RowCount; i++)
  180. {
  181. grvDetail.SetRowCellValue(i, colisSelect, "");
  182. }
  183. }
  184. #endregion
  185. #region 刷新
  186. private void btnFalsh_Click(object sender, EventArgs e)
  187. {
  188. if (sqlconn == null || sqlconn == "")
  189. {
  190. return;
  191. }
  192. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  193. try
  194. {
  195. _wait.Show();
  196. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  197. filter.OldTempTableName = tempTableName;
  198. //tempTableName = filter.NewTempTableName;
  199. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  200. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  201. grdDetail.DataSource = dataSource;
  202. grvDetail.BestFitColumns();
  203. rptPage.RecordNum = dataSource.Rows.Count;
  204. rptPage.PageIndex = 1;
  205. rptPage.ReLoad();
  206. _wait.Close();
  207. }
  208. catch (Exception ex)
  209. {
  210. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  211. _wait.Close();
  212. }
  213. }
  214. #endregion
  215. #region 列表
  216. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  217. {
  218. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  219. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  220. }
  221. #endregion
  222. #region 双击选择
  223. private void grvDetail_DoubleClick(object sender, EventArgs e)
  224. {
  225. if (grvDetail.FocusedRowHandle < 0)
  226. {
  227. return;
  228. }
  229. if (grvDetail.FocusedColumn == colisSelect)
  230. {
  231. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  232. {
  233. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  234. }
  235. else
  236. {
  237. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  238. }
  239. }
  240. }
  241. #endregion
  242. //#region 删除
  243. //private void btnDel_Click(object sender, EventArgs e)
  244. //{
  245. // grvDetail.PostEditor();
  246. // this.Validate();
  247. // if (grvDetail.RowCount == 0)
  248. // return;
  249. // SimpleButton btntemp = (SimpleButton)sender;
  250. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  251. // {
  252. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  253. // }
  254. // List<string> guidList = new List<string>();
  255. // List<string> guidList1 = new List<string>();
  256. // for (int i = 0; i < grvDetail.RowCount; i++)
  257. // {
  258. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  259. // {
  260. // guidList.Add(grvDetail.GetRowCellValue(i, colGUID).ToString());
  261. // }
  262. // }
  263. // if (guidList.Count == 0)
  264. // {
  265. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  266. // return;
  267. // }
  268. // if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该设备保养计划吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  269. // return;
  270. // try
  271. // {
  272. // ICSEQPMaintainPlanBLL.delete(guidList);
  273. // ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  274. // }
  275. // catch (Exception ex)
  276. // {
  277. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  278. // }
  279. // btnFalsh_Click(null, null);
  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. MessageBox.Show("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  289. return;
  290. }
  291. FormICSEQPMaintainPlanAdd add = new FormICSEQPMaintainPlanAdd();
  292. add.ShowDialog();
  293. btnFalsh_Click(null, null);
  294. }
  295. #endregion
  296. #region 绑定数据源
  297. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  298. {
  299. if (AppConfig.UserCode.ToLower() != "demo")
  300. {
  301. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  302. return;
  303. }
  304. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  305. fdata.ShowDialog();
  306. }
  307. #endregion
  308. private void FormICSShift_Load(object sender, EventArgs e)
  309. {
  310. btnFilter_Click(sender, e);
  311. }
  312. //#region 修改
  313. //private void btnEdit_Click(object sender, EventArgs e)
  314. //{
  315. // SimpleButton btntemp = (SimpleButton)sender;
  316. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  317. // {
  318. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  319. // return;
  320. // }
  321. // int count = 0;
  322. // for (int i = 0; i < grvDetail.RowCount; i++)
  323. // {
  324. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  325. // {
  326. // count++;
  327. // }
  328. // }
  329. // if (count != 1)
  330. // {
  331. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  332. // return;
  333. // }
  334. // try
  335. // {
  336. // string id;
  337. // for (int i = 0; i < grvDetail.RowCount; i++)
  338. // {
  339. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  340. // {
  341. // id = grvDetail.GetRowCellValue(i, colGUID).ToString();
  342. // FormICSEQPMaintainPlanAdd add = new FormICSEQPMaintainPlanAdd(id);
  343. // add.ShowDialog();
  344. // }
  345. // }
  346. // btnFalsh_Click(null, null);
  347. // }
  348. // catch (Exception ex)
  349. // {
  350. // //throw ex;
  351. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  352. // }
  353. //}
  354. //#endregion
  355. private void btnOutPut_Click(object sender, EventArgs e)
  356. {
  357. try
  358. {
  359. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  360. foe.ShowDialog();
  361. }
  362. catch (Exception ex)
  363. {
  364. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  365. }
  366. //FormOutExcel foe = new FormOutExcel();
  367. //if (foe.ShowDialog() == DialogResult.OK)
  368. //{
  369. // try
  370. // {
  371. // string outtype = foe._OutType;
  372. // string exceltype = foe._ExcelType;
  373. // string filename = foe._FileName;
  374. // string url = foe._Url;
  375. // string sheetname = foe._SheetName;
  376. // if (outtype.ToLower() == "excel")
  377. // {
  378. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  379. // op.SheetName = sheetname;
  380. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  381. // }
  382. // else
  383. // {
  384. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  385. // }
  386. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  387. // }
  388. // catch (Exception ex)
  389. // {
  390. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  391. // }
  392. //}
  393. }
  394. //private void grvDetail_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  395. //{
  396. // //if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  397. // //{
  398. // // e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  399. // //}
  400. // //if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  401. // //{
  402. // // e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  403. // //}
  404. // for (int i = 0; i < grvDetail.RowCount; i++)
  405. // {
  406. // bool bijiao = (DateTime.Compare(Convert.ToDateTime(grvDetail.GetRowCellValue(i, colnextTime).ToString()), AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss")) < 0) ? true : false;
  407. // if (!bijiao)
  408. // {
  409. // e.Appearance.BackColor = Color.Yellow;
  410. // }
  411. // else
  412. // e.Appearance.BackColor = Color.Pink;
  413. // }
  414. //}
  415. private void FormICSEQPMaintainPlan_Load(object sender, EventArgs e)
  416. {
  417. btnFilter_Click(sender, e);
  418. }
  419. private void grvDetail_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
  420. {
  421. int hand = e.RowHandle;
  422. if (hand < 0)
  423. return;
  424. DataRow dr = this.grvDetail.GetDataRow(hand);
  425. if (dr == null)
  426. return;
  427. if (grvDetail.GetRowCellValue(e.RowHandle, colnextTime).ToString() != "")
  428. {
  429. bool bijiao = (DateTime.Compare(Convert.ToDateTime(grvDetail.GetRowCellValue(e.RowHandle, colnextTime).ToString()), AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss")) < 0) ? true : false;
  430. if (!bijiao)
  431. {
  432. e.Appearance.BackColor = Color.Yellow;
  433. }
  434. else
  435. e.Appearance.BackColor = Color.Pink;
  436. }
  437. }
  438. }
  439. }