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

394 lines
14 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 FromICSDateDiff : 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 FromICSDateDiff()
  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 FromICSDateDiff(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. foreach (Control ctr in ControlList)
  125. {
  126. if (ctr.GetType() == typeof(SimpleButton))
  127. {
  128. DataRow dr = rData.NewRow();
  129. dr["BtnName"] = ctr.Name;
  130. dr["ActionName"] = ctr.Text;
  131. rData.Rows.Add(dr);
  132. }
  133. }
  134. rData.AcceptChanges();
  135. return rData;
  136. }
  137. /// <summary>
  138. /// 数据权限
  139. /// </summary>
  140. /// <returns></returns>
  141. public DataTable RightOfData()
  142. {
  143. DataTable rData = new DataTable();
  144. rData.Columns.Add("BodyName");
  145. rData.Columns.Add("ControlName");
  146. rData.Columns.Add("ControlCaption");
  147. rData.AcceptChanges();
  148. return rData;
  149. }
  150. #endregion
  151. #region 退出
  152. private void btnClose_Click(object sender, EventArgs e)
  153. {
  154. AppConfig.CloseFormShow(this.Text);
  155. this.Close();
  156. }
  157. private void btnExit_Click(object sender, EventArgs e)
  158. {
  159. AppConfig.CloseFormShow(this.Text);
  160. this.Close();
  161. }
  162. #endregion
  163. #region 过滤
  164. private string tempTableName = "";
  165. private void btnFilter_Click(object sender, EventArgs e)
  166. {
  167. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  168. filter.OldTempTableName = tempTableName;
  169. if (filter.ShowDialog() == DialogResult.OK)
  170. {
  171. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  172. try
  173. {
  174. _wait.Show();
  175. tempTableName = filter.NewTempTableName;
  176. sqltxt = filter.SqlText;
  177. sqlconn = filter.FilterConnectString;
  178. dataSource = filter.FilterData.Tables[0];
  179. grdDetail.DataSource = dataSource;
  180. grvDetail.BestFitColumns();
  181. rptPage.RecordNum = dataSource.Rows.Count;
  182. rptPage.PageSize = 499;
  183. rptPage.PageIndex = 1;
  184. rptPage.ReLoad();
  185. rptPage.PageSize = 500;
  186. rptPage.PageIndex = 1;
  187. rptPage.ReLoad();
  188. _wait.Close();
  189. }
  190. catch (Exception ex)
  191. {
  192. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  193. _wait.Close();
  194. }
  195. }
  196. }
  197. #endregion
  198. #region 分页
  199. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  200. {
  201. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  202. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  203. grdDetail.DataSource = data;
  204. }
  205. #endregion
  206. #region 刷新
  207. private void btnFalsh_Click(object sender, EventArgs e)
  208. {
  209. if (sqlconn == null || sqlconn == "")
  210. {
  211. return;
  212. }
  213. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  214. try
  215. {
  216. _wait.Show();
  217. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  218. filter.OldTempTableName = tempTableName;
  219. //tempTableName = filter.NewTempTableName;
  220. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  221. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  222. grdDetail.DataSource = dataSource;
  223. grvDetail.BestFitColumns();
  224. rptPage.RecordNum = dataSource.Rows.Count;
  225. rptPage.PageIndex = 1;
  226. rptPage.ReLoad();
  227. _wait.Close();
  228. }
  229. catch (Exception ex)
  230. {
  231. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  232. _wait.Close();
  233. }
  234. }
  235. #endregion
  236. #region 列表
  237. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  238. {
  239. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  240. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  241. }
  242. #endregion
  243. #region 双击选择:单选
  244. private void grvDetail_DoubleClick(object sender, EventArgs e)
  245. {
  246. if (grvDetail.FocusedRowHandle < 0)
  247. {
  248. return;
  249. }
  250. if (grvDetail.FocusedColumn == colisSelect)
  251. {
  252. string oriSelected = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString();
  253. for (int i = 0; i < grvDetail.RowCount; i++)
  254. {
  255. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  256. }
  257. if (oriSelected == "")
  258. {
  259. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  260. id = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString();
  261. btnSave.Text = "修改";
  262. }
  263. else
  264. {
  265. id = "";
  266. btnSave.Text = "新增";
  267. }
  268. }
  269. }
  270. #endregion
  271. string id = "";
  272. #region 编辑
  273. private void btnSave_Click(object sender, EventArgs e)
  274. {
  275. SimpleButton btntemp = (SimpleButton)sender;
  276. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  277. {
  278. MessageBox.Show("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  279. return;
  280. }
  281. try
  282. {
  283. FromICSDateDiffAdd add = new FromICSDateDiffAdd(id);
  284. DialogResult dr = add.ShowDialog();
  285. if (dr == DialogResult.OK)
  286. {
  287. ICSBaseSimpleCode.AppshowMessageBox(btnSave.Text + "OK");
  288. btnSave.Text = "新增";
  289. btnFalsh_Click(null, null);
  290. }
  291. }
  292. catch (Exception ex)
  293. {
  294. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  295. }
  296. }
  297. #endregion
  298. #region 绑定数据源
  299. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  300. {
  301. if (AppConfig.UserCode.ToLower() != "demo")
  302. {
  303. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  304. return;
  305. }
  306. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  307. fdata.ShowDialog();
  308. }
  309. #endregion
  310. private void FormICSShift_Load(object sender, EventArgs e)
  311. {
  312. btnFilter_Click(sender, e);
  313. }
  314. private void btnOutPut_Click(object sender, EventArgs e)
  315. {
  316. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  317. foe.ShowDialog();
  318. }
  319. //#region 全选
  320. //private void btnSelect_Click(object sender, EventArgs e)
  321. //{
  322. // for (int i = 0; i < grvDetail.RowCount; i++)
  323. // {
  324. // grvDetail.SetRowCellValue(i, colisSelect, "Y");
  325. // }
  326. //}
  327. //#endregion
  328. //#region 全消
  329. //private void btnCanSelect_Click(object sender, EventArgs e)
  330. //{
  331. // for (int i = 0; i < grvDetail.RowCount; i++)
  332. // {
  333. // grvDetail.SetRowCellValue(i, colisSelect, "");
  334. // }
  335. //}
  336. //#endregion
  337. //private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  338. //{
  339. // if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  340. // {
  341. // e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  342. // }
  343. // if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  344. // {
  345. // e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  346. // }
  347. //}
  348. }
  349. }