using Demo.Model.Model; using Kingdee.BOS.Core; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.CommonFilter; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using ZD.Cloud.WebApi; using NPOI.XSSF.UserModel; using NPOI.SS.UserModel; namespace Demo.BillView.PRD { [Description("生产计划平台(月度计划)按钮功能")] [HotUpdate] public class Pro_WorkBillPlatformMonth : AbstractDynamicFormPlugIn { string _OutServicePath = ""; string PathName = "日计划(月度计划)导入模板.xlsx"; List ListInventory;//库存明细 List ListInventoryByStockOrgId;//物料总库存 private bool isSearched = false; ///// ///// 页面初始化 渲染界面 将T0-T60更改为日期显示 ///// ///// //public override void OnInitialize(InitializeEventArgs e) //{ // base.OnInitialize(e); // DateTime DateNow = DateTime.Now; // for (int m = 0; m <= 60; m++) // { // this.View.GetControl("FT" + "" + m + "").ControlAppearance.TextColor = "#FFFF00"; // this.View.GetControl("FT" + "" + m + "").Text = DateNow.AddDays(m).ToShortDateString(); // } // this.View.SendDynamicFormAction(View); //} public override void DataChanged(DataChangedEventArgs e) { if (!isSearched) return; base.DataChanged(e); var columns = new List() { "", "" }; for (int i = 0; i < 100; i++) { columns.Add("FT" + i.ToString()); } var model = this.View.Model; if (columns.Contains(e.Field.Key)) { var sum = columns.Select(x => Convert.ToDouble(model.GetValue(x, e.Row))).Sum();//日计划总和 var scOrderCount = Convert.ToDouble(model.GetValue("FOrderQuantity", e.Row));//生产订单数量 var FQTYLS = Convert.ToDouble(model.GetValue("FQTYLS", e.Row));//历史 this.View.Model.SetValue("FNoScheduled", scOrderCount - sum - FQTYLS, e.Row); this.View.Model.SetValue("FDayPlanQuantity", sum, e.Row); } } public override void BarItemClick(BarItemClickEventArgs e) { base.BarItemClick(e); try { if (e.BarItemKey.ToUpper() == "BTIMPORT") { ////LogHelper.Info("导入功能点击按钮:"); DynamicFormShowParameter formPa = new DynamicFormShowParameter(); formPa.FormId = "bsv_ScDayImportMonth"; this.View.ShowForm(formPa); } if (e.BarItemKey.ToUpper() == "BTEXPORT") { ExportExcel(); string path = PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, PathName); DynamicFormShowParameter dynamicForm = new DynamicFormShowParameter(); dynamicForm.FormId = "BOS_FileDownLoad"; dynamicForm.OpenStyle.ShowType = ShowType.Modal; dynamicForm.CustomParams.Add("IsExportData", "true"); dynamicForm.CustomParams.Add("url", path); this.View.ShowForm(dynamicForm); } if (e.BarItemKey.ToUpper() == "TBSEARCH") { isSearched = false; SearchList(); isSearched = true; } //保存 if (e.BarItemKey.ToUpper() == "BTNSAVE") { Save(); } //选单 if (e.BarItemKey.ToUpper().Contains("TBSELECTMENU")) { SelectMenu(e.BarItemKey.ToString()); } } catch (Exception ex) { this.View.ShowErrMessage(ex.Message.ToString()); } } public override void EntryBarItemClick(BarItemClickEventArgs e) { base.EntryBarItemClick(e); if (e.BarItemKey.ToUpper() == "TBEDIT") { isSearched = false; SearchListEdit(); isSearched = true; } } /// /// 行双击 跳出齐套分析明细列表 /// /// public override void EntityRowDoubleClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.EntityRowClickEventArgs e) { //LogHelper.Info("[行双击事件]"); base.EntityRowClick(e); DynamicFormShowParameter formPa = new DynamicFormShowParameter(); if (e.ColKey == "FDELAYLNUM") { //生产计划平台拖期明细跳转 formPa.FormId = "paez_TardinessDetails"; formPa.CustomParams.Add("FID", Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString())); this.View.ShowForm(formPa); } else if (e.ColKey == "FQTYLS") { //生产计划平台 string pageId = Guid.NewGuid().ToString(); BillShowParameter showParameter = new BillShowParameter(); showParameter.FormId = "Paez_Sc_WorkBillAutoSortBill"; showParameter.OpenStyle.ShowType = ShowType.MainNewTabPage; showParameter.PageId = pageId; showParameter.Status = OperationStatus.EDIT; // 传入需要修改的日计划工单内码, showParameter.PKey = Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString()); this.View.ShowForm(showParameter); } else { var type = this.View.Model.GetValue("FQTTYPE"); if (type == "标准Bom") formPa.CustomParams.Add("tempName", "JIT_MOMaterReadysBomBill"); //齐套分析明细列表跳转 formPa.FormId = "paez_CompleteAnalysisDetail"; formPa.CustomParams.Add("FHICMOInterID", Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString())); this.View.ShowForm(formPa); } } public void ExportExcel() { List Title = new List { "组织编码*", "销售订单号*", "销售订单明细行号*", "生产车间编码*", "物料编码*", "物料名称", "规格型号" }; DateTime date = DateTime.Now; string sheetname = "月度计划"; string file = ""; file = @"D:\办公\K3Cloud\WebSite\TempfilePath\" + sheetname; //@"D:\办公\K3Cloud\WebSite\"; //通过Directory类的CreateDirectory方法创建。 string activeDir = AppDomain.CurrentDomain.BaseDirectory; string newPath = System.IO.Path.Combine(activeDir, "TempfilePath"); System.IO.Directory.CreateDirectory(newPath); file = newPath + "\\" + PathName; //Server.MapPath("/"); DataTable dt = null; XSSFWorkbook xssfworkbook = new XSSFWorkbook();//创建xlsx XSSFSheet sheet = (XSSFSheet)xssfworkbook.CreateSheet(sheetname);//新建一个名称为sheetname的工作簿 //设置基本样式 ICellStyle style = xssfworkbook.CreateCellStyle(); style.WrapText = true; IFont font = xssfworkbook.CreateFont(); font.FontHeightInPoints = 9; font.FontName = "Arial"; style.SetFont(font); //设置统计样式 ICellStyle style1 = xssfworkbook.CreateCellStyle(); style1.WrapText = true; IFont font1 = xssfworkbook.CreateFont(); font1.FontHeightInPoints = 9; font1.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; font1.FontName = "Arial"; style1.SetFont(font1); //设置大类样式 ICellStyle style2 = xssfworkbook.CreateCellStyle(); style2.WrapText = true; //style2.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Gold.Index; //style2.FillPattern = FillPattern.SolidForeground; IFont font2 = xssfworkbook.CreateFont(); font2.FontHeightInPoints = 9; font2.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; font2.FontName = "Arial"; style2.SetFont(font2); //设置列名 XSSFRow row = (XSSFRow)sheet.CreateRow(0); for (int i = 0; i < Title.Count; i++) { ICell cell = (ICell)row.CreateCell(i); var rowName = Title[i]; cell.SetCellValue(rowName); cell.CellStyle = style; } //单元格赋值 //列宽自适应,只对英文和数字有效 for (int i = 0; i <= Title.Count; i++) { sheet.AutoSizeColumn(i); } using (System.IO.Stream stream = System.IO.File.OpenWrite(file)) { xssfworkbook.Write(stream); stream.Close(); _OutServicePath = file; } } /// /// 保存功能 /// public void Save() { List sqlList = new List(); string sql; //获取单据体信息 Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity"); //单据体信息转换为列表集合 DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity); var prd_DayPlanSave = entityDataObjoct.Select(x => new PRD_DayPlanSave { FSCOrderNo = Convert.ToString(x["FSCOrderNo"]), FSrcbillEntrySeq = Convert.ToString(x["FSRCBILLENTRYSEQ"]) }).ToList(); //判断重复生产订单 foreach (var item in prd_DayPlanSave) { if (prd_DayPlanSave.Where(x => x.FSCOrderNo == item.FSCOrderNo && x.FSrcbillEntrySeq == item.FSrcbillEntrySeq).ToList().Count > 1) { this.View.ShowMessage("生产订单号:" + item.FSCOrderNo + ",生产订单行号:" + item.FSrcbillEntrySeq + "信息重复"); return; } } foreach (DynamicObject current in entityDataObjoct) { string _sql = string.Format(@" /*dialect*/ SELECT FID FROM Sc_WorkBillMainMonth A WHERE FSCORDERNO = '{0}' AND FSRCBILLENTRYSEQ ='{1}' " , Convert.ToString(current["FSCOrderNo"]), Convert.ToString(current["FSRCBILLENTRYSEQ"])); int _FDayPlanWorkID = DBServiceHelper.ExecuteScalar(Context, _sql, 0); if (_FDayPlanWorkID > 0) continue; else { string FOrderType = Convert.ToString(current["FOrderType"]) ?? ""; string FTempName = "T_PRD_MO"; string FTempNameEntry = "T_PRD_MOENTRY"; if (FOrderType == "委外订单") { FTempName = "T_SUB_REQORDER"; FTempNameEntry = "T_SUB_REQORDERENTRY"; } ///查询生产订单数据 sql = string.Format(@" /*dialect*/ SELECT t4.FNAME as FMoFBillType,T1.FBILLNO,T2.*,t3.FNUMBER as FUnitNumber,tBom.FNUMBER as FBomNumber FROM {0} T1 LEFT JOIN {1} T2 ON T1.FID = T2.FID LEFT JOIN T_ENG_BOM tBom on t2.FBOMID = tBom.FID join T_BD_UNIT t3 on t2.FUNITID=t3.FUNITID join ( select A.FBILLTYPEID,B.FNAME from T_BAS_BILLTYPE A JOIN T_BAS_BILLTYPE_L B ON A.FBILLTYPEID =B.FBILLTYPEID where FBILLFORMID in ('PRD_MO','SUB_SUBREQORDER') AND b.FLOCALEID = 2052)t4 on t1.FBILLTYPE =t4.FBILLTYPEID WHERE T1.FBILLNO = '{2}' AND T2.FMATERIALID = '{3}' AND T2.FSEQ = '{4}'", FTempName, FTempNameEntry, Convert.ToString(current["FSCOrderNo"]), Convert.ToString(current["FMatrailId_Id"]), Convert.ToString(current["FSRCBILLENTRYSEQ"])); DataTable dt = new DataTable(); dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; if (dt.Rows.Count == 0) continue; string FID = "";//FID 源单主内码 string FENTRYID = "";//FENTRYID 源单子内码 string FLOT = "";//FLOT 批次 string FQTY = "";//FQTY 生产订单数量 string FBILLNO = "";//FBILLNO 原单号 string FHUnitID = "";//单位 string FPlanBeginDate = "";//开始日期 string FPlanEndDate = "";//结束日期 string FMoFBillType = "";// string FBomNumber = "";//Bom 版本 if (dt.Rows.Count > 0) { FID = dt.Rows[0]["FID"].ToString(); FENTRYID = dt.Rows[0]["FENTRYID"].ToString(); FLOT = dt.Rows[0]["FLOT"].ToString(); FQTY = dt.Rows[0]["FQTY"].ToString(); FBILLNO = dt.Rows[0]["FBILLNO"].ToString(); FHUnitID = dt.Rows[0]["FUnitNumber"].ToString(); FPlanBeginDate = dt.Rows[0]["FPlanStartDate"].ToString(); FPlanEndDate = dt.Rows[0]["FPlanFinishDate"].ToString(); FMoFBillType = dt.Rows[0]["FMoFBillType"].ToString(); FBomNumber = dt.Rows[0]["FBomNumber"].ToString(); } //选单数据 做新增 JObject jsonRoot = new JObject(); jsonRoot.Add("Creator", ""); jsonRoot.Add("NeedUpDateFields", new JArray()); jsonRoot.Add("NeedReturnFields", new JArray()); jsonRoot.Add("IsDeleteEntry", "false"); jsonRoot.Add("SubSystemId", ""); jsonRoot.Add("IsVerifyBaseDataField", ""); JObject jsonModel = new JObject(); jsonModel.Add("FPreparatDate", Convert.ToString(current["FBzDate"]));//编制日期(改为预计开工日期) jsonModel.Add("FMonthPlan", 1);//月度计划标识 jsonModel.Add("FMoFBillType", FMoFBillType);// jsonModel.Add("FOrderType", FOrderType);// jsonModel.Add("FSRCBILLENTRYSEQ", Convert.ToString(current["FSRCBILLENTRYSEQ"]));//生产订单明细行号 jsonModel.Add("FSCOrderNo", Convert.ToString(current["FSCOrderNo"])); //生产订单号FSCOrderNo jsonModel.Add("FHSeOrderBillNo", Convert.ToString(current["FSalOrderNo"]));//销售订单号 jsonModel.Add("FHOrderLev", current["FOrderLevel"].ToString());//订单等级 jsonModel.Add("FHOrderQty", Convert.ToString(current["FSalOrderCount"]));//销售订单数量 jsonModel.Add("FHOrderCommitDate", Convert.ToString(current["FDeliveryDate"]));//交货期HOrderCommitDate jsonModel.Add("FHUnitID", new JObject() { ["Fnumber"] = FHUnitID });//单位 jsonModel.Add("FBOMID", new JObject() { ["Fnumber"] = FBomNumber });//BOM版本 jsonModel.Add("FHPlanBeginDate", FPlanBeginDate);//计划开始日期 jsonModel.Add("FHPlanEndDate", FPlanEndDate);//计划完工日期 jsonModel.Add("FPriority", Convert.ToString(current["FPriority"])); jsonModel.Add("FBatch", FLOT);//批次 jsonModel.Add("FHOrderNeedQty", FQTY);// 订单需求数量 jsonModel.Add("FPrdBillNo", FBILLNO); ;//源单编号 jsonModel.Add("FPRDMOMAINID", FID); ;//源单主内码 jsonModel.Add("FPRDMOENTYID", FENTRYID); ;//源单子内码 jsonModel.Add("FMoFID", FID); ;//源单主内码 jsonModel.Add("FMoFentryId", FENTRYID); ;//源单子内码 //jsonModel.Add("FCDQuantity", Convert.ToString(current["FCDQuantity"])); ;//拆单数量 //jsonModel.Add("FOrderQuantity", Convert.ToString(current["FOrderQuantity"])); ;//生产订单数量 //jsonModel.Add("FDayPlanQuantity", Convert.ToString(current["FDayPlanQuantity"])); ;//日计划数量 //jsonModel.Add("FNoScheduled", Convert.ToString(current["FNoScheduled"])); ;//未排数量 JObject jsonFHMaterID = new JObject(); jsonFHMaterID.Add("FNumber", (current["FMatrailId"] as DynamicObject)["Number"].ToString()); jsonModel.Add("FHMaterID", jsonFHMaterID);//FHMaterID 物料 if (Convert.ToString(current["FORGID_Id"]) != "0") { JObject jsonFHPRDORGID = new JObject(); jsonFHPRDORGID.Add("FNumber", (current["FORGID"] as DynamicObject)["Number"].ToString()); jsonModel.Add("FHPRDORGID", jsonFHPRDORGID);//FHMaterID 生产组织 } //if (Convert.ToString(current["FResourcesId_Id"]) != "0") //{ // JObject jsonFProductWorkShopId = new JObject(); // jsonFProductWorkShopId.Add("FNumber", (current["FResourcesId"] as DynamicObject)["Number"].ToString()); // jsonModel.Add("FHSourceID", jsonFProductWorkShopId);//FHSourceID 生产资源 //} if (Convert.ToString(current["FProductWorkShopId_Id"]) != "0") { JObject jsonFResourcesId = new JObject(); jsonFResourcesId.Add("FNumber", (current["FProductWorkShopId"] as DynamicObject)["Number"].ToString()); jsonModel.Add("FHWorkShopID", jsonFResourcesId);//FHWorkShopID 生产车间 } jsonRoot.Add("Model", jsonModel); CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/"); var result = cloudClient.Save("bsv_Sc_WorkBillAutoSortBillMonth", jsonRoot.ToString()); JObject saveObj = JObject.Parse(result); string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper(); if (saveIsSuc != "TRUE") { //LogHelper.Error("生产计划平台新增保存失败:" + saveObj.ToString()); this.View.ShowMessage(saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString()); return; } if (saveIsSuc == "TRUE") { string FDayPlanBillNo = saveObj["Result"]["Number"].ToString(); string FDayPlanID = saveObj["Result"]["Id"].ToString(); this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToInt32(current["SEQ"]) - 1);// this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToInt32(current["SEQ"]) - 1);// } } } this.View.ShowMessage("操作成功"); SearchList(); } /// /// 查询 /// public void SearchList() { string sqlwhere = " and 1=1"; //生产组织 if ((this.Model.GetValue("FPRDOrgId") as DynamicObject) != null) { string FHPRDORGID = (this.Model.GetValue("FPRDOrgId") as DynamicObject)["Id"].ToString(); if (!string.IsNullOrEmpty(FHPRDORGID)) sqlwhere += $" and FHPRDORGID='{FHPRDORGID}'"; } else { this.View.ShowErrMessage("请选择生产订单组织"); return; } //生产车间 if ((this.Model.GetValue("FProWorkShopId") as DynamicObject) != null) { string FProWorkShopId = (this.Model.GetValue("FProWorkShopId") as DynamicObject)["Id"].ToString(); if (!string.IsNullOrEmpty(FProWorkShopId)) sqlwhere += $" and FHWorkShopID='{FProWorkShopId}'"; } else { this.View.ShowErrMessage("请选择生产车间"); return; } //销售订单号 string FSalOrder = Convert.ToString((this.Model.GetValue("FSalOrder"))); if (!string.IsNullOrEmpty(FSalOrder)) sqlwhere += $" and FHSeOrderBillNo like '%{FSalOrder}%'"; //生产订单号 string FScOrderMainNo = Convert.ToString((this.Model.GetValue("FScOrderMainNo"))); if (!string.IsNullOrEmpty(FScOrderMainNo)) sqlwhere += $" and FSCORDERNO like '%{FScOrderMainNo}%'"; //物料 if ((this.Model.GetValue("FMatralId") as DynamicObject) != null) { string FMatralId = (this.Model.GetValue("FMatralId") as DynamicObject)["Number"].ToString(); if (!string.IsNullOrEmpty(FMatralId)) sqlwhere += $" and t3.FNumber='{FMatralId}'"; } //编制日期 string FBeginPreparatDate = Convert.ToString((this.Model.GetValue("FBrginPreparatDate"))); if (!string.IsNullOrEmpty(FBeginPreparatDate)) sqlwhere += $" and FPreparatDate>='{FBeginPreparatDate}'"; //编制日期 string FEndPreparatDate = Convert.ToString((this.Model.GetValue("FEndPreparatDate"))); if (!string.IsNullOrEmpty(FEndPreparatDate)) sqlwhere += $" and FPreparatDate<='{FEndPreparatDate}'"; try { string sql = @" /*dialect*/ select isnull(t5.FDATAVALUE,'') F_DY, isnull(t6.FDATAVALUE,'') F_GL, isnull(t7.FDATAVALUE,'') F_DB,TE.F_SB,TE.FKHXH,tq.FNoStockInQty,ta.FStockInQuaAuxQty,tq.FSCHEDULESTARTTIME,tq.FSCHEDULEFINISHTIME ,t1.*,ta.FSTATUS ,isnull((select SUM(isnull(FNotProductNum,0)) from SC_WORKBILLSORTBILLSub t2 where t2.FID = t1.FID and DATEDIFF(D,FHMASTERDATE,GETDATE())>0),0)FNotProductNum ,isnull((select SUM(isnull(FHQTY,0)) from SC_WORKBILLSORTBILLSub t2 where t2.FID = t1.FID and DATEDIFF(D,FHMASTERDATE,GETDATE())>0),0)FQTYLS from Sc_WorkBillMainMonth t1 join T_PRD_MOENTRY_A ta on t1.FPRDMOENTYID = ta.FENTRYID join T_PRD_MOENTRY_Q tq on t1.FPRDMOENTYID = tq.FENTRYID left join T_BD_MATERIAL t3 on t1.FHMaterID=t3.FMATERIALID join T_PRD_MOENTRY t2 on t1.FPRDMOENTYID = t2.FENTRYID left join T_SAL_ORDER t4 on t2.FSALEORDERID = t4.FID left join T_SAL_ORDERENTRY TE on t4.FID = TE.FID AND t2.FSALEORDERENTRYID = TE.FENTRYID left join ( select T3.FENTRYID,T3.FDATAVALUE from T_BAS_ASSISTANTDATA_L T1 JOIN T_BAS_ASSISTANTDATAENTRY T2 ON T1.FID= T2.FID JOIN T_BAS_ASSISTANTDATAENTRY_L T3 ON T2.FENTRYID= T3.FENTRYID WHERE T1.FNAME in ('电压','功率','底板') ) t5 on t4.F_DY = t5.FENTRYID left join ( select T3.FENTRYID,T3.FDATAVALUE from T_BAS_ASSISTANTDATA_L T1 JOIN T_BAS_ASSISTANTDATAENTRY T2 ON T1.FID= T2.FID JOIN T_BAS_ASSISTANTDATAENTRY_L T3 ON T2.FENTRYID= T3.FENTRYID WHERE T1.FNAME in ('电压','功率','底板') ) t6 on t4.F_GL = t6.FENTRYID left join ( select T3.FENTRYID,T3.FDATAVALUE from T_BAS_ASSISTANTDATA_L T1 JOIN T_BAS_ASSISTANTDATAENTRY T2 ON T1.FID= T2.FID JOIN T_BAS_ASSISTANTDATAENTRY_L T3 ON T2.FENTRYID= T3.FENTRYID WHERE T1.FNAME in ('电压','功率','底板') ) t7 on t4.F_DB = t7.FENTRYID where t1.FDOCUMENTSTATUS not in ('E') and ta.FSTATUS in (1,2,3,4) and t1.FMonthPlan = 1 " + sqlwhere + " " + " order by FHSourceID,t1.FPRIORITY"; DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; DateTime DateNow = DateTime.Now;//获取当前日期 this.Model.DeleteEntryData("FEntity"); EntryGrid grid = this.View.GetControl("FEntity"); for (int i = 0; i < dt.Rows.Count; i++) { this.Model.CreateNewEntryRow("FEntity"); this.Model.SetValue("FSEQ", i + 1, i);//序号 this.Model.SetValue("FMOFBILLTYPE", Convert.ToString(dt.Rows[i]["FMOFBILLTYPE"]), i);//生产订单单据类型 this.Model.SetValue("FOrderType", Convert.ToString(dt.Rows[i]["FOrderType"]), i);//订单类型 this.Model.SetValue("FStatus", Convert.ToString(dt.Rows[i]["FStatus"]), i);// this.Model.SetValue("FCompleteSetCount", "", i);//总齐套数量 this.Model.SetValue("FKhsb", Convert.ToString(dt.Rows[i]["F_SB"]), i);//客户商标 this.Model.SetValue("FKhxh", Convert.ToString(dt.Rows[i]["FKhxh"]), i);//客户型号 this.Model.SetValue("FStockInQuaAuxQty", Convert.ToString(dt.Rows[i]["FStockInQuaAuxQty"]), i);//已完成 this.Model.SetValue("FSxDate", Convert.ToString(dt.Rows[i]["FSCHEDULESTARTTIME"]), i);//上线日期 this.Model.SetValue("FWgDate", Convert.ToString(dt.Rows[i]["FSCHEDULEFINISHTIME"]), i);//完工日期 //客户商标 FKhsb 客户型号 FKhxh 已完成 FStockInQuaAuxQty 上线日期 FSxDate 完工日期 FWgDate this.Model.SetValue("F_bsv_Text", Convert.ToString(dt.Rows[i]["F_DY"]) + Convert.ToString(dt.Rows[i]["F_GL"]) + Convert.ToString(dt.Rows[i]["F_DB"]), i);//电压/功率/底板 this.Model.SetValue("FPriority", Convert.ToString(dt.Rows[i]["FPriority"]), i);//优先级 this.Model.SetValue("FProOrderCount", dt.Rows[i]["FHOrderNeedQty"].ToString(), i);//生产订单数量 this.Model.SetValue("FSRCBILLENTRYSEQ", dt.Rows[i]["FSRCBILLENTRYSEQ"].ToString(), i);// this.Model.SetValue("FSalOrderCount", dt.Rows[i]["FHOrderQty"].ToString(), i);//销售订单数量 this.Model.SetValue("FBatch", dt.Rows[i]["FBatch"].ToString(), i);//批次号 this.Model.SetValue("FUnit", dt.Rows[i]["FHUnitID"].ToString(), i);//计量单位 this.Model.SetValue("FORGID", dt.Rows[i]["FHPRDORGID"].ToString(), i);//生产组织 this.Model.SetValue("FMatrailId", dt.Rows[i]["FHMaterID"].ToString(), i);//产品代码 this.Model.SetValue("FDeliverydate", dt.Rows[i]["FHOrderCommitDate"].ToString(), i);//交货日期 this.Model.SetValue("FOrderLevel", dt.Rows[i]["FHOrderLev"].ToString(), i);//订单等级 this.Model.SetValue("FSCOrderNo", dt.Rows[i]["FSCOrderNo"].ToString(), i);//生产订单号 this.Model.SetValue("FSalOrderNo", dt.Rows[i]["FHSEORDERBILLNO"].ToString(), i);//销售订单号 this.Model.SetValue("FBzDate", dt.Rows[i]["FPreparatDate"].ToString(), i);//预计开工日期 this.Model.SetValue("FProOrderCount", dt.Rows[i]["FHOrderNeedQty"].ToString(), i);//生产订单数量 this.Model.SetValue("FHMainSourceInterID", dt.Rows[i]["FPRDMOMAINID"].ToString(), i);//源单主内码FHMainSourceInterID this.Model.SetValue("FHMainSourceEntryID", dt.Rows[i]["FPRDMOENTYID"].ToString(), i);//源单子内码FHMainSourceEntryID this.Model.SetValue("FDayPlanWorkID", dt.Rows[i]["FID"].ToString(), i);//日计划工单FID this.Model.SetValue("FResourcesId", dt.Rows[i]["FHSourceID"].ToString(), i);//生产资源 this.Model.SetValue("FProductWorkShopId", dt.Rows[i]["FHWorkShopID"].ToString(), i);//生产车间 this.Model.SetValue("FCompleteSetCount", dt.Rows[i]["FCompleteCount"].ToString(), i);//齐套数量 this.Model.SetValue("FOrderQuantity", dt.Rows[i]["FOrderQuantity"].ToString(), i);//生产订单数量 this.Model.SetValue("FDayPlanQuantity", Convert.ToDecimal(dt.Rows[i]["FDAYPLANQUANTITY"]) - Convert.ToDecimal(dt.Rows[i]["FQTYLS"]), i);//日计划数量 this.Model.SetValue("FQTYLS", dt.Rows[i]["FQTYLS"].ToString(), i);//历史遗留 this.Model.SetValue("FNoScheduled", dt.Rows[i]["FNoScheduled"].ToString(), i);//未排数量 this.Model.SetValue("FDelaylnUM", dt.Rows[i]["FNotProductNum"].ToString(), i);//拖期数量 //sql = @"/*dialect*/SELECT * FROM Sc_WorkBillSortBillSub WHERE DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0 and FID=" + dt.Rows[i]["FID"].ToString(); //DataTable _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; //foreach (DataRow dr in _dt.Rows) //{ // DateTime start = Convert.ToDateTime(DateNow.ToShortDateString()); // DateTime end = Convert.ToDateTime(Convert.ToDateTime(dr["FHMASTERDATE"]).ToShortDateString()); // TimeSpan getDay = end.Subtract(start); // if (getDay.Days > 60) // continue; // this.Model.SetValue("FT" + getDay.Days.ToString(), dr["FHQTY"].ToString(), i);//日计划工单FID // if (dr["FHLockedSub"].ToString() == "1") // this.View.GetFieldEditor("FT" + getDay.Days.ToString(), i).Enabled = false; //单据体行锁定字段 //} //this.View.InvokeFieldUpdateService("FMatrailId", i);//GetControl } this.View.UpdateView(); //for (int j = 0; j < dt.Rows.Count; j++) //{ // sql = @"/*dialect*/SELECT * FROM Sc_WorkBillSortBillSub WHERE DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0 and FID=" + dt.Rows[j]["FID"].ToString(); // DataTable _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; // foreach (DataRow dr in _dt.Rows) // { // DateTime start = Convert.ToDateTime(DateNow.ToShortDateString()); // DateTime end = Convert.ToDateTime(Convert.ToDateTime(dr["FHMASTERDATE"]).ToShortDateString()); // TimeSpan getDay = end.Subtract(start); // if (getDay.Days > 60) // continue; // if (dr["FHLockedSub"].ToString() == "1") // this.View.GetFieldEditor("FT" + getDay.Days.ToString(), j).Enabled = false; //单据体行锁定字段 // if (dr["FCOMPLETE"].ToString() == "未齐套") // { // this.View.GetFieldEditor("FT" + getDay.Days.ToString(), j).Enabled = false; //单据体行锁定字段 // grid.SetForecolor("FT" + "" + getDay.Days.ToString() + "", "#FF0000", j); // } // else if (dr["FCOMPLETE"].ToString() == "齐套") // { // this.View.GetFieldEditor("FT" + getDay.Days.ToString(), j).Enabled = false; //单据体行锁定字段 // grid.SetForecolor("FT" + "" + getDay.Days.ToString() + "", "#00FF00", j); // } // } //} //for (int m = 0; m <= 60; m++) //{ // this.View.GetControl("FT" + "" + m + "").Text = DateNow.AddDays(m).ToShortDateString(); //} } catch (Exception ex) { this.View.ShowErrMessage(ex.Message.ToString()); } } /// /// 编辑 /// public void SearchListEdit() { string sqlwhere = " and 1=1"; //生产组织 if ((this.Model.GetValue("FPRDOrgId") as DynamicObject) != null) { string FHPRDORGID = (this.Model.GetValue("FPRDOrgId") as DynamicObject)["Id"].ToString(); if (!string.IsNullOrEmpty(FHPRDORGID)) sqlwhere += $" and FHPRDORGID='{FHPRDORGID}'"; } else { this.View.ShowErrMessage("请选择生产订单组织"); return; } //生产车间 if ((this.Model.GetValue("FProWorkShopId") as DynamicObject) != null) { string FProWorkShopId = (this.Model.GetValue("FProWorkShopId") as DynamicObject)["Id"].ToString(); if (!string.IsNullOrEmpty(FProWorkShopId)) sqlwhere += $" and FHWorkShopID='{FProWorkShopId}'"; } //else //{ // this.View.ShowErrMessage("请选择生产车间"); // return; //} //销售订单号 string FSalOrder = Convert.ToString((this.Model.GetValue("FSalOrder"))); if (!string.IsNullOrEmpty(FSalOrder)) sqlwhere += $" and FHSeOrderBillNo like '%{FSalOrder}%'"; //生产订单号 string FScOrderMainNo = Convert.ToString((this.Model.GetValue("FScOrderMainNo"))); if (!string.IsNullOrEmpty(FScOrderMainNo)) sqlwhere += $" and FSCORDERNO like '%{FScOrderMainNo}%'"; //物料 if ((this.Model.GetValue("FMatralId") as DynamicObject) != null) { string FMatralId = (this.Model.GetValue("FMatralId") as DynamicObject)["Number"].ToString(); if (!string.IsNullOrEmpty(FMatralId)) sqlwhere += $" and t3.FNumber='{FMatralId}'"; } //编制日期开始 string FBeginPreparatDate = Convert.ToString((this.Model.GetValue("FBrginPreparatDate"))); if (!string.IsNullOrEmpty(FBeginPreparatDate)) sqlwhere += $" and FPreparatDate>='{FBeginPreparatDate}'"; //编制日期结束 string FEndPreparatDate = Convert.ToString((this.Model.GetValue("FEndPreparatDate"))); if (!string.IsNullOrEmpty(FEndPreparatDate)) sqlwhere += $" and FPreparatDate<='{FEndPreparatDate}'"; try { string sql = @" /*dialect*/ select t1.*,ta.FSTATUS,isnull((select SUM(isnull(FNotProductNum,0)) from SC_WORKBILLSORTBILLSub t2 where t2.FID = t1.FID and DATEDIFF(D,FHMASTERDATE,GETDATE())>0),0)FNotProductNum ,isnull((select SUM(isnull(FHQTY,0)) from SC_WORKBILLSORTBILLSub t2 where t2.FID = t1.FID and DATEDIFF(D,FHMASTERDATE,GETDATE())>0),0)FQTYLS from Sc_WorkBillSortBillMain t1 join T_PRD_MOENTRY_A ta on t1.FPRDMOENTYID = ta.FENTRYID left join T_BD_MATERIAL t3 on t1.FHMaterID=t3.FMATERIALID where t1.FDOCUMENTSTATUS not in ('E') and ta.FSTATUS in (1,2,3,4) and t1.FMonthPlan = 1 " + sqlwhere + " " + " order by FHSourceID,t1.FPRIORITY"; DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; DateTime DateNow = DateTime.Now;//获取当前日期 this.Model.DeleteEntryData("FEntity"); EntryGrid grid = this.View.GetControl("FEntity"); for (int i = 0; i < dt.Rows.Count; i++) { this.Model.CreateNewEntryRow("FEntity"); this.Model.SetValue("FSEQ", i + 1, i);//序号 this.Model.SetValue("FMOFBILLTYPE", Convert.ToString(dt.Rows[i]["FMOFBILLTYPE"]), i);//生产订单单据类型 this.Model.SetValue("FOrderType", Convert.ToString(dt.Rows[i]["FOrderType"]), i);//订单类型 this.Model.SetValue("FStatus", Convert.ToString(dt.Rows[i]["FStatus"]), i);//订单类型 this.Model.SetValue("FCompleteSetCount", "", i);//总齐套数量 this.Model.SetValue("FPriority", Convert.ToString(dt.Rows[i]["FPriority"]), i);//优先级 this.Model.SetValue("FProOrderCount", dt.Rows[i]["FHOrderNeedQty"].ToString(), i);//生产订单数量 this.Model.SetValue("FSRCBILLENTRYSEQ", dt.Rows[i]["FSRCBILLENTRYSEQ"].ToString(), i);// this.Model.SetValue("FSalOrderCount", dt.Rows[i]["FHOrderQty"].ToString(), i);//销售订单数量 this.Model.SetValue("FBatch", dt.Rows[i]["FBatch"].ToString(), i);//批次号 this.Model.SetValue("FUnit", dt.Rows[i]["FHUnitID"].ToString(), i);//计量单位 this.Model.SetValue("FORGID", dt.Rows[i]["FHPRDORGID"].ToString(), i);//生产组织 this.Model.SetValue("FMatrailId", dt.Rows[i]["FHMaterID"].ToString(), i);//产品代码 this.Model.SetValue("FDeliverydate", dt.Rows[i]["FHOrderCommitDate"].ToString(), i);//交货日期 this.Model.SetValue("FOrderLevel", dt.Rows[i]["FHOrderLev"].ToString(), i);//订单等级 this.Model.SetValue("FSCOrderNo", dt.Rows[i]["FSCOrderNo"].ToString(), i);//生产订单号 this.Model.SetValue("FSalOrderNo", dt.Rows[i]["FHSEORDERBILLNO"].ToString(), i);//销售订单号 this.Model.SetValue("FBzDate", dt.Rows[i]["FPreparatDate"].ToString(), i);//预计开工日期 this.Model.SetValue("FProOrderCount", dt.Rows[i]["FHOrderNeedQty"].ToString(), i);//生产订单数量 this.Model.SetValue("FHMainSourceInterID", dt.Rows[i]["FPRDMOMAINID"].ToString(), i);//源单主内码FHMainSourceInterID this.Model.SetValue("FHMainSourceEntryID", dt.Rows[i]["FPRDMOENTYID"].ToString(), i);//源单子内码FHMainSourceEntryID this.Model.SetValue("FDayPlanWorkID", dt.Rows[i]["FID"].ToString(), i);//日计划工单FID this.Model.SetValue("FResourcesId", dt.Rows[i]["FHSourceID"].ToString(), i);//生产资源 this.Model.SetValue("FProductWorkShopId", dt.Rows[i]["FHWorkShopID"].ToString(), i);//生产车间 this.Model.SetValue("FCompleteSetCount", dt.Rows[i]["FCompleteCount"].ToString(), i);//齐套数量 this.Model.SetValue("FOrderQuantity", dt.Rows[i]["FOrderQuantity"].ToString(), i);//生产订单数量 this.Model.SetValue("FDayPlanQuantity", Convert.ToDecimal(dt.Rows[i]["FOrderQuantity"]) - Convert.ToDecimal(dt.Rows[i]["FQTYLS"]), i);//日计划数量 this.Model.SetValue("FQTYLS", dt.Rows[i]["FQTYLS"].ToString(), i);//历史遗留 this.Model.SetValue("FNoScheduled", dt.Rows[i]["FNoScheduled"].ToString(), i);//未排数量 this.Model.SetValue("FDelaylnUM", dt.Rows[i]["FNotProductNum"].ToString(), i);//拖期数量 sql = @"/*dialect*/SELECT * FROM Sc_WorkBillSortBillSub WHERE DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0 and FID=" + dt.Rows[i]["FID"].ToString(); DataTable _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; foreach (DataRow dr in _dt.Rows) { DateTime start = Convert.ToDateTime(DateNow.ToShortDateString()); DateTime end = Convert.ToDateTime(Convert.ToDateTime(dr["FHMASTERDATE"]).ToShortDateString()); TimeSpan getDay = end.Subtract(start); if (getDay.Days > 60) continue; this.Model.SetValue("FT" + getDay.Days.ToString(), dr["FHQTY"].ToString(), i);//日计划工单FID if (dr["FHLockedSub"].ToString() == "1") this.View.GetFieldEditor("FT" + getDay.Days.ToString(), i).Enabled = false; //单据体行锁定字段 } this.View.InvokeFieldUpdateService("FMatrailId", i);//调用数量值更新 } this.View.UpdateView(); for (int j = 0; j < dt.Rows.Count; j++) { sql = @"/*dialect*/SELECT * FROM Sc_WorkBillSortBillSub WHERE DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0 and FID=" + dt.Rows[j]["FID"].ToString(); DataTable _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; foreach (DataRow dr in _dt.Rows) { DateTime start = Convert.ToDateTime(DateNow.ToShortDateString()); DateTime end = Convert.ToDateTime(Convert.ToDateTime(dr["FHMASTERDATE"]).ToShortDateString()); TimeSpan getDay = end.Subtract(start); if (getDay.Days > 60) continue; if (dr["FHLockedSub"].ToString() == "1") this.View.GetFieldEditor("FT" + getDay.Days.ToString(), j).Enabled = false; //单据体行锁定字段 } } for (int m = 0; m <= 60; m++) { this.View.GetControl("FT" + "" + m + "").Text = DateNow.AddDays(m).ToShortDateString(); } } catch (Exception ex) { this.View.ShowErrMessage(ex.Message.ToString()); } } //生产计划平台选单 生产订单数据 public void SelectMenu(string FBarItemKey) { try { //获取单据体信息 Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity"); //单据体信息转换为列表集合 DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity); int Fseq = entityDataObjoct.Count(); ListShowParameter showParameter = new ListShowParameter(); IRegularFilterParameter filterParameter = new ListRegularFilterParameter(); filterParameter.Filter = string.Format(" FPickMtrlStatus in (1,2) ");//部分领料 或者 未领料 filterParameter.SelectEntitys = new List() { "FTreeEntity" }; string pageId = Guid.NewGuid().ToString(); showParameter.PageId = pageId; showParameter.ListFilterParameter = filterParameter; showParameter.UseOrgId = this.Context.CurrentOrganizationInfo.ID; showParameter.IsLookUp = true; if (FBarItemKey == "tbSelectMenuSC") { showParameter.FormId = "PRD_MO"; this.View.ShowForm(showParameter, delegate (FormResult result) { object returnData = result.ReturnData; if (returnData is ListSelectedRowCollection) { ListSelectedRowCollection listSelectedRowCollection = returnData as ListSelectedRowCollection; //LogHelper.Info("生产计划平台选单 行数" + listSelectedRowCollection.Count().ToString()); if (listSelectedRowCollection != null) { var ret = ""; foreach (var listSelectedRow in listSelectedRowCollection) { //if (entityDataObjoct.Where(x => x["FSRCBILLENTRYSEQ"].ToString() == listSelectedRow.DataRow["t1_FSeq"].ToString() && x["FSCOrderNo"].ToString() == listSelectedRow.DataRow["FBillNo"].ToString()).Count() > 0) //{ // //LogHelper.Info("生产计划平台选单:" + listSelectedRow.DataRow["FBillNo"].ToString() + ", 行号," + listSelectedRow.DataRow["t1_FSeq"].ToString() + ",已选"); // ret += "生产订单号:" + listSelectedRow.DataRow["FBillNo"].ToString() + ", 行号," + listSelectedRow.DataRow["t1_FSeq"].ToString() + ",已选" + "\n"; // continue; //} //string sql = $"select FID from Sc_WorkBillSortBillMain where FDOCUMENTSTATUS NOT IN ('E') and FPRDMOENTYID = {listSelectedRow.DataRow["t1_FENTRYID"].ToString()}"; //int day = DBServiceHelper.ExecuteScalar(Context, sql, 0); //if (day > 0) //{ // ret += "生产订单号:" + listSelectedRow.DataRow["FBillNo"].ToString() + ", 行号:" + listSelectedRow.DataRow["t1_FSeq"].ToString() + ",已存在日计划\n"; // continue; //} ////今天以前的数据是显示不出来的 //sql = $"select DATEDIFF(d,getdate(),FPlanStartDate)days from T_PRD_MOENTRY where FENTRYID = {listSelectedRow.DataRow["t1_FENTRYID"].ToString()}"; //day = DBServiceHelper.ExecuteScalar(Context, sql, 0); //if (day < 0) //{ // ret += "计划开工日期在今天之前,生产订单号:" + listSelectedRow.DataRow["FBillNo"].ToString() + ", 行号:" + listSelectedRow.DataRow["t1_FSeq"].ToString() + "\n"; // continue; //} string sql = @"SELECT T2.FBILLNO,T2.FPRDORGID,T1.FSEQ,T1.FMATERIALID,TA.FSTATUS,T1.FUNITID,T1.FQTY,T1.FWORKSHOPID,T1.FPLANSTARTDATE ,T1.FSALEORDERNO,T3.FPLANDELIVERYDATE,T3.FQTY AS FSALEORDERQTY,TQ.FNoStockInQty FROM T_PRD_MOENTRY T1 JOIN T_PRD_MOENTRY_A TA ON T1.FENTRYID =TA.FENTRYID JOIN T_PRD_MOENTRY_Q TQ on t1.FENTRYID = TQ.FENTRYID JOIN T_PRD_MO T2 ON T1.FID =T2.FID LEFT JOIN T_SAL_ORDERENTRY T3 ON T1.FSALEORDERENTRYID =T3.FENTRYID LEFT JOIN T_SAL_ORDER T4 ON T3.FID =T4.FID WHERE T1.FENTRYID = " + listSelectedRow.DataRow["t1_FENTRYID"].ToString() + " "; DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; if (dt.Rows.Count > 0) { this.Model.CreateNewEntryRow("FEntity"); this.View.Model.SetValue("FOrderType", "生产订单", Fseq); this.View.Model.SetValue("FStatus", dt.Rows[0]["FSTATUS"]?.ToString(), Fseq); this.View.Model.SetValue("FORGID", dt.Rows[0]["FPRDORGID"]?.ToString(), Fseq); this.View.Model.SetValue("FSCOrderNo", dt.Rows[0]["FBILLNO"]?.ToString(), Fseq); this.View.Model.SetValue("FSRCBILLENTRYSEQ", dt.Rows[0]["FSEQ"]?.ToString(), Fseq); this.View.Model.SetValue("FMatrailId", dt.Rows[0]["FMATERIALID"]?.ToString(), Fseq);//2129900005 this.View.Model.SetValue("FFUnit", dt.Rows[0]["FUNITID"]?.ToString(), Fseq); this.View.Model.SetValue("FOrderQuantity", dt.Rows[0]["FQTY"]?.ToString(), Fseq); this.View.Model.SetValue("FProductWorkShopId", dt.Rows[0]["FWORKSHOPID"]?.ToString(), Fseq); this.View.Model.SetValue("FOrderLevel", "3", Fseq); this.View.Model.SetValue("FBzDate", dt.Rows[0]["FPLANSTARTDATE"]?.ToString(), Fseq);//预计开工日期 this.View.Model.SetValue("FSalOrderNo", dt.Rows[0]["FSALEORDERNO"]?.ToString(), Fseq);//销售订单号 this.View.Model.SetValue("FSalOrderCount", dt.Rows[0]["FSALEORDERQTY"]?.ToString(), Fseq);//销售订单数量 //this.View.Model.SetValue("FNoStockInQty", dt.Rows[0]["FNoStockInQty"].ToString(), Fseq);//未入库数量 this.View.Model.SetValue("FDeliveryDate", dt.Rows[0]["FPLANDELIVERYDATE"]?.ToString(), Fseq);//交货日期 //this.View.Model.SetValue("FT" + day.ToString(), dt.Rows[0]["FQTY"]?.ToString(), Fseq); Fseq++; } else { this.View.ShowMessage("联系管理员"); } } if (ret != "") { this.View.ShowMessage(ret); } } } }); } } catch (Exception ex) { //LogHelper.Error("选单失败:" + ex.Message); } } } }