This commit is contained in:
liangjunyu
2025-09-08 18:00:05 +08:00
parent 40034d1db2
commit 9d7b07cde9
5 changed files with 314 additions and 2 deletions

View File

@@ -349,6 +349,7 @@
<Compile Include="QPHY_AutoWrire\Bill5.cs" />
<Compile Include="QPHY_AutoWrire\SearchWriteRecord.cs" />
<Compile Include="ReceivablesDetails\ReceivablesPlugIn.cs" />
<Compile Include="SAL_DELIVERYNOTICE\Bill.cs" />
<Compile Include="SAL_DELIVERYNOTICE\ConvertServicePlugIn\SaleOrder_DeliveryNoticeConvert.cs" />
<Compile Include="Sal_Order\Bill.cs" />
<Compile Include="Sal_Order\ConvertPlugIn\SalOrder2DeliveryConvert.cs" />

View File

@@ -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);
}
}
/// <summary>
/// 联动修改数量
/// </summary>
/// <param name="e"></param>
private void LinkedModifiQty(DataChangedEventArgs e)
{
var groupIdObj = this.View.Model.GetValue("FGroup", e.Row);
var groupId = groupIdObj == null ? "" : groupIdObj.Convert<string>();
if (!groupId.IsNullOrEmptyOrWhiteSpace())
{
var groupItemObj = this.View.Model.GetValue("F_GroupItem", e.Row);
var groupItem = groupItemObj == null ? "" : groupItemObj.Convert<string>();
if (groupItem.IsNullOrEmptyOrWhiteSpace())
{
var entrys = this.View.Model.DataObject["SAL_DELIVERYNOTICEENTRY"] as DynamicObjectCollection;
if (entrys != null && entrys.Count > 0)
{
var mainQty = e.NewValue.Convert<decimal>();
var currIndex = 0;
foreach (var entry in entrys)
{
var currGroup = entry["FGroup"].Convert<string>();
var currGroupItem = entry["F_GroupItem"].Convert<string>();
if (currGroup.EqualsIgnoreCase(groupId) && !currGroupItem.IsNullOrEmptyOrWhiteSpace())
{
var currGroupDosage = entry["F_GroupDosage"].Convert<decimal>();
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<string>();
if (groupId.IsNullOrEmptyOrWhiteSpace())
return;
var groupItemObj = currDataEntity["F_GroupItem"];
var groupItem = groupItemObj == null ? "" : groupItemObj.Convert<string>();
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<int>();
foreach (var entry in entrys)
{
var currGroup = entry["FGroup"].Convert<string>();
var currGroupItem = entry["F_GroupItem"].Convert<string>();
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;
}
}
}

View File

@@ -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 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<string>();
foreach (var entry in entrys)
{
var materialId = entry["MaterialID_Id"].Long2Int();
if (materialId == 0)
continue;
var qty = entry["Qty"].Convert<decimal>();
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<decimal>();
var itemDosage = item["FQTY"].Convert<decimal>();
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;
}
}
}
}
}
}
/// <summary>
/// 创建单据视图
/// </summary>
/// <param name="ctx"></param>
/// <param name="metaData"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 创建输入参数
/// </summary>
/// <param name="ctx"></param>
/// <param name="metaData"></param>
/// <returns></returns>
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<AbstractDynamicFormPlugIn> plugins = form.CreateFormPlugIns();
openPara.SetCustomParameter(FormConst.PlugIns, plugins);
return openPara;
}
}
}

View File

@@ -575,5 +575,28 @@ namespace Pilot_KD_Parino.SQL
//执行SQL
return DBServiceHelper.ExecuteDynamicObject(ctx, sql.ToString(), null, null, CommandType.Text, null) as DynamicObjectCollection;
}
/// <summary>
/// 获取物料配件信息
/// </summary>
/// <param name="ctx"></param>
/// <param name="sqlL"></param>
/// <returns></returns>
public static DynamicObjectCollection QueryMainDodyParts(Context ctx, List<string> 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;
}
}
}