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

435 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 FormICSShift : 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 FormICSShift()
  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(btnAdd);
  82. ControlList.Add(btnEdit);
  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 btnDel_Click(object sender, EventArgs e)
  243. {
  244. grvDetail.PostEditor();
  245. this.Validate();
  246. if (grvDetail.RowCount == 0)
  247. return;
  248. SimpleButton btntemp = (SimpleButton)sender;
  249. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  250. {
  251. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  252. }
  253. List<string> guidList = new List<string>();
  254. List<string> guidList1 = new List<string>();
  255. for (int i = 0; i < grvDetail.RowCount; i++)
  256. {
  257. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  258. {
  259. guidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  260. }
  261. }
  262. if (guidList.Count == 0)
  263. {
  264. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  265. return;
  266. }
  267. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该班次吗?班次删除后无法恢复,确定吗?") != DialogResult.OK)
  268. return;
  269. try
  270. {
  271. if (!ICSShiftBLL.isIncludingInICSTP(guidList, AppConfig.AppConnectString))
  272. {
  273. ICSShiftBLL.delete(guidList);
  274. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  275. }
  276. else
  277. {
  278. ICSBaseSimpleCode.AppshowMessageBox("该班次在时段维护中已经存在,暂时无法删除");
  279. return;
  280. }
  281. }
  282. catch (Exception ex)
  283. {
  284. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  285. }
  286. btnFalsh_Click(null, null);
  287. }
  288. #endregion
  289. #region 新增
  290. private void btnAdd_Click(object sender, EventArgs e)
  291. {
  292. SimpleButton btntemp = (SimpleButton)sender;
  293. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  294. {
  295. MessageBox.Show("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  296. return;
  297. }
  298. FormICSShiftAdd add = new FormICSShiftAdd();
  299. add.ShowDialog();
  300. btnFalsh_Click(null, null);
  301. }
  302. #endregion
  303. #region 绑定数据源
  304. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  305. {
  306. if (AppConfig.UserCode.ToLower() != "demo")
  307. {
  308. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  309. return;
  310. }
  311. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  312. fdata.ShowDialog();
  313. }
  314. #endregion
  315. private void FormICSShift_Load(object sender, EventArgs e)
  316. {
  317. btnFilter_Click(sender, e);
  318. }
  319. #region 修改
  320. private void btnEdit_Click(object sender, EventArgs e)
  321. {
  322. SimpleButton btntemp = (SimpleButton)sender;
  323. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  324. {
  325. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  326. return;
  327. }
  328. int count = 0;
  329. for (int i = 0; i < grvDetail.RowCount; i++)
  330. {
  331. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  332. {
  333. count++;
  334. }
  335. }
  336. if (count != 1)
  337. {
  338. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  339. return;
  340. }
  341. try
  342. {
  343. string Code;
  344. for (int i = 0; i < grvDetail.RowCount; i++)
  345. {
  346. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  347. {
  348. Code = grvDetail.GetRowCellValue(i, colSHIFTCODE).ToString();
  349. FormICSShiftAdd add = new FormICSShiftAdd(Code);
  350. add.ShowDialog();
  351. }
  352. }
  353. btnFalsh_Click(null, null);
  354. }
  355. catch (Exception ex)
  356. {
  357. //throw ex;
  358. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  359. }
  360. }
  361. #endregion
  362. private void btnOutPut_Click(object sender, EventArgs e)
  363. {
  364. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  365. foe.ShowDialog();
  366. }
  367. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  368. {
  369. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTBTIME")
  370. {
  371. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  372. }
  373. if (e.RowHandle >= 0 && e.Column.FieldName == "SHIFTETIME")
  374. {
  375. e.DisplayText = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(e.CellValue.ToString()));
  376. }
  377. }
  378. }
  379. }