430 lines
25 KiB
C#
430 lines
25 KiB
C#
using Kingdee.BOS;
|
|
using Kingdee.BOS.App.Data;
|
|
using Kingdee.BOS.Core.Bill.PlugIn;
|
|
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
|
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
|
using Kingdee.BOS.Log;
|
|
using Kingdee.BOS.Orm.DataEntity;
|
|
using Kingdee.BOS.ServiceHelper;
|
|
using Kingdee.BOS.Util;
|
|
using Pilot_KD_Parino.Common;
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using static Kingdee.K3.SCM.Common.BusinessEntity.Sales.SaleOrder;
|
|
|
|
namespace Pilot_KD_Parino.Sal_Order
|
|
{
|
|
[Description("销售订单保存前刷正确的合同号"), HotUpdate]
|
|
public class SaleOrderContractnumber : AbstractOperationServicePlugIn
|
|
{
|
|
|
|
public override void BeforeDoSaveExecute(BeforeDoSaveExecuteEventArgs e)
|
|
{
|
|
base.BeforeDoSaveExecute(e);
|
|
var FEntity = e.DataEntities[0];
|
|
var FNAME1 = FEntity["BillTypeId_Id"].ToString();
|
|
if (FNAME1.ToString() == "a300e2620037435492aed9842875b451" && FNAME1 != null)
|
|
{
|
|
|
|
var json = JsonUtil.Serialize(FEntity);
|
|
//Logger.Error("销售订单保存前刷正确的合同号", json, new Exception());
|
|
var fid = FEntity["id"];
|
|
|
|
var sql3333 = $@"SELECT F_contractnumber FROM dbo.T_SAL_ORDER WHERE fid={fid} and F_contractnumber !='' ";
|
|
var sqlDS33 = DBUtils.ExecuteDynamicObject(this.Context, sql3333);
|
|
if (sqlDS33 != null && sqlDS33.Count > 0)
|
|
{
|
|
string contractnumber = sqlDS33[0]["F_contractnumber"].ToString();
|
|
//Logger.Error("销售订单保存前刷正确的合同号2", contractnumber, new Exception());
|
|
FEntity["F_contractnumber"] = contractnumber;
|
|
|
|
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
|
|
var formID = FEntity["FFormId"];
|
|
//销售订单新变更单
|
|
if (formID.ToString() == "SAL_XORDER")
|
|
{
|
|
|
|
if (FNAME1.ToString() == "a300e2620037435492aed9842875b451" && FNAME1 != null)
|
|
{
|
|
var FSaleOrderEntry_Link = FEntity["SaleOrderEntry"] as DynamicObjectCollection;
|
|
if (FSaleOrderEntry_Link.Count > 0)
|
|
{
|
|
var details = FSaleOrderEntry_Link[0]["FSaleOrderEntry_Link"] as DynamicObjectCollection;
|
|
//var FbiLLNO = this.View.Model.GetValue("FBILLNO");
|
|
|
|
if (details != null)
|
|
{
|
|
var entrys = details;
|
|
if (entrys != null && entrys.Count > 0)
|
|
{
|
|
foreach (var entry in entrys)
|
|
{
|
|
|
|
var sBillId = entry == null ? 0 : entry["sBillId"].Long2Int();
|
|
|
|
//获取退货类型字段
|
|
var F_Returntype = FEntity["F_Returntype"];
|
|
|
|
//获取纸质合同号
|
|
String F_contractnumber = FEntity["F_contractnumber"].ToString();
|
|
string yuanF_contractnumber = F_contractnumber;
|
|
int dashPosition;
|
|
if (F_contractnumber.Contains("-TH"))
|
|
{
|
|
|
|
dashPosition = F_contractnumber.IndexOf("-TH");
|
|
F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
}
|
|
else if (F_contractnumber.Contains("-HH"))
|
|
{
|
|
dashPosition = F_contractnumber.IndexOf("-HH");
|
|
F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
}
|
|
else
|
|
{
|
|
dashPosition = -2;
|
|
}
|
|
var sql = string.Format(@"SELECT COUNT(*) AS FNUMBER FROM T_SAL_ORDERENTRY_LK WHERE FSBILLID = '{0}'AND FRULEID = 'SaleOrder-ReturnSaleOrder'", sBillId);
|
|
var sqlDS = DBUtils.ExecuteDynamicObject(this.Context, sql);
|
|
String F_contractnumber2 = FEntity["F_contractnumber"].ToString();
|
|
int number;
|
|
if (F_contractnumber2.Contains("-") && dashPosition != -2)
|
|
{
|
|
number = F_contractnumber2.Substring(F_contractnumber2.Length - 2).Long2Int();
|
|
}
|
|
else
|
|
{
|
|
number = sqlDS[0]["FNUMBER"].Long2Int();
|
|
number += 1;
|
|
//if (number == 1)
|
|
//{
|
|
// number += 1;
|
|
//}
|
|
}
|
|
|
|
string F_contractnumber1;
|
|
|
|
int IFnumber = sqlDS[0]["FNUMBER"].Long2Int();
|
|
|
|
if (IFnumber != 0 && !F_Returntype.IsNullOrEmpty())
|
|
{
|
|
F_contractnumber1 = yuanF_contractnumber.ToString() + '-' + F_Returntype + '0' + number.ToString();
|
|
FEntity["F_contractnumber"] = F_contractnumber1;
|
|
break;
|
|
}
|
|
else if (!F_Returntype.IsNullOrEmpty())
|
|
{
|
|
F_contractnumber1 = yuanF_contractnumber.ToString() + '-' + F_Returntype + '0' + '1';
|
|
|
|
FEntity["F_contractnumber"] = F_contractnumber1;
|
|
break;
|
|
}
|
|
//else if (IFnumber != 0 && !F_Returntype.IsNullOrEmpty())
|
|
//{
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//销售订单
|
|
else if (formID.ToString() == "SAL_SaleOrder")
|
|
{
|
|
var FNAME = FEntity["BillTypeId_Id"].ToString();
|
|
if (FNAME == "a300e2620037435492aed9842875b451" && FNAME != null)
|
|
{
|
|
var FSaleOrderEntry_Link = FEntity["SaleOrderEntry"] as DynamicObjectCollection;
|
|
if (FSaleOrderEntry_Link.Count > 0)
|
|
{
|
|
var details = FSaleOrderEntry_Link[0]["FSaleOrderEntry_Link"] as DynamicObjectCollection;
|
|
|
|
|
|
//var details = this.View.BusinessInfo.GetEntity("FSaleOrderEntry_Link");
|
|
//var FbiLLNO = this.View.Model.GetValue("FID");
|
|
|
|
if (details != null)
|
|
{
|
|
var entrys = details;
|
|
if (entrys != null && entrys.Count > 0)
|
|
{
|
|
foreach (var entry in entrys)
|
|
{
|
|
|
|
var sBillId = entry == null ? 0 : entry["sBillId"].Long2Int();
|
|
|
|
//获取退货类型字段
|
|
var F_Returntype = FEntity["F_Returntype"];
|
|
|
|
//获取纸质合同号
|
|
String F_contractnumber = FEntity["F_contractnumber"].ToString();
|
|
string yuanF_contractnumber = F_contractnumber;
|
|
int dashPosition;
|
|
if (F_contractnumber.Contains("-TH"))
|
|
{
|
|
|
|
dashPosition = F_contractnumber.IndexOf("-TH");
|
|
F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
}
|
|
else if (F_contractnumber.Contains("-HH"))
|
|
{
|
|
dashPosition = F_contractnumber.IndexOf("-HH");
|
|
F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
}
|
|
else
|
|
{
|
|
dashPosition = -2;
|
|
}
|
|
|
|
var sql = string.Format(@"SELECT COUNT(*) AS FNUMBER FROM T_SAL_ORDERENTRY_LK WHERE FSBILLID = '{0}' AND FRULEID = 'SaleOrder-ReturnSaleOrder'", sBillId);
|
|
var sqlDS = DBUtils.ExecuteDynamicObject(this.Context, sql);
|
|
String F_contractnumber2 = F_contractnumber;
|
|
int number;
|
|
if (F_contractnumber2.Contains("-") && dashPosition != -2)
|
|
{
|
|
number = F_contractnumber2.Substring(F_contractnumber2.Length - 2).Long2Int();
|
|
}
|
|
else
|
|
{
|
|
number = sqlDS[0]["FNUMBER"].Long2Int();
|
|
number += 1;
|
|
//if (number == 1)
|
|
//{
|
|
// number += 1;
|
|
//}
|
|
}
|
|
|
|
string F_contractnumber1;
|
|
|
|
int IFnumber = sqlDS[0]["FNUMBER"].Long2Int();
|
|
|
|
if (IFnumber != 0 && !F_Returntype.IsNullOrEmpty())
|
|
{
|
|
F_contractnumber1 = yuanF_contractnumber.ToString() + '-' + F_Returntype + '0' + number.ToString();
|
|
FEntity["F_contractnumber"]= F_contractnumber1;
|
|
break;
|
|
}
|
|
else if (!F_Returntype.IsNullOrEmpty() )
|
|
{
|
|
F_contractnumber1 = yuanF_contractnumber.ToString() + '-' + F_Returntype + '0' + '1';
|
|
FEntity["F_contractnumber"] = F_contractnumber1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//public override void BeforeUpdateValue(BeforeUpdateValueEventArgs e)
|
|
//{
|
|
// base.BeforeUpdateValue(e);
|
|
// if (e.Key.ToLower() == ("f_contractnumber").ToLower())
|
|
// {
|
|
// var FEntity = this.View.Model.DataObject;
|
|
// var json = JsonUtil.Serialize(FEntity);
|
|
// Logger.Error("销售订单保存前刷正确的合同号", json, new Exception());
|
|
// var fid = FEntity["id"];
|
|
|
|
// var sql3333 = $@"SELECT F_contractnumber FROM dbo.T_SAL_ORDER WHERE fid={fid} and F_contractnumber !='' ";
|
|
// var sqlDS33 = DBUtils.ExecuteDynamicObject(this.Context, sql3333);
|
|
// if (sqlDS33 != null && sqlDS33.Count > 0)
|
|
// {
|
|
// string contractnumber = sqlDS33[0]["F_contractnumber"].ToString();
|
|
// Logger.Error("销售订单保存前刷正确的合同号2", contractnumber, new Exception());
|
|
// this.View.Model.SetValue("F_contractnumber", contractnumber);
|
|
// this.View.UpdateView("F_contractnumber");
|
|
// //throw new KDBusinessException("", "销售订单保存前刷正确的合同号2: "+ contractnumber);
|
|
// Thread.Sleep(500);
|
|
// return;
|
|
// }
|
|
// else
|
|
// {
|
|
|
|
// var formID = this.View.Model.DataObject["FFormId"];
|
|
// //销售订单新变更单
|
|
// if (formID.ToString() == "SAL_XORDER")
|
|
// {
|
|
// var FNAME1 = this.Model.GetValue("FBILLTYPEIDX").ToString();
|
|
// if (FNAME1.ToString() == "a300e2620037435492aed9842875b451" && FNAME1 != null)
|
|
// {
|
|
// var details = this.View.BusinessInfo.GetEntity("FSaleOrderEntry_Link");
|
|
// //var FbiLLNO = this.View.Model.GetValue("FBILLNO");
|
|
|
|
// if (details != null)
|
|
// {
|
|
// var entrys = this.View.Model.GetEntityDataObject(details);
|
|
// if (entrys != null && entrys.Count > 0)
|
|
// {
|
|
// foreach (var entry in entrys)
|
|
// {
|
|
|
|
// var sBillId = entry == null ? 0 : entry["sBillId"].Long2Int();
|
|
|
|
// //获取退货类型字段
|
|
// var F_Returntype = this.View.Model.GetValue("F_Returntype");
|
|
|
|
// //获取纸质合同号
|
|
// String F_contractnumber = this.View.Model.GetValue("F_contractnumber").ToString();
|
|
// int dashPosition;
|
|
// if (F_contractnumber.Contains("-TH"))
|
|
// {
|
|
|
|
// dashPosition = F_contractnumber.IndexOf("-TH");
|
|
// F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
// }
|
|
// else if (F_contractnumber.Contains("-HH"))
|
|
// {
|
|
// dashPosition = F_contractnumber.IndexOf("-HH");
|
|
// F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
// }
|
|
// else
|
|
// {
|
|
// dashPosition = -2;
|
|
// }
|
|
// var sql = string.Format(@"SELECT COUNT(*) AS FNUMBER FROM T_SAL_ORDERENTRY_LK WHERE FSBILLID = '{0}'AND FRULEID = 'SaleOrder-ReturnSaleOrder'", sBillId);
|
|
// var sqlDS = DBUtils.ExecuteDynamicObject(this.Context, sql);
|
|
// String F_contractnumber2 = this.View.Model.GetValue("F_contractnumber").ToString();
|
|
// int number;
|
|
// if (F_contractnumber2.Contains("-") && dashPosition != -2)
|
|
// {
|
|
// number = F_contractnumber2.Substring(F_contractnumber2.Length - 2).Long2Int();
|
|
// }
|
|
// else
|
|
// {
|
|
// number = sqlDS[0]["FNUMBER"].Long2Int();
|
|
// if (number == 1)
|
|
// {
|
|
// number += 1;
|
|
// }
|
|
// }
|
|
|
|
// string F_contractnumber1;
|
|
|
|
// int IFnumber = sqlDS[0]["FNUMBER"].Long2Int();
|
|
|
|
// if (IFnumber != 0 && !F_Returntype.IsNullOrEmpty() && !F_contractnumber.ToString().Contains("TH") && !F_contractnumber.ToString().Contains("HH"))
|
|
// {
|
|
// F_contractnumber1 = F_contractnumber.ToString() + '-' + F_Returntype + '0' + number.ToString();
|
|
// this.View.Model.SetValue("F_contractnumber", F_contractnumber1);
|
|
// break;
|
|
// }
|
|
// else if (!F_Returntype.IsNullOrEmpty() && !F_contractnumber.ToString().Contains("TH") && !F_contractnumber.ToString().Contains("HH"))
|
|
// {
|
|
// F_contractnumber1 = F_contractnumber.ToString() + '-' + F_Returntype + '0' + '1';
|
|
// this.View.Model.SetValue("F_contractnumber", F_contractnumber1);
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// //销售订单
|
|
// else if (formID.ToString() == "SAL_SaleOrder")
|
|
// {
|
|
// var FNAME = (DynamicObject)this.Model.GetValue("FBillTypeID");
|
|
// if (FNAME["Id"].ToString() == "a300e2620037435492aed9842875b451" && FNAME != null)
|
|
// {
|
|
|
|
// {
|
|
// var details = this.View.BusinessInfo.GetEntity("FSaleOrderEntry_Link");
|
|
// //var FbiLLNO = this.View.Model.GetValue("FID");
|
|
|
|
// if (details != null)
|
|
// {
|
|
// var entrys = this.View.Model.GetEntityDataObject(details);
|
|
// if (entrys != null && entrys.Count > 0)
|
|
// {
|
|
// foreach (var entry in entrys)
|
|
// {
|
|
|
|
// var sBillId = entry == null ? 0 : entry["sBillId"].Long2Int();
|
|
|
|
// //获取退货类型字段
|
|
// var F_Returntype = this.View.Model.GetValue("F_Returntype");
|
|
|
|
// //获取纸质合同号
|
|
// String F_contractnumber = this.View.Model.GetValue("F_contractnumber").ToString();
|
|
// int dashPosition;
|
|
// if (F_contractnumber.Contains("-TH"))
|
|
// {
|
|
|
|
// dashPosition = F_contractnumber.IndexOf("-TH");
|
|
// F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
// }
|
|
// else if (F_contractnumber.Contains("-HH"))
|
|
// {
|
|
// dashPosition = F_contractnumber.IndexOf("-HH");
|
|
// F_contractnumber = dashPosition > -1 ? F_contractnumber.Substring(0, dashPosition) : F_contractnumber;
|
|
// }
|
|
// else
|
|
// {
|
|
// dashPosition = -2;
|
|
// }
|
|
|
|
// var sql = string.Format(@"SELECT COUNT(*) AS FNUMBER FROM T_SAL_ORDERENTRY_LK WHERE FSBILLID = '{0}' AND FRULEID = 'SaleOrder-ReturnSaleOrder'", sBillId);
|
|
// var sqlDS = DBUtils.ExecuteDynamicObject(this.Context, sql);
|
|
// String F_contractnumber2 = this.View.Model.GetValue("F_contractnumber").ToString();
|
|
// int number;
|
|
// if (F_contractnumber2.Contains("-") && dashPosition != -2)
|
|
// {
|
|
// number = F_contractnumber2.Substring(F_contractnumber2.Length - 2).Long2Int();
|
|
// }
|
|
// else
|
|
// {
|
|
// number = sqlDS[0]["FNUMBER"].Long2Int();
|
|
// if (number == 1)
|
|
// {
|
|
// number += 1;
|
|
// }
|
|
// }
|
|
|
|
// string F_contractnumber1;
|
|
|
|
// int IFnumber = sqlDS[0]["FNUMBER"].Long2Int();
|
|
|
|
// if (IFnumber != 0 && !F_Returntype.IsNullOrEmpty() && !F_contractnumber.ToString().Contains("TH") && !F_contractnumber.ToString().Contains("HH"))
|
|
// {
|
|
// F_contractnumber1 = F_contractnumber.ToString() + '-' + F_Returntype + '0' + number.ToString();
|
|
// this.View.Model.SetValue("F_contractnumber", F_contractnumber1);
|
|
// break;
|
|
// }
|
|
// else if (!F_Returntype.IsNullOrEmpty() && !F_contractnumber.ToString().Contains("TH") && !F_contractnumber.ToString().Contains("HH"))
|
|
// {
|
|
// F_contractnumber1 = F_contractnumber.ToString() + '-' + F_Returntype + '0' + '1';
|
|
// this.View.Model.SetValue("F_contractnumber", F_contractnumber1);
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|