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

531 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. using ICSSoft.Frame.Data.Entity;
  19. namespace ICSSoft.Frame.APP
  20. {
  21. public partial class FormICSEQPHandle : 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 FormICSEQPHandle()
  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. public FormICSEQPHandle(string EQPID)
  37. {
  38. InitializeComponent();
  39. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  40. this.WindowState = FormWindowState.Maximized;
  41. chargeFormState("view");
  42. SearchItemLotInfo(EQPID);
  43. }
  44. #endregion
  45. private void chargeFormState(string state)
  46. {
  47. switch (state)
  48. {
  49. case "view":
  50. btnFilter.Enabled = false;
  51. btnConfig.Enabled = false;
  52. break;
  53. //case "Edit":
  54. // //txtModel.Properties.ReadOnly = true;
  55. // //txtEQPStatus.Properties.ReadOnly = false;
  56. // txtMUSERName.Properties.ReadOnly = true;
  57. // txtMTIME.Properties.ReadOnly = true;
  58. // break;
  59. }
  60. }
  61. private void SearchItemLotInfo(string EQPID)
  62. {
  63. string sql = @"select '' as [isSelect],
  64. b.EQPID as EQPID,
  65. b.EQPCode as EQPCode,
  66. b.EQPName as EQPName,
  67. b.EQPStatus as EQPStatus,
  68. b.MUSERName as MUSERName,
  69. b.MTIME as MTIME
  70. from dbo.ICSEquipment b
  71. where b.EQPID='{0}'";
  72. sql = string.Format(sql, EQPID);
  73. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  74. grdDetail.DataSource = dt;
  75. }
  76. #region 移动窗体
  77. private const int WM_NCHITTEST = 0x84;
  78. private const int HTCLIENT = 0x1;
  79. private const int HTCAPTION = 0x2;
  80. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  81. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  82. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  83. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  84. //重写窗体,使窗体可以不通过自带标题栏实现移动
  85. protected override void WndProc(ref Message m)
  86. {
  87. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  88. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  89. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  90. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  91. switch (m.Msg)
  92. {
  93. case WM_NCHITTEST:
  94. base.WndProc(ref m);
  95. if ((int)m.Result == HTCLIENT)
  96. m.Result = (IntPtr)HTCAPTION;
  97. return;
  98. }
  99. //拦截双击标题栏、移动窗体的系统消息
  100. if (m.Msg != 0xA3)
  101. {
  102. base.WndProc(ref m);
  103. }
  104. }
  105. #endregion
  106. #region SystemOptition
  107. /// <summary>
  108. /// 操作权限
  109. /// </summary>
  110. /// <returns></returns>
  111. public DataTable RightOfExute()
  112. {
  113. DataTable rData = new DataTable();
  114. rData.Columns.Add("BtnName");
  115. rData.Columns.Add("ActionName");
  116. //查看权限(必须有)
  117. DataRow seeRow = rData.NewRow();
  118. seeRow["BtnName"] = "see";
  119. seeRow["ActionName"] = "查看";
  120. rData.Rows.Add(seeRow);
  121. List<Control> ControlList = new List<Control>();
  122. ControlList.Add(btnConfig);
  123. ControlList.Add(btnSave);
  124. //ControlList.Add(btnEdit);
  125. //ControlList.Add(btnDelLable);
  126. foreach (Control ctr in ControlList)
  127. {
  128. if (ctr.GetType() == typeof(SimpleButton))
  129. {
  130. DataRow dr = rData.NewRow();
  131. dr["BtnName"] = ctr.Name;
  132. dr["ActionName"] = ctr.Text;
  133. rData.Rows.Add(dr);
  134. }
  135. }
  136. rData.AcceptChanges();
  137. return rData;
  138. }
  139. /// <summary>
  140. /// 数据权限
  141. /// </summary>
  142. /// <returns></returns>
  143. public DataTable RightOfData()
  144. {
  145. DataTable rData = new DataTable();
  146. rData.Columns.Add("BodyName");
  147. rData.Columns.Add("ControlName");
  148. rData.Columns.Add("ControlCaption");
  149. rData.AcceptChanges();
  150. return rData;
  151. }
  152. #endregion
  153. #region 退出
  154. private void btnClose_Click(object sender, EventArgs e)
  155. {
  156. AppConfig.CloseFormShow(this.Text);
  157. this.Close();
  158. }
  159. private void btnExit_Click(object sender, EventArgs e)
  160. {
  161. AppConfig.CloseFormShow(this.Text);
  162. this.Close();
  163. }
  164. #endregion
  165. #region 过滤
  166. private string tempTableName = "";
  167. private void btnFilter_Click(object sender, EventArgs e)
  168. {
  169. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  170. filter.OldTempTableName = tempTableName;
  171. if (filter.ShowDialog() == DialogResult.OK)
  172. {
  173. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  174. try
  175. {
  176. _wait.Show();
  177. tempTableName = filter.NewTempTableName;
  178. sqltxt = filter.SqlText;
  179. sqlconn = filter.FilterConnectString;
  180. dataSource = filter.FilterData.Tables[0];
  181. grdDetail.DataSource = dataSource;
  182. grvDetail.BestFitColumns();
  183. rptPage.RecordNum = dataSource.Rows.Count;
  184. rptPage.PageSize = 499;
  185. rptPage.PageIndex = 1;
  186. rptPage.ReLoad();
  187. rptPage.PageSize = 500;
  188. rptPage.PageIndex = 1;
  189. rptPage.ReLoad();
  190. _wait.Close();
  191. }
  192. catch (Exception ex)
  193. {
  194. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  195. _wait.Close();
  196. }
  197. }
  198. }
  199. #endregion
  200. #region 分页
  201. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  202. {
  203. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  204. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  205. grdDetail.DataSource = data;
  206. }
  207. #endregion
  208. #region 全选
  209. private void btnSelect_Click(object sender, EventArgs e)
  210. {
  211. for (int i = 0; i < grvDetail.RowCount; i++)
  212. {
  213. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  214. }
  215. }
  216. #endregion
  217. #region 全消
  218. private void btnCanSelect_Click(object sender, EventArgs e)
  219. {
  220. for (int i = 0; i < grvDetail.RowCount; i++)
  221. {
  222. grvDetail.SetRowCellValue(i, colisSelect, "");
  223. }
  224. }
  225. #endregion
  226. #region 刷新
  227. private void btnFalsh_Click(object sender, EventArgs e)
  228. {
  229. if (sqlconn == null || sqlconn == "")
  230. {
  231. return;
  232. }
  233. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  234. try
  235. {
  236. _wait.Show();
  237. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  238. filter.OldTempTableName = tempTableName;
  239. //tempTableName = filter.NewTempTableName;
  240. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  241. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  242. grdDetail.DataSource = dataSource;
  243. grvDetail.BestFitColumns();
  244. rptPage.RecordNum = dataSource.Rows.Count;
  245. rptPage.PageIndex = 1;
  246. rptPage.ReLoad();
  247. _wait.Close();
  248. }
  249. catch (Exception ex)
  250. {
  251. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  252. _wait.Close();
  253. }
  254. }
  255. #endregion
  256. #region 列表
  257. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  258. {
  259. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  260. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  261. }
  262. #endregion
  263. #region 双击选择
  264. private void grvDetail_DoubleClick(object sender, EventArgs e)
  265. {
  266. if (grvDetail.FocusedRowHandle < 0)
  267. {
  268. return;
  269. }
  270. if (grvDetail.FocusedColumn == colisSelect)
  271. {
  272. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  273. {
  274. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  275. }
  276. else
  277. {
  278. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  279. }
  280. }
  281. }
  282. #endregion
  283. #region 删除
  284. private void btnDel_Click(object sender, EventArgs e)
  285. {
  286. grvDetail.PostEditor();
  287. this.Validate();
  288. if (grvDetail.RowCount == 0)
  289. return;
  290. SimpleButton btntemp = (SimpleButton)sender;
  291. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  292. {
  293. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  294. }
  295. List<string> guidList = new List<string>();
  296. List<string> guidList1 = new List<string>();
  297. for (int i = 0; i < grvDetail.RowCount; i++)
  298. {
  299. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  300. {
  301. guidList.Add(grvDetail.GetRowCellValue(i, colEQPCode).ToString());
  302. guidList.Add(grvDetail.GetRowCellValue(i, colEQPStatus).ToString());
  303. }
  304. }
  305. if (guidList.Count == 0)
  306. {
  307. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  308. return;
  309. }
  310. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该设备导测试项目吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  311. return;
  312. try
  313. {
  314. ICSEQPCHECKLISTBLL.delete(guidList);
  315. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  316. }
  317. catch (Exception ex)
  318. {
  319. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  320. }
  321. btnFalsh_Click(null, null);
  322. }
  323. #endregion
  324. #region 保存
  325. private void btnSave_Click(object sender, EventArgs e)
  326. {
  327. string guid="";
  328. string status="";
  329. for (int i = 0; i < grvDetail.RowCount; i++)
  330. {
  331. guid=grvDetail.GetRowCellValue(i, colEQPID).ToString();
  332. status=grvDetail.GetRowCellValue(i, colEQPStatus).ToString();
  333. }
  334. try
  335. {
  336. ICSEQPHandleBLL.update(guid,status);
  337. ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功");
  338. }
  339. catch (Exception ex)
  340. {
  341. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  342. }
  343. btnFalsh_Click(null, null);
  344. }
  345. #endregion
  346. #region 绑定数据源
  347. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  348. {
  349. if (AppConfig.UserCode.ToLower() != "demo")
  350. {
  351. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  352. return;
  353. }
  354. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  355. fdata.ShowDialog();
  356. }
  357. #endregion
  358. private void FormICSShift_Load(object sender, EventArgs e)
  359. {
  360. btnFilter_Click(sender, e);
  361. }
  362. #region 修改
  363. private void btnEdit_Click(object sender, EventArgs e)
  364. {
  365. SimpleButton btntemp = (SimpleButton)sender;
  366. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  367. {
  368. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  369. return;
  370. }
  371. int count = 0;
  372. for (int i = 0; i < grvDetail.RowCount; i++)
  373. {
  374. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  375. {
  376. count++;
  377. }
  378. }
  379. if (count != 1)
  380. {
  381. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  382. return;
  383. }
  384. try
  385. {
  386. string eqpid;
  387. string ckgroup;
  388. for (int i = 0; i < grvDetail.RowCount; i++)
  389. {
  390. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  391. {
  392. eqpid = grvDetail.GetRowCellValue(i, colEQPID).ToString();
  393. ckgroup = grvDetail.GetRowCellValue(i, colEQPStatus).ToString();
  394. FormICSEQPCHECKLISTAdd add = new FormICSEQPCHECKLISTAdd(eqpid, ckgroup);
  395. add.ShowDialog();
  396. }
  397. }
  398. btnFalsh_Click(null, null);
  399. }
  400. catch (Exception ex)
  401. {
  402. //throw ex;
  403. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  404. }
  405. }
  406. #endregion
  407. private void btnOutPut_Click(object sender, EventArgs e)
  408. {
  409. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  410. foe.ShowDialog();
  411. }
  412. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  413. {
  414. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  415. {
  416. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  417. }
  418. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  419. {
  420. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  421. }
  422. }
  423. private void repositoryItemButtonEdit1_BottonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  424. {
  425. ButtonEdit btn = (ButtonEdit)sender;
  426. string sql = "select '投产' as 状态 union all select '转固' as 状态 union all select '报废' as 状态 union all select '闲置' as 状态 union all select '开启' as 状态 WHERE 1=1";
  427. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  428. //if (obj == null)
  429. //{
  430. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  431. //}
  432. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  433. FormDataRefer reForm = new FormDataRefer();
  434. reForm.FormTitle = "设备信息";
  435. DataTable menuData = data;
  436. reForm.DataSource = menuData;
  437. reForm.MSelectFlag = false;
  438. reForm.RowIndexWidth = 35;
  439. reForm.HideCols.Add("ID");
  440. reForm.FormWidth = 500;
  441. reForm.FormHeight = 500;
  442. //reForm.FilterKey = btn.Text;
  443. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  444. if (reForm.ShowDialog() == DialogResult.OK)
  445. {
  446. DataTable retData = reForm.ReturnData;
  447. foreach (DataRow dr in retData.Rows)
  448. {
  449. if (grvDetail.FocusedColumn == colEQPStatus)
  450. {
  451. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPStatus, dr["状态"].ToString());
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }