diff --git a/Pilot_KD_Parino/Pilot_KD_Parino.csproj b/Pilot_KD_Parino/Pilot_KD_Parino.csproj index fb4d82d..9741e45 100644 --- a/Pilot_KD_Parino/Pilot_KD_Parino.csproj +++ b/Pilot_KD_Parino/Pilot_KD_Parino.csproj @@ -349,6 +349,7 @@ + diff --git a/Pilot_KD_Parino/SAL_DELIVERYNOTICE/Bill.cs b/Pilot_KD_Parino/SAL_DELIVERYNOTICE/Bill.cs new file mode 100644 index 0000000..51fc2de --- /dev/null +++ b/Pilot_KD_Parino/SAL_DELIVERYNOTICE/Bill.cs @@ -0,0 +1,139 @@ +using Kingdee.BOS.Core.Bill.PlugIn; +using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; +using Kingdee.BOS.Orm.DataEntity; +using Kingdee.BOS.Util; +using Kingdee.K3.BD.NewCode.Core.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Pilot_KD_Parino.SAL_DELIVERYNOTICE +{ + [HotUpdate, Description("1.发货通知单表单插件")] + public class Bill : AbstractBillPlugIn + { + public override void DataChanged(DataChangedEventArgs e) + { + base.DataChanged(e); + if (e.Field.Key.EqualsIgnoreCase("FQty")) + { + LinkedModifiQty(e); + } + + if (e.Field.Key.EqualsIgnoreCase("FBaseUnitQty")) + { + LinkedModifiQty(e); + } + } + + /// + /// 联动修改数量 + /// + /// + private void LinkedModifiQty(DataChangedEventArgs e) + { + var groupIdObj = this.View.Model.GetValue("FGroup", e.Row); + var groupId = groupIdObj == null ? "" : groupIdObj.Convert(); + if (!groupId.IsNullOrEmptyOrWhiteSpace()) + { + var groupItemObj = this.View.Model.GetValue("F_GroupItem", e.Row); + var groupItem = groupItemObj == null ? "" : groupItemObj.Convert(); + if (groupItem.IsNullOrEmptyOrWhiteSpace()) + { + var entrys = this.View.Model.DataObject["SAL_DELIVERYNOTICEENTRY"] as DynamicObjectCollection; + if (entrys != null && entrys.Count > 0) + { + var mainQty = e.NewValue.Convert(); + var currIndex = 0; + foreach (var entry in entrys) + { + var currGroup = entry["FGroup"].Convert(); + var currGroupItem = entry["F_GroupItem"].Convert(); + if (currGroup.EqualsIgnoreCase(groupId) && !currGroupItem.IsNullOrEmptyOrWhiteSpace()) + { + var currGroupDosage = entry["F_GroupDosage"].Convert(); + this.View.Model.SetValue("FQty", mainQty * currGroupDosage, currIndex); + this.View.InvokeFieldUpdateService("FQty", currIndex); + } + + currIndex++; + } + } + } + } + + } + + public override void AfterDeleteRow(AfterDeleteRowEventArgs e) + { + + if (e.EntityKey.EqualsIgnoreCase("FEntity")) + { + //this.View.ShowErrMessage(JsonUtil.Serialize(e.DataEntity)); + var currDataEntity = e.DataEntity; + var groupIdObj = currDataEntity["FGroup"]; + var groupId = groupIdObj == null ? "" : groupIdObj.Convert(); + if (groupId.IsNullOrEmptyOrWhiteSpace()) + return; + + var groupItemObj = currDataEntity["F_GroupItem"]; + var groupItem = groupItemObj == null ? "" : groupItemObj.Convert(); + if (!groupItem.IsNullOrEmptyOrWhiteSpace()) + return; + + var entrys = this.View.Model.DataObject["SAL_DELIVERYNOTICEENTRY"] as DynamicObjectCollection; + if (entrys != null && entrys.Count > 0) + { + + var rowIndex = 0; + var deleteIndexs = new List(); + foreach (var entry in entrys) + { + var currGroup = entry["FGroup"].Convert(); + var currGroupItem = entry["F_GroupItem"].Convert(); + if (currGroup.EqualsIgnoreCase(groupId) && !currGroupItem.IsNullOrEmptyOrWhiteSpace()) + { + deleteIndexs.Add(rowIndex); + } + + rowIndex++; + } + + if (deleteIndexs.Count > 0) + { + deleteIndexs.Reverse(); + foreach (var index in deleteIndexs) + { + this.View.Model.DeleteEntryRow("FEntity", index); + } + } + } + } + + base.AfterDeleteRow(e); + } + + public override void AfterBindData(EventArgs e) + { + base.AfterBindData(e); + + + } + + private void SetFieldEditorDisabled(int rowIndex) + { + this.View.GetFieldEditor("FMaterialID", rowIndex).Enabled = false; + this.View.GetFieldEditor("FUnitID", rowIndex).Enabled = false; + this.View.GetFieldEditor("FQty", rowIndex).Enabled = false; + this.View.GetFieldEditor("FIsFree", rowIndex).Enabled = false; + this.View.GetFieldEditor("FDeliveryDate", rowIndex).Enabled = false; + //billView.GetFieldEditor("FStockID", rowIndex).Enabled = false; + //billView.GetFieldEditor("FStockLocID", rowIndex).Enabled = false; + this.View.GetFieldEditor("FTaxPrice", rowIndex).Enabled = false; + this.View.GetFieldEditor("FEntryTaxRate", rowIndex).Enabled = false; + } + } +} diff --git a/Pilot_KD_Parino/SAL_DELIVERYNOTICE/ConvertServicePlugIn/SaleOrder_DeliveryNoticeConvert.cs b/Pilot_KD_Parino/SAL_DELIVERYNOTICE/ConvertServicePlugIn/SaleOrder_DeliveryNoticeConvert.cs index 854f041..42a6085 100644 --- a/Pilot_KD_Parino/SAL_DELIVERYNOTICE/ConvertServicePlugIn/SaleOrder_DeliveryNoticeConvert.cs +++ b/Pilot_KD_Parino/SAL_DELIVERYNOTICE/ConvertServicePlugIn/SaleOrder_DeliveryNoticeConvert.cs @@ -1,4 +1,13 @@ -using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn; +using Kingdee.BOS.Core.Bill; +using Kingdee.BOS.Core.DynamicForm.PlugIn; +using Kingdee.BOS.Core.DynamicForm; +using Kingdee.BOS.Core.Metadata; +using Kingdee.BOS.Core; +using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn; +using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args; +using Kingdee.BOS.Core.Metadata.FormElement; +using Kingdee.BOS.Orm.DataEntity; +using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; @@ -6,11 +15,151 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Kingdee.BOS; +using Kingdee.K3.BD.NewCode.Core.Utils; +using Pilot_KD_Parino.SQL; +using DocumentFormat.OpenXml.Drawing.Spreadsheet; namespace Pilot_KD_Parino.SAL_DELIVERYNOTICE.ConvertServicePlugIn { [Description("生产订单装换插件#"), HotUpdate] - public class SaleOrder_DeliveryNoticeConvert: AbstractConvertPlugIn + public class SaleOrder_DeliveryNoticeConvert : AbstractConvertPlugIn { + public override void AfterConvert(AfterConvertEventArgs e) + { + base.AfterConvert(e); + foreach (var billHeadEntity in e.Result.FindByEntityKey("FBillHead")) + { + var billHead = billHeadEntity.DataEntity; + var entrys = billHead["SAL_DELIVERYNOTICEENTRY"] as DynamicObjectCollection; + if (entrys != null && entrys.Count > 0) + { + var idx = 0; + var sqlL = new List(); + foreach (var entry in entrys) + { + var materialId = entry["MaterialID_Id"].Long2Int(); + if (materialId == 0) + continue; + + var qty = entry["Qty"].Convert(); + var guid = Guid.NewGuid().ToString("N"); + //entry["FGroup"] = guid; + + sqlL.Add($"SELECT {idx} 'Idx',{materialId} MaterialId,{qty} MaterialQty,'{guid}' GroupId"); + idx++; + } + + if (sqlL.Count > 0) + { + var dataList = SqlManage.QueryMainDodyParts(this.Context, sqlL); + if (dataList.Count > 0) + { + var billView = CreateView("SAL_DELIVERYNOTICE"); + billView.Model.DataObject = billHead;//给模型设置数据包 + + var mainRowIndex = -1; + + foreach (var item in dataList) + { + //主体物料索引 + var rowIndex = item["Idx"].Long2Int(); + + if (mainRowIndex != rowIndex) + { + mainRowIndex = rowIndex; + billView.Model.SetValue("FGroup", item["GroupId"], mainRowIndex); + } + + //配件物料索引 + rowIndex = rowIndex + item["FSEQ"].Long2Int(); + + var MaterialQty = item["MaterialQty"].Convert(); + var itemDosage = item["FQTY"].Convert(); + billView.Model.InsertEntryRow("FEntity", rowIndex); + + billView.Model.SetValue("FIsFree", true, rowIndex); + + billView.Model.SetItemValueByID("FMaterialId", item["FMATERIALIDCHILD"].Long2Int(), rowIndex); + billView.InvokeFieldUpdateService("FMaterialId", rowIndex); + + billView.Model.SetValue("FQty", MaterialQty * itemDosage, rowIndex); + billView.InvokeFieldUpdateService("FQty", rowIndex); + //组别 + billView.Model.SetValue("FGroup", item["GroupId"], rowIndex); + //组别用量 + billView.Model.SetValue("F_GroupDosage", item["FQTY"], rowIndex); + //单位 + billView.Model.SetItemValueByID("FUnitID", item["FCHILDUNITID"].Long2Int(), rowIndex); + billView.InvokeFieldUpdateService("FUnitID", rowIndex); + + billView.Model.SetValue("F_GroupItem", Guid.NewGuid().ToString("N"), rowIndex); + + //billView.GetFieldEditor("FMaterialID", rowIndex).Enabled = false; + //billView.GetFieldEditor("FUnitID", rowIndex).Enabled = false; + //billView.GetFieldEditor("FQty", rowIndex).Enabled = false; + //billView.GetFieldEditor("FIsFree", rowIndex).Enabled = false; + //billView.GetFieldEditor("FDeliveryDate", rowIndex).Enabled = false; + ////billView.GetFieldEditor("FStockID", rowIndex).Enabled = false; + ////billView.GetFieldEditor("FStockLocID", rowIndex).Enabled = false; + //billView.GetFieldEditor("FTaxPrice", rowIndex).Enabled = false; + //billView.GetFieldEditor("FEntryTaxRate", rowIndex).Enabled = false; + } + } + } + } + } + } + + /// + /// 创建单据视图 + /// + /// + /// + /// + private IDynamicFormView CreateView(string formId) + { + FormMetadata metadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formId); + var OpenParameter = CreateOpenParameter(this.Context, metadata); + var Provider = metadata.BusinessInfo.GetForm().GetFormServiceProvider(true); + string importViewClass = "Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web"; + Type type = Type.GetType(importViewClass); + IDynamicFormView view = (IDynamicFormView)Activator.CreateInstance(type); + ((IDynamicFormViewService)view).Initialize(OpenParameter, Provider); + return view; + } + + /// + /// 创建输入参数 + /// + /// + /// + /// + private BillOpenParameter CreateOpenParameter(Context ctx, FormMetadata metaData) + { + Form form = metaData.BusinessInfo.GetForm(); + BillOpenParameter openPara = new BillOpenParameter(form.Id, metaData.GetLayoutInfo().Id); + openPara = new BillOpenParameter(form.Id, string.Empty); + openPara.Context = ctx; + openPara.ServiceName = form.FormServiceName; + openPara.PageId = Guid.NewGuid().ToString(); + // 单据 + openPara.FormMetaData = metaData; + openPara.LayoutId = metaData.GetLayoutInfo().Id; + // 操作相关参数 + openPara.Status = OperationStatus.ADDNEW; + openPara.PkValue = null; + openPara.CreateFrom = CreateFrom.Default; + openPara.ParentId = 0; + openPara.GroupId = ""; + openPara.DefaultBillTypeId = null; + openPara.DefaultBusinessFlowId = null; + // 修改主业务组织无须用户确认 + openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false); + // 插件 + List plugins = form.CreateFormPlugIns(); + openPara.SetCustomParameter(FormConst.PlugIns, plugins); + return openPara; + } } } diff --git a/Pilot_KD_Parino/SQL/SqlManage.cs b/Pilot_KD_Parino/SQL/SqlManage.cs index a9374a9..18b870e 100644 --- a/Pilot_KD_Parino/SQL/SqlManage.cs +++ b/Pilot_KD_Parino/SQL/SqlManage.cs @@ -575,5 +575,28 @@ namespace Pilot_KD_Parino.SQL //执行SQL return DBServiceHelper.ExecuteDynamicObject(ctx, sql.ToString(), null, null, CommandType.Text, null) as DynamicObjectCollection; } + + /// + /// 获取物料配件信息 + /// + /// + /// + /// + public static DynamicObjectCollection QueryMainDodyParts(Context ctx, List sqlL) + { + //定义SQL,调用物料视图 + string sql = $@"/*dialect*/ +;WITH #基础数据 AS ( + {string.Join(" UNION ALL ", sqlL)} +) +SELECT tt.*,t0.FMATERIALID,t0.FAUXQTY,t0e.FSEQ,t0e.FMATERIALIDCHILD,t0e.FQTY,t0e.FCHILDUNITID +FROM #基础数据 tt + INNER JOIN t_MainDodyParts t0 on t0.FMATERIALID = tt.MaterialId + INNER JOIN t_MainDodyPartsEntry t0e on t0.FID = t0e.FID +ORDER BY tt.Idx DESC,t0.FMATERIALID,t0e.FSEQ --DESC +"; + //执行SQL + return DBServiceHelper.ExecuteDynamicObject(ctx, sql.ToString(), null, null, CommandType.Text, null) as DynamicObjectCollection; + } } } diff --git a/Pilot_KD_Parino/bin/Debug/Kingdee.K3.BD.NewCode.Core.dll b/Pilot_KD_Parino/bin/Debug/Kingdee.K3.BD.NewCode.Core.dll new file mode 100644 index 0000000..47cedbe Binary files /dev/null and b/Pilot_KD_Parino/bin/Debug/Kingdee.K3.BD.NewCode.Core.dll differ