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

453 lines
16 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 FormICSEQPMaintainPlanForLog : 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 FormICSEQPMaintainPlanForLog()
  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 void rptPage_PageIndexChanged(object Sender, EventArgs e)
  126. {
  127. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  128. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  129. grdDetail.DataSource = data;
  130. }
  131. #endregion
  132. #region 全选
  133. private void btnSelect_Click(object sender, EventArgs e)
  134. {
  135. for (int i = 0; i < grvDetail.RowCount; i++)
  136. {
  137. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  138. }
  139. }
  140. #endregion
  141. #region 全消
  142. private void btnCanSelect_Click(object sender, EventArgs e)
  143. {
  144. for (int i = 0; i < grvDetail.RowCount; i++)
  145. {
  146. grvDetail.SetRowCellValue(i, colisSelect, "");
  147. }
  148. }
  149. #endregion
  150. #region 刷新
  151. private void btnFalsh_Click(object sender, EventArgs e)
  152. {
  153. //if (sqlconn == null || sqlconn == "")
  154. //{
  155. // return;
  156. //}
  157. //DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  158. //try
  159. //{
  160. // _wait.Show();
  161. // FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  162. // filter.OldTempTableName = tempTableName;
  163. // //tempTableName = filter.NewTempTableName;
  164. // //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  165. // dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  166. // grdDetail.DataSource = dataSource;
  167. // grvDetail.BestFitColumns();
  168. // rptPage.RecordNum = dataSource.Rows.Count;
  169. // rptPage.PageIndex = 1;
  170. // rptPage.ReLoad();
  171. // _wait.Close();
  172. //}
  173. //catch (Exception ex)
  174. //{
  175. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  176. // _wait.Close();
  177. //}
  178. }
  179. #endregion
  180. #region 列表
  181. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  182. {
  183. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  184. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  185. }
  186. #endregion
  187. #region 双击选择
  188. private void grvDetail_DoubleClick(object sender, EventArgs e)
  189. {
  190. if (grvDetail.FocusedRowHandle < 0)
  191. {
  192. return;
  193. }
  194. if (grvDetail.FocusedColumn == colisSelect)
  195. {
  196. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  197. {
  198. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  199. }
  200. else
  201. {
  202. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  203. }
  204. }
  205. }
  206. #endregion
  207. #region 删除
  208. private void btnDel_Click(object sender, EventArgs e)
  209. {
  210. grvDetail.PostEditor();
  211. this.Validate();
  212. if (grvDetail.RowCount == 0)
  213. return;
  214. SimpleButton btntemp = (SimpleButton)sender;
  215. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  216. {
  217. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  218. }
  219. List<string> guidList = new List<string>();
  220. List<string> guidList1 = new List<string>();
  221. for (int i = 0; i < grvDetail.RowCount; i++)
  222. {
  223. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  224. {
  225. guidList.Add(grvDetail.GetRowCellValue(i, colGUID).ToString());
  226. }
  227. }
  228. if (guidList.Count == 0)
  229. {
  230. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  231. return;
  232. }
  233. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该设备保养计划吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  234. return;
  235. try
  236. {
  237. ICSEQPMaintainPlanBLL.delete(guidList);
  238. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  239. }
  240. catch (Exception ex)
  241. {
  242. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  243. }
  244. btnFalsh_Click(null, null);
  245. }
  246. #endregion
  247. #region 新增
  248. private void btnAdd_Click(object sender, EventArgs e)
  249. {
  250. SimpleButton btntemp = (SimpleButton)sender;
  251. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  252. {
  253. MessageBox.Show("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  254. return;
  255. }
  256. FormICSEQPMaintainPlanAdd add = new FormICSEQPMaintainPlanAdd();
  257. add.ShowDialog();
  258. btnFalsh_Click(null, null);
  259. }
  260. #endregion
  261. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  262. {
  263. // if (AppConfig.UserCode.ToLower() != "demo")
  264. // {
  265. // //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  266. // return;
  267. // }
  268. // FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  269. // fdata.ShowDialog();
  270. //}
  271. //#endregion
  272. //private void FormICSShift_Load(object sender, EventArgs e)
  273. //{
  274. // btnFilter_Click(sender, e);
  275. }
  276. #region 修改
  277. private void btnEdit_Click(object sender, EventArgs e)
  278. {
  279. SimpleButton btntemp = (SimpleButton)sender;
  280. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  281. {
  282. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  283. return;
  284. }
  285. int count = 0;
  286. for (int i = 0; i < grvDetail.RowCount; i++)
  287. {
  288. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  289. {
  290. count++;
  291. }
  292. }
  293. if (count != 1)
  294. {
  295. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  296. return;
  297. }
  298. try
  299. {
  300. string id;
  301. for (int i = 0; i < grvDetail.RowCount; i++)
  302. {
  303. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  304. {
  305. id = grvDetail.GetRowCellValue(i, colGUID).ToString();
  306. FormICSEQPMaintainPlanAdd add = new FormICSEQPMaintainPlanAdd(id);
  307. add.ShowDialog();
  308. }
  309. }
  310. btnFalsh_Click(null, null);
  311. }
  312. catch (Exception ex)
  313. {
  314. //throw ex;
  315. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  316. }
  317. }
  318. #endregion
  319. private void btnOutPut_Click(object sender, EventArgs e)
  320. {
  321. try
  322. {
  323. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  324. foe.ShowDialog();
  325. }
  326. catch (Exception ex)
  327. {
  328. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  329. }
  330. //FormOutExcel foe = new FormOutExcel();
  331. //if (foe.ShowDialog() == DialogResult.OK)
  332. //{
  333. // try
  334. // {
  335. // string outtype = foe._OutType;
  336. // string exceltype = foe._ExcelType;
  337. // string filename = foe._FileName;
  338. // string url = foe._Url;
  339. // string sheetname = foe._SheetName;
  340. // if (outtype.ToLower() == "excel")
  341. // {
  342. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  343. // op.SheetName = sheetname;
  344. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  345. // }
  346. // else
  347. // {
  348. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  349. // }
  350. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  351. // }
  352. // catch (Exception ex)
  353. // {
  354. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  355. // }
  356. //}
  357. }
  358. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  359. {
  360. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  361. {
  362. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  363. }
  364. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  365. {
  366. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  367. }
  368. }
  369. private void FormICSEQPMaintainPlan_Load(object sender, EventArgs e)
  370. {
  371. try
  372. {
  373. string sql = @"select '' as isSelect,a.GUID as GUID,b.EQPID as EQPID,b.EQPCode as EQPCode,b.EQPDESC as EQPDESC,
  374. a.MaintainItem as MaintainItem,a.CycleType as CycleType,a.Frequency as Frequency,a.MUSERName as MUSERName,a.MTIME as MTIME
  375. from ICSEQPMaintainPlan a
  376. Left join ICSEquipment b on a.EQPID=b.EQPID
  377. where 1=1";
  378. DataTable ddf = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  379. grdDetail.DataSource = ddf;
  380. }
  381. catch (Exception ex)
  382. {
  383. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  384. }
  385. }
  386. private void grdDetail_Click(object sender, EventArgs e)
  387. {
  388. }
  389. }
  390. }