1 Star 0 Fork 0

momoxxx/cq.Plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
WWDD_edit.cs 17.12 KB
一键复制 编辑 原始数据 按行查看 历史
momoxxx 提交于 2024-01-09 14:40 . 添加项目文件。
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()";
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/momoxxx/cq.-plugins.git
git@gitee.com:momoxxx/cq.-plugins.git
momoxxx
cq.-plugins
cq.Plugins
master

搜索帮助