using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using FireBirdUtil.SqlUtils;
|
|
using Forks.JsonRpc.Client;
|
|
using Forks.JsonRpc.Client.Data;
|
|
using WeighBusiness.BO;
|
|
using WeighBusiness.Utils;
|
|
using WeighBusiness.Utils.SqlUtils;
|
|
|
|
namespace WeighBusiness.BL
|
|
{
|
|
public static class DispatchBillDetailBL
|
|
{
|
|
public static bool Insert(DispatchBillDetail detail)
|
|
{
|
|
string insertSql = InsertUtil.GetInsertSql(TableNames.已审核派工明细,
|
|
new string[] { "ProductShift_ID", "Detail_ID", "BatchNumber_ID", "RowVersion" },
|
|
new string[] { detail.ProductShift_ID == null ? "null" : detail.ProductShift_ID.ToString(), detail.Detail_ID.ToString(), detail.BatchNumber_ID == null ? "null" : detail.BatchNumber_ID.ToString(),detail.RowVersion.ToString() });
|
|
return ExcuteSql(insertSql);
|
|
}
|
|
|
|
private static bool ExcuteSql(string sql)
|
|
{
|
|
bool success;
|
|
using (var she = new SqlHelperEx()) {
|
|
she.CreateTransaction();
|
|
she.ExecuteNonQuery(sql, out success);
|
|
if (!success)
|
|
she.Rollback();
|
|
else
|
|
she.Commit();
|
|
}
|
|
return success;
|
|
}
|
|
|
|
public static List<DispatchBillDetail> GetDispatchBillRowVersion()
|
|
{
|
|
var table = SqlHelperEx.DoQuery(string.Format("select Detail_ID,RowVersion from {0}", TableNames.已审核派工明细));
|
|
if (table.Rows.Count == 0)
|
|
return new List<DispatchBillDetail>();
|
|
var list = new List<DispatchBillDetail>();
|
|
foreach (DataRow row in table.Rows) {
|
|
var detail = new DispatchBillDetail();
|
|
detail.Detail_ID = (long)(int.Parse(row[0].ToString()));
|
|
detail.RowVersion = int.Parse(row[1].ToString());
|
|
list.Add(detail);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static void Delete(long ID)
|
|
{
|
|
var sql = SqlUtil.GetDeleteSql(TableNames.已审核派工明细, "where Detail_ID=" + ID.ToString());
|
|
using (var she = new SqlHelperEx()) {
|
|
bool success;
|
|
she.CreateTransaction();
|
|
she.ExecuteNonQuery(sql, out success);
|
|
if (!success)
|
|
she.Rollback();
|
|
else
|
|
she.Commit();
|
|
}
|
|
}
|
|
|
|
public static void Delete()
|
|
{
|
|
var sql = SqlUtil.GetDeleteSql(TableNames.已审核派工明细);
|
|
using (var she = new SqlHelperEx()) {
|
|
bool success;
|
|
she.CreateTransaction();
|
|
she.ExecuteNonQuery(sql, out success);
|
|
if (!success)
|
|
she.Rollback();
|
|
else
|
|
she.Commit();
|
|
}
|
|
}
|
|
|
|
public static void SyncDispatchBillDetail()
|
|
{
|
|
string method2 = "/MainSystem/B3_HaoYue/Rpcs/RpcFun/GetDispatchBillDetailRowVersion";
|
|
var domain_ID = ConfigurationManager.AppSettings["Food_Domain_ID"];
|
|
var accountingUnit_ID = ConfigurationManager.AppSettings["Food_AccountingUnit_ID"];
|
|
if (domain_ID != null && !string.IsNullOrEmpty(domain_ID.ToString()) && accountingUnit_ID != null && !string.IsNullOrEmpty(accountingUnit_ID.ToString())) {
|
|
|
|
var dispatchBillVersions = RpcFacade.Call<List<RpcObject>>(method2, long.Parse(domain_ID.ToString()), long.Parse(accountingUnit_ID.ToString()));
|
|
var oldDispatchBillRowVersions = DispatchBillDetailBL.GetDispatchBillRowVersion();
|
|
|
|
var needInsertDetailID = new List<long?>();
|
|
var needDeleteAndInsertDetailID = new List<long>();
|
|
var needDeleteDetailID = new List<long>();
|
|
if (dispatchBillVersions.Count > 0) {
|
|
if (oldDispatchBillRowVersions == null || oldDispatchBillRowVersions.Count() <= 0) {
|
|
dispatchBillVersions.ForEach(x => needInsertDetailID.Add(x.Get<long>("Detail_ID")));
|
|
} else {
|
|
foreach (var disRowVersion in dispatchBillVersions) {
|
|
var detailID = disRowVersion.Get<long>("Detail_ID");
|
|
var oldDis = oldDispatchBillRowVersions.Where(x => x.Detail_ID == detailID);
|
|
if (oldDis != null && oldDis.Count() > 0 && oldDis.FirstOrDefault().RowVersion != disRowVersion.Get<int>("RowVersion")) {
|
|
needDeleteAndInsertDetailID.Add(detailID);
|
|
} else if (oldDis == null || oldDis.Count() <= 0) {
|
|
needInsertDetailID.Add(detailID);
|
|
}
|
|
}
|
|
|
|
foreach (var oldVersion in oldDispatchBillRowVersions) {
|
|
if (!dispatchBillVersions.Any(x => x.Get<long>("Detail_ID") == oldVersion.Detail_ID)) {
|
|
DispatchBillDetailBL.Delete(oldVersion.Detail_ID);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
DispatchBillDetailBL.Delete();
|
|
}
|
|
|
|
if (needDeleteAndInsertDetailID.Count() > 0) {
|
|
foreach (var detailID in needDeleteAndInsertDetailID) {
|
|
DispatchBillDetailBL.Delete(detailID);
|
|
needInsertDetailID.Add(detailID);
|
|
}
|
|
}
|
|
|
|
|
|
if (needInsertDetailID.Count() > 0) {
|
|
string method = "/MainSystem/B3_HaoYue/Rpcs/RpcFun/GetDispatchBillDetails";
|
|
var dispatchBillDetails = RpcFacade.Call<List<RpcObject>>(method, needInsertDetailID.ToArray());
|
|
if (dispatchBillDetails.Count() > 0) {
|
|
foreach (var batch in dispatchBillDetails) {
|
|
var pBatch = new DispatchBillDetail();
|
|
pBatch.ProductShift_ID = batch.Get<long?>("ProductShift_ID");
|
|
pBatch.Detail_ID = batch.Get<long>("Detail_ID");
|
|
pBatch.BatchNumber_ID = batch.Get<long?>("BatchNumber_ID");
|
|
pBatch.RowVersion = batch.Get<int>("RowVersion");
|
|
DispatchBillDetailBL.Insert(pBatch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|