添加项目文件。
This commit is contained in:
195
UseGetFmaterialData/BeforeSaveEventBillPlugIn.cs
Normal file
195
UseGetFmaterialData/BeforeSaveEventBillPlugIn.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user