|
|
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.AccountCustomer_ID != 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.AccountCustomer_ID));
|
|
|
using (var reader = context.Session.ExecuteReader(query)) {
|
|
|
while (reader.Read()) {
|
|
|
tuple = new Tuple<long?, long>((long?)reader[0], (long)reader[1]);
|
|
|
}
|
|
|
}
|
|
|
if (tuple != null && 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.AccountCustomer_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);
|
|
|
}
|
|
|
|
|
|
List<Tuple<long?, long?, long?>> list = new List<Tuple<long?, long?, long?>>();
|
|
|
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.Columns.Add(DQSelectColumn.Field("AccountingUnit_ID", saleCreditPolicy));
|
|
|
main.Where.Conditions.Add(DQCondition.EQ("CreditPolicy_ID", customer.CreditPolicy_ID));
|
|
|
using (var reader = context.Session.ExecuteReader(main)) {
|
|
|
while (reader.Read()) {
|
|
|
list.Add(new Tuple<long?, long?, long?>((long?)reader[0], (long?)reader[1], (long?)reader[2]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (list.Count() > 0 && !list.Any(x => x.Item1 == customer.AccountCustomer_ID)) {
|
|
|
var first = list.First();
|
|
|
var customerDetail = new SaleCreditPolicy_Detail();
|
|
|
customerDetail.Customer_ID = customer.AccountCustomer_ID.Value;
|
|
|
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);
|
|
|
DeleteHeadOfficeCreditPolicyToday(context, customer.AccountCustomer_ID, first.Item3);
|
|
|
context.Session.AddInsertOrUpdate(new CustomerCreditPolicyToday {
|
|
|
Customer_ID = customer.AccountCustomer_ID.Value,
|
|
|
SaleCreditPolicy_ID = first.Item2.Value,
|
|
|
AccountingUnit_ID = first.Item3 ?? 0
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void DeleteHeadOfficeCreditPolicyToday(IDmoContext context, long? customer_ID, long? accountingUnit_ID)
|
|
|
{
|
|
|
var type = typeof(CustomerCreditPolicyToday);
|
|
|
var deldom = new DQDeleteDom(type);
|
|
|
deldom.Where.Conditions.Add(DQCondition.EQ("Customer_ID", customer_ID));
|
|
|
deldom.Where.Conditions.Add(DQCondition.EQ("AccountingUnit_ID", accountingUnit_ID ?? 0));
|
|
|
context.Session.ExecuteNonQuery(deldom);
|
|
|
}
|
|
|
|
|
|
public IList<string> Features
|
|
|
{
|
|
|
get { return new List<string>(); }
|
|
|
}
|
|
|
|
|
|
public string Name
|
|
|
{
|
|
|
get { return "B3_YunKen.【信用政策单】客户明细增加客户"; }
|
|
|
}
|
|
|
}
|
|
|
}
|