From f1354249a78d6e76feac9c7e7902fdfa42609ae1 Mon Sep 17 00:00:00 2001 From: wugang <425674808@qq.com> Date: Tue, 9 Jan 2018 10:19:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=8D=95No.138104?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BLActions/CustomerCreditPolicyBLAction.cs | 91 +++++++++++++++++++ BWP.B3_YunKen/BWP.B3_YunKen.csproj | 1 + 2 files changed, 92 insertions(+) create mode 100644 BWP.B3_YunKen/BLActions/CustomerCreditPolicyBLAction.cs diff --git a/BWP.B3_YunKen/BLActions/CustomerCreditPolicyBLAction.cs b/BWP.B3_YunKen/BLActions/CustomerCreditPolicyBLAction.cs new file mode 100644 index 0000000..80a1e76 --- /dev/null +++ b/BWP.B3_YunKen/BLActions/CustomerCreditPolicyBLAction.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BWP.B3Sale.BL; +using BWP.B3Sale.BO; +using Forks.EnterpriseServices.BusinessInterfaces; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; +using TSingSoft.WebPluginFramework.BIPlugins.BLEvents; + +namespace BWP.B3_YunKen.BLActions +{ + public class CustomerCreditPolicyBLAction : IBLMethodAction + { + public string Description + { + get { return "根据[信用政策]往【信用政策单据】客户明细中插入一条明细"; } + } + + public void Execute(Forks.EnterpriseServices.BusinessInterfaces.IDmoContext context, object dmo, object parameter) + { + var customer = dmo as Customer; + if (customer != null && customer.CreditPolicy_ID != null) { + Tuple tuple = null; + var detail = new JoinAlias(typeof(SaleCreditPolicy_Detail)); + var saleCreditPolicy = new JoinAlias(typeof(SaleCreditPolicy)); + var query = new DQueryDom(detail); + query.From.AddJoin(JoinType.Left, new DQDmoSource(saleCreditPolicy), DQCondition.EQ(detail, "SaleCreditPolicy_ID", saleCreditPolicy, "ID")); + query.Columns.Add(DQSelectColumn.Field("CreditPolicy_ID", saleCreditPolicy)); + query.Columns.Add(DQSelectColumn.Field("ID", saleCreditPolicy)); + query.Where.Conditions.Add(DQCondition.EQ("Customer_ID", customer.ID)); + using (var reader = context.Session.ExecuteReader(query)) { + while (reader.Read()) { + tuple = new Tuple((long?)reader[0], (long)reader[1]); + } + } + if (customer.CreditPolicy_ID == tuple.Item1) + return; + + if (tuple != null && tuple.Item1 != null) { + var del = new DQDeleteDom(typeof(SaleCreditPolicy_Detail)); + del.Where.Conditions.Add(DQCondition.EQ("Customer_ID", customer.ID)); + context.Session.ExecuteNonQuery(del); + + var update = new DQUpdateDom(typeof(SaleCreditPolicy)); + update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1)))); + update.Where.Conditions.Add(DQCondition.EQ("ID", tuple.Item2)); + context.Session.ExecuteNonQuery(update); + } + + var scp = new JoinAlias(typeof(SaleCreditPolicy)); + var scp_detail = new JoinAlias(typeof(SaleCreditPolicy_Detail)); + var main = new DQueryDom(saleCreditPolicy); + main.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(detail, "SaleCreditPolicy_ID", saleCreditPolicy, "ID")); + main.Columns.Add(DQSelectColumn.Field("Customer_ID", detail)); + main.Columns.Add(DQSelectColumn.Field("ID", saleCreditPolicy)); + main.Where.Conditions.Add(DQCondition.EQ("CreditPolicy_ID", customer.CreditPolicy_ID)); + List> list = new List>(); + using (var reader = context.Session.ExecuteReader(query)) { + while (reader.Read()) { + list.Add(new Tuple((long?)reader[0], (long?)reader[1])); + } + } + + if (list.Count() > 0 && !list.Any(x => x.Item1 == customer.ID)) { + var first = list.First(); + var customerDetail = new SaleCreditPolicy_Detail(); + customerDetail.Customer_ID = customer.ID; + customerDetail.SaleCreditPolicy_ID = first.Item2; + context.Session.Insert(customerDetail); + var update = new DQUpdateDom(typeof(SaleCreditPolicy)); + update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1)))); + update.Where.Conditions.Add(DQCondition.EQ("ID", first.Item2)); + context.Session.ExecuteNonQuery(update); + } + } + } + + public IList Features + { + get { return new List(); } + } + + public string Name + { + get { return "B3_YunKen.【信用政策单】客户明细增加客户"; } + } + } +} diff --git a/BWP.B3_YunKen/BWP.B3_YunKen.csproj b/BWP.B3_YunKen/BWP.B3_YunKen.csproj index f6c6fa2..4a1aa0a 100644 --- a/BWP.B3_YunKen/BWP.B3_YunKen.csproj +++ b/BWP.B3_YunKen/BWP.B3_YunKen.csproj @@ -63,6 +63,7 @@ +