| @ -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<long?, long> 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?, long>((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<Tuple<long?, long?>> list = new List<Tuple<long?, long?>>(); | |||
| using (var reader = context.Session.ExecuteReader(query)) { | |||
| while (reader.Read()) { | |||
| list.Add(new Tuple<long?, long?>((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<string> Features | |||
| { | |||
| get { return new List<string>(); } | |||
| } | |||
| public string Name | |||
| { | |||
| get { return "B3_YunKen.【信用政策单】客户明细增加客户"; } | |||
| } | |||
| } | |||
| } | |||