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

384 lines
13 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 FromICSEQPWeeklyMaintenance : DevExpress.XtraEditors.XtraForm
  22. {
  23. private string sqltxt = "";
  24. private string sqlconn = "";
  25. private DataTable dataSource = null;
  26. #region 构造函数
  27. public FromICSEQPWeeklyMaintenance()
  28. {
  29. InitializeComponent();
  30. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  31. this.WindowState = FormWindowState.Maximized;
  32. }
  33. #endregion
  34. #region 移动窗体
  35. private const int WM_NCHITTEST = 0x84;
  36. private const int HTCLIENT = 0x1;
  37. private const int HTCAPTION = 0x2;
  38. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  39. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  40. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  41. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  42. //重写窗体,使窗体可以不通过自带标题栏实现移动
  43. protected override void WndProc(ref Message m)
  44. {
  45. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  46. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  47. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  48. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  49. switch (m.Msg)
  50. {
  51. case WM_NCHITTEST:
  52. base.WndProc(ref m);
  53. if ((int)m.Result == HTCLIENT)
  54. m.Result = (IntPtr)HTCAPTION;
  55. return;
  56. }
  57. //拦截双击标题栏、移动窗体的系统消息
  58. if (m.Msg != 0xA3)
  59. {
  60. base.WndProc(ref m);
  61. }
  62. }
  63. #endregion
  64. #region SystemOptition
  65. /// <summary>
  66. /// 操作权限
  67. /// </summary>
  68. /// <returns></returns>
  69. public DataTable RightOfExute()
  70. {
  71. DataTable rData = new DataTable();
  72. rData.Columns.Add("BtnName");
  73. rData.Columns.Add("ActionName");
  74. //查看权限(必须有)
  75. DataRow seeRow = rData.NewRow();
  76. seeRow["BtnName"] = "see";
  77. seeRow["ActionName"] = "查看";
  78. rData.Rows.Add(seeRow);
  79. List<Control> ControlList = new List<Control>();
  80. ControlList.Add(btnConfig);
  81. ControlList.Add(btnModify);
  82. ControlList.Add(btnDel);
  83. //ControlList.Add(btnDelLable);
  84. foreach (Control ctr in ControlList)
  85. {
  86. if (ctr.GetType() == typeof(SimpleButton))
  87. {
  88. DataRow dr = rData.NewRow();
  89. dr["BtnName"] = ctr.Name;
  90. dr["ActionName"] = ctr.Text;
  91. rData.Rows.Add(dr);
  92. }
  93. }
  94. rData.AcceptChanges();
  95. return rData;
  96. }
  97. /// <summary>
  98. /// 数据权限
  99. /// </summary>
  100. /// <returns></returns>
  101. public DataTable RightOfData()
  102. {
  103. DataTable rData = new DataTable();
  104. rData.Columns.Add("BodyName");
  105. rData.Columns.Add("ControlName");
  106. rData.Columns.Add("ControlCaption");
  107. rData.AcceptChanges();
  108. return rData;
  109. }
  110. #endregion
  111. #region 退出
  112. private void btnClose_Click(object sender, EventArgs e)
  113. {
  114. AppConfig.CloseFormShow(this.Text);
  115. this.Close();
  116. }
  117. private void btnExit_Click(object sender, EventArgs e)
  118. {
  119. AppConfig.CloseFormShow(this.Text);
  120. this.Close();
  121. }
  122. #endregion
  123. #region 过滤
  124. private string tempTableName = "";
  125. private void btnFilter_Click(object sender, EventArgs e)
  126. {
  127. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  128. filter.OldTempTableName = tempTableName;
  129. if (filter.ShowDialog() == DialogResult.OK)
  130. {
  131. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  132. try
  133. {
  134. _wait.Show();
  135. tempTableName = filter.NewTempTableName;
  136. sqltxt = filter.SqlText;
  137. sqlconn = filter.FilterConnectString;
  138. dataSource = filter.FilterData.Tables[0];
  139. grdDetail.DataSource = dataSource;
  140. grvDetail.BestFitColumns();
  141. rptPage.RecordNum = dataSource.Rows.Count;
  142. rptPage.PageSize = 499;
  143. rptPage.PageIndex = 1;
  144. rptPage.ReLoad();
  145. rptPage.PageSize = 500;
  146. rptPage.PageIndex = 1;
  147. rptPage.ReLoad();
  148. _wait.Close();
  149. }
  150. catch (Exception ex)
  151. {
  152. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  153. _wait.Close();
  154. }
  155. }
  156. }
  157. #endregion
  158. #region 分页
  159. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  160. {
  161. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  162. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  163. grdDetail.DataSource = data;
  164. }
  165. #endregion
  166. #region 全选
  167. private void btnSelect_Click(object sender, EventArgs e)
  168. {
  169. for (int i = 0; i < grvDetail.RowCount; i++)
  170. {
  171. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  172. }
  173. }
  174. #endregion
  175. #region 全消
  176. private void btnCanSelect_Click(object sender, EventArgs e)
  177. {
  178. for (int i = 0; i < grvDetail.RowCount; i++)
  179. {
  180. grvDetail.SetRowCellValue(i, colisSelect, "");
  181. }
  182. }
  183. #endregion
  184. #region 刷新
  185. private void btnFalsh_Click(object sender, EventArgs e)
  186. {
  187. if (sqlconn == null || sqlconn == "")
  188. {
  189. return;
  190. }
  191. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  192. try
  193. {
  194. _wait.Show();
  195. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  196. filter.OldTempTableName = tempTableName;
  197. //tempTableName = filter.NewTempTableName;
  198. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  199. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  200. grdDetail.DataSource = dataSource;
  201. grvDetail.BestFitColumns();
  202. rptPage.RecordNum = dataSource.Rows.Count;
  203. rptPage.PageIndex = 1;
  204. rptPage.ReLoad();
  205. _wait.Close();
  206. }
  207. catch (Exception ex)
  208. {
  209. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  210. _wait.Close();
  211. }
  212. }
  213. #endregion
  214. #region 列表
  215. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  216. {
  217. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  218. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  219. }
  220. #endregion
  221. #region 双击选择
  222. private void grvDetail_DoubleClick(object sender, EventArgs e)
  223. {
  224. if (grvDetail.FocusedRowHandle < 0)
  225. {
  226. return;
  227. }
  228. if (grvDetail.FocusedColumn == colisSelect)
  229. {
  230. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  231. {
  232. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  233. }
  234. else
  235. {
  236. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  237. }
  238. }
  239. }
  240. #endregion
  241. #region 绑定数据源
  242. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  243. {
  244. if (AppConfig.UserCode.ToLower() != "demo")
  245. {
  246. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  247. return;
  248. }
  249. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  250. fdata.ShowDialog();
  251. }
  252. #endregion
  253. private void ICSEQPWeeklyMaintenanceAdd_Load(object sender, EventArgs e)
  254. {
  255. btnFilter_Click(sender, e);
  256. }
  257. #region 编辑
  258. private void btnModify_Click(object sender, EventArgs e)
  259. {
  260. string EQPID = "";
  261. for (int i = 0; i < grvDetail.RowCount; i++)
  262. {
  263. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  264. {
  265. string selectedEQPID = grvDetail.GetRowCellValue(i, colEQPID).ToString(); ;
  266. if (EQPID == "")
  267. {
  268. EQPID = selectedEQPID;
  269. }
  270. else
  271. {
  272. if (EQPID != selectedEQPID)
  273. {
  274. ICSBaseSimpleCode.AppshowMessageBox("只能选择一台设备进行修改");
  275. return;
  276. }
  277. }
  278. }
  279. }
  280. try
  281. {
  282. FromICSEQPWeeklyMaintenanceAdd f = new FromICSEQPWeeklyMaintenanceAdd(EQPID);
  283. f.ShowDialog();
  284. }
  285. catch (Exception ex)
  286. {
  287. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  288. }
  289. btnFalsh_Click(null, null);
  290. }
  291. #endregion
  292. #region 删除
  293. private void btnDel_Click(object sender, EventArgs e)
  294. {
  295. List<string> list = new List<string>();
  296. for (int i = 0; i < grvDetail.RowCount; i++)
  297. {
  298. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  299. {
  300. string id = grvDetail.GetRowCellValue(i, colID).ToString();
  301. list.Add(id);
  302. }
  303. }
  304. if (list.Count == 0)
  305. {
  306. return;
  307. }
  308. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在删除...请稍等...");
  309. try
  310. {
  311. _wait.Show();
  312. ICSEQPWeeklyMaintenanceBLL.DeleteById(list, AppConfig.AppConnectString);
  313. _wait.Close();
  314. }
  315. catch (Exception ex)
  316. {
  317. _wait.Close();
  318. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  319. }
  320. btnFalsh_Click(null, null);
  321. }
  322. #endregion
  323. #region 导出
  324. private void btnOutPut_Click(object sender, EventArgs e)
  325. {
  326. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  327. foe.ShowDialog();
  328. }
  329. #endregion
  330. private void btnSave_Click(object sender, EventArgs e)
  331. {
  332. try
  333. {
  334. FromICSEQPWeeklyMaintenanceAdd f = new FromICSEQPWeeklyMaintenanceAdd("");
  335. f.ShowDialog();
  336. }
  337. catch (Exception ex)
  338. {
  339. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  340. }
  341. btnFalsh_Click(null, null);
  342. }
  343. }
  344. }