using System; using System.Collections.Generic; using System.Linq; using System.Text; using FireBirdUtil.SqlUtils; using Forks.JsonRpc.Client; using Forks.JsonRpc.Client.Data; using Utils; using Utils.Datas; using WeighBusiness.BO; using WeighBusiness.Utils; using WeighBusiness.Utils.SqlUtils; namespace WeighBusiness.BL { public static class ProduceOutputBL { 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 bool Insert(ProduceOutput outPut, SqlHelperEx she) { string insertHeadSql = InsertUtil.GetInsertSql(TableNames.产出单, new string[] { "AccountingUnit_ID", "Department_ID", "Employee_ID", "CreateTime", "BatchNumber_ID", "ProductLink", "Routing_ID", "ProductShift_ID", "Domain_ID", "IsSend" }, new string[] { outPut.AccountingUnit_ID.ToString(), outPut.Department_ID.ToString(), outPut.Employee_ID.ToString(), outPut.CreateTime.ToString(), outPut.BatchNumber_ID.ToString(), outPut.ProductLink, outPut.Routing_ID.ToString(), outPut.ProductShift_ID.ToString(), outPut.Domain_ID.ToString(), outPut.IsSend ? "1" : "0" }); if (string.IsNullOrEmpty(insertHeadSql)) throw new ApplicationException("表头数据不允许为空"); bool success; string errorMsg; she.ExecuteNonQuery(insertHeadSql, out success, out errorMsg); if (!success) { she.Rollback(); throw new ApplicationException(errorMsg); } var outPutID = she.GetCurrentID(TableNames.产出单); outPut.ID = outPutID; List insertDetailSqls = InsertDetailsSqls(outPut.Details, outPutID); if (insertDetailSqls.Count == 0) { return true; } foreach (var detailSql in insertDetailSqls) { she.ExecuteNonQuery(detailSql, out success, out errorMsg); if (!success) { she.Rollback(); throw new ApplicationException(errorMsg); } } return success; } private static List InsertDetailsSqls(List details, long produceOutput_ID) { List insertDetailSqls = new List(); if (details == null || details.Count == 0) return insertDetailSqls; string[] columns = new string[] { "ProduceOutput_ID", "Goods_ID", "MainNumber" }; foreach (var d in details) { insertDetailSqls.Add(InsertUtil.GetInsertSql(TableNames.产出单明细, columns, GetValue(d, produceOutput_ID))); } return insertDetailSqls; } private static string[] GetValue(ProduceOutput_Detail detail, long produceOutput_ID) { return new string[]{ produceOutput_ID.ToString(), DataTypeUtil.ToStringNullIfNull(detail.Goods_ID), DataTypeUtil.ToStringNullIfNull(detail.MainNumber), }; } public static ProduceOutput Load(long id) { ProduceOutput result = LocalQueryUtil.GetLocalProduceOutputHead(id); if (result == null) return result; var details = LocalQueryUtil.GetLocalProduceOutputDetails(id); if (details == null || details.Count == 0) return result; foreach (var d in details) { result.Details.Add(d); } return result; } public static List GetNotSendProduceOutputID() { return LocalQueryUtil.GetNotSendProduceOutputID(); } public static decimal? GetBatchGoodsNumber(long batchNumberId, string productLink, long? routingId, long goodsId, long? productShift_ID) { string method = "/MainSystem/B3_HaoYue/Rpcs/B3SaleRpcFun/GetBatchNumberGoodsNum"; return RpcFacade.Call(method, batchNumberId, productLink, routingId, goodsId, productShift_ID); } public static void UpdateIsSendByID(long id) { string updateSql = string.Format("update "+TableNames.产出单+" set IsSend = 1 where ID ={0}", id); bool success = true; using (var she = new SqlHelperEx()) { she.CreateTransaction(); she.ExecuteNonQuery(updateSql, out success); if (!success) { she.Rollback(); } else { she.Commit(); } } } } }