using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Linq; using System.Linq; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid; using System.IO; using System.Threading; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.UserControl.MessageControl; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.Report.GridReport; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.MRP { public partial class FormICSMRP : DevExpress.XtraEditors.XtraForm { private DataTable dataSource = null; private string IDs = ""; #region 构造函数 public FormICSMRP() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } #endregion #region 操作权限 public DataTable RightOfExute() { DataTable rData = new DataTable(); rData.Columns.Add("BtnName"); rData.Columns.Add("ActionName"); //查看权限(必须有) DataRow seeRow = rData.NewRow(); seeRow["BtnName"] = "see"; seeRow["ActionName"] = "查看"; rData.Rows.Add(seeRow); //List ControlList = new List(); //ControlList.Add(btnOutPut); //foreach (Control ctr in ControlList) //{ // if (ctr.GetType() == typeof(SimpleButton)) // { // DataRow dr = rData.NewRow(); // dr["BtnName"] = ctr.Name; // dr["ActionName"] = ctr.Text; // rData.Rows.Add(dr); // } //} rData.AcceptChanges(); return rData; } public DataTable RightOfData()// 数据权限 { DataTable rData = new DataTable(); rData.Columns.Add("BodyName"); rData.Columns.Add("ControlName"); rData.Columns.Add("ControlCaption"); rData.AcceptChanges(); return rData; } #endregion #region 退出r0 private void btnClose_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } private void btnExit_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } #endregion[ #region 移动窗体 private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时, //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION , //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。 //重写窗体,使窗体可以不通过自带标题栏实现移动 protected override void WndProc(ref Message m) { //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息, //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体, //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。 //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。 switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } #endregion #region 列表 private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString(); } #endregion #region 分页 private void rptPage_PageIndexChanged(object Sender, EventArgs e) { DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy(); //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count); gcAging.DataSource = data; } #endregion #region 导出 private void btnOutPut_Click(object sender, EventArgs e) { FormOutExcel foe = new FormOutExcel(); if (foe.ShowDialog() == DialogResult.OK) { try { string outtype = foe._OutType; string exceltype = foe._ExcelType; string filename = foe._FileName; string url = foe._Url; string sheetname = foe._SheetName; if (outtype.ToLower() == "excel") { DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions(); op.SheetName = sheetname; gcAging.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op); } else { gcAging.MainView.ExportToPdf(url + "\\" + filename + ".pdf"); } MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } #endregion private void FormICSMRP_Load(object sender, EventArgs e) { //btnFilter_Click(sender, e); dateEditMonthS.Text = DateTime.Now.ToString("yyyy-MM-dd"); } #region 选择单据 private void txtTransferNO_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { txtTransferNO.Text = ""; ButtonEdit btn = (ButtonEdit)sender; string sql = @"SELECT D.MoCode AS 生产订单号,A.SortSeq as 行号,C.startDate AS 计划开工日期,A.InvCode AS 存货编码,E.cInvName AS 存货名称,E.cInvStd AS 规格型号 ,A.modid,D.MoCode+CAST(A.SortSeq as varchar(10)) as Code FROM mom_orderdetail A inner join mom_morder C on A.modid=C.modid inner join mom_order D on A.MoId=D.MoId inner join inventory E on A.InvCode=E.cInvCode where A.Status<4 ORDER BY C.startDate desc"; sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP103]"), CommandType.Text, sql).Tables[0]; FormDataRefer reForm = new FormDataRefer(); reForm.FormTitle = "生产订单号信息"; DataTable menuData = data; reForm.DataSource = menuData; reForm.MSelectFlag = true; reForm.RowIndexWidth = 35; reForm.HideCols.Add("modid"); reForm.HideCols.Add("Code"); reForm.FormWidth = 800; reForm.FormHeight = 600; reForm.FilterKey = btn.Text; if (reForm.ShowDialog() == DialogResult.OK) { DataTable retData = reForm.ReturnData; string Num = ""; IDs = ""; foreach (DataRow dr in retData.Rows) { Num += dr["Code"].ToString() + ","; IDs += dr["modid"].ToString() + ","; } txtTransferNO.Text = Num.TrimEnd(','); } } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion private void btnFilter_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtTransferNO.Text.ToString())) { MessageBox.Show("生产订单号不能为空!"); return; } if (string.IsNullOrWhiteSpace(dateEditMonthS.Text.Trim())) { MessageBox.Show("需求截止日期不能为空!"); return; } DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { 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, --b.SortSeq,b.Define25,d.cInvAddCode,d.cInvStd,c.StartDate,c.DueDate,b.MDeptCode,f.cDepName, --g.SortSeq AS SubSortSeq,h.cInvAddCode AS SubcInvAddCode,CAST(g.Qty-g.IssQty AS DECIMAL(28,3)) AS SurplusQty, g.InvCode AS SubInvCode,h.cInvName AS SubcInvName,h.cInvStd AS SubcInvStd,i.cComUnitName AS SubcComUnitName, SUM(CAST(g.Qty AS DECIMAL(28,3))) AS SubQty, SUM(CAST(ISNULL(g.IssQty, 0) AS DECIMAL(28,3))) AS IssQty, MAX(CAST(ISNULL(j.iQuantity, 0) AS DECIMAL(28,3))) AS iQuantity, MAX(CAST(ISNULL(k.WayQty, 0) AS DECIMAL(28,3))) AS WayQty, MAX(CAST(ISNULL(k.Qty, 0) AS DECIMAL(28,3))) AS Qty, MAX(CAST(ISNULL(l.MakeQty, 0) AS DECIMAL(28,3))) AS MakeQty, MAX(CAST(ISNULL(m.OutQty, 0) AS DECIMAL(28,3))) AS OutQty, MAX(CAST(ISNULL(n.PickQty, 0) AS DECIMAL(28,3))) AS PickQty, 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 FROM mom_order a INNER JOIN mom_orderdetail b ON a.MoId=b.MoId INNER JOIN mom_morder c ON c.MoDId = b.MoDId INNER JOIN Inventory d ON b.InvCode=d.cInvCode INNER JOIN ComputationUnit e ON d.cComUnitCode=e.cComunitCode INNER JOIN Department f ON b.MDeptCode=f.cDepCode INNER JOIN mom_moallocate g ON b.MoDId=g.MoDId INNER JOIN Inventory h ON g.InvCode=h.cInvCode INNER JOIN ComputationUnit i ON h.cComUnitCode=i.cComunitCode LEFT JOIN ( SELECT cInvCode,SUM(iQuantity) AS iQuantity FROM CurrentStock WHERE cWhcode IN (SELECT cWhcode FROM Warehouse WHERE bMRP=1) GROUP BY cInvCode ) j ON g.InvCode=j.cInvCode LEFT JOIN ( SELECT A.cinvcode,sum(A.iquantity-isnull(A.iArrQTY,0)) as WayQty,sum(isnull(A.iArrQTY,0)-isnull(A.freceivedqty,0)) as Qty FROM po_podetails A where A.cbcloser is null --and dArriveDate<={1} group by A.cinvcode ) k ON g.InvCode=k.cinvcode LEFT JOIN ( SELECT a.invcode,sum(a.Qty-a.QualifiedinQty) as MakeQty FROM mom_orderdetail A inner join mom_morder B on A.modid=b.modid WHERE a.Status=3 and b.DueDate<={1} group by a.InvCode ) l ON g.InvCode=l.invcode LEFT JOIN ( SELECT b.cinvcode,SUM(b.iquantity -isnull(b.foutquantity,0)) as OutQty FROM SO_SOMain A inner join so_sodetails B on a.id=b.id and dPreDate<={1} GROUP BY b.cinvcode ) m ON g.InvCode=m.cinvcode LEFT JOIN ( SELECT B.invcode,sum(b.qty-b.issqty) as PickQty FROM mom_orderdetail A inner join mom_moallocate B on A.modid=B.modid inner join mom_morder C on A.modid=C.modid where A.Status=3 and C.startDate<={1} group by B.invcode ) n ON g.InvCode=n.invcode WHERE b.MoDId in ('{0}') {2} GROUP BY g.InvCode,h.cInvName,h.cInvStd,i.cComUnitName ORDER BY g.InvCode"; string date = "''"; if(!string.IsNullOrWhiteSpace(dateEditMonthS.Text.Trim())) date="'"+dateEditMonthS.Text.Trim()+"'"; string qtystr = ""; if (chkAll.Checked) qtystr = " AND l.MakeQty<=0 AND j.iQuantity+k.Qty<=n.PickQty"; sql = string.Format(sql, IDs.Replace(",", "','"), date, qtystr); dataSource = DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP103]"), CommandType.Text, sql).Tables[0]; gcAging.DataSource = dataSource; gvAging.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageSize = 99; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageSize = 100; rptPage.PageIndex = 1; rptPage.ReLoad(); _wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } } } }