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

545 lines
19 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.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Base.Report.Filter;
  15. using ICSSoft.Base.Config.DBHelper;
  16. using ICSSoft.Base.UserControl.FormControl;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Base.Lable.PrintTool;
  19. using ICSSoft.Frame.Data.DAL;
  20. using ICSSoft.Frame.Data.BLL;
  21. using ICSSoft.Frame.Data.Entity;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSMO2User : DevExpress.XtraEditors.XtraForm
  25. {
  26. private string sqltxt = "";
  27. private string sqlconn = "";
  28. String guid = AppConfig.GetGuid();
  29. private DataTable dataSource = null;
  30. #region 构造函数
  31. public FormICSMO2User()
  32. {
  33. InitializeComponent();
  34. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  35. this.WindowState = FormWindowState.Maximized;
  36. foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns)
  37. {
  38. // col.OptionsColumn.AllowEdit = col.Name == colSerial.Name;
  39. // col.OptionsColumn.ReadOnly = true;
  40. }
  41. }
  42. #endregion
  43. #region 操作权限
  44. public DataTable RightOfExute()
  45. {
  46. DataTable rData = new DataTable();
  47. rData.Columns.Add("BtnName");
  48. rData.Columns.Add("ActionName");
  49. //查看权限(必须有)
  50. DataRow seeRow = rData.NewRow();
  51. seeRow["BtnName"] = "see";
  52. seeRow["ActionName"] = "查看";
  53. rData.Rows.Add(seeRow);
  54. foreach (Control ctr in panelControl3.Controls)
  55. {
  56. if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name ||
  57. ctr.Name == btnSelectAll.Name || ctr.Name == btnCancelAll.Name ||
  58. ctr.Name == btnOutPut.Name ||
  59. ctr.Name == btnRefresh.Name || ctr.Name == btnExit.Name || ctr.Name == MOTitle.Name || ctr.Name == btnClose.Name)
  60. continue;
  61. DataRow dr = rData.NewRow();
  62. dr["BtnName"] = ctr.Name;
  63. dr["ActionName"] = ctr.Text;
  64. rData.Rows.Add(dr);
  65. }
  66. //List<Control> ControlList = new List<Control>();
  67. ////ControlList.Add(btnCreate);
  68. ////ControlList.Add(btnModify);
  69. //ControlList.Add(btnsend);
  70. //ControlList.Add(btnOutPut);
  71. //foreach (Control ctr in ControlList)
  72. //{
  73. // if (ctr.GetType() == typeof(SimpleButton))
  74. // {
  75. // DataRow dr = rData.NewRow();
  76. // dr["BtnName"] = ctr.Name;
  77. // dr["ActionName"] = ctr.Text;
  78. // rData.Rows.Add(dr);
  79. // }
  80. //}
  81. rData.AcceptChanges();
  82. return rData;
  83. }
  84. public DataTable RightOfData()// 数据权限
  85. {
  86. DataTable rData = new DataTable();
  87. rData.Columns.Add("BodyName");
  88. rData.Columns.Add("ControlName");
  89. rData.Columns.Add("ControlCaption");
  90. rData.AcceptChanges();
  91. return rData;
  92. }
  93. #endregion
  94. #region 退出
  95. private void btnClose_Click(object sender, EventArgs e)
  96. {
  97. AppConfig.CloseFormShow(this.Text);
  98. this.Close();
  99. }
  100. private void btnExit_Click(object sender, EventArgs e)
  101. {
  102. AppConfig.CloseFormShow(this.Text);
  103. this.Close();
  104. }
  105. #endregion
  106. #region 移动窗体
  107. private const int WM_NCHITTEST = 0x84;
  108. private const int HTCLIENT = 0x1;
  109. private const int HTCAPTION = 0x2;
  110. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  111. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  112. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  113. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  114. //重写窗体,使窗体可以不通过自带标题栏实现移动
  115. protected override void WndProc(ref Message m)
  116. {
  117. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  118. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  119. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  120. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  121. switch (m.Msg)
  122. {
  123. case WM_NCHITTEST:
  124. base.WndProc(ref m);
  125. if ((int)m.Result == HTCLIENT)
  126. m.Result = (IntPtr)HTCAPTION;
  127. return;
  128. }
  129. //拦截双击标题栏、移动窗体的系统消息
  130. if (m.Msg != 0xA3)
  131. {
  132. base.WndProc(ref m);
  133. }
  134. }
  135. #endregion
  136. #region 列表
  137. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  138. {
  139. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  140. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  141. }
  142. #endregion
  143. #region 过滤
  144. private string tempTableName = "";
  145. private void btnFilter_Click(object sender, EventArgs e)
  146. {
  147. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  148. filter.OldTempTableName = tempTableName;
  149. if (filter.ShowDialog() == DialogResult.OK)
  150. {
  151. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  152. try
  153. {
  154. _wait.Show();
  155. tempTableName = filter.NewTempTableName;
  156. sqltxt = filter.SqlText;
  157. sqlconn = filter.FilterConnectString;
  158. dataSource = filter.FilterData.Tables[0];
  159. grdDetail.DataSource = dataSource;
  160. grvDetail.BestFitColumns();
  161. rptPage.RecordNum = dataSource.Rows.Count;
  162. rptPage.PageSize = 500;
  163. rptPage.PageIndex = 1;
  164. rptPage.ReLoad();
  165. _wait.Close();
  166. }
  167. catch (Exception ex)
  168. {
  169. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  170. _wait.Close();
  171. }
  172. }
  173. }
  174. #endregion
  175. #region 绑定数据源
  176. private void btnConfig_Click(object sender, EventArgs e)
  177. {
  178. if (AppConfig.UserCode.ToLower() != "demo")
  179. {
  180. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  181. return;
  182. }
  183. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  184. fdata.ShowDialog();
  185. }
  186. #endregion
  187. #region 分页
  188. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  189. {
  190. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  191. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  192. grdDetail.DataSource = data;
  193. }
  194. #endregion
  195. #region 过滤方法
  196. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  197. {
  198. AppConfig.DropTemTable(tempTableName);
  199. }
  200. #endregion
  201. #region 全选
  202. private void btnSelectAll_Click(object sender, EventArgs e)
  203. {
  204. grvDetail.PostEditor();
  205. this.Validate();
  206. for (int i = 0; i < grvDetail.RowCount; i++)
  207. {
  208. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  209. }
  210. }
  211. #endregion
  212. #region 全消
  213. private void btnCancelAll_Click(object sender, EventArgs e)
  214. {
  215. grvDetail.PostEditor();
  216. this.Validate();
  217. for (int i = 0; i < grvDetail.RowCount; i++)
  218. {
  219. grvDetail.SetRowCellValue(i, colisSelect, "");
  220. }
  221. }
  222. #endregion
  223. #region 双击
  224. private void grvDetail_DoubleClick(object sender, EventArgs e)
  225. {
  226. if (grvDetail.FocusedRowHandle < 0)
  227. {
  228. return;
  229. }
  230. if (grvDetail.FocusedColumn == colisSelect)
  231. {
  232. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  233. {
  234. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  235. }
  236. else
  237. {
  238. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  239. }
  240. }
  241. }
  242. #endregion
  243. #region 导出
  244. private void btnOutPut_Click(object sender, EventArgs e)
  245. {
  246. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  247. foe.ShowDialog();
  248. }
  249. #endregion
  250. #region 刷新
  251. private void btnRefresh_Click(object sender, EventArgs e)
  252. {
  253. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  254. try
  255. {
  256. _wait.Show();
  257. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  258. filter.OldTempTableName = tempTableName;
  259. //tempTableName = filter.NewTempTableName;
  260. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  261. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  262. grdDetail.DataSource = dataSource;
  263. grvDetail.BestFitColumns();
  264. rptPage.RecordNum = dataSource.Rows.Count;
  265. rptPage.PageIndex = 1;
  266. rptPage.ReLoad();
  267. _wait.Close();
  268. }
  269. catch (Exception ex)
  270. {
  271. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  272. _wait.Close();
  273. }
  274. }
  275. #endregion
  276. //#region 新增
  277. //private void btnCreate_Click(object sender, EventArgs e)
  278. //{
  279. // SimpleButton btntemp = (SimpleButton)sender;
  280. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  281. // {
  282. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  283. // return;
  284. // }
  285. // FormICSMOAdd add = new FormICSMOAdd();
  286. // add.ShowDialog();
  287. // btnRefresh_Click(null, null);
  288. //}
  289. //#endregion
  290. //#region 修改
  291. //private void btnModify_Click(object sender, EventArgs e)
  292. //{
  293. // SimpleButton btntemp = (SimpleButton)sender;
  294. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  295. // {
  296. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  297. // return;
  298. // }
  299. // int count = 0;
  300. // for (int i = 0; i < grvDetail.RowCount; i++)
  301. // {
  302. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  303. // {
  304. // count++;
  305. // }
  306. // }
  307. // if (count != 1)
  308. // {
  309. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  310. // return;
  311. // }
  312. // try
  313. // {
  314. // string moid;
  315. // for (int i = 0; i < grvDetail.RowCount; i++)
  316. // {
  317. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  318. // {
  319. // moid = grvDetail.GetRowCellValue(i, colID).ToString();
  320. // FormICSMOAdd add = new FormICSMOAdd(moid);
  321. // add.ShowDialog();
  322. // }
  323. // }
  324. // btnRefresh_Click(null, null);
  325. // }
  326. // catch (Exception ex)
  327. // {
  328. // //throw ex;
  329. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  330. // }
  331. //}
  332. //#endregion
  333. //#region 删除
  334. //private void btnDel_Click(object sender, EventArgs e)
  335. //{
  336. // SimpleButton btntemp = (SimpleButton)sender;
  337. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  338. // {
  339. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  340. // return;
  341. // }
  342. // List<string> moidList = new List<string>();
  343. // for (int i = 0; i < grvDetail.RowCount; i++)
  344. // {
  345. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  346. // {
  347. // moidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  348. // }
  349. // }
  350. // if (moidList.Count == 0 || moidList == null)
  351. // {
  352. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  353. // return;
  354. // }
  355. // if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除工单吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  356. // {
  357. // btnCancelAll_Click(sender, e);
  358. // return;
  359. // }
  360. // try
  361. // {
  362. // ICSMOBLL.deleteInfo(moidList, AppConfig.AppConnectString);
  363. // ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  364. // }
  365. // catch (Exception ex)
  366. // {
  367. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  368. // }
  369. // btnRefresh_Click(null, null);
  370. //}
  371. //#endregion
  372. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  373. {
  374. AppConfig.DropTemTable(tempTableName);
  375. }
  376. private void FormICSMO_Load(object sender, EventArgs e)
  377. {
  378. btnFilter_Click(sender, e);
  379. }
  380. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  381. {
  382. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  383. {
  384. //e.DisplayText = FormatHelper.
  385. e.CellValue = "cccc";
  386. }
  387. }
  388. #region 下发
  389. private void txtsend_Click(object sender, EventArgs e)
  390. {
  391. SimpleButton btntemp = (SimpleButton)sender;
  392. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  393. {
  394. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  395. return;
  396. }
  397. int count = 0;
  398. //20190704新增
  399. string MOCode = string.Empty;
  400. string moseq = string.Empty;
  401. for (int i = 0; i < grvDetail.RowCount; i++)
  402. {
  403. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  404. {
  405. count++;
  406. //20190704新增
  407. MOCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  408. moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString();
  409. }
  410. }
  411. if (count != 1)
  412. {
  413. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  414. return;
  415. }
  416. //
  417. ////新增逻辑5.2. 判断工单里是否已经领过料,没有领过料的无法派工
  418. //DataTable _dt = ICSMO2LotBLL.IsUsingMO(MOCode, moseq);
  419. //if (_dt != null && _dt.Rows.Count > 0)
  420. //{
  421. // string isUsing = _dt.Rows[0][0].ToString();
  422. // if (!string.IsNullOrWhiteSpace(isUsing))
  423. // {
  424. // int _isUsing = Int32.Parse(isUsing);
  425. // if (_isUsing <= 0)
  426. // {
  427. // ICSBaseSimpleCode.AppshowMessageBox("该工单料号还未领用,无法派工");
  428. // return;
  429. // }
  430. // }
  431. //}
  432. try
  433. {
  434. string MOID = "";
  435. for (int i = 0; i < grvDetail.RowCount; i++)
  436. {
  437. //if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  438. //{
  439. // MOID = grvDetail.GetRowCellValue(i, colID).ToString();
  440. // FormICSMO2UserSend send = new FormICSMO2UserSend(MOID);
  441. // send.ShowDialog();
  442. //}
  443. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  444. {
  445. MOID = grvDetail.GetRowCellValue(i, colID).ToString();
  446. Dictionary<string, string> sendMes = new Dictionary<string, string>();
  447. //sendMes.Add("projectCode", grvDetail.GetRowCellValue(i, colProjectCode).ToString());
  448. sendMes.Add("MoLotCode", grvDetail.GetRowCellValue(i, colMOVER).ToString());
  449. sendMes.Add("moCode", grvDetail.GetRowCellValue(i, colMOCODE).ToString());
  450. sendMes.Add("itemCode", grvDetail.GetRowCellValue(i, colITEMCODE).ToString());
  451. sendMes.Add("MOSEQ", grvDetail.GetRowCellValue(i, colMOSEQ).ToString());
  452. FormICSMO2UserSendNew send = new FormICSMO2UserSendNew(sendMes);
  453. send.ShowDialog();
  454. }
  455. }
  456. btnRefresh_Click(null, null);
  457. }
  458. catch (Exception ex)
  459. {
  460. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  461. }
  462. }
  463. #endregion
  464. }
  465. }