王 垚
2021-04-13 58de9116152c3a0f8aa436a2c82b520ad940b367
src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs
@@ -1,15 +1,12 @@
using Demo.Model.Model;
using Demo.Model.Model.PODemandPlan;
using K3Cloud.Extend.Utils;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Const;
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.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.JSON;
using Kingdee.BOS.KDThread;
@@ -19,25 +16,16 @@
using Kingdee.BOS.Util;
using Kingdee.K3.Core.SCM.STK;
using Kingdee.K3.SCM.ServiceHelper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Documents;
using ZD.Cloud.Logger;
using ZD.Cloud.WebApi;
using ZD.Share.Common;
@@ -88,6 +76,7 @@
                if (e.BarItemKey.ToUpper() == "TBCOMPLETE")
                {
                    COMPLETE();
                }
                //提料计划
                if (e.BarItemKey.ToUpper() == "TBEXTRACTION")
@@ -268,7 +257,7 @@
            jObject.Put("desc", "请点击打开附件:");
            jObject.Put("urltitle", "这是文件名");
            this.View.AddAction(JSAction.openUrlWindow, new JSONArray { jObject });
        }
        }
        /// <summary>
        /// 锁定
        /// </summary>
@@ -307,73 +296,80 @@
                sql = $"/*dialect*/update t1 set t1.FHLockedSub=0 from Sc_WorkBillSortBillSub t1  join Sc_WorkBillSortBillMain t2 on  t1.FID = t2.FID  where  FHMASTERDATE between  DATEADD(day,-1,getdate()) and DATEADD(day,{day - 1},getdate())   and t1.FID = { Convert.ToString(item["FDayPlanWorkID"])} ";
                sqlList.Add(sql);
            }
            int result = DBServiceHelper.ExecuteBatch(Context, sqlList);
            if (result > 0)
            {
                SearchList();
                this.View.ShowMessage("操作成功");
            }
            else
                this.View.ShowMessage("操作失败,联系管理员!");
            SearchList();
            this.View.ShowMessage("操作成功");
        }
        /// <summary>
        /// 保存功能
        /// </summary>  
        public void Save()
        {
            List<string> sqlList = new List<string>();
            string sql;
            //获取单据体信息
            Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
            //单据体信息转换为列表集合
            DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity);
            DateTime date = DateTime.Now;
            DateTime date = Convert.ToDateTime(DateTime.Now.ToString("d"));
            string _result = "";
            foreach (DynamicObject current in entityDataObjoct)
            {
                if (Convert.ToInt32(current["FNoScheduled"]) < 0)
                    _result += "序号:" + Convert.ToString(current["SEQ"]) + ",日计划总数量超出生产订单数量";
            }
            if (_result != "")
            {
                this.View.ShowErrMessage(_result);
                return;
            }
            foreach (DynamicObject current in entityDataObjoct)
            {
                sql = $"/*dialect*/ update Sc_WorkBillSortBillMain set FOrderQuantity={current["FOrderQuantity"]},FDayPlanQuantity={current["FDayPlanQuantity"]},FNoScheduled={current["FNoScheduled"]} where FID = {current["FDayPlanWorkID"]}";
                sqlList.Add(sql);
                DateTime FBzDate = Convert.ToDateTime(Convert.ToDateTime(current["FBzDate"]));
                DateTime end = Convert.ToDateTime(Convert.ToDateTime(current["FBzDate"]).AddDays(60).ToShortDateString());//最大日期
                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("FID", Convert.ToString(current["FDayPlanWorkID"]));
                jsonModel.Add("FOrderQuantity", Convert.ToString(current["FOrderQuantity"]));
                jsonModel.Add("FDayPlanQuantity", Convert.ToString(current["FDayPlanQuantity"]));
                jsonModel.Add("FNoScheduled", Convert.ToString(current["FNoScheduled"]));
                sql = $" /*dialect*/ select FEntryID, FHMASTERDATE from SC_WORKBILLSORTBILLSub  where FID={Convert.ToString(current["FDayPlanWorkID"])} ";
                List<DayPlanModel> dayPlanModel = new List<DayPlanModel>();
                dayPlanModel = DBServiceHelper.ExecuteDataSet(Context, sql).ToModelList<DayPlanModel>();
                JArray Entry = new JArray();
                for (int i = 0; i <= 60; i++)
                {
                    DateTime start = Convert.ToDateTime(date.AddDays(i).ToShortDateString());
                    TimeSpan getDay = end.Subtract(start);
                    //编制日期+61天>date.AddDays(i).ToShortDateString() continue
                    if (getDay.Days < 0)
                        break;
                    sql = $"/*dialect*/update t1 set FHQTY='{Convert.ToString(current["FT" + "" + i + ""])}' from Sc_WorkBillSortBillSub t1 join " +
                        $" Sc_WorkBillSortBillMain t2 on  t1.FID = t2.FID where FHMASTERDATE='{date.AddDays(i).ToShortDateString()}' and t2.FID='{Convert.ToString(current["FDayPlanWorkID"])}'";
                    sqlList.Add(sql);
                    if (Convert.ToString(current["FT" + "" + i + ""]) == "" || Convert.ToString(current["FT" + "" + i + ""]) == "0")
                        continue;
                    JObject jsonFPOOrderEntry = new JObject();
                    jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//主日期
                    jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//日计划数量
                    List<DayPlanModel> _dayPlanModel = dayPlanModel.Where(x => x.FHMASTERDATE == date.AddDays(i)).ToList();
                    if (_dayPlanModel.Count > 0)
                    {
                        jsonFPOOrderEntry.Add("FEntryID", _dayPlanModel.FirstOrDefault().FEntryID); ;//序号
                    }
                    Entry.Add(jsonFPOOrderEntry);
                }
                jsonModel.Add("FEntity", Entry);
                jsonRoot.Add("Model", jsonModel);
                CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                var result = cloudClient.Save("Paez_Sc_WorkBillAutoSortBill", jsonRoot.ToString());
                JObject saveObj = JObject.Parse(result);
                string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
                if (saveIsSuc != "TRUE")
                {
                    LogHelper.Error("生产计划平台保存失败:" + jsonRoot.ToString());
                    this.View.ShowMessage("数据储存失败!请联系管理员!");
                }
            }
            int result = DBServiceHelper.ExecuteBatch(Context, sqlList);
            this.View.ShowMessage("操作成功");
            SearchList();
            //if (result > 0)
            //{
            //}
            //else
            //    this.View.ShowMessage("操作失败,联系管理员!");
        }
        /// <summary>
        /// 齐套分析
@@ -646,7 +642,7 @@
                    if (item.FOwnerId != null)
                        jsonModel.Add("FOwnerId", new JObject() { ["FNUMBER"] = item.FOwnerId });
                    jsonRoot.Add("Model", jsonModel);
                    CloudClient cloudClient = new CloudClient("http://localhost/K3Cloud/");
                    CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                    var result = cloudClient.Save("paez_CompleteAnalysisTemp", jsonRoot.ToString());
                    JObject saveObj = JObject.Parse(result);
                    string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
@@ -897,7 +893,7 @@
                            ["IsVerifyBaseDataField"] = "false",
                            ["Model"] = Fentity
                        };
                        CloudClient cloudClient = new CloudClient("http://localhost/K3Cloud/");
                        CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                        var result = cloudClient.BatchSave("paez_CompleteAnalysisTemp", jsonRoot.ToString());
                        JObject saveObj = JObject.Parse(result);
                        string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
@@ -1159,11 +1155,11 @@
            //销售订单号
            string FSalOrder = Convert.ToString((this.Model.GetValue("FSalOrder")));
            if (!string.IsNullOrEmpty(FSalOrder))
                sqlwhere += $" and FHSeOrderBillNo='{FSalOrder}'";
                sqlwhere += $" and FHSeOrderBillNo like '%{FSalOrder}%'";
            //生产订单号
            string FScOrderMainNo = Convert.ToString((this.Model.GetValue("FScOrderMainNo")));
            if (!string.IsNullOrEmpty(FScOrderMainNo))
                sqlwhere += $" and FSCORDERNO='{FScOrderMainNo}'";
                sqlwhere += $" and FSCORDERNO like '%{FScOrderMainNo}%'";
            //物料
            if ((this.Model.GetValue("FMatralId") as DynamicObject) != null)
            {
@@ -1225,7 +1221,7 @@
                        if (dr["FHLockedSub"].ToString() == "1")
                            this.View.GetFieldEditor("FT" + getDay.Days.ToString(), i).Enabled = false; //单据体行锁定字段
                    }
                    this.View.InvokeFieldUpdateService("FMatrailId", i);//调用数量值更新
                    this.View.InvokeFieldUpdateService("FMatrailId", i);//GetControl
                }
                this.View.UpdateView();
                for (int j = 0; j < dt.Rows.Count; j++)
@@ -1279,20 +1275,12 @@
            }
            //销售订单号
            string FSalOrder = Convert.ToString((this.Model.GetValue("FSalOrder")));
            if (string.IsNullOrEmpty(FSalOrder))
            {
            }
            else
                sqlwhere += $" and FHSeOrderBillNo='{FSalOrder}'";
            if (!string.IsNullOrEmpty(FSalOrder))
                sqlwhere += $" and FHSeOrderBillNo like '%{FSalOrder}%'";
            //生产订单号
            string FScOrderMainNo = Convert.ToString((this.Model.GetValue("FScOrderMainNo")));
            if (string.IsNullOrEmpty(FScOrderMainNo))
            {
            }
            else
                sqlwhere += $" and FSCORDERNO='{FScOrderMainNo}'";
            if (!string.IsNullOrEmpty(FScOrderMainNo))
                sqlwhere += $" and FSCORDERNO like '%{FScOrderMainNo}%'";
            //物料
            if ((this.Model.GetValue("FMatralId") as DynamicObject) != null)
@@ -1490,7 +1478,7 @@
                            ["Model"] = model
                        };
                        CloudClient cloudClient = new CloudClient("http://localhost/K3Cloud/");
                        CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                        var result = cloudClient.Save("Paez_Sc_DayPlanPPBomBill", jsonRoot.ToString());
                        JObject saveObj = JObject.Parse(result);
                        string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
@@ -1645,13 +1633,13 @@
                                ["IsVerifyBaseDataField"] = "false",
                                ["Model"] = Fentity
                            };
                            CloudClient cloudClient = new CloudClient("http://localhost/K3Cloud/");
                            CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                            var result = cloudClient.BatchSave("Paez_Sc_DayPlanPPBomBill", jsonRoot.ToString());
                            JObject saveObj = JObject.Parse(result);
                            string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
                            if (saveIsSuc != "TRUE")
                            {
                                LogHelper.Error(jsonRoot.ToString());
                                LogHelper.Error(saveObj.ToString());
                            }
                            Fentity = new JArray();
                        }
@@ -2074,7 +2062,7 @@
                            ["IsVerifyBaseDataField"] = "false",
                            ["Model"] = FinalyResult
                        };
                        CloudClient cloudClient = new CloudClient("http://localhost/K3Cloud/");
                        CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                        var result = cloudClient.BatchSave("paez_PODemandPlan", jsonRoot.ToString());
                        JObject saveObj = JObject.Parse(result);
                        string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();