添加项目文件。

This commit is contained in:
PastSaid
2023-12-08 23:53:07 +08:00
parent 8b00e15a57
commit c4fceda660
34 changed files with 3378 additions and 0 deletions

View File

@@ -0,0 +1,195 @@
using ExtensionMethods;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace UseGetFmaterialData
{
/// <summary>
/// 【单据插件】保存前事件
/// 触发顺序BeforeDoOperation->BeforeSave
/// </summary>
[Description("【单据插件】保存前事件"), HotUpdate]
public class BeforeSaveEventBillPlugIn : AbstractBillPlugIn
{
public override void BeforeSave(BeforeSaveEventArgs e)
{
base.BeforeSave(e);
this.View.ShowMessage("插件触发了保存前事件BeforeSave");
if (this.Model.DataObject["Id"].Long2Int() == 0)
if (OrgIdCheck())
{
Entity details = null;
//其他出库单 明细表
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
details = this.View.BusinessInfo.GetEntity("FEntity");
//直接调拨单 明细表
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
details = this.View.BusinessInfo.GetEntity("FBillEntry");
if (details != null)
{
var entrys = this.View.Model.GetEntityDataObject(details);
if (entrys != null && entrys.Any())
{
var tempValue2 = this.View.Model.GetValue("FDATE");
var dateValue = tempValue2.IsNullOrEmptyOrWhiteSpace() ? string.Empty : tempValue2.ToString();
foreach (var entry in entrys)
{
var rowIndex = this.View.Model.GetRowIndex(details, entry);
var tempValue = entry["MaterialId_Id"];
var rowValue = tempValue.IsNullOrEmptyOrWhiteSpace() ? string.Empty : tempValue.ToString();
UpdReferPriceAndExplain(dateValue, rowValue, rowIndex);
}
TotalReferAmount(entrys, details);
}
}
}
}
/// <summary>
/// 参考金额汇总
/// </summary>
/// <param name="entrys"></param>
public void TotalReferAmount(DynamicObjectCollection entrys, Entity details)
{
if (entrys == null)
{
//其他出库单 明细表
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
details = this.View.BusinessInfo.GetEntity("FEntity");
//直接调拨单 明细表
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
details = this.View.BusinessInfo.GetEntity("FBillEntry");
if (details != null)
entrys = this.View.Model.GetEntityDataObject(details);
}
var total = 0M;
if (entrys != null && entrys.Any())
{
foreach (var entry in entrys)
{
var rowIndex = this.View.Model.GetRowIndex(details, entry);
var tAmount = this.View.Model.GetValue("FReferAmount", rowIndex).ToDecimal();
total += tAmount;
}
}
try
{
this.View.Model.SetValue("F_GAT_Decimal1", total);
this.View.Model.SetValue("FTotalReferAmount", total);
}
catch
{
try
{
this.View.Model.SetValue("FTotalReferAmount", total);
this.View.Model.SetValue("F_GAT_Decimal1", total);
}
catch { }
finally { }
}
finally { }
}
/// <summary>
/// 检测组织
/// </summary>
/// <returns></returns>
public bool OrgIdCheck()
{
//直接调拨单 调出库存组织
var org = this.View.Model.GetValue("FStockOutOrgId") as DynamicObject;
//其他出库单 库存组织
if (org == null)
org = this.View.Model.GetValue("FStockOrgId") as DynamicObject;
return org != null && Convert.ToInt32(org["Id"]) != 101542;
}
/// <summary>
/// 更新对应行数的参考单价与取价方向
/// </summary>
/// <param name="date">表头日期</param>
/// <param name="materialId">子表物料id物料编码</param>
/// <param name="row"></param>
private void UpdReferPriceAndExplain(string date, string materialId, int row)
{
var returnFlag = false;
if (date.IsNullOrEmptyOrWhiteSpace())
returnFlag = true;
if (!returnFlag && (materialId.IsNullOrEmptyOrWhiteSpace() || materialId.Equals("0")))
returnFlag = true;
if (returnFlag)
{
//参考单价
this.View.Model.SetValue("FReferPrice", "", row);
//参考金额
this.View.Model.SetValue("FReferAmount", "", row);
////小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", 0, row);
//参考方向
this.View.Model.SetValue("FExplain", "", row);
}
else
{
var sqlL = $"EXEC GetFmaterialData {materialId},'{date}'";
var dataSet = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{sqlL}");
if (dataSet != null && dataSet.Any())
{
var price = dataSet[0]["Fprice"].ToDecimalR();
//数量
var qty = this.View.Model.GetValue("FQty", row).ToDecimal();
var amount = (qty * price).ToDecimalR();
//参考单价
this.View.Model.SetValue("FReferPrice", (price == 0 ? "" : price.ToString()), row);
//参考金额
this.View.Model.SetValue("FReferAmount", (amount == 0 ? "" : amount.ToString()), row);
//小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", amount, row);
//参考方向
this.View.Model.SetValue("FExplain", dataSet[0]["FNOTE"], row);
}
else
{
//参考单价
this.View.Model.SetValue("FReferPrice", "", row);
//参考金额
this.View.Model.SetValue("FReferAmount", "", row);
//小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", 0, row);
//参考方向
this.View.Model.SetValue("FExplain", "", row);
}
}
}
}
}

View File

@@ -0,0 +1,261 @@
using ExtensionMethods;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.Util;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Linq;
using static System.Net.WebRequestMethods;
namespace UseGetFmaterialData
{
[Description("根据日期物料Id更新参考单价、取价方向、参考金额-控件触发、新增加载触发"), HotUpdate]
public class DataChangedEventFormPlugIn : AbstractDynamicFormPlugIn
{
//对应控件数值改变时触发
public override void DataChanged(DataChangedEventArgs e)
{
base.DataChanged(e);
//表头日期
if (e.Field.Key.EqualsIgnoreCase("FDATE"))
{
if (OrgIdCheck())
{
Entity details = null;
//其他出库单 明细表
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
details = this.View.BusinessInfo.GetEntity("FEntity");
//直接调拨单 明细表
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
details = this.View.BusinessInfo.GetEntity("FBillEntry");
if (details != null)
{
var entrys = this.View.Model.GetEntityDataObject(details);
if (entrys != null && entrys.Any())
{
var dateValue = e.NewValue == null ? string.Empty : e.NewValue.ToString();
foreach (var entry in entrys)
{
var rowIndex = this.View.Model.GetRowIndex(details, entry);
var tempValue = entry["MaterialId_Id"];
var rowValue = tempValue == null ? string.Empty : tempValue.ToString();
UpdReferPriceAndExplain(dateValue, rowValue, rowIndex);
}
TotalReferAmount(entrys, details);
}
}
}
}
//子表物料id
if (e.Field.Key.EqualsIgnoreCase("FMaterialId"))
{
if (OrgIdCheck())
{
var rowValue = e.NewValue == null ? string.Empty : e.NewValue.ToString();
var tempValue = this.View.Model.GetValue("FDATE");
var dateValue = tempValue == null ? string.Empty : tempValue.ToString();
UpdReferPriceAndExplain(dateValue, rowValue, e.Row);
TotalReferAmount(null, null);
}
}
//数量
if (e.Field.Key.EqualsIgnoreCase("FQty"))
{
if (OrgIdCheck())
{
//参考单价
var referPrice = this.View.Model.GetValue("FReferPrice", e.Row).ToDecimalR();
var amount = (e.NewValue.ToDecimal() * referPrice).ToDecimalR();
//参考金额
this.View.Model.SetValue("FReferAmount", amount, e.Row);
//小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", amount, e.Row);
TotalReferAmount(null, null);
}
}
}
//新增加载时触发
public override void AfterCreateNewData(EventArgs e)
{
base.AfterCreateNewData(e);
if (OrgIdCheck())
{
Entity details = null;
//其他出库单 明细表
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
details = this.View.BusinessInfo.GetEntity("FEntity");
//直接调拨单 明细表
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
details = this.View.BusinessInfo.GetEntity("FBillEntry");
if (details != null)
{
var entrys = this.View.Model.GetEntityDataObject(details);
if (entrys != null && entrys.Any())
{
var tempValue2 = this.View.Model.GetValue("FDATE");
var dateValue = tempValue2.IsNullOrEmptyOrWhiteSpace() ? string.Empty : tempValue2.ToString();
foreach (var entry in entrys)
{
var rowIndex = this.View.Model.GetRowIndex(details, entry);
var tempValue = entry["MaterialId_Id"];
var rowValue = tempValue.IsNullOrEmptyOrWhiteSpace() ? string.Empty : tempValue.ToString();
UpdReferPriceAndExplain(dateValue, rowValue, rowIndex);
}
TotalReferAmount(entrys, details);
}
}
}
}
/// <summary>
/// 参考金额汇总
/// </summary>
/// <param name="entrys"></param>
public void TotalReferAmount(DynamicObjectCollection entrys, Entity details)
{
if (entrys == null)
{
//其他出库单 明细表
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
details = this.View.BusinessInfo.GetEntity("FEntity");
//直接调拨单 明细表
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
details = this.View.BusinessInfo.GetEntity("FBillEntry");
if (details != null)
entrys = this.View.Model.GetEntityDataObject(details);
}
var total = 0M;
if (entrys != null && entrys.Any())
{
foreach (var entry in entrys)
{
var rowIndex = this.View.Model.GetRowIndex(details, entry);
var tAmount = this.View.Model.GetValue("FReferAmount", rowIndex).ToDecimal();
total += tAmount;
}
}
try
{
this.View.Model.SetValue("F_GAT_Decimal1", total);
}
catch
{
try
{
this.View.Model.SetValue("FTotalReferAmount", total);
}
catch { }
finally { }
}
finally { }
}
/// <summary>
/// 检测组织
/// </summary>
/// <returns></returns>
public bool OrgIdCheck()
{
//直接调拨单 调出库存组织
var org = this.View.Model.GetValue("FStockOutOrgId") as DynamicObject;
//其他出库单 库存组织
if (org == null)
org = this.View.Model.GetValue("FStockOrgId") as DynamicObject;
return org != null && Convert.ToInt32(org["Id"]) == 101542;
}
/// <summary>
/// 更新对应行数的参考单价与取价方向
/// </summary>
/// <param name="date">表头日期</param>
/// <param name="materialId">子表物料id物料编码</param>
/// <param name="row"></param>
private void UpdReferPriceAndExplain(string date, string materialId, int row)
{
var returnFlag = false;
if (date.IsNullOrEmptyOrWhiteSpace())
returnFlag = true;
if (!returnFlag && (materialId.IsNullOrEmptyOrWhiteSpace() || materialId.Equals("0")))
returnFlag = true;
if (returnFlag)
{
//参考单价
this.View.Model.SetValue("FReferPrice", "", row);
//参考金额
this.View.Model.SetValue("FReferAmount", "", row);
////小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", 0, row);
//参考方向
this.View.Model.SetValue("FExplain", "", row);
}
else
{
var sqlL = $"EXEC GetFmaterialData {materialId},'{date}'";
var dataSet = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{sqlL}");
if (dataSet != null && dataSet.Any())
{
var price = dataSet[0]["Fprice"].ToDecimalR();
//数量
var qty = this.View.Model.GetValue("FQty", row).ToDecimal();
var amount = (qty * price).ToDecimalR();
//参考单价
this.View.Model.SetValue("FReferPrice", (price == 0 ? "" : price.ToString()), row);
//参考金额
this.View.Model.SetValue("FReferAmount", (amount == 0 ? "" : amount.ToString()), row);
//小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", amount, row);
//参考方向
this.View.Model.SetValue("FExplain", dataSet[0]["FNOTE"], row);
}
else
{
//参考单价
this.View.Model.SetValue("FReferPrice", "", row);
//参考金额
this.View.Model.SetValue("FReferAmount", "", row);
//小数类型参考金额控件
//this.View.Model.SetValue("FReferAmountM", 0, row);
//参考方向
this.View.Model.SetValue("FExplain", "", row);
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("UseGetFmaterialData")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UseGetFmaterialData")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("4d6bda2d-fed0-4514-b4cd-ff32c5389247")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4D6BDA2D-FED0-4514-B4CD-FF32C5389247}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UseGetFmaterialData</RootNamespace>
<AssemblyName>UseGetFmaterialData</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Kingdee.BOS">
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.dll</HintPath>
</Reference>
<Reference Include="Kingdee.BOS.App">
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.App.dll</HintPath>
</Reference>
<Reference Include="Kingdee.BOS.Core">
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.Core.dll</HintPath>
</Reference>
<Reference Include="Kingdee.BOS.DataEntity">
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Kingdee.BOS.DataEntity.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Program Files (x86)\Kingdee\K3Cloud\WebSite\bin\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BeforeSaveEventBillPlugIn.cs" />
<Compile Include="DataChangedEventFormPlugIn.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Extensions\ExtensionMethods.csproj">
<Project>{50532462-8f7f-455c-b4b3-732ed764e2fa}</Project>
<Name>ExtensionMethods</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>