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

436 lines
15 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 FormICSEQPData : 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 FormICSEQPData()
  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. ICSEQPDataBLL.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. FormICSEQPDataInfoAdd add = new FormICSEQPDataInfoAdd();
  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. FormICSEQPDataAdd add = new FormICSEQPDataAdd(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. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  358. foe.ShowDialog();
  359. }
  360. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  361. {
  362. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  363. {
  364. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  365. }
  366. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  367. {
  368. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  369. }
  370. }
  371. private void FormICSEQPMaintainPlan_Load(object sender, EventArgs e)
  372. {
  373. btnFilter_Click(sender, e);
  374. }
  375. }
  376. }