From 3ee1243be7aa6a7bdbfc23a96da82dc72b4de3b4 Mon Sep 17 00:00:00 2001 From: 王 垚 <1402714037@qq.com> Date: 星期四, 31 十二月 2020 11:25:06 +0800 Subject: [PATCH] 代码上传 --- src/BLL/Demo.BillView/PRD/Pro_ScDayImport.cs | 283 ++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 191 insertions(+), 92 deletions(-) diff --git a/src/BLL/Demo.BillView/PRD/Pro_ScDayImport.cs b/src/BLL/Demo.BillView/PRD/Pro_ScDayImport.cs index 5347640..ebac424 100644 --- a/src/BLL/Demo.BillView/PRD/Pro_ScDayImport.cs +++ b/src/BLL/Demo.BillView/PRD/Pro_ScDayImport.cs @@ -19,6 +19,7 @@ using Demo.TimedTaskPlugIn.PRD; using ZD.Cloud.Logger; + namespace Demo.BillView.PRD { @@ -26,11 +27,8 @@ [HotUpdate] public class Pro_ScDayImport : AbstractDynamicFormPlugIn { - - - + CloudClient cloudClient = new CloudClient("http://localhost/K3Cloud/"); private string fileFullPath = string.Empty; - //public override void BarItemClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e) //{ // base.BarItemClick(e); @@ -52,8 +50,6 @@ // } //} - - public override void AfterBarItemClick(AfterBarItemClickEventArgs e) { base.AfterBarItemClick(e); @@ -97,6 +93,10 @@ } base.CustomEvents(e); } + /// <summary> + /// 鏂囦欢涓婁紶鐣岄潰鏁版嵁鏄剧ず + /// </summary> + /// <param name="fileFullPath"></param> private void ImportDataSC(string fileFullPath) { using (ExcelOperation helper = new ExcelOperation(this.View)) @@ -115,6 +115,34 @@ for (int i = 0; i < dt.Rows.Count; i++) { + //鏍规嵁鐢熶骇璁㈠崟鍙峰拰鐗╂枡鏌ヨ鏄惁瀛樺湪鏄庣粏 + string sql = string.Format(@"/*dialect*/ SELECT T1.FBILLNO,T2.* FROM T_PRD_MO T1 +LEFT JOIN T_PRD_MOENTRY T2 ON T1.FID = T2.FID +JOIN T_BD_MATERIAL T3 ON T2.FMATERIALID = T3.FMATERIALID +WHERE T1.FBILLNO = '{0}' AND T3.FNUMBER = '{1}'", dt.Rows[i][1].ToString(), dt.Rows[i][5].ToString()); + DataTable _dt = new DataTable(); + _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; + string FLOT = "";//FLOT 鎵规 + string FQTY = "";//FQTY 鐢熶骇璁㈠崟鏁伴噺 + string FBILLNO = "";//FBILLNO 鍘熷崟鍙� + if (_dt.Rows.Count > 0) + { + FLOT = _dt.Rows[0]["FLOT"].ToString(); + FQTY = _dt.Rows[0]["FQTY"].ToString(); + FBILLNO = _dt.Rows[0]["FBILLNO"].ToString(); + } + //鐗╂枡缂栫爜 + 鐢熶骇璁㈠崟鍙� + 鐢熶骇璧勬簮 鍘诲垽鏂槸鍚﹀鍏ヨ繃 甯﹀嚭鏃ヨ鍒掑伐鍗旾D鍙婄紪鍙� + string fDayPlanID = ""; + string fDayPlanBillNo = ""; + sql = string.Format(@"select a.FID,FBILLNO,FSCOrderNo,FHMaterID,FHSourceID from Sc_WorkBillSortBillMain a JOIN T_BD_MATERIAL b ON a.FHMaterID = b.FMATERIALID +left join T_ENG_WORKCENTER c on a.FHSourceID=c.fid + where FSCOrderNo ='{0}' and b.FNUMBER ='{1}' and isnull(c.FNUMBER,'') ='{2}' ", dt.Rows[i][1].ToString(), dt.Rows[i][5].ToString(), dt.Rows[i][4].ToString()); + DataTable dayPlanDt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; + if (dayPlanDt.Rows.Count > 0) + { + fDayPlanID = dayPlanDt.Rows[0]["FID"].ToString(); + fDayPlanBillNo = dayPlanDt.Rows[0]["FBILLNO"].ToString(); + } //DynamicObject row = new DynamicObject(entity.DynamicObjectType); this.Model.CreateNewEntryRow("FEntity"); this.Model.SetValue("FSEQ", i + 1, i); @@ -125,24 +153,23 @@ this.Model.SetItemValueByNumber("FResourcesId", dt.Rows[i][4].ToString(), i); // this.Model.SetValue("FMatrailId", dt.Rows[i][5].ToString(), i); this.Model.SetItemValueByNumber("FMatrailId", dt.Rows[i][5].ToString(), i); - this.Model.SetValue("FMatrailName", dt.Rows[i][6].ToString(), i); - this.Model.SetValue("FModel", dt.Rows[i][7].ToString(), i); - this.Model.SetValue("FUnit", dt.Rows[i][8].ToString(), i); this.Model.SetValue("FBatch", dt.Rows[i][9].ToString(), i); this.Model.SetValue("FSalOrderCount", dt.Rows[i][10].ToString(), i); - this.Model.SetValue("FProOrderCount", dt.Rows[i][11].ToString(), i); this.Model.SetValue("FCompleteSetCount", dt.Rows[i][12].ToString(), i); - this.Model.SetValue("FDeliveryDate", GetDateTime(Convert.ToInt32(dt.Rows[i][13].ToString())), i); - this.Model.SetValue("FOrderLevel", dt.Rows[i][14].ToString(), i); + this.Model.SetValue("FDeliveryDate", ToDateTimeValue(dt.Rows[i][13].ToString()), i); + this.Model.SetValue("FOrderLevel", OrderType(dt.Rows[i][14].ToString()), i); + this.Model.SetValue("FOrderQuantity", FQTY, i); + this.Model.SetValue("FDayPlanID", fDayPlanID, i);//鏃ヨ鍒掑伐鍗旾D + this.Model.SetValue("FDayPlanBillNo", fDayPlanBillNo, i);//鏃ュ伐鍗曠紪鍙� for (int j = 0; j <= 60; j++) { this.Model.SetValue("FT" + "" + j + "", dt.Rows[i][15 + j].ToString(), i); } + //璋冪敤鏁伴噺鍊兼洿鏂� + this.View.InvokeFieldUpdateService("FT0", i); } } - this.View.UpdateView(); - for (int j = 0; j <= 60; j++) { this.View.GetControl("FT" + "" + j + "").Text = date.AddDays(j).ToShortDateString(); @@ -154,7 +181,30 @@ } + /// <summary> + /// 璁㈠崟鐘舵�佺瓑绾� + /// </summary> + /// <param name="Type"></param> + /// <returns></returns> + public string OrderType(string Type) + { + switch (Type) + { + case "鐗规��": + return "1"; + break; + case "绱ф��": + return "2"; + break; + case "鏅��": + return "3"; + break; + default: + return " "; + break; + } + } /// <summary> /// 鏃堕棿鎴砊imestamp杞崲鎴愭棩鏈� /// </summary> @@ -168,7 +218,6 @@ DateTime targetDt = dtStart.Add(toNow); return targetDt; } - /// <summary> /// 瀵煎叆鍔熻兘 /// </summary> @@ -176,13 +225,26 @@ { try { + LogService.WriteAsync("娴嬭瘯"); string sql; DateTime date = Convert.ToDateTime(this.Model.GetValue("F_Paez_Date")); //鑾峰彇鍗曟嵁浣撲俊鎭� Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity"); //鍗曟嵁浣撲俊鎭浆鎹负鍒楄〃闆嗗悎 DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity); - + List<string> sqlList = new List<string>(); + foreach (DynamicObject current in entityDataObjoct) + { + if (Convert.ToString(current["FDayPlanID"]) == "0") + continue; + for (int i = 0; i <= 60; i++) + { + JObject jsonFPOOrderEntry = new JObject(); + sql = string.Format($"update SC_WORKBILLSORTBILLSub set FHQTY ='{Convert.ToString(current["FT" + "" + i + ""])}' where FID ={Convert.ToString(current["FDayPlanID"])} and FHMASTERDATE ={date.AddDays(i).ToShortDateString()} and FHLOCKEDSUB = 0"); + sqlList.Add(sql); + } + } + int res = DBServiceHelper.ExecuteBatch(Context, sqlList); string _result = ""; foreach (DynamicObject current in entityDataObjoct) { @@ -201,13 +263,20 @@ this.View.ShowErrMessage(_result); return; } - - + 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) { if (string.IsNullOrEmpty(Convert.ToString(current["FSalOrderNo"])) || string.IsNullOrEmpty(Convert.ToString(current["FSCOrderNo"]))) continue; - //鏍规嵁鐢熶骇璁㈠崟鍙峰拰鐗╂枡鏌ヨ鏄惁瀛樺湪鏄庣粏 sql = string.Format(@"/*dialect*/SELECT T1.FBILLNO,T2.* FROM T_PRD_MO T1 LEFT JOIN T_PRD_MOENTRY T2 ON T1.FID = T2.FID @@ -216,7 +285,6 @@ dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0]; if (dt.Rows.Count == 0) continue; - string FID = "";//FID 婧愬崟涓诲唴鐮� string FENTRYID = "";//FENTRYID 婧愬崟瀛愬唴鐮� string FLOT = "";//FLOT 鎵规 @@ -230,8 +298,6 @@ FQTY = dt.Rows[0]["FQTY"].ToString(); FBILLNO = dt.Rows[0]["FBILLNO"].ToString(); } - - JObject jsonRoot = new JObject(); jsonRoot.Add("Creator", ""); jsonRoot.Add("NeedUpDateFields", new JArray()); @@ -239,7 +305,6 @@ jsonRoot.Add("IsDeleteEntry", "false"); jsonRoot.Add("SubSystemId", ""); jsonRoot.Add("IsVerifyBaseDataField", ""); - JObject jsonModel = new JObject(); jsonModel.Add("FPreparatDate", date.ToString());//缂栧埗鏃ユ湡 jsonModel.Add("FSCOrderNo", current["FSCOrderNo"].ToString()); //鐢熶骇璁㈠崟鍙稦SCOrderNo @@ -253,12 +318,12 @@ jsonModel.Add("FPrdBillNo", FBILLNO); ;//婧愬崟缂栧彿 jsonModel.Add("FPRDMOMAINID", FID); ;//婧愬崟涓诲唴鐮� jsonModel.Add("FPRDMOENTYID", FENTRYID); ;//婧愬崟瀛愬唴鐮� - - + jsonModel.Add("FOrderQuantity", current["FOrderQuantity"].ToString()); ;//鐢熶骇璁㈠崟鏁伴噺 + jsonModel.Add("FDayPlanQuantity", current["FDayPlanQuantity"].ToString()); ;//鏃ヨ鍒掓暟閲� + jsonModel.Add("FNoScheduled", current["FNoScheduled"].ToString()); ;//鏈帓鏁伴噺 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(); @@ -266,94 +331,85 @@ jsonModel.Add("FHPRDORGID", jsonFHPRDORGID);//FHMaterID 鐢熶骇缁勭粐 } - if (Convert.ToString(current["FProductWorkShopId_Id"]) != "0") - { - JObject jsonFProductWorkShopId = new JObject(); - jsonFProductWorkShopId.Add("FNumber", (current["FProductWorkShopId"] as DynamicObject)["Number"].ToString()); - jsonModel.Add("FHSourceID", jsonFProductWorkShopId);//FHSourceID 鐢熶骇杞﹂棿 - } - 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["FResourcesId"] as DynamicObject)["Number"].ToString()); + jsonFResourcesId.Add("FNumber", (current["FProductWorkShopId"] as DynamicObject)["Number"].ToString()); jsonModel.Add("FHWorkShopID", jsonFResourcesId);//FHWorkShopID 鐢熶骇璧勬簮 } JArray Entry = new JArray(); - for (int i = 0; i <= 60; i++) - { - JObject jsonFPOOrderEntry = new JObject(); - - jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//涓绘棩鏈� - jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//鏃ヨ鍒掓暟閲� - jsonFPOOrderEntry.Add("FColumn", "FT" + "" + i + ""); ;//瀵瑰簲鐨勫垪澶� - //jsonFPOOrderEntry.Add("FHMainSourceBillType ", "鐢熶骇璁㈠崟"); ;//婧愬崟绫诲瀷 - //jsonFPOOrderEntry.Add("FHMainSourceBillNo", FBILLNO); ;//婧愬崟缂栧彿 - //jsonFPOOrderEntry.Add("FHMainSourceInterID", FID); ;//婧愬崟涓诲唴鐮� - //jsonFPOOrderEntry.Add("FHMainSourceEntryID", FENTRYID); ;//婧愬崟瀛愬唴鐮� - - Entry.Add(jsonFPOOrderEntry); - } - - jsonModel.Add("FEntity", Entry); - //鏃ヨ鍒掑伐鍗曚笉涓虹┖鏃秛pdate if (Convert.ToString(current["FDayPlanID"]) != "0") { + sql = $"select max(FHMASTERDATE)FHMASTERDATE from SC_WORKBILLSORTBILLSub where FID={Convert.ToString(current["FDayPlanID"])} "; + DateTime EndDate = DBServiceHelper.ExecuteScalar<DateTime>(Context, sql, DateTime.Now); + for (int i = 0; i <= 60; i++) + { + if (EndDate >= date.AddDays(i)) + continue; + JObject jsonFPOOrderEntry = new JObject(); + jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//涓绘棩鏈� + jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//鏃ヨ鍒掓暟閲� + jsonFPOOrderEntry.Add("FColumn", "FT" + "" + i + ""); ;//瀵瑰簲鐨勫垪澶� + Entry.Add(jsonFPOOrderEntry); + } + jsonModel.Add("FEntity", Entry); jsonModel.Add("FID", Convert.ToString(current["FDayPlanID"])); ;//婧愬崟缂栧彿 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") - { - string FDayPlanBillNo = saveObj["Result"]["ResponseStatus"]["SuccessEntitys"]["Number"].ToString(); - string FDayPlanID = saveObj["Result"]["ResponseStatus"]["SuccessEntitys"]["Id"].ToString(); - - //this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToString(current["SEQ"]));// - // this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToString(current["SEQ"]));// - - - this.View.ShowMessage("瀵煎叆鎴愬姛"); - - } - else - { - this.View.ShowErrMessage("瀵煎叆澶辫触"); - - } - } - else - { - 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(); - + LogService.WriteAsync(jsonRoot); if (saveIsSuc == "TRUE") { string FDayPlanBillNo = saveObj["Result"]["Number"].ToString(); string FDayPlanID = saveObj["Result"]["Id"].ToString(); - - //this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToString(current["SEQ"]));// - // this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToString(current["SEQ"]));// - - this.View.ShowMessage("瀵煎叆鎴愬姛"); - } else { - this.View.ShowErrMessage("瀵煎叆澶辫触"); - + LogService.WriteAsync(jsonRoot); + LogHelper.Error(jsonRoot.ToString()); + this.View.ShowErrMessage(jsonRoot.ToString()); } } - - - - + else + { + for (int i = 0; i <= 60; i++) + { + JObject jsonFPOOrderEntry = new JObject(); + jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//涓绘棩鏈� + jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//鏃ヨ鍒掓暟閲� + jsonFPOOrderEntry.Add("FColumn", "FT" + "" + i + ""); ;//瀵瑰簲鐨勫垪澶� + Entry.Add(jsonFPOOrderEntry); + } + jsonModel.Add("FEntity", Entry); + jsonRoot.Add("Model", jsonModel); + var result = cloudClient.Save("Paez_Sc_WorkBillAutoSortBill", jsonRoot.ToString()); + JObject saveObj = JObject.Parse(result); + string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper(); + LogService.WriteAsync(jsonRoot); + 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("瀵煎叆鎴愬姛"); + } + else + { + LogService.WriteAsync(jsonRoot); + LogHelper.Error(jsonRoot.ToString()); + this.View.ShowErrMessage(jsonRoot.ToString()); + } + } + this.View.UpdateView(); } } catch (Exception ex) @@ -363,10 +419,53 @@ } } + /// <summary> + /// 鏁板瓧杞崲鏃堕棿鏍煎紡 + /// </summary> + /// <param name="timeStr">鏁板瓧,濡�:42095.7069444444/0.650694444444444</param> + /// <returns>鏃ユ湡/鏃堕棿鏍煎紡</returns> + private string ToDateTimeValue(string strNumber) + { + if (!string.IsNullOrWhiteSpace(strNumber)) + { + Decimal tempValue; + //鍏堟鏌� 鏄笉鏄暟瀛�; + if (Decimal.TryParse(strNumber, out tempValue)) + { + //澶╂暟,鍙栨暣 + int day = Convert.ToInt32(Math.Truncate(tempValue)); + //杩欓噷涔熶笉鐭ラ亾涓轰粈涔�. 濡傛灉鏄皬浜�32,鍒欏噺1,鍚﹀垯鍑�2 + //鏃ユ湡浠�1900-01-01寮�濮嬬疮鍔� + // day = day < 32 ? day - 1 : day - 2; + DateTime dt = new DateTime(1900, 1, 1).AddDays(day < 32 ? (day - 1) : (day - 2)); + //灏忔椂:鍑忔帀澶╂暟,杩欎釜鏁板瓧杞崲灏忔椂:(* 24) + Decimal hourTemp = (tempValue - day) * 24;//鑾峰彇灏忔椂鏁� + //鍙栨暣.灏忔椂鏁� + int hour = Convert.ToInt32(Math.Truncate(hourTemp)); + //鍒嗛挓:鍑忔帀灏忔椂,( * 60) + //杩欓噷鑸嶅叆,鍚﹀垯鍙栧�间細鏈�1鍒嗛挓璇樊. + Decimal minuteTemp = Math.Round((hourTemp - hour) * 60, 2);//鑾峰彇鍒嗛挓鏁� + int minute = Convert.ToInt32(Math.Truncate(minuteTemp)); + //绉�:鍑忔帀鍒嗛挓,( * 60) + //杩欓噷鑸嶅叆,鍚﹀垯鍙栧�间細鏈�1绉掕宸�. + Decimal secondTemp = Math.Round((minuteTemp - minute) * 60, 2);//鑾峰彇绉掓暟 + int second = Convert.ToInt32(Math.Truncate(secondTemp)); + //鏃堕棿鏍煎紡:00:00:00 + string resultTimes = string.Format("{0}:{1}:{2}", + (hour < 10 ? ("0" + hour) : hour.ToString()), + (minute < 10 ? ("0" + minute) : minute.ToString()), + (second < 10 ? ("0" + second) : second.ToString())); - + if (day > 0) + return string.Format("{0} {1}", dt.ToString("yyyy-MM-dd"), resultTimes); + else + return resultTimes; + } + } + return string.Empty; + } } } -- Gitblit v1.9.1