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

586 lines
22 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.Linq;
  6. using System.Linq;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.BandedGrid;
  12. using DevExpress.XtraGrid.Columns;
  13. using DevExpress.XtraGrid;
  14. using System.IO;
  15. using System.Threading;
  16. using ICSSoft.Base.Language.Tool;
  17. using ICSSoft.Base.Config.AppConfig;
  18. using ICSSoft.Base.UserControl.MessageControl;
  19. using ICSSoft.Base.Config.DBHelper;
  20. using ICSSoft.Base.Report.Filter;
  21. using ICSSoft.Base.UserControl.FormControl;
  22. using ICSSoft.Base.Report.GridReport;
  23. using ICSSoft.Base.ReferForm.AppReferForm;
  24. using ICSSoft.Frame.Data.BLL;
  25. using ICSSoft.Frame.Data.Entity;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSASNIQC : DevExpress.XtraEditors.XtraForm
  29. {
  30. private string sqltxt = "";
  31. private string sqlconn = "";
  32. String guid = AppConfig.GetGuid();
  33. private DataTable dataSource = null;
  34. #region 构造函数
  35. public FormICSASNIQC()
  36. {
  37. InitializeComponent();
  38. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  39. this.WindowState = FormWindowState.Maximized;
  40. }
  41. #endregion
  42. #region 操作权限
  43. public DataTable RightOfExute()
  44. {
  45. DataTable rData = new DataTable();
  46. rData.Columns.Add("BtnName");
  47. rData.Columns.Add("ActionName");
  48. //查看权限(必须有)
  49. DataRow seeRow = rData.NewRow();
  50. seeRow["BtnName"] = "see";
  51. seeRow["ActionName"] = "查看";
  52. rData.Rows.Add(seeRow);
  53. List<Control> ControlList = new List<Control>();
  54. ControlList.Add(simpleButton2);
  55. ControlList.Add(btnCancel);
  56. ControlList.Add(btnOutPut);
  57. foreach (Control ctr in ControlList)
  58. {
  59. if (ctr.GetType() == typeof(SimpleButton))
  60. {
  61. DataRow dr = rData.NewRow();
  62. dr["BtnName"] = ctr.Name;
  63. dr["ActionName"] = ctr.Text;
  64. rData.Rows.Add(dr);
  65. }
  66. }
  67. rData.AcceptChanges();
  68. return rData;
  69. }
  70. public DataTable RightOfData()// 数据权限
  71. {
  72. DataTable rData = new DataTable();
  73. rData.Columns.Add("BodyName");
  74. rData.Columns.Add("ControlName");
  75. rData.Columns.Add("ControlCaption");
  76. rData.AcceptChanges();
  77. return rData;
  78. }
  79. #endregion
  80. #region 退出
  81. private void btnClose_Click(object sender, EventArgs e)
  82. {
  83. AppConfig.CloseFormShow(this.Text);
  84. this.Close();
  85. }
  86. private void btnExit_Click(object sender, EventArgs e)
  87. {
  88. AppConfig.CloseFormShow(this.Text);
  89. this.Close();
  90. }
  91. #endregion
  92. #region 移动窗体
  93. private const int WM_NCHITTEST = 0x84;
  94. private const int HTCLIENT = 0x1;
  95. private const int HTCAPTION = 0x2;
  96. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  97. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  98. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  99. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  100. //重写窗体,使窗体可以不通过自带标题栏实现移动
  101. protected override void WndProc(ref Message m)
  102. {
  103. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  104. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  105. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  106. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  107. switch (m.Msg)
  108. {
  109. case WM_NCHITTEST:
  110. base.WndProc(ref m);
  111. if ((int)m.Result == HTCLIENT)
  112. m.Result = (IntPtr)HTCAPTION;
  113. return;
  114. }
  115. //拦截双击标题栏、移动窗体的系统消息
  116. if (m.Msg != 0xA3)
  117. {
  118. base.WndProc(ref m);
  119. }
  120. }
  121. #endregion
  122. #region 列表
  123. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  124. {
  125. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  126. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  127. }
  128. #endregion
  129. #region 过滤
  130. private string tempTableName = "";
  131. private void btnFilter_Click(object sender, EventArgs e)
  132. {
  133. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  134. filter.OldTempTableName = tempTableName;
  135. if (filter.ShowDialog() == DialogResult.OK)
  136. {
  137. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  138. try
  139. {
  140. _wait.Show();
  141. tempTableName = filter.NewTempTableName;
  142. sqltxt = filter.SqlText;
  143. sqlconn = filter.FilterConnectString;
  144. dataSource = filter.FilterData.Tables[0];
  145. grdDetail.DataSource = dataSource;
  146. grvDetail.BestFitColumns();
  147. rptPage.RecordNum = dataSource.Rows.Count;
  148. rptPage.PageSize = 499;
  149. rptPage.PageIndex = 1;
  150. rptPage.ReLoad();
  151. rptPage.PageSize = 500;
  152. rptPage.PageIndex = 1;
  153. rptPage.ReLoad();
  154. _wait.Close();
  155. }
  156. catch (Exception ex)
  157. {
  158. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  159. _wait.Close();
  160. }
  161. }
  162. }
  163. #endregion
  164. #region 绑定数据源
  165. private void btnConfig_Click(object sender, EventArgs e)
  166. {
  167. if (AppConfig.UserCode.ToLower() != "demo")
  168. {
  169. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  170. return;
  171. }
  172. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  173. fdata.ShowDialog();
  174. }
  175. #endregion
  176. #region 分页
  177. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  178. {
  179. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  180. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  181. grdDetail.DataSource = data;
  182. }
  183. #endregion
  184. #region 过滤方法
  185. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  186. {
  187. AppConfig.DropTemTable(tempTableName);
  188. }
  189. #endregion
  190. #region 全选
  191. private void btnSelectAll_Click(object sender, EventArgs e)
  192. {
  193. grvDetail.PostEditor();
  194. this.Validate();
  195. for (int i = 0; i < grvDetail.RowCount; i++)
  196. {
  197. grvDetail.SetRowCellValue(i, coSelect, "Y");
  198. }
  199. }
  200. #endregion
  201. #region 全消
  202. private void btnCancelAll_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, coSelect, "");
  209. }
  210. }
  211. #endregion
  212. #region 双击
  213. private void grvDetail_DoubleClick(object sender, EventArgs e)
  214. {
  215. if (grvDetail.FocusedRowHandle < 0)
  216. {
  217. return;
  218. }
  219. if (grvDetail.FocusedColumn == coSelect)
  220. {
  221. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coSelect).ToString() == "")
  222. {
  223. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, coSelect, "Y");
  224. }
  225. else
  226. {
  227. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, coSelect, "");
  228. }
  229. }
  230. }
  231. #endregion
  232. #region 删除
  233. private void btnDel_Click(object sender, EventArgs e)
  234. {
  235. grvDetail.PostEditor();
  236. this.Validate();
  237. if (grvDetail.RowCount == 0)
  238. return;
  239. SimpleButton btntemp = (SimpleButton)sender;
  240. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  241. {
  242. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  243. return;
  244. }
  245. List<string> guidList = new List<string>();
  246. for (int i = 0; i < grvDetail.RowCount; i++)
  247. {
  248. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, STATUS).ToString() != "新建")
  249. {
  250. ICSBaseSimpleCode.AppshowMessageBox("请选择新建状态的送检单进行删除!!");
  251. return;
  252. }
  253. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, STATUS).ToString() == "新建")
  254. {
  255. guidList.Add(grvDetail.GetRowCellValue(i, ID).ToString());
  256. }
  257. }
  258. if (guidList.Count == 0)
  259. {
  260. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  261. return;
  262. }
  263. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该单据吗?单据删除后无法恢复,确定吗?") != DialogResult.OK)
  264. return;
  265. try
  266. {
  267. ICSASNIQCBLL.delete(guidList);
  268. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  269. btnRefresh_Click(null, null);
  270. }
  271. catch (Exception ex)
  272. {
  273. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  274. }
  275. }
  276. #endregion
  277. #region 刷新
  278. private void btnRefresh_Click(object sender, EventArgs e)
  279. {
  280. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  281. try
  282. {
  283. _wait.Show();
  284. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  285. filter.OldTempTableName = tempTableName;
  286. //tempTableName = filter.NewTempTableName;
  287. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  288. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  289. grdDetail.DataSource = dataSource;
  290. grvDetail.BestFitColumns();
  291. rptPage.RecordNum = dataSource.Rows.Count;
  292. rptPage.PageIndex = 1;
  293. rptPage.ReLoad();
  294. _wait.Close();
  295. }
  296. catch (Exception ex)
  297. {
  298. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  299. _wait.Close();
  300. }
  301. }
  302. #endregion
  303. #region 新增
  304. private void btnCreate_Click(object sender, EventArgs e)
  305. {
  306. SimpleButton btn = ((SimpleButton)sender);
  307. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btn.Name) == false)
  308. {
  309. ICSBaseSimpleCode.AppshowMessageBox(1, "对不起您无" + btn.Text + "权限,请联系管理员!");
  310. return;
  311. }
  312. try
  313. {
  314. string ERPSql = @"SELECT a.ID, [ReceiptNO] AS 入库单号
  315. ,b.StorageName AS
  316. ,c.VendorName AS
  317. ,[RECTYPE] AS
  318. ,[MEMO] AS
  319. ,a.[MUSERName] AS
  320. ,a.[MTIME] AS
  321. FROM [ICSINVReceipt] a LEFT JOIN ICSStorage b ON a.StorageID=b.Serial
  322. LEFT JOIN ICSVendor c ON a.[VENDORCODE]=c.ID
  323. WHERE [ReceiptNO] NOT IN
  324. (SELECT DISTINCT STNO FROM dbo.ICSASNIQC)
  325. and a.WorkPoint='" + AppConfig.WorkPointCode + "' ";
  326. DataTable czData = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, ERPSql).Tables[0];
  327. FormDataRefer reForm = new FormDataRefer();
  328. reForm.FormTitle = "入库单列表";
  329. reForm.DataSource = czData;
  330. reForm.MSelectFlag = true;
  331. reForm.RowIndexWidth = 35;
  332. reForm.HideCols.Add("ID");
  333. reForm.Width = this.Width - 10;
  334. reForm.Height = this.Height - 10;
  335. if (reForm.ShowDialog() != DialogResult.OK)
  336. {
  337. return;
  338. }
  339. DataTable retData = reForm.ReturnData;
  340. if (retData.Rows.Count == 0)
  341. {
  342. return;
  343. }
  344. ICSASNIQCBLL.save(retData,AppConfig.AppConnectString);
  345. ICSBaseSimpleCode.AppshowMessageBox("生成成功");
  346. btnRefresh_Click(null, null);
  347. }
  348. catch (Exception ex)
  349. {
  350. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  351. }
  352. }
  353. #endregion
  354. #region 页面加载
  355. private void grdDetail_Load(object sender, EventArgs e)
  356. {
  357. btnFilter_Click(null, null);
  358. }
  359. #endregion
  360. #region 修改
  361. private void btnModify_Click(object sender, EventArgs e)
  362. {
  363. String id = "";
  364. SimpleButton btntemp = (SimpleButton)sender;
  365. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  366. {
  367. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  368. return;
  369. }
  370. List<string> editList = new List<string>();
  371. List<string> guidList1 = new List<string>();
  372. for (int i = 0; i < grvDetail.RowCount; i++)
  373. {
  374. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y")
  375. {
  376. id = grvDetail.GetRowCellValue(i, ID).ToString();
  377. editList.Add(id);
  378. }
  379. }
  380. if (editList.Count != 1)
  381. {
  382. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  383. return;
  384. }
  385. try
  386. {
  387. ICSDCTBLL.select(id, AppConfig.AppConnectString);
  388. FormICSCREWAdd add = new FormICSCREWAdd(id);
  389. add.ShowDialog();
  390. btnRefresh_Click(null, null);
  391. }
  392. catch (Exception ex)
  393. {
  394. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  395. }
  396. }
  397. #endregion
  398. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  399. {
  400. AppConfig.DropTemTable(tempTableName);
  401. }
  402. private void FormICSCREW_Load(object sender, EventArgs e)
  403. {
  404. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  405. filter.OldTempTableName = tempTableName;
  406. if (filter.ShowDialog() == DialogResult.OK)
  407. {
  408. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  409. try
  410. {
  411. _wait.Show();
  412. tempTableName = filter.NewTempTableName;
  413. sqltxt = filter.SqlText;
  414. sqlconn = filter.FilterConnectString;
  415. dataSource = filter.FilterData.Tables[0];
  416. grdDetail.DataSource = dataSource;
  417. grvDetail.BestFitColumns();
  418. rptPage.RecordNum = dataSource.Rows.Count;
  419. rptPage.PageSize = 499;
  420. rptPage.PageIndex = 1;
  421. rptPage.ReLoad();
  422. rptPage.PageSize = 500;
  423. rptPage.PageIndex = 1;
  424. rptPage.ReLoad();
  425. _wait.Close();
  426. }
  427. catch (Exception ex)
  428. {
  429. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  430. _wait.Close();
  431. }
  432. }
  433. }
  434. private void btnOutPut_Click_1(object sender, EventArgs e)
  435. {
  436. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  437. foe.ShowDialog();
  438. }
  439. private void btnCancel_Click(object sender, EventArgs e)
  440. {
  441. grvDetail.PostEditor();
  442. this.Validate();
  443. if (grvDetail.RowCount == 0)
  444. return;
  445. SimpleButton btntemp = (SimpleButton)sender;
  446. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  447. {
  448. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  449. return;
  450. }
  451. List<string> guidList = new List<string>();
  452. List<string> lineList = new List<string>();
  453. for (int i = 0; i < grvDetail.RowCount; i++)
  454. {
  455. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, STATUS).ToString() != "待检")
  456. {
  457. ICSBaseSimpleCode.AppshowMessageBox("请选择待检状态的数据撤回!!");
  458. return;
  459. }
  460. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, STATUS).ToString() == "待检")
  461. {
  462. guidList.Add(grvDetail.GetRowCellValue(i, ID).ToString());
  463. lineList.Add(grvDetail.GetRowCellValue(i, STNO_SEQ).ToString());
  464. }
  465. }
  466. if (guidList.Count == 0)
  467. {
  468. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  469. return;
  470. }
  471. try
  472. {
  473. ICSASNIQCBLL.cancel(guidList, lineList);
  474. ICSBaseSimpleCode.AppshowMessageBox(0, "撤回成功");
  475. btnRefresh_Click(null, null);
  476. }
  477. catch (Exception ex)
  478. {
  479. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  480. }
  481. }
  482. private void btnOK_Click(object sender, EventArgs e)
  483. {
  484. grvDetail.PostEditor();
  485. this.Validate();
  486. if (grvDetail.RowCount == 0)
  487. return;
  488. SimpleButton btntemp = (SimpleButton)sender;
  489. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  490. {
  491. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  492. return;
  493. }
  494. List<string> guidList = new List<string>();
  495. List<string> lineList = new List<string>();
  496. for (int i = 0; i < grvDetail.RowCount; i++)
  497. {
  498. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, STATUS).ToString() != "新建")
  499. {
  500. ICSBaseSimpleCode.AppshowMessageBox("请选择状态为新建的数据送检!!");
  501. return;
  502. }
  503. if (grvDetail.GetRowCellValue(i, coSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, STATUS).ToString() == "新建")
  504. {
  505. guidList.Add(grvDetail.GetRowCellValue(i, ID).ToString());
  506. lineList.Add(grvDetail.GetRowCellValue(i, STNO_SEQ).ToString());
  507. }
  508. }
  509. if (guidList.Count == 0)
  510. {
  511. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  512. return;
  513. }
  514. try
  515. {
  516. ICSASNIQCBLL.OK(guidList,lineList);
  517. ICSBaseSimpleCode.AppshowMessageBox(0, "送检成功");
  518. btnRefresh_Click(null, null);
  519. }
  520. catch (Exception ex)
  521. {
  522. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  523. }
  524. }
  525. }
  526. }