锐腾搅拌上料功能
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.

542 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.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. using ICSSoft.Frame.Data.Entity;
  19. namespace ICSSoft.Frame.APP
  20. {
  21. public partial class FormICSEQPMaintainLog : DevExpress.XtraEditors.XtraForm
  22. {
  23. private string sqltxt = "";
  24. private string sqlconn = "";
  25. String guid = AppConfig.GetGuid();
  26. private DataTable dataSource = null;
  27. #region 构造函数
  28. public FormICSEQPMaintainLog()
  29. {
  30. InitializeComponent();
  31. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  32. this.WindowState = FormWindowState.Maximized;
  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(btnSave);
  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. private void repositoryItemCheckEdit1_QueryCheckStateByValue(object sender, DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs e)
  248. {
  249. string val = "";
  250. if (e.Value != null)
  251. {
  252. val = e.Value.ToString();
  253. }
  254. else
  255. {
  256. val = "False";//默认为不选
  257. }
  258. switch (val)
  259. {
  260. case "True":
  261. e.CheckState = CheckState.Checked;
  262. break;
  263. case "False":
  264. e.CheckState = CheckState.Unchecked;
  265. break;
  266. //default:
  267. // e.CheckState = CheckState.Checked;
  268. // break;
  269. }
  270. e.Handled = true;
  271. }
  272. private void repositoryItemCheckEdit1_QueryValueByCheckState(object sender, DevExpress.XtraEditors.Controls.QueryValueByCheckStateEventArgs e)
  273. {
  274. //if (e.CheckState == CheckState.Checked)
  275. //{
  276. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colRESULT, 1);
  277. //}
  278. //else
  279. //{
  280. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colRESULT, 0);
  281. //}
  282. }
  283. #region 保存
  284. private void btnSave_Click(object sender, EventArgs e)
  285. {
  286. List<string> guidList = new List<string>();
  287. for (int i = 0; i < grvDetail.RowCount; i++)
  288. {
  289. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  290. {
  291. guidList.Add(grvDetail.GetRowCellValue(i, colEQPCode).ToString());
  292. }
  293. }
  294. if (guidList.Count == 0)
  295. {
  296. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  297. return;
  298. }
  299. for (int i = 0; i < grvDetail.RowCount; i++)
  300. {
  301. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  302. {
  303. FormICSEQPMaintainLogUIModel equipmentInfo = new FormICSEQPMaintainLogUIModel();
  304. equipmentInfo.Guid = AppConfig.GetGuid(); ;
  305. equipmentInfo.EQPID = grvDetail.GetRowCellValue(i, colEQPID).ToString();
  306. equipmentInfo.EQPCode = grvDetail.GetRowCellValue(i, colEQPCode).ToString();
  307. equipmentInfo.MaintainItem = grvDetail.GetRowCellValue(i, colMaintainItem).ToString();
  308. equipmentInfo.MEMO = grvDetail.GetRowCellValue(i, colMEMO).ToString();
  309. if (grvDetail.GetRowCellValue(i, colRESULT).ToString().Equals("True"))
  310. {
  311. equipmentInfo.RESULT = "OK";
  312. }
  313. if (grvDetail.GetRowCellValue(i, colRESULT).ToString().Equals("False"))
  314. {
  315. equipmentInfo.RESULT = "NG";
  316. }
  317. equipmentInfo.MUSER = AppConfig.UserId;
  318. equipmentInfo.MUSERName = AppConfig.UserName;
  319. equipmentInfo.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  320. equipmentInfo.WorkPoint = AppConfig.WorkPointCode;
  321. equipmentInfo.EATTRIBUTE1 = null;
  322. try
  323. {
  324. ICSEQPMaintainLogBLL.Add(equipmentInfo, AppConfig.AppConnectString);
  325. //this.Close();
  326. }
  327. catch (Exception ex)
  328. {
  329. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  330. }
  331. }
  332. }
  333. ICSBaseSimpleCode.AppshowMessageBox("操作成功");
  334. //btnFalsh_Click(null, null);
  335. }
  336. #endregion
  337. private string getcheckeditvalue(object sender, EventArgs e)
  338. {
  339. string result="";
  340. if (repositoryItemCheckEdit1.Equals("True"))
  341. {
  342. result = "OK";
  343. }
  344. if (repositoryItemCheckEdit1.Equals("False"))
  345. {
  346. result = "NG";
  347. }
  348. return result;
  349. }
  350. //#region 绑定数据源
  351. //private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  352. //{
  353. // if (AppConfig.UserCode.ToLower() != "demo")
  354. // {
  355. // //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  356. // return;
  357. // }
  358. // FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  359. // fdata.ShowDialog();
  360. //}
  361. //#endregion
  362. private void FormICSShift_Load(object sender, EventArgs e)
  363. {
  364. try
  365. {
  366. string sql = @"select '' as isSelect, b.EQPID as EQPID,b.EQPCode as EQPCode,b.EQPName as EQPName,c.MaintainItem as MaintainItem,
  367. '' as MEMO,cast( 0 as bit) as RESULT,''as MUSERName,'' as MTIME
  368. from ICSEquipment b
  369. left join ICSEQPMaintainPlan c on b.EQPCode=c.EQPCode
  370. where 1=1";
  371. DataTable ddf = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  372. grdDetail.DataSource = ddf;
  373. }
  374. catch (Exception ex)
  375. {
  376. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  377. }
  378. }
  379. //#region 修改
  380. //private void btnEdit_Click(object sender, EventArgs e)
  381. //{
  382. // SimpleButton btntemp = (SimpleButton)sender;
  383. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  384. // {
  385. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  386. // return;
  387. // }
  388. // int count = 0;
  389. // for (int i = 0; i < grvDetail.RowCount; i++)
  390. // {
  391. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  392. // {
  393. // count++;
  394. // }
  395. // }
  396. // if (count != 1)
  397. // {
  398. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  399. // return;
  400. // }
  401. // try
  402. // {
  403. // string id;
  404. // for (int i = 0; i < grvDetail.RowCount; i++)
  405. // {
  406. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  407. // {
  408. // //id = grvDetail.GetRowCellValue(i, colGUID).ToString();
  409. // //FormICSEQPMaintainPlanAdd add = new FormICSEQPMaintainPlanAdd(id);
  410. // //add.ShowDialog();
  411. // }
  412. // }
  413. // btnFalsh_Click(null, null);
  414. // }
  415. // catch (Exception ex)
  416. // {
  417. // //throw ex;
  418. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  419. // }
  420. //}
  421. //#endregion
  422. private void btnOutPut_Click(object sender, EventArgs e)
  423. {
  424. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  425. foe.ShowDialog();
  426. }
  427. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  428. {
  429. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  430. {
  431. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  432. }
  433. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  434. {
  435. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  436. }
  437. }
  438. #region 测试项目按钮
  439. private void repositoryItemButtonEdit1_BottonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  440. {
  441. ButtonEdit btn = (ButtonEdit)sender;
  442. string sql = "select 'OK' as 保养结果 union all select 'NG' as 保养结果 WHERE 1=1";
  443. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  444. //if (obj == null)
  445. //{
  446. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  447. //}
  448. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  449. FormDataRefer reForm = new FormDataRefer();
  450. reForm.FormTitle = "保养结果";
  451. DataTable menuData = data;
  452. reForm.DataSource = menuData;
  453. reForm.MSelectFlag = false;
  454. reForm.RowIndexWidth = 35;
  455. reForm.HideCols.Add("ID");
  456. reForm.FormWidth = 500;
  457. reForm.FormHeight = 500;
  458. //reForm.FilterKey = btn.Text;
  459. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  460. if (reForm.ShowDialog() == DialogResult.OK)
  461. {
  462. DataTable retData = reForm.ReturnData;
  463. foreach (DataRow dr in retData.Rows)
  464. {
  465. if (grvDetail.FocusedColumn == colRESULT)
  466. {
  467. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colRESULT, dr["保养结果"].ToString());
  468. }
  469. }
  470. }
  471. }
  472. #endregion
  473. }
  474. }