代码拉取完成,页面将自动刷新
using System;
using System.Linq;
using System.Data;
using System.ComponentModel;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.App.Core.Utils;
//using JW.Plugins.Common.BusinessEntity.Material;
//using JW.Plugins.Common.BusinessEntity;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS;
using Kingdee.BOS.Resource;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Util;
/// <summary>
///
/// 宇祥 2019.04.12
/// </summary>
namespace JW.Plugins
{
[Kingdee.BOS.Util.HotUpdate]
[Description("委外订单")]
public class WWDD_edit : AbstractBillPlugIn
{
public override void DataChanged(DataChangedEventArgs e)
{
//控制一张销售订单里的物料同一道工序只能完整下推一次
chkWWGXQtyIsOk();
base.DataChanged(e);
if (e.Field.Key.ToUpper().Equals("FMATERIALID") && !e.NewValue.ToString().Equals("") && e.NewValue != e.OldValue)
{
//var Mtrl = new BD_Material().LoadSingle(this.Context, e.NewValue);
//if (Mtrl != null)
//{
var FSUPPLIER = "";
//var FSUPPLIER = Model.DataObject.GetDynamicObjectItemValue<int>("SupplierId_Id");
if (!this.View.Model.GetValue("FSupplierId", e.Row).IsNullOrEmptyOrWhiteSpace())
FSUPPLIER = (this.View.Model.GetValue("FSupplierId", e.Row) as DynamicObject)["Id"].ToString();
//this.View.ShowErrMessage(FSUPPLIER);
var WWGX = Model.DataObject.GetDynamicObjectItemValue<string>("F_BP_Assistant_Id");
//this.View.ShowMessage(WWGX);
//var WWGX = Mtrl["F_AAAA_WeiWaiGongxu_Id"].ToString();
if (!FSUPPLIER.Equals("") && !WWGX.IsNullOrEmptyOrWhiteSpace())
{
//var WWGXJMB = new RHTW_WWGXJMB().Load(this.Context, string.Format("FSUPPLIER='{0}' and FITEMID='{1}' and FWWGX='{2}'", FSUPPLIER, e.NewValue, WWGX)).FirstOrDefault();
//if (WWGXJMB != null)
//{
// var entity = WWGXJMB.GetDynamicObjectItemValue<DynamicObjectCollection>("FEntity");
// var item = entity.Where(w => w["FITEMID_Id"].Equals(e.NewValue) && w["FWWGX_Id"].ToString().Equals(WWGX)).FirstOrDefault();
// if (item != null)
// {
// this.View.Model.SetValue("FPrice", item["FPRICE"], e.Row);
// this.View.Model.SetValue("FTaxPrice", item["FPRICE"], e.Row);
// //this.View.Model.SetValue("FBaseUnitPrice", item["FPRICE"], e.Row);
// }
//}
System.Data.IDataReader data3;
// string ls_sql = @"/*dialect*/ SELECT TOP 1 T2.FPRICE FROM T_RHTW_WWGXJMB T1 JOIN T_RHTW_WWGXJMBENTRY T2 ON T1.FID=T2.FID
//WHERE T1.FSUPPLIER ='" + FSUPPLIER + @"' AND T2.FITEMID = '" + e.NewValue + @"' AND T2.FWWGX='" + WWGX + "'";
//this.View.ShowErrMessage(getPrieceSql(e.NewValue.ToString(), e.NewValue.ToString(), WWGX));
data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, getPrieceSql(FSUPPLIER.ToString(), e.NewValue.ToString(), WWGX));
this.View.Model.SetValue("FTaxPricekdzs", 0, e.Row);
while (data3.Read())
{
//this.View.Model.SetValue("FPrice", data3["FPRICE"].ToString(), e.Row);
this.View.Model.SetValue("FTaxPricekdzs", data3["FPRICE"].ToString(), e.Row);
}
}
}
else if (e.Field.Key.ToUpper().Equals("FSUPPLIERID") && e.NewValue != e.OldValue)
{
var FMaterialId = "";
//var FSUPPLIER = Model.DataObject.GetDynamicObjectItemValue<int>("SupplierId_Id");
if (!this.View.Model.GetValue("FMaterialId", e.Row).IsNullOrEmptyOrWhiteSpace())
FMaterialId = (this.View.Model.GetValue("FMaterialId", e.Row) as DynamicObject)["Id"].ToString();
if (!FMaterialId.Equals(""))
{
var WWGX = Model.DataObject.GetDynamicObjectItemValue<string>("F_BP_Assistant_Id");
//this.View.ShowMessage(WWGX);
//var WWGX = Mtrl["F_AAAA_WeiWaiGongxu_Id"].ToString();
if (!FMaterialId.Equals("") && !WWGX.IsNullOrEmptyOrWhiteSpace())
{
//var WWGXJMB = new RHTW_WWGXJMB().Load(this.Context, string.Format("FSUPPLIER='{0}' and FITEMID='{1}' and FWWGX='{2}'", FSUPPLIER, e.NewValue, WWGX)).FirstOrDefault();
//if (WWGXJMB != null)
//{
// var entity = WWGXJMB.GetDynamicObjectItemValue<DynamicObjectCollection>("FEntity");
// var item = entity.Where(w => w["FITEMID_Id"].Equals(e.NewValue) && w["FWWGX_Id"].ToString().Equals(WWGX)).FirstOrDefault();
// if (item != null)
// {
// this.View.Model.SetValue("FPrice", item["FPRICE"], e.Row);
// this.View.Model.SetValue("FTaxPrice", item["FPRICE"], e.Row);
// //this.View.Model.SetValue("FBaseUnitPrice", item["FPRICE"], e.Row);
// }
//}
System.Data.IDataReader data3;
// string ls_sql = @"/*dialect*/ SELECT TOP 1 T2.FPRICE FROM T_RHTW_WWGXJMB T1 JOIN T_RHTW_WWGXJMBENTRY T2 ON T1.FID=T2.FID
//WHERE T1.FSUPPLIER ='" + FSUPPLIER + @"' AND T2.FITEMID = '" + e.NewValue + @"' AND T2.FWWGX='" + WWGX + "'";
//this.View.ShowErrMessage(getPrieceSql(e.NewValue.ToString(), FMaterialId, WWGX));
data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, getPrieceSql(e.NewValue.ToString(), FMaterialId, WWGX));
this.View.Model.SetValue("FTaxPricekdzs", 0, e.Row);
while (data3.Read())
{
//this.View.Model.SetValue("FPrice", data3["FPRICE"].ToString(), e.Row);
this.View.Model.SetValue("FTaxPricekdzs", data3["FPRICE"].ToString(), e.Row);
}
}
}
}
else if (e.Field.Key.ToUpper().Equals("F_BP_ASSISTANT") && e.NewValue != e.OldValue)
{
var entry = Model.DataObject.GetDynamicObjectItemValue<DynamicObjectCollection>("TreeEntity");
int i = 0;
foreach (var row in entry)
{
if (row["MaterialId_Id"] != null && Convert.ToInt32(row["MaterialId_Id"]) > 0 && row["SupplierId_Id"] != null && Convert.ToInt32(row["SupplierId_Id"]) > 0)
{
//var Mtrl = new BD_Material().LoadSingle(this.Context, row["MaterialId_Id"]);
//if (Mtrl != null)
//{
var FSUPPLIER = row["SupplierId_Id"];
var WWGX = Model.DataObject.GetDynamicObjectItemValue<string>("F_BP_Assistant_Id");
//this.View.ShowMessage(WWGX);
//var WWGX = Mtrl["F_AAAA_WeiWaiGongxu_Id"].ToString();
if (!FSUPPLIER.Equals("") && !WWGX.IsNullOrEmptyOrWhiteSpace())
{
System.Data.IDataReader data3;
// string ls_sql = @"/*dialect*/ SELECT TOP 1 T2.FPRICE FROM T_RHTW_WWGXJMB T1 JOIN T_RHTW_WWGXJMBENTRY T2 ON T1.FID=T2.FID
//WHERE T1.FSUPPLIER ='" + FSUPPLIER + @"' AND T2.FITEMID = '" + row["MaterialId_Id"] + @"' AND T2.FWWGX='" + WWGX + "'";
data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, getPrieceSql(FSUPPLIER.ToString(), row["MaterialId_Id"].ToString(), WWGX));
this.View.Model.SetValue("FTaxPricekdzs", 0, i);
while (data3.Read())
{
this.View.Model.SetValue("FTaxPricekdzs", data3["FPRICE"].ToString(), i);
((IDynamicFormView)View).InvokeFieldUpdateService("FTaxPricekdzs", i);
}
}
//}
}
i++;
}
}
}
public override void BeforeSave(BeforeSaveEventArgs e)
{
//控制一张销售订单里的物料同一道工序只能完整下推一次
chkWWGXQtyIsOk();
base.BeforeSave(e);
}
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
var entry = Model.DataObject.GetDynamicObjectItemValue<DynamicObjectCollection>("TreeEntity");
int i = 0;
foreach (var row in entry)
{
if (row["MaterialId_Id"] != null && Convert.ToInt32(row["MaterialId_Id"]) > 0 && row["SupplierId_Id"] != null && Convert.ToInt32(row["SupplierId_Id"]) > 0)
{
//var Mtrl = new BD_Material().LoadSingle(this.Context, row["MaterialId_Id"]);
//if (Mtrl != null)
//{
var FSUPPLIER = row["SupplierId_Id"];
var WWGX = Model.DataObject.GetDynamicObjectItemValue<string>("F_BP_Assistant_Id");
//this.View.ShowMessage(WWGX);
//var WWGX = Mtrl["F_AAAA_WeiWaiGongxu_Id"].ToString();
if (!FSUPPLIER.Equals("") && !WWGX.IsNullOrEmptyOrWhiteSpace())
{
System.Data.IDataReader data3;
// string ls_sql = @"/*dialect*/ SELECT TOP 1 T2.FPRICE FROM T_RHTW_WWGXJMB T1 JOIN T_RHTW_WWGXJMBENTRY T2 ON T1.FID=T2.FID
//WHERE T1.FSUPPLIER ='" + FSUPPLIER + @"' AND T2.FITEMID = '" + row["MaterialId_Id"] + @"' AND T2.FWWGX='" + WWGX + "'";
data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, getPrieceSql(FSUPPLIER.ToString(), row["MaterialId_Id"].ToString(), WWGX));
this.View.Model.SetValue("FTaxPricekdzs", 0, i);
while (data3.Read())
{
this.View.Model.SetValue("FTaxPricekdzs", data3["FPRICE"].ToString(), i);
((IDynamicFormView)View).InvokeFieldUpdateService("FTaxPricekdzs", i);
}
}
//}
}
i++;
}
}
public void chkWWGXQtyIsOk()
{
//控制一张销售订单里的物料同一道工序只能完整下推一次
string sResult = "";
string sWWDDfid = "";
string sfid = "";
string sfentryid = "";
double dNowRowQty = 0;
// this.View.ShowMessage("222");
if (Model.DataObject.GetDynamicObjectItemValue<DynamicObject>("BillType") != null)
{
var FBillTypeID = Model.DataObject.GetDynamicObjectItemValue<DynamicObject>("BillType")["Number"].ToString();//单据类型
// this.View.ShowMessage(FBillTypeID);
if (FBillTypeID.Equals("WWGXDD"))//委外工序 订单
{
// this.View.ShowMessage(FBillTypeID.ToString());
//委外工序
if (Model.DataObject.GetDynamicObjectItemValue<DynamicObject>("F_BP_ASSISTANT") != null)
{
var wwgx = Model.DataObject.GetDynamicObjectItemValue<DynamicObject>("F_BP_ASSISTANT")["Id"].ToString();
//this.View.ShowMessage(wwgx);
sWWDDfid = this.View.Model.DataObject["Id"].ToString();
var entry = Model.DataObject.GetDynamicObjectItemValue<DynamicObjectCollection>("TreeEntity");
int i = 0;
//var FSUPPLIER = Model.DataObject.GetDynamicObjectItemValue<int>("SupplierId_Id");
foreach (var row in entry)
{
if (row["MaterialId_Id"] != null && Convert.ToInt32(row["MaterialId_Id"]) > 0)
{
sfid = this.View.Model.GetValue("FSaleOrderId", i).ToString();
sfentryid = this.View.Model.GetValue("FSaleOrderEntryId", i).ToString();
// this.View.ShowMessage(sfid);
// this.View.ShowMessage(sfentryid);
dNowRowQty = Convert.ToDouble(this.View.Model.GetValue("FQty", i));
sResult = chkSoQty(sfid, sfentryid, dNowRowQty, wwgx, sWWDDfid);
// this.View.ShowMessage(sResult);
if (sResult.Equals("0"))
throw new KDExceptionValidate("convert", ResManager.LoadKDString("不符合条件", "004002030004060", SubSystemType.SCM, new object[0]), ResManager.LoadKDString("一张销售订单里的物料同一道工序只能完整下推一次!", "004002030004063", SubSystemType.SCM, new object[0]));
}
i++;
}
}
}
}
}
//控制一张销售订单里的物料同一道工序只能完整下推一次
public string chkSoQty(string fid, string fentryid, double dNowRowQty, string sWWGX, string sWWDDfid)
{
string result = "1";
System.Data.IDataReader data3;
string ls_sql = "";
if (sWWDDfid.Equals("0"))
{
ls_sql = @"/*dialect*/
---委外种类,数量都触发
SET NOCOUNT ON
---取销售订单行数量
DECLARE @SOQTY DECIMAL(28,10)
DECLARE @WWQTY DECIMAL(28,10)
SET @SOQTY=0
SET @WWQTY=0
SELECT @SOQTY=T2.FQTY
FROM T_SAL_ORDER T1 JOIN T_SAL_ORDERENTRY T2 ON T1.FID=T2.FID
WHERE T1.FID='" + fid + @"' AND T2.FENTRYID='" + fentryid + @"'
---汇总销售订单对应的所有已经保存委外订单数量
SELECT @WWQTY=SUM(T2.FQTY)
FROM T_SUB_REQORDER T1 JOIN T_SUB_REQORDERENTRY T2 ON T1.FID=T2.FID
JOIN T_SUB_REQORDERENTRY_A T3 ON T2.FID=T3.FID AND T2.FENTRYID=T3.FENTRYID
WHERE T3.FSALEORDERID= '" + fid + @"' and T3.FSALEORDERENTRYID='" + fentryid + @"'
and T1.F_BP_ASSISTANT='" + sWWGX + @"'
SELECT CASE WHEN isnull(@SOQTY,0)>=isnull(@WWQTY,0)+" + dNowRowQty + @" then 1 else 0 end result";
}
else
{
ls_sql = @"/*dialect*/
---委外种类,数量都触发
SET NOCOUNT ON
---取销售订单行数量
DECLARE @SOQTY DECIMAL(28,10)
DECLARE @WWQTY DECIMAL(28,10)
SET @SOQTY=0
SET @WWQTY=0
SELECT @SOQTY=T2.FQTY
FROM T_SAL_ORDER T1 JOIN T_SAL_ORDERENTRY T2 ON T1.FID=T2.FID
WHERE T1.FID='" + fid + @"' AND T2.FENTRYID='" + fentryid + @"'
---汇总销售订单对应的所有已经保存委外订单数量
SELECT @WWQTY=SUM(T2.FQTY)
FROM T_SUB_REQORDER T1 JOIN T_SUB_REQORDERENTRY T2 ON T1.FID=T2.FID
JOIN T_SUB_REQORDERENTRY_A T3 ON T2.FID=T3.FID AND T2.FENTRYID=T3.FENTRYID
WHERE T1.FID<>'" + sWWDDfid + @"' AND T3.FSALEORDERID= '" + fid + @"' and T3.FSALEORDERENTRYID='" + fentryid + @"'
and T1.F_BP_ASSISTANT='" + sWWGX + @"'
SELECT CASE WHEN isnull(@SOQTY,0)>=isnull(@WWQTY,0)+" + dNowRowQty + @" then 1 else 0 end result";
}
data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, ls_sql);
//this.View.ShowErrMessage(ls_sql);
while (data3.Read())
{
return data3["result"].ToString();
}
return result;
}
public string getPrieceSql(string FSUPPLIER, string FITEMID, string FWWGX)
{
return @"/*dialect*/ SET NOCOUNT ON
SELECT T1.FSUPPLIER,T2.FITEMID,T2.FWWGX,MAX(FAPPROVEDATE)FAPPROVEDATE
into #tmp
FROM T_RHTW_WWGXJMB T1 JOIN T_RHTW_WWGXJMBENTRY T2 ON T1.FID = T2.FID
WHERE T1.FDOCUMENTSTATUS = 'C' and t1.FEFFECTIVEDATE <= getdate() and t1.FEXPIRYDATE >= getdate()
and T1.FSUPPLIER='" + FSUPPLIER + @"' and T2.FITEMID='" + FITEMID + @"' and T2.FWWGX='" + FWWGX + @"'
GROUP BY T1.FSUPPLIER,T2.FITEMID,T2.FWWGX
SELECT T1.FSUPPLIER,T2.FITEMID,T2.FWWGX,t2.FPRICE
FROM T_RHTW_WWGXJMB T1 JOIN T_RHTW_WWGXJMBENTRY T2 ON T1.FID = T2.FID
join #tmp t3 on t1.FSUPPLIER=t3.FSUPPLIER and t2.FITEMID=t3.FITEMID and t2.FWWGX=t3.FWWGX and t1.FAPPROVEDATE=t3.FAPPROVEDATE
WHERE T1.FDOCUMENTSTATUS = 'C' and t1.FEFFECTIVEDATE <= getdate() and t1.FEXPIRYDATE >= getdate()";
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。