华恒Mes鼎捷代码
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.

345 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.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.MRP
  27. {
  28. public partial class FormICSMRP : DevExpress.XtraEditors.XtraForm
  29. {
  30. private DataTable dataSource = null;
  31. private string IDs = "";
  32. #region 构造函数
  33. public FormICSMRP()
  34. {
  35. InitializeComponent();
  36. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  37. this.WindowState = FormWindowState.Maximized;
  38. }
  39. #endregion
  40. #region 操作权限
  41. public DataTable RightOfExute()
  42. {
  43. DataTable rData = new DataTable();
  44. rData.Columns.Add("BtnName");
  45. rData.Columns.Add("ActionName");
  46. //查看权限(必须有)
  47. DataRow seeRow = rData.NewRow();
  48. seeRow["BtnName"] = "see";
  49. seeRow["ActionName"] = "查看";
  50. rData.Rows.Add(seeRow);
  51. //List<Control> ControlList = new List<Control>();
  52. //ControlList.Add(btnOutPut);
  53. //foreach (Control ctr in ControlList)
  54. //{
  55. // if (ctr.GetType() == typeof(SimpleButton))
  56. // {
  57. // DataRow dr = rData.NewRow();
  58. // dr["BtnName"] = ctr.Name;
  59. // dr["ActionName"] = ctr.Text;
  60. // rData.Rows.Add(dr);
  61. // }
  62. //}
  63. rData.AcceptChanges();
  64. return rData;
  65. }
  66. public DataTable RightOfData()// 数据权限
  67. {
  68. DataTable rData = new DataTable();
  69. rData.Columns.Add("BodyName");
  70. rData.Columns.Add("ControlName");
  71. rData.Columns.Add("ControlCaption");
  72. rData.AcceptChanges();
  73. return rData;
  74. }
  75. #endregion
  76. #region 退出r0
  77. private void btnClose_Click(object sender, EventArgs e)
  78. {
  79. AppConfig.CloseFormShow(this.Text);
  80. this.Close();
  81. }
  82. private void btnExit_Click(object sender, EventArgs e)
  83. {
  84. AppConfig.CloseFormShow(this.Text);
  85. this.Close();
  86. }
  87. #endregion[
  88. #region 移动窗体
  89. private const int WM_NCHITTEST = 0x84;
  90. private const int HTCLIENT = 0x1;
  91. private const int HTCAPTION = 0x2;
  92. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  93. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  94. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  95. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  96. //重写窗体,使窗体可以不通过自带标题栏实现移动
  97. protected override void WndProc(ref Message m)
  98. {
  99. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  100. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  101. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  102. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  103. switch (m.Msg)
  104. {
  105. case WM_NCHITTEST:
  106. base.WndProc(ref m);
  107. if ((int)m.Result == HTCLIENT)
  108. m.Result = (IntPtr)HTCAPTION;
  109. return;
  110. }
  111. //拦截双击标题栏、移动窗体的系统消息
  112. if (m.Msg != 0xA3)
  113. {
  114. base.WndProc(ref m);
  115. }
  116. }
  117. #endregion
  118. #region 列表
  119. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  120. {
  121. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  122. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  123. }
  124. #endregion
  125. #region 分页
  126. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  127. {
  128. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  129. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  130. gcAging.DataSource = data;
  131. }
  132. #endregion
  133. #region 导出
  134. private void btnOutPut_Click(object sender, EventArgs e)
  135. {
  136. FormOutExcel foe = new FormOutExcel();
  137. if (foe.ShowDialog() == DialogResult.OK)
  138. {
  139. try
  140. {
  141. string outtype = foe._OutType;
  142. string exceltype = foe._ExcelType;
  143. string filename = foe._FileName;
  144. string url = foe._Url;
  145. string sheetname = foe._SheetName;
  146. if (outtype.ToLower() == "excel")
  147. {
  148. DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  149. op.SheetName = sheetname;
  150. gcAging.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  151. }
  152. else
  153. {
  154. gcAging.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  155. }
  156. MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  157. }
  158. catch (Exception ex)
  159. {
  160. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  161. }
  162. }
  163. }
  164. #endregion
  165. private void FormICSMRP_Load(object sender, EventArgs e)
  166. {
  167. //btnFilter_Click(sender, e);
  168. dateEditMonthS.Text = DateTime.Now.ToString("yyyy-MM-dd");
  169. }
  170. #region 选择单据
  171. private void txtTransferNO_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  172. {
  173. try
  174. {
  175. txtTransferNO.Text = "";
  176. ButtonEdit btn = (ButtonEdit)sender;
  177. string sql = @"SELECT D.MoCode AS 生产订单号,A.SortSeq as 行号,C.startDate AS 计划开工日期,A.InvCode AS 存货编码,E.cInvName AS 存货名称,E.cInvStd AS 规格型号
  178. ,A.modid,D.MoCode+CAST(A.SortSeq as varchar(10)) as Code
  179. FROM mom_orderdetail A
  180. inner join mom_morder C on A.modid=C.modid
  181. inner join mom_order D on A.MoId=D.MoId
  182. inner join inventory E on A.InvCode=E.cInvCode
  183. where A.Status<4
  184. ORDER BY C.startDate desc";
  185. sql = string.Format(sql);
  186. DataTable data = DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP103]"), CommandType.Text, sql).Tables[0];
  187. FormDataRefer reForm = new FormDataRefer();
  188. reForm.FormTitle = "生产订单号信息";
  189. DataTable menuData = data;
  190. reForm.DataSource = menuData;
  191. reForm.MSelectFlag = true;
  192. reForm.RowIndexWidth = 35;
  193. reForm.HideCols.Add("modid");
  194. reForm.HideCols.Add("Code");
  195. reForm.FormWidth = 800;
  196. reForm.FormHeight = 600;
  197. reForm.FilterKey = btn.Text;
  198. if (reForm.ShowDialog() == DialogResult.OK)
  199. {
  200. DataTable retData = reForm.ReturnData;
  201. string Num = "";
  202. IDs = "";
  203. foreach (DataRow dr in retData.Rows)
  204. {
  205. Num += dr["Code"].ToString() + ",";
  206. IDs += dr["modid"].ToString() + ",";
  207. }
  208. txtTransferNO.Text = Num.TrimEnd(',');
  209. }
  210. }
  211. catch (Exception ex)
  212. {
  213. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  214. }
  215. }
  216. #endregion
  217. private void btnFilter_Click(object sender, EventArgs e)
  218. {
  219. if (string.IsNullOrWhiteSpace(txtTransferNO.Text.ToString()))
  220. {
  221. MessageBox.Show("生产订单号不能为空!");
  222. return;
  223. }
  224. if (string.IsNullOrWhiteSpace(dateEditMonthS.Text.Trim()))
  225. {
  226. MessageBox.Show("需求截止日期不能为空!");
  227. return;
  228. }
  229. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  230. try
  231. {
  232. string sql = @"SELECT --a.MoCode,b.InvCode,d.cInvName,c.StartDate,e.cComUnitName,CAST(b.Qty AS DECIMAL(28,3)) AS Qty,CAST(g.BaseQtyN/g.BaseQtyD AS DECIMAL(28,3)) AS Rate,
  233. --b.SortSeq,b.Define25,d.cInvAddCode,d.cInvStd,c.StartDate,c.DueDate,b.MDeptCode,f.cDepName,
  234. --g.SortSeq AS SubSortSeq,h.cInvAddCode AS SubcInvAddCode,CAST(g.Qty-g.IssQty AS DECIMAL(28,3)) AS SurplusQty,
  235. g.InvCode AS SubInvCode,h.cInvName AS SubcInvName,h.cInvStd AS SubcInvStd,i.cComUnitName AS SubcComUnitName,
  236. SUM(CAST(g.Qty AS DECIMAL(28,3))) AS SubQty,
  237. SUM(CAST(ISNULL(g.IssQty, 0) AS DECIMAL(28,3))) AS IssQty,
  238. MAX(CAST(ISNULL(j.iQuantity, 0) AS DECIMAL(28,3))) AS iQuantity,
  239. MAX(CAST(ISNULL(k.WayQty, 0) AS DECIMAL(28,3))) AS WayQty,
  240. MAX(CAST(ISNULL(k.Qty, 0) AS DECIMAL(28,3))) AS Qty,
  241. MAX(CAST(ISNULL(l.MakeQty, 0) AS DECIMAL(28,3))) AS MakeQty,
  242. MAX(CAST(ISNULL(m.OutQty, 0) AS DECIMAL(28,3))) AS OutQty,
  243. MAX(CAST(ISNULL(n.PickQty, 0) AS DECIMAL(28,3))) AS PickQty,
  244. MAX(CAST(ISNULL(j.iQuantity, 0)+ISNULL(k.WayQty, 0)+ISNULL(k.Qty, 0)+ISNULL(l.MakeQty, 0)-ISNULL(m.OutQty, 0)-ISNULL(n.PickQty, 0) AS DECIMAL(28,3))) AS NeedQty
  245. FROM mom_order a
  246. INNER JOIN mom_orderdetail b ON a.MoId=b.MoId
  247. INNER JOIN mom_morder c ON c.MoDId = b.MoDId
  248. INNER JOIN Inventory d ON b.InvCode=d.cInvCode
  249. INNER JOIN ComputationUnit e ON d.cComUnitCode=e.cComunitCode
  250. INNER JOIN Department f ON b.MDeptCode=f.cDepCode
  251. INNER JOIN mom_moallocate g ON b.MoDId=g.MoDId
  252. INNER JOIN Inventory h ON g.InvCode=h.cInvCode
  253. INNER JOIN ComputationUnit i ON h.cComUnitCode=i.cComunitCode
  254. LEFT JOIN
  255. (
  256. SELECT cInvCode,SUM(iQuantity) AS iQuantity
  257. FROM CurrentStock
  258. WHERE cWhcode IN (SELECT cWhcode FROM Warehouse WHERE bMRP=1)
  259. GROUP BY cInvCode
  260. ) j ON g.InvCode=j.cInvCode
  261. LEFT JOIN
  262. (
  263. SELECT A.cinvcode,sum(A.iquantity-isnull(A.iArrQTY,0)) as WayQty,sum(isnull(A.iArrQTY,0)-isnull(A.freceivedqty,0)) as Qty
  264. FROM po_podetails A
  265. where A.cbcloser is null --and dArriveDate<={1}
  266. group by A.cinvcode
  267. ) k ON g.InvCode=k.cinvcode
  268. LEFT JOIN
  269. (
  270. SELECT a.invcode,sum(a.Qty-a.QualifiedinQty) as MakeQty
  271. FROM mom_orderdetail A inner join mom_morder B on A.modid=b.modid
  272. WHERE a.Status=3 and b.DueDate<={1}
  273. group by a.InvCode
  274. ) l ON g.InvCode=l.invcode
  275. LEFT JOIN
  276. (
  277. SELECT b.cinvcode,SUM(b.iquantity -isnull(b.foutquantity,0)) as OutQty
  278. FROM SO_SOMain A inner join so_sodetails B on a.id=b.id and dPreDate<={1}
  279. GROUP BY b.cinvcode
  280. ) m ON g.InvCode=m.cinvcode
  281. LEFT JOIN
  282. (
  283. SELECT B.invcode,sum(b.qty-b.issqty) as PickQty
  284. FROM mom_orderdetail A inner join mom_moallocate B on A.modid=B.modid
  285. inner join mom_morder C on A.modid=C.modid
  286. where A.Status=3 and C.startDate<={1}
  287. group by B.invcode
  288. ) n ON g.InvCode=n.invcode
  289. WHERE b.MoDId in ('{0}') {2}
  290. GROUP BY g.InvCode,h.cInvName,h.cInvStd,i.cComUnitName
  291. ORDER BY g.InvCode";
  292. string date = "''";
  293. if(!string.IsNullOrWhiteSpace(dateEditMonthS.Text.Trim()))
  294. date="'"+dateEditMonthS.Text.Trim()+"'";
  295. string qtystr = "";
  296. if (chkAll.Checked)
  297. qtystr = " AND l.MakeQty<=0 AND j.iQuantity+k.Qty<=n.PickQty";
  298. sql = string.Format(sql, IDs.Replace(",", "','"), date, qtystr);
  299. dataSource = DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP103]"), CommandType.Text, sql).Tables[0];
  300. gcAging.DataSource = dataSource;
  301. gvAging.BestFitColumns();
  302. rptPage.RecordNum = dataSource.Rows.Count;
  303. rptPage.PageSize = 99;
  304. rptPage.PageIndex = 1;
  305. rptPage.ReLoad();
  306. rptPage.PageSize = 100;
  307. rptPage.PageIndex = 1;
  308. rptPage.ReLoad();
  309. _wait.Close();
  310. }
  311. catch (Exception ex)
  312. {
  313. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  314. _wait.Close();
  315. }
  316. }
  317. }
  318. }