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

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