using CK.SCP.Models; using CK.SCP.Models.Enums; using CK.SCP.Models.ExchangeCenterTables; using CK.SCP.Models.AppBoxEntity; using CK.SCP.Models.ScpEntity; using CK.SCP.Models.ScpEntity.ExcelExportEnttity; using CK.SCP.Utils; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data.Entity.Migrations; using System.Linq; using System.Text; using System.Threading; using System.Transactions; using System.Data.Entity.Core; using System.Data; using CK.SCP.Controller.WebReference; using CK.SCP.Models.UniApiEntity; using System.Threading.Tasks; //using WebSrvAPITest; namespace CK.SCP.Controller { public class SCP_DC_UNI_CONTROLLER { public SCP_DC_UNI_CONTROLLER() { } /// /// 随机密码 /// /// public static string GenerateComplexPassword() { int length = 12; StringBuilder password = new StringBuilder(length); Random random = new Random(); for (int i = 0; i < length; i++) { int a = random.Next(0, 89); password.Append((char)(a + '!')); } return password.ToString(); } public static ResultObject> Get_TEA_SUBSCRIBE_List(TEA_SUBSCRIBE p_entity) { ResultObject> _ret = new ResultObject>(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { IQueryable q = db.TEA_SUBSCRIBE; if (!string.IsNullOrEmpty(p_entity.TableName)) { q = q.Where(p => p.TableName.Contains(p_entity.TableName)); } if (!string.IsNullOrEmpty(p_entity.Creator)) { q = q.Where(p => p.Creator.Contains(p_entity.Creator)); } if (!string.IsNullOrEmpty(p_entity.Subscriber)) { q = q.Where(p => p.Subscriber.Contains(p_entity.Subscriber)); } if (p_entity.UID != 0) { q = q.Where(p => p.UID == p_entity.UID); } if (!string.IsNullOrEmpty(p_entity.CreateUser)) { q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser)); } if (!string.IsNullOrEmpty(p_entity.Remark)) { q = q.Where(p => p.Remark.Contains(p_entity.Remark)); } if (!string.IsNullOrEmpty(p_entity.UpdateUser)) { q = q.Where(p => p.UpdateUser.Contains(p_entity.UpdateUser)); } if (p_entity.IsChecked != false) { q = q.Where(p => p.IsChecked == p_entity.IsChecked); } if (p_entity.Enable != false) { q = q.Where(p => p.Enable == p_entity.Enable); } _ret.State = ReturnStatus.Succeed; _ret.Result = q.ToList(); } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.ErrorList.Add(e); LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Get_TEA_SUBSCRIBE_List", e.Message); throw e; } return _ret; } public ResultObject Save_TEA_SUBSCRIBE(List p_entitys) { ResultObject _ret = new ResultObject(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { foreach (var itm in p_entitys) { db.TEA_SUBSCRIBE.AddOrUpdate(itm); } if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Save_TEA_SUBSCRIBE", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public ResultObject Del_TEA_SUBSCRIBE(List p_entitys) { ResultObject _ret = new ResultObject(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { foreach (var itm in p_entitys) { db.TEA_SUBSCRIBE.Remove(itm); } if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.ErrorList.Add(e); LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Del_TEA_SUBSCRIBE", e.Message); throw e; } return _ret; } /// /// 获取 /// /// //public static List Get_TEA_TASK_SUB_List(TEA_TASK_SUB p_entity) //{ // List list = new List(); // using (var db = EntitiesFactory.CreateExchangeCenterInstance()) // { // string _sql = "select * from TEA_TASK_SUB where TaskState = '{0}' and Subscriber = '{1}'"; // _sql = string.Format(_sql, (int)p_entity.TaskState, p_entity.Subscriber); // list = db.Database.SqlQuery(_sql).ToList(); // } // return list; //} public static List Get_TEA_TASK_SUB_List(TEA_TASK_SUB p_entity) { //ResultObject> _ret = new ResultObject>(); //try //{ List _ret = new List(); using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { string _sql = "select * from TEA_TASK_SUB with(nolock) where TaskState = '{0}' and Subscriber = '{1}'"; _sql = string.Format(_sql, (int)p_entity.TaskState, p_entity.Subscriber); var q = db.Database.SqlQuery(_sql).OrderBy(p=>p.CreateTime).ToList(); //_ret.State = ReturnStatus.Succeed; _ret = q; } //} //catch (Exception e) //{ // _ret.State = ReturnStatus.Failed; // _ret.ErrorList.Add(e); // LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Get_TEA_TASK_SUB_List", e.Message); // throw e; //} return _ret; } public static ResultObject Update_TEA_TASK_SUB(ExchangeCenterContext db, TEA_TASK_SUB p_task) { ResultObject _ret = new ResultObject(); try { var _task = db.TEA_TASK_SUB.Where(p => p.TaskID == p_task.TaskID && p.TableName == p.TableName && p.Subscriber == "SCP").FirstOrDefault(); if (_task != null) { _task.TaskState = EnumTaskState.Success; _task.DataCount = p_task.DataCount; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Update_TEA_TASK_SUB", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject CREATE_TEA_TASK_SUB(ExchangeCenterContext db, bool p_ismasterslave, TEA_TASK_SUB p_task) { ResultObject _ret = new ResultObject(); try { var _list = db.TEA_SUBSCRIBE.Where(p => p.Creator == "SCP" && p.TableName == p_task.TableName).ToList(); foreach (var itm in _list) { var _task = new TEA_TASK_SUB(); _task.GUID = Guid.NewGuid(); _task.TaskID = p_task.TaskID; _task.TaskState = EnumTaskState.Unread; _task.TableName = p_task.TableName; _task.Domain = p_task.Domain; _task.Site = p_task.Site; _task.DataCount = p_task.DataCount; _task.Creator = itm.Creator; _task.CreateTime = DateTime.Now; _task.CreateUser = itm.CreateUser; _task.UpdateTime = DateTime.Now; _task.UpdateUser = itm.CreateUser; _task.Subscriber = itm.Subscriber; db.TEA_TASK_SUB.Add(_task); } var _task1 = new TEA_TASK(); _task1.GUID = p_task.GUID; _task1.DataCount = _list.Count; _task1.TaskID = p_task.TaskID; _task1.TableName = p_task.TableName; _task1.Domain = p_task.Domain; _task1.Site = p_task.Site; _task1.IsMasterSlave = p_ismasterslave; _task1.Creator = "SCP"; _task1.CreateTime = DateTime.Now; _task1.CreateUser = "SCP"; _task1.UpdateTime = DateTime.Now; _task1.UpdateUser = "SCP"; db.TEA_TASK.Add(_task1); _ret.State = ReturnStatus.Succeed; } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常 { var sb = new StringBuilder(); foreach (var error in dbEx.EntityValidationErrors.ToList()) { error.ValidationErrors.ToList().ForEach(i => { sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage); }); } _ret.State = ReturnStatus.Failed; _ret.ErrorList.Add(dbEx); LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Get_V_TB_ASK_List", sb.ToString()); throw new ScpException(ResultCode.DbEntityValidationException, sb.ToString(), "字段验证失败" + sb.ToString()); } catch (OptimisticConcurrencyException ex)//并发冲突异常 { _ret.State = ReturnStatus.Failed; _ret.ErrorList.Add(ex); LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Get_V_TB_ASK_List", ex.ToString()); throw new ScpException(ResultCode.Exception, "9999", ex.ToString()); } catch (ScpException ex) { _ret.State = ReturnStatus.Failed; _ret.ErrorList.Add(ex); LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_ASK_CONTROLLER), "Get_V_TB_ASK_List", ex.ToString()); if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UpdateException)) { var inner = (UpdateException)ex.InnerException; throw new ScpException(ResultCode.Exception, "0000", ex.ToString()); } else { if (ex.InnerException != null) throw ex.InnerException; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "CREATE_TEA_TASK_SUB", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public ResultObject Del_TEA_TASK_SUB(List p_entitys) { ResultObject _ret = new ResultObject(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { foreach (var itm in p_entitys) { db.TEA_TASK_SUB.Remove(itm); } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.ErrorList.Add(e); LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Del_TEA_TASK_SUB", e.Message); throw e; } return _ret; } public static void ReadService(Action> p_action) { ResultObject result = new ResultObject(); //ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); // ResultObject> result = new ResultObject>(); var _result = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP"}); //List tasklist = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP" }); if (_result.Count() > 0) //if (_result.State == ReturnStatus.Succeed) { foreach (var _task in _result) //foreach (var _task in _result.Result) { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); DataCenterContext dc = EntitiesFactory.CreateDataCenterInstance(); AppBoxContext authdb = EntitiesFactory.CreateAppBoxInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); using (var scope = // 注释内容可去掉dtc //new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions() new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.Serializable, Timeout = new TimeSpan(0, 20, 0) })) { try { switch (_task.TableName) { //case "TED_POD": // result = UpdatePo(db, scpdb, _task); // break; case "TED_RECEIPT_MSTR": if (_task.Creator == "QAD") { result = UpdateRecive(db, scpdb, _task); Update_TEA_TASK_SUB(db, _task); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); EntitiesFactory.SaveDb(dc); scope.Complete(); result.Message = _task.TaskID.ToString(); } else { result = UpdateARRIVE(db, scpdb, _task); Update_TEA_TASK_SUB(db, _task); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); EntitiesFactory.SaveDb(dc); scope.Complete(); result.Message = _task.TaskID.ToString(); } break; case "TED_RETURN_MSTR": result = UpdateReturn(db, scpdb, _task); result.Message = _task.TaskID.ToString(); Update_TEA_TASK_SUB(db, _task); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); EntitiesFactory.SaveDb(dc); scope.Complete(); break; #region 单独读取 供应商和零件 //case "TES_SUPPLIER": // var _supplierlist = db.TES_SUPPLIER.Where(p => p.TaskID == _task.TaskID).ToList(); // result = UpdateSupplier(_supplierlist, scpdb, authdb, _task); // result.Message = _task.TaskID.ToString(); // Update_TEA_TASK_SUB(db, _task); // scpdb.BulkSaveChanges(); // db.BulkSaveChanges(); // //authdb.BulkSaveChanges(); // dc.BulkSaveChanges(); // //EntitiesFactory.SaveDb(scpdb); // //EntitiesFactory.SaveDb(db); // //EntitiesFactory.SaveDb(dc); // //EntitiesFactory.SaveDb(authdb); // //取消自动创建 // //UpdateSupplierExtend(_supplierlist); // scope.Complete(); // break; // 吴哥更改时 把这个注释掉 把获取基础数据的更新零件注释取消 case "TES_PART_MSTR": result = UpdatePart(db, scpdb, _task); result.Message = _task.TaskID.ToString(); Update_TEA_TASK_SUB(db, _task); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); EntitiesFactory.SaveDb(dc); scope.Complete(); break; #endregion case "TED_PPOD_DET": result = UpdatePPod(db, scpdb, _task); result.Message = _task.TaskID.ToString(); Update_TEA_TASK_SUB(db, _task); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); EntitiesFactory.SaveDb(dc); scope.Complete(); break; // 作废asn单 case "TED_SCRAPASN": result = UpApAsn(db, scpdb, _task); result.Message = _task.TaskID.ToString(); Update_TEA_TASK_SUB(db, _task); scpdb.BulkSaveChanges(); db.BulkSaveChanges(); dc.BulkSaveChanges(); scope.Complete(); break; //case "TES_SITE": // result = UpdateFactory(db, scpdb, appscpdb, _task); // break; } // p_action(result); result.State = ReturnStatus.Succeed; result.Result = true; } //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常 //{ // var sb = new StringBuilder(); // foreach (var error in dbEx.EntityValidationErrors.ToList()) // { // error.ValidationErrors.ToList().ForEach(i => // { // sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage); // }); // } // scope.Dispose(); // result.State = ReturnStatus.Failed; // result.ErrorList.Add(dbEx); //} //catch (OptimisticConcurrencyException ex)//并发冲突异常 //{ // scope.Dispose(); // result.State = ReturnStatus.Failed; // result.ErrorList.Add(ex); //} catch (Exception ex) { scope.Dispose(); result.State = ReturnStatus.Failed; result.ErrorList.Add(ex); result.Message = ex.Message; //_task.TaskID.ToString(); if (ex.InnerException != null) { result.Message = ex.InnerException.Message; } // result.MessageList.Add("任务编号:" + _task.TaskID + "错误信息:" + ex.Message); } } p_action(result); } } p_action(result); } /// /// 基础数据 /// /// public static void BaseReadService(Action> p_action) { ResultObject result = new ResultObject(); // 添加不同的地点服务引用 // 重庆服务 //CQExchangeCenterService service = new CQExchangeCenterService(); // 北京服务 ExchangeCenterService service = new ExchangeCenterService(); #region 获取服务的SessionId 可放到方法内 var jsonResult = service.GetSessionId("SCP", "5C2DE907DB859810", ""); var serviceResultEntityList = JsonConvert.DeserializeObject< List>(jsonResult); string SessionId = ""; SessionId = serviceResultEntityList.First().Data; #endregion var _result = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP" }); if (_result.Count() > 0) { foreach (var _task in _result) //foreach (var _task in _result.Result) { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); DataCenterContext dc = EntitiesFactory.CreateDataCenterInstance(); AppBoxContext authdb = EntitiesFactory.CreateAppBoxInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); using (var scope = new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.RepeatableRead, Timeout = new TimeSpan(0, 20, 0) })) { try { switch (_task.TableName) { case "TES_SUPPLIER": var _supplierlist = db.TES_SUPPLIER.Where(p => p.TaskID == _task.TaskID).ToList(); result = UpdateSupplier(_supplierlist, scpdb, authdb, _task); result.Message = _task.TaskID.ToString(); //根据域去判断调用哪个服务更新状态 // 更新北汽task状态 service.UpdateTaskState(SessionId, _task.TaskID.ToString(), 2,0,""); // 更新重庆task状态 //CQExchangeCenterService.UpdateTaskState(SessionId, _task.TaskID.ToString(), 2, 0, ""); //Update_TEA_TASK_SUB(db, _task); scpdb.BulkSaveChanges(); scope.Complete(); break; // 更新零件注释去掉 //case "TES_PART_MSTR": // result = UpdatePart(db, scpdb, _task); // result.Message = _task.TaskID.ToString(); // service.UpdateTaskState(SessionId, _task.TaskID.ToString(), 2, 0, ""); // //Update_TEA_TASK_SUB(db, _task); // EntitiesFactory.SaveDb(scpdb); // scope.Complete(); // break; } result.State = ReturnStatus.Succeed; result.Result = true; } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常 { var sb = new StringBuilder(); foreach (var error in dbEx.EntityValidationErrors.ToList()) { error.ValidationErrors.ToList().ForEach(i => { sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage); }); } scope.Dispose(); result.State = ReturnStatus.Failed; result.ErrorList.Add(dbEx); } catch (OptimisticConcurrencyException ex)//并发冲突异常 { scope.Dispose(); result.State = ReturnStatus.Failed; result.ErrorList.Add(ex); } catch (Exception ex) { scope.Dispose(); result.State = ReturnStatus.Failed; result.ErrorList.Add(ex); result.Message = ex.Message; //_task.TaskID.ToString(); if (ex.InnerException != null) { result.Message = ex.InnerException.Message; } } } p_action(result); } } p_action(result); } public static void WriteService(Action>> p_action) { ResultObject> result = new ResultObject>(); List _msglist = new List(); using (var scope = new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.Serializable, Timeout = new TimeSpan(0, 20, 0) })) { try { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); var _list = scpdb.TS_UNI_API.Where(p => p.State == (int)DataState.Enabled && p.Domain == "ZZBMPT").OrderBy(p => p.UID).ToList(); var _list1 = scpdb.TS_UNI_API.Where(p => p.State == (int)DataState.Enabled && p.Domain == "ZZBMPT" && p.InterfaceType == "Price").OrderBy(p => p.UID).ToList(); var apiii = _list1.Count(); if (apiii > 0) { var ret = UpdateTES_PURCHASE_PRICE(db, scpdb, _list1); } var billNumList = _list.Select(p => p.BillNum).Distinct(); foreach (var itm in billNumList) { var _dataList = _list.Where(p => p.BillNum == itm).ToList(); var _asnList = _dataList.Where(P => P.InterfaceType == UniApiType.Receive.ToString()).ToList(); if (_asnList.Count > 0) { var _taskId = Guid.NewGuid(); _msglist.Add(new LogModel() { LogMessage = string.Format("发现发货单信息{0}条", _asnList.Count), LogTime = DateTime.Now.ToString(), TaskId = _taskId.ToString(), TableName = "TED_ASN_MSTR" }); var ret = UpdateAsn(db, scpdb, _asnList, _taskId); if (ret.State == ReturnStatus.Succeed) { _msglist.Add(ret.Result); } } var _invoiceList = _dataList.Where(p => p.InterfaceType == UniApiType.Invoice.ToString()).ToList(); if (_invoiceList.Count > 0) { var _taskId = Guid.NewGuid(); _msglist.Add(new LogModel() { LogMessage = string.Format("发现发票信息{0}条", _invoiceList.Count), LogTime = DateTime.Now.ToString(), TaskId = _taskId.ToString(), TableName = "TED_INVOICE_MSTR" }); var ret = UpdateInvoice(db, scpdb, _invoiceList, _taskId); if (ret.State == ReturnStatus.Succeed) { _msglist.Add(ret.Result); } } var _poList = _dataList.Where(p => p.InterfaceType == UniApiType.PO.ToString()).ToList(); if (_poList.Count > 0) { var _taskId = Guid.NewGuid(); _msglist.Add(new LogModel() { LogMessage = string.Format("发现订单信息{0}条", _poList.Count), LogTime = DateTime.Now.ToString(), TaskId = _taskId.ToString(), TableName = "TED_PO_MSTR" }); var ret = UpdatePo(db, scpdb, _poList, _taskId); if (ret.State == ReturnStatus.Succeed) { _msglist.Add(ret.Result); } } //var _priceList = _dataList.Where(p => p.InterfaceType == UniApiType.Price.ToString()).ToList(); //if (_priceList.Count > 0) //{ // var _taskId = Guid.NewGuid(); // _msglist.Add(new LogModel() { LogMessage = string.Format("发现价格单信息{0}条", _priceList.Count), LogTime = DateTime.Now.ToString(), TaskId = _taskId.ToString(), TableName = "TES_PURCHASE_PRICE" }); // var ret = UpdatePrice(db, scpdb, _priceList, _taskId); // if (ret.State == ReturnStatus.Succeed) // { // _msglist.Add(ret.Result); // } //} Thread.Sleep(10); } EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); scope.Complete(); result.State = ReturnStatus.Succeed; result.Result = _msglist; } catch (Exception e) { _msglist.Add(new LogModel() { LogMessage = e.Message, LogTime = DateTime.Now.ToString(), TaskId = string.Empty, TableName = "ERROR" }); result.State = ReturnStatus.Failed; result.Result = _msglist; scope.Dispose(); } //finally //{ //} } p_action(result); } public static ResultObject UpdateTES_PURCHASE_PRICE(ExchangeCenterContext db, ScpEntities scpdb, List _priceList) { ResultObject _ret = new ResultObject(); try { List _teslist = new List(); var _api = _priceList.FirstOrDefault(); foreach (var detail in _priceList) { Guid _taskguid = Guid.NewGuid(); TES_PURCHASE_PRICE _entity = new TES_PURCHASE_PRICE(); _entity.GUID = Guid.NewGuid(); _entity.PriceList = detail.BillNum; _entity.Currency = detail.Currency; _entity.PartCode = detail.PartCode; _entity.Um = detail.PoUnit; _entity.Start = detail.CreateTime; _entity.ExpireDate = detail.PutTime; _entity.CreateUser = "scp"; _entity.ProductLine = ""; _entity.AmountType = "P"; _entity.CreateTime = DateTime.Now; _entity.Remark = detail.Extend1; _entity.TaskID = _taskguid; _entity.CommandType = "A"; _entity.DataID = Guid.NewGuid(); _entity.Domain = detail.Domain; _entity.Site = detail.Site; _entity.SupplierCode = detail.VendId; _entity.VendAmount = detail.Price; _entity.Desc = detail.Batch; _entity.Amount = detail.Qty; _teslist.Add(_entity); detail.State = (int)BillState.Finish; var ret = CREATE_TEA_TASK_SUB(db, false, new TEA_TASK_SUB() { DataCount = _teslist.Count, TaskID = _taskguid, TableName = "TES_PURCHASE_PRICE", Site = _entity.Site, Domain = _entity.Domain, CreateTime = _entity.CreateTime, CreateUser = _api.CreateOper, Creator = "SCP", }); } db.TES_PURCHASE_PRICE.AddOrUpdate(_teslist.ToArray()); if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = "数据更新失败!"; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = e.InnerException.Message; } return _ret; } //public static ResultObject UpdateAsnDetail(ExchangeCenterContext db, ScpEntities scpdb,List p_asnDetailList) //{ // ResultObject _ret = new ResultObject(); // try // { // foreach (var itm in p_asnDetailList) // { // } // } // catch (Exception e) // { // _ret.State = ReturnStatus.Failed; // LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsnDetail", e.Message); // _ret.Result = false; // _ret.ErrorList.Add(e); // throw e; // } // return _ret; //} public static List GetASN(string p_asn) { List _ls = new List(); using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { _ls = db.TED_ASN_MSTR.Where(p => p.ASN == p_asn).ToList(); } return _ls; } public static List GetASN_ASN(string p_asn) { List _ls = new List(); using (var db = EntitiesFactory.CreateScpInstance()) { _ls = db.TB_ASN.Where(p => p.AsnBillNum == p_asn && p.State == 3).ToList(); } return _ls; } public static ResultObject UpdateAsn(ExchangeCenterContext db, ScpEntities scpdb, List _asnList, Guid p_taskID/*EnumCommandType p_command*/) { ResultObject _ret = new ResultObject(); try { List _ls = new List(); if (_asnList.FirstOrDefault() != null) { var _api = _asnList.FirstOrDefault(); TED_ASN_MSTR _asn = new TED_ASN_MSTR(); var asn = JsonConvert.DeserializeObject(_api.Extend1); _asn.ASN = _api.BillNum; _asn.CommandType = "A"; _asn.CreateTime = _api.CreateTime; _asn.CreateUser = _api.CreateOper; _asn.KanbanBillNum = asn.AskBillNum; _asn.PurchaseOrder = asn.PoBillNum.Trim(); if (_api.Domain == "CQBMPT") { _asn.Domain = "CQBMPT"; _asn.Site = "CQ01"; } else { _asn.Site = asn.SubSite; _asn.Domain = asn.Site; } _asn.Supplier = asn.VendId.Trim(); _asn.TaskID = p_taskID; _asn.DataID = Guid.NewGuid(); _asn.ShippingDate = asn.ShipTime == null ? DateTime.Now : asn.ShipTime.Value; _asn.PromiseDate = asn.ReceiveTime == null ? DateTime.Now : asn.ReceiveTime.Value; db.TED_ASN_MSTR.Add(_asn); foreach (var detail in _asnList) { TED_ASN_DET _entity = new TED_ASN_DET(); var asnDetail = JsonConvert.DeserializeObject(_api.Extend2); _entity.ASN = detail.BillNum; _entity.PurchaseOrder = asn.PoBillNum.Trim(); _entity.Line = detail.ErpLineNum; _entity.PartCode = detail.PartCode.Trim(); _entity.Lot = detail.Batch; _entity.Qty = detail.Qty; _entity.TaskID = p_taskID; _entity.PackQty = detail.PackQty; _entity.Location = asnDetail.DockCode; _entity.Reference = ""; _entity.SupplierLot = detail.VendBatch; _entity.WareClass = ""; _entity.WareId = ""; _entity.Price = detail.Price; _entity.PoUm = detail.PoUnit; _entity.LocUm = detail.LocUnit; _entity.Conv = detail.UmConv; _entity.PartType = ""; _entity.VendBatch = detail.VendBatch; _entity.ProduceDate = asnDetail.ProduceDate == null ? DateTime.Now : asnDetail.ProduceDate.Value; _entity.DueDate = asnDetail.EndTime == null ? DateTime.Now : asnDetail.EndTime.Value; _entity.CreateUser = detail.CreateOper; _entity.CreateTime = detail.CreateTime; _entity.CommandType = "A"; if (_api.Domain == "CQBMPT") { _entity.Domain = "CQBMPT"; _entity.Site = "CQ01"; } else { _entity.Site = asn.SubSite; _entity.Domain = asn.Site; } _entity.DataID = Guid.NewGuid(); db.TED_ASN_DET.Add(_entity); _ls.Add(_entity); detail.State = (int)BillState.Finish; detail.PutTime = DateTime.Now; } var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() { DataCount = _asnList.Count, TaskID = p_taskID, TableName = "TED_ASN_MSTR", Site = asn.SubSite, Domain = asn.Site, CreateTime = _api.CreateTime, CreateUser = _api.CreateOper, Creator = "SCP", }); } _ret.State = ReturnStatus.Succeed; _ret.Result = new LogModel() { LogMessage = string.Format("成功发布发货单信息{0}条", _asnList.Count), LogTime = DateTime.Now.ToString(), TaskId = p_taskID.ToString(), TableName = "TED_ASN_MSTR" }; } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsn", e.Message); _ret.Result = new LogModel() { LogMessage = "发布发货单信息失败", LogTime = DateTime.Now.ToString(), TaskId = p_taskID.ToString(), TableName = "TED_ASN_MSTR" }; ; _ret.ErrorList.Add(e); throw e; } return _ret; } private static ResultObject UpdatePPod(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity /*UniApiEntities idb, ScpEntities wdb, string seq*/) { ResultObject _ret = new ResultObject(); string _sql = "SELECT a.*\n" + "FROM (SELECT Ppod_Nbr, Ppod_Line, Ppod_Part, Ppod_Desc, Ppod_Type, Pod_Wolot, Ppod_pricum, Ppod_reccum, \n" + " Ppod_qty_ord, Ppod_Qty_Std, Ppod_Due_Date, Ppod_Loc_Um, Ppod_Um, Ppod_Um_Conv, Ppod_Vend, \n" + " Ppod_Buyer, Ppod_Buyer_Phone, Ppod_Prj, Ppod_Plan, GUID , UID, CreateUser, CreateTime, Remark, \n" + " TaskID, CommandType, DataID, Domain, Site, CASE LEN(replace([Ppod_rev], '-', '')) \n" + " WHEN 8 THEN replace([Ppod_rev], '-', '') + '000' WHEN 11 THEN replace([Ppod_rev], '-', '') \n" + " END AS Ppod_rev\n" + " FROM TED_PPOD_DET\n" + " WHERE (TaskID = '{0}')) AS a INNER JOIN\n" + " (SELECT TaskId, Ppod_nbr, Ppod_line, Domain, Ppod_part, Ppod_due_date, Ppod_vend, \n" + " MAX(CASE LEN(replace([Ppod_rev], '-', '')) WHEN 8 THEN replace([Ppod_rev], '-', '') \n" + " + '000' WHEN 11 THEN replace([Ppod_rev], '-', '') END) AS Ppod_rev\n" + " FROM TED_PPOD_DET\n" + " WHERE (TaskId = '{0}')\n" + " GROUP BY TaskId, Ppod_nbr, Ppod_line, Domain, Ppod_part, Ppod_due_date, Ppod_vend) AS b ON \n" + " a.TaskID = b.TaskId AND a.Domain = b.Domain AND a.Ppod_Due_Date = b.Ppod_due_date AND \n" + " a.Ppod_Line = b.Ppod_line AND a.Ppod_Nbr = b.Ppod_nbr AND a.Ppod_Vend = b.Ppod_vend AND \n" + " a.Ppod_Part = b.Ppod_part AND a.Ppod_rev = b.Ppod_rev"; //string _sql = "select * from\n" + //"(SELECT [xxqad_ppod_uid]\n" + //" ,[xxqad_ppod_seq]\n" + //" ,[xxqad_ppod_nbr]\n" + //" ,[xxqad_ppod_line]\n" + //" ,case\n" + //" LEN(replace([xxqad_ppod_rev],'-',''))\n" + //" when 8 then replace([xxqad_ppod_rev],'-','')+'000'\n" + //" when 11 then replace([xxqad_ppod_rev],'-','') end as xxqad_ppod_rev\n" + //" ,[xxqad_ppod_site]\n" + //" ,[xxqad_ppod_domain]\n" + //" ,[xxqad_ppod_part]\n" + //" ,[xxqad_ppod_desc]\n" + //" ,[xxqad_ppod_type]\n" + //" ,[xxqad_ppod_wolot]\n" + //" ,[xxqad_ppod_pricum]\n" + //" ,[xxqad_ppod_reccum]\n" + //" ,[xxqad_ppod_qty_ord]\n" + //" ,[xxqad_ppod_qty_std]\n" + //" ,[xxqad_ppod_due_date]\n" + //" ,[xxqad_ppod_loc_um]\n" + //" ,[xxqad_ppod_um]\n" + //" ,[xxqad_ppod_um_conv]\n" + //" ,[xxqad_ppod_vend]\n" + //" ,[xxqad_ppod_buyer]\n" + //" ,[xxqad_ppod_buyer_phone]\n" + //" ,[xxqad_ppod_status]\n" + //" ,[xxqad_ppod_qadread]\n" + //" ,[xxqad_ppod_wmsread]\n" + //" ,[xxqad_ppod_scmread]\n" + //" ,[xxqad_ppod_mesread]\n" + //" ,[xxqad_ppod_rmks]\n" + //" ,[xxqad_ppod_createdt]\n" + //" ,[xxqad_ppod_createur]\n" + //" ,[xxqad_ppod_updatedt]\n" + //" ,[xxqad_ppod_prj]\n" + //其他地区注释此项 //" ,[xxqad_ppod_plan]\n" + //其他地区注释此项 //" ,[xxqad_ppod_updateur] from xxqad_ppod_det\n" + //" where xxqad_ppod_seq = '{0}' and xxqad_ppod_scmread = '0'\n" + //" ) as a\n" + //"inner join\n" + //"(\n" + //"SELECT\n" + //" xxqad_ppod_seq\n" + //" ,[xxqad_ppod_nbr]\n" + //" ,[xxqad_ppod_line]\n" + //" ,[xxqad_ppod_domain]\n" + //" ,[xxqad_ppod_part]\n" + //" ,[xxqad_ppod_due_date]\n" + //" ,[xxqad_ppod_vend]\n" + //" ,max(\n" + //" case\n" + //" LEN(replace([xxqad_ppod_rev],'-',''))\n" + //" when 8 then replace([xxqad_ppod_rev],'-','')+'000'\n" + //" when 11 then replace([xxqad_ppod_rev],'-','') end\n" + //" ) as xxqad_ppod_rev\n" + //" FROM [xxqad_ppod_det]\n" + //" where xxqad_ppod_seq = '{0}' and xxqad_ppod_scmread = '0'\n" + //" group by\n" + //" xxqad_ppod_seq\n" + //" ,[xxqad_ppod_nbr]\n" + //" ,[xxqad_ppod_line]\n" + //" ,[xxqad_ppod_domain]\n" + //" ,[xxqad_ppod_part]\n" + //" ,[xxqad_ppod_due_date]\n" + //" ,[xxqad_ppod_vend]) as b\n" + //" on\n" + //" a.xxqad_ppod_seq=b.xxqad_ppod_seq\n" + //" and a.xxqad_ppod_domain=b.xxqad_ppod_domain\n" + //" and a.xxqad_ppod_due_date=b.xxqad_ppod_due_date\n" + //" and a.xxqad_ppod_line=b.xxqad_ppod_line\n" + //" and a.xxqad_ppod_nbr=b.xxqad_ppod_nbr\n" + //" and a.xxqad_ppod_vend=b.xxqad_ppod_vend\n" + //" and a.xxqad_ppod_part=b.xxqad_ppod_part\n" + //" and a.xxqad_ppod_rev=b.xxqad_ppod_rev"; _sql = string.Format(_sql, p_entity.TaskID.ToString()); var _ppodList = db.Database.SqlQuery(_sql).ToList(); List _list = new List(); try { foreach (var itm in _ppodList) { var _plan = scpdb.TB_PO_PLAN.Where(p => p.PoBillNum == itm.Ppod_Nbr && p.PartCode == itm.Ppod_Part && p.EndTime == itm.Ppod_Due_Date && p.Domain == itm.Domain && p.Site == itm.Site && p.Version == itm.Ppod_Rev).FirstOrDefault(); if (_plan != null) { _plan.PlanQty = itm.Ppod_qty_ord; continue; } _plan = new TB_PO_PLAN(); _plan.PoBillNum = itm.Ppod_Nbr; _plan.VendId = itm.Ppod_Vend; _plan.IsDeleted = false;//操作员 _plan.CreateTime = DateTime.Parse(DateTime.Now.ToShortDateString()); _plan.CreateUser = itm.CreateUser; _plan.Domain = itm.Domain; _plan.Site = itm.Site; _plan.PlanType = (int)PoPlanType.New; _plan.ErpBillNum = itm.Ppod_Nbr; _plan.BeginTime = itm.CreateTime == null ? DateTime.Now : itm.CreateTime; _plan.EndTime = itm.Ppod_Due_Date; _plan.Buyer = itm.Ppod_Buyer; _plan.BuyerPhone = itm.Ppod_Buyer_Phone; _plan.PoLine = itm.Ppod_Line; _plan.PoUnit = itm.Ppod_Um; _plan.PartCode = itm.Ppod_Part; _plan.EndTime = itm.Ppod_Due_Date; _plan.PlanQty = itm.Ppod_qty_ord; _plan.IsDeleted = false; _plan.LocUnit = itm.Ppod_Um; _plan.UnConv = itm.Ppod_Um_Conv; _plan.State = (int)AskState.New; _plan.GUID = Guid.NewGuid(); _plan.Version = itm.Ppod_Rev; _plan.Extend1 = itm.Ppod_Prj; _plan.Extend2 = itm.Ppod_Plan; //_plan.Extend3 = itm.LastRece; //_plan.PackQty = itm.OutstandQty; _list.Add(_plan); } List _ls = new List(); foreach (var itm in _list) { var _count = _ls.Count(p => p.PoBillNum == itm.PoBillNum && p.PartCode == itm.PartCode && p.EndTime == itm.EndTime && p.Domain == p.Domain && p.Site == itm.Site && p.Version == itm.Version); if (_count == 0) { _ls.Add(itm); } } scpdb.TB_PO_PLAN.AddOrUpdate(_ls.ToArray()); _ret.MessageList.Add(string.Format("更新计划数据{0}任务编号{1}", _ppodList.Count.ToString(), p_entity.TaskID)); Console.WriteLine($"更新看板数据:{_ppodList.Count}"); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateSupplierPart", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject UpdatePo(ExchangeCenterContext db, ScpEntities scpdb, List _poList, Guid p_taskID/*EnumCommandType p_command*/) { ResultObject _ret = new ResultObject(); try { List _ls = new List(); if (_poList.FirstOrDefault() != null) { var _api = _poList.FirstOrDefault(); TED_PO_MSTR _po = new TED_PO_MSTR(); _po.GUID = Guid.NewGuid(); _po.PurchaseOrder = _api.BillNum; _po.ModeType = _api.SubBillType.ToString(); _po.Supplier = _api.VendId; _po.Contact = _api.Buyer; _po.ShipTo = _api.Site; _po.OrderDate = _api.CreateTime; _po.DueDate = _api.PutTime; _po.Confirm = true; _po.Buyer = _api.Buyer; if (_api.SubBillType == 1) { _po.ScheduledOrder = true; } else { _po.ScheduledOrder = false; } _po.BuyerPhone = _api.BuyerPhone; _po.Status = (int)PoState.Open; _po.Taxclass = _api.Extend1; _po.StartDate = DateTime.Now; _po.EndDate = _api.ValidDate; _po.CreateUser = _api.VendBatch; _po.CreateTime = DateTime.Now; _po.Domain = _api.Domain; _po.Site = _api.Site; _po.Remark = _api.Extend2; _po.CommandType = "A"; _po.TaskID = p_taskID; _po.DataID = Guid.NewGuid(); if (_api.Site =="CD01") { _po.Pricelist = _api.VendId.ToUpper().Trim() + _api.Site.Trim().Substring(0, 1) + _api.Site.Substring(3, 1).Trim(); } else { _po.Pricelist = _api.VendId.ToUpper().Trim() + _api.Site.Trim().Substring(1, 1) + _api.Site.Substring(3, 1).Trim(); } db.TED_PO_MSTR.Add(_po); foreach (var detail in _poList) { TED_PO_DET _entity = new TED_PO_DET(); _entity.GUID = Guid.NewGuid(); _entity.PurchaseOrder = detail.BillNum; _entity.Line = detail.ErpLineNum; _entity.PartCode = detail.PartCode; _entity.Qty = detail.Qty; _entity.QtyOpen = 0; _entity.PackQty = 1; _entity.Currency = "CNY"; _entity.Price = detail.Price; _entity.Pricelist = _po.Pricelist; _entity.PoUm = detail.PoUnit; _entity.LocUm = detail.LocUnit; _entity.Conv = 1; _entity.Status = 1; _entity.Operation = 0; _entity.Firmdays = 7; _entity.Scheduledays = 7; _entity.Schedulemonth = 1; _entity.Transportdays = 0; _entity.StartDate = DateTime.Now; _entity.EndDate = detail.ValidDate; _entity.CreateUser = detail.VendBatch; _entity.CreateTime = DateTime.Now; _entity.DataID = Guid.NewGuid(); _entity.TaskID = _po.TaskID; _entity.CommandType = "A"; _entity.Domain = _po.Domain; _entity.Site = _po.Site; _entity.Scheduleweeks = 2; _entity.DueDate = detail.PutTime; _entity.PoType = detail.ModType; db.TED_POD_DET.Add(_entity); _ls.Add(_entity); detail.State = (int)BillState.Finish; } var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() { DataCount = _poList.Count, TaskID = p_taskID, TableName = "TED_PO_MSTR", Site = _po.Site, Domain = _po.Domain, CreateTime = _api.CreateTime, CreateUser = _api.CreateOper, Creator = "SCP", }); } _ret.State = ReturnStatus.Succeed; _ret.Result = new LogModel() { LogMessage = string.Format("成功发布采购订单信息{0}条", _poList.Count), LogTime = DateTime.Now.ToString(), TaskId = p_taskID.ToString(), TableName = "TED_PO_DET" }; } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsn", e.Message); _ret.Result = new LogModel() { LogMessage = "发布采购订单信息失败", LogTime = DateTime.Now.ToString(), TaskId = p_taskID.ToString(), TableName = "TED_PO_DET" }; ; _ret.ErrorList.Add(e); throw e; } return _ret; } //public static ResultObject UpdatePrice(ExchangeCenterContext db, ScpEntities scpdb, List _PriceList, Guid p_taskID/*EnumCommandType p_command*/) //{ // ResultObject _ret = new ResultObject(); // try // { // List _ls = new List(); // TES_PURCHASE_PRICE _entity = new TES_PURCHASE_PRICE(); // var _api = _PriceList.FirstOrDefault(); // foreach (var detail in _PriceList) // { // _entity.GUID= Guid.NewGuid(); // _entity.PriceList = detail.BillNum; // _entity.Currency = detail.Currency; // _entity.PartCode = detail.PartCode; // _entity.Um = detail.PoUnit; // _entity.Start = detail.CreateTime; // _entity.ExpireDate = detail.PutTime; // _entity.CreateUser = "scp"; // _entity.ProductLine = ""; // _entity.AmountType = "P"; // _entity.CreateTime = DateTime.Now; // _entity.Remark = detail.Extend1; // _entity.TaskID = p_taskID; // _entity.CommandType = "A"; // _entity.DataID = Guid.NewGuid(); // _entity.Domain = detail.Domain; // _entity.Site = detail.Site; // _entity.SupplierCode = detail.VendId; // _entity.VendAmount = detail.Price; // _entity.Desc = detail.Batch; // _entity.Amount = detail.Qty; // db.TES_PURCHASE_PRICE.Add(_entity); // _ls.Add(_entity); // detail.State = (int)BillState.Finish; // } // var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() // { // DataCount = _PriceList.Count, // TaskID = p_taskID, // TableName = "TES_PURCHASE_PRICE", // Site = _entity.Site, // Domain = _entity.Domain, // CreateTime = _entity.CreateTime, // CreateUser = _api.CreateOper, // Creator = "SCP", // }); // _ret.State = ReturnStatus.Succeed; // _ret.Result = new LogModel() { LogMessage = string.Format("成功发布价格单信息{0}条", _PriceList.Count), LogTime = DateTime.Now.ToString(), TaskId = p_taskID.ToString(), TableName = "TES_PURCHASE_PRICE" }; // } // catch (Exception e) // { // _ret.State = ReturnStatus.Failed; // LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsn", e.Message); // _ret.Result = new LogModel() { LogMessage = "发布价格单信息失败", LogTime = DateTime.Now.ToString(), TaskId = p_taskID.ToString(), TableName = "TES_PURCHASE_PRICE" }; ; // _ret.ErrorList.Add(e); // throw e; // } // return _ret; //} public static ResultObject UpdateReciveDetail(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var scpRcveDetailList = new List(); var _reciveDetailList = db.TED_RECEIPT_DET.Where(p => p.TaskID == p_entity.TaskID).ToList(); foreach (var detail in _reciveDetailList) { var poLineNum = Convert.ToInt32(detail.Line); var scpRcvDetail = scpdb.TB_RECEIVE_DETAIL.SingleOrDefault( p => p.RecvBillNum == detail.ReceiveNbr && p.PoBillNum == detail.PurchaseOrder && p.PoLine == detail.Line && p.PartCode == detail.PartCode && p.Batch == detail.Lot ); if (scpRcvDetail == null) { //int istate = 0; //if (isRerviceOk == false) //{ // istate = (int)FormState.关闭; //} //else //{ // istate = (int)FormState.开放; //} scpRcvDetail = new TB_RECEIVE_DETAIL(); scpRcvDetail.RecvBillNum = detail.ReceiveNbr.Trim();//收货单号 scpRcvDetail.PoBillNum = detail.PurchaseOrder.Trim();//采购单 scpRcvDetail.PoLine = detail.Line;//订单行 scpRcvDetail.PartCode = detail.PartCode.ToUpper().Trim();//零件号 scpRcvDetail.Batch = detail.PartCode;//批次 scpRcvDetail.VendBatch = detail.SupplierLot;//供应商批号 scpRcvDetail.PoUnit = detail.Um;//采购单位 scpRcvDetail.LocUnit = detail.logisticsUm;//物流单位 scpRcvDetail.Qty = detail.ReceiveQuantity;//收货总量 //DockCode = ?,//收货口 scpRcvDetail.State = 0;// (int)FormState.关闭, scpRcvDetail.Remark = detail.Remark; scpRcvDetail.CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime;//创建日期 scpRcvDetail.CreateUser = detail.CreateUser;//创建用户 scpRcvDetail.IsDeleted = false; scpRcvDetail.GUID = detail.TaskID; scpRcvDetail.BillType = 0; scpRcvDetail.SubSite = detail.Shipto; scpRcvDetail.Site = detail.Domain; scpRcvDetail.Currency = detail.Currency; scpRcvDetail.Currencyamount = detail.Currencyamount; scpRcvDetail.ExchangeRateType = detail.Exchangeratetype; scpRcvDetail.WorkOrderID = detail.WorkOrderID; scpRcvDetail.POSite = detail.Posite; scpRcvDetail.POCost = detail.Purchasecost; scpRcvDetail.POStandardCost = detail.Purchasestandardcost; scpRcvDetail.ReceiptType = detail.receipttype; scpRcvDetail.ReturnReasonCode = detail.Returnreason; scpRcvDetail.Requestedby = detail.Requestby; scpRcvDetail.TaxEnvironment = detail.Taxenvironment; scpRcvDetail.TaxIn = detail.taxin; scpRcvDetail.TaxUsage = detail.Taxusage; scpRcvDetail.TaxClass = detail.Taxclass; scpRcvDetail.PurchaseType = detail.Purchasetype; scpRcvDetail.UMConversion = detail.Umconversion; scpRcveDetailList.Add(scpRcvDetail); } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsnDetail", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject UpdateRecive(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _reciveList = db.TED_RECEIPT_MSTR.Where(p => p.TaskID == p_entity.TaskID).ToList(); var _scpPoDetailList = new List(); foreach (var detail in _reciveList) { var scpRcv = scpdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum != null && p.RecvBillNum == detail.ReceiveNbr && p.Site == detail.Domain && p.SubSite == detail.Site); var scpRcvList = new List(); bool isRerviceOk = false; if (!string.IsNullOrEmpty(detail.Site) && !string.IsNullOrEmpty(detail.Domain)) { string _domain = detail.Domain; string _site = detail.Site; List configs = scpdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == _domain).ToList(); foreach (TA_FACTORY_CONFIG cfg in configs) { TA_CONFIG tacfg = scpdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault(); if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核") { if ("允许" == tacfg.ParamValue) { isRerviceOk = true; } } } } if (scpRcv == null) { int istate = 0; if (isRerviceOk == false) { istate = (int)FormState.关闭; } else { istate = (int)FormState.开放; } scpRcv = new TB_RECEIVE { RecvBillNum = detail.ReceiveNbr,//收货单号 State = istate, Remark = "", CreateTime = detail.ReceiptDate == null ? DateTime.Now : (DateTime)detail.ReceiptDate,//创建日期 CreateUser = detail.CreateUser,//创建用户 IsDeleted = false, GUID = detail.TaskID, BillType = 0 }; scpRcvList.Add(scpRcv); } scpRcv.PoBillNum = detail.PurchaseOrder.Trim();//采购单 scpRcv.AsnBillNum = detail.ASN;//发货单号 scpRcv.Site = detail.Domain;//地点 scpRcv.VendId = detail.Supplier.Trim();//供货商名称 scpRcv.ShipTime = detail.ReceiptDate;//收货日期 scpRcv.SubSite = detail.Site; scpdb.TB_RECEIVE.AddOrUpdate(scpRcvList.ToArray()); } var scpRcveDetailList = new List(); var _reciveDetailList = db.TED_RECEIPT_DET.Where(p => p.TaskID == p_entity.TaskID).ToList(); foreach (var detail in _reciveDetailList) { var poLineNum = Convert.ToInt32(detail.Line); var scpRcvDetail = scpdb.TB_RECEIVE_DETAIL.FirstOrDefault( p => p.RecvBillNum == detail.ReceiveNbr && p.PoBillNum == detail.PurchaseOrder && p.PoLine == detail.Line && p.PartCode == detail.PartCode && p.SubSite == detail.Site ); if (scpRcvDetail == null) { //int istate = 0; //if (isRerviceOk == false) //{ // istate = (int)FormState.关闭; //} //else //{ // istate = (int)FormState.开放; //} scpRcvDetail = new TB_RECEIVE_DETAIL(); scpRcvDetail.RecvBillNum = detail.ReceiveNbr;//收货单号 scpRcvDetail.PoBillNum = detail.PurchaseOrder.Trim();//采购单 scpRcvDetail.PoLine = detail.Line;//订单行 scpRcvDetail.PartCode = detail.PartCode.Trim();//零件号 scpRcvDetail.Batch = detail.Lot;//批次 scpRcvDetail.VendBatch = detail.SupplierLot;//供应商批号 scpRcvDetail.PoUnit = detail.Um;//采购单位 scpRcvDetail.LocUnit = detail.logisticsUm;//物流单位 //收货总量 //DockCode = ?,//收货口 scpRcvDetail.State = 1;// (int)FormState.关闭, scpRcvDetail.Remark = detail.Remark; scpRcvDetail.CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime;//创建日期 scpRcvDetail.CreateUser = detail.CreateUser;//创建用户 scpRcvDetail.IsDeleted = false; scpRcvDetail.GUID = detail.TaskID; scpRcvDetail.BillType = 0; scpRcvDetail.SubSite = detail.Shipto; scpRcvDetail.Site = detail.Domain; scpRcvDetail.Currency = detail.Currency; scpRcvDetail.Currencyamount = detail.Currencyamount; scpRcvDetail.ExchangeRate = detail.Exchangerate == null ? "1" : detail.Exchangerate.Value.ToString(); scpRcvDetail.ExchangeRate1 = detail.Exchangerate2 == null ? "1" : detail.Exchangerate2.Value.ToString(); scpRcvDetail.ExchangeRateType = detail.Exchangeratetype; scpRcvDetail.WorkOrderID = detail.WorkOrderID; scpRcvDetail.POSite = detail.Posite; scpRcvDetail.POCost = detail.Purchasecost; scpRcvDetail.POStandardCost = detail.Purchasestandardcost; scpRcvDetail.ReceiptType = detail.receipttype; scpRcvDetail.ReturnReasonCode = detail.Returnreason; scpRcvDetail.Requestedby = detail.Requestby; scpRcvDetail.TaxEnvironment = detail.Taxenvironment; scpRcvDetail.TaxIn = detail.taxin; scpRcvDetail.TaxUsage = detail.Taxusage; scpRcvDetail.TaxClass = detail.Taxclass; scpRcvDetail.PurchaseType = detail.Purchasetype; scpRcvDetail.UMConversion = detail.Umconversion; scpRcveDetailList.Add(scpRcvDetail); } scpRcvDetail.Qty = detail.ReceiveQuantity; } // var _str=JsonHelper.GetJson>(scpRcveDetailList); scpdb.TB_RECEIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray()); _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("QAD收货单更新{0}任务编号{1}", _reciveDetailList.Count().ToString(), p_entity.TaskID)); _ret.Result = true; // var retDetail=UpdateReciveDetail(db, scpdb, p_entity); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateRecive", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); _ret.MessageList.Add(string.Format("QAD收货单更新失败任务编号{0}", p_entity.TaskID)); throw e; } return _ret; } public static ResultObject UpdateARRIVE(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _reciveList = db.TED_RECEIPT_MSTR.Where(p => p.TaskID == p_entity.TaskID && !string.IsNullOrEmpty(p.ReceiveNbr)).ToList(); var _scpPoDetailList = new List(); foreach (var detail in _reciveList) { var scpRcv = scpdb.TB_ARRIVE.SingleOrDefault(p => p.ArrvBillNum != null && p.ArrvBillNum == detail.ReceiveNbr && p.Site == detail.Domain && p.SubSite == detail.Site); var scpRcvList = new List(); bool isRerviceOk = false; if (!string.IsNullOrEmpty(detail.Site) && !string.IsNullOrEmpty(detail.Domain)) { string _domain = detail.Domain; string _site = detail.Site; List configs = scpdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == _domain).ToList(); foreach (TA_FACTORY_CONFIG cfg in configs) { TA_CONFIG tacfg = scpdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault(); if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核") { if ("允许" == tacfg.ParamValue) { isRerviceOk = true; } } } } if (scpRcv == null) { int istate = 0; if (isRerviceOk == false) { istate = (int)FormState.关闭; } else { istate = (int)FormState.开放; } scpRcv = new TB_ARRIVE { ArrvBillNum = detail.ReceiveNbr,//收货单号 State = istate, Remark = "", CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime,//创建日期 CreateUser = detail.CreateUser,//创建用户 IsDeleted = false, GUID = detail.TaskID, BillType = 0 }; scpRcvList.Add(scpRcv); } scpRcv.PoBillNum = detail.PurchaseOrder;//采购单 scpRcv.AsnBillNum = detail.ASN;//发货单号 if (!string.IsNullOrEmpty(detail.ASN)) { var _entity = scpdb.TB_ASN.Where(p => p.AsnBillNum == detail.ASN).FirstOrDefault(); if (_entity != null) { _entity.State = 4; } } scpRcv.Site = detail.Domain;//地点 scpRcv.VendId = detail.Supplier.Trim();//供货商名称 scpRcv.ShipTime = detail.ReceiptDate;//收货日期 scpRcv.SubSite = detail.Site; scpdb.TB_ARRIVE.AddOrUpdate(scpRcvList.ToArray()); } var scpRcveDetailList = new List(); var _reciveDetailList = db.TED_RECEIPT_DET.Where(p => p.TaskID == p_entity.TaskID && !string.IsNullOrEmpty(p.ReceiveNbr)).ToList(); foreach (var detail in _reciveDetailList) { var poLineNum = Convert.ToInt32(detail.Line); var scpRcvDetail = scpdb.TB_ARRIVE_DETAIL.SingleOrDefault( p => p.ArrvBillNum == detail.ReceiveNbr && p.PoBillNum == detail.PurchaseOrder && p.PoLine == detail.Line && p.PartCode == detail.PartCode && p.Batch == detail.Lot && p.SubSite == detail.Site ); if (scpRcvDetail == null) { //int istate = 0; //if (isRerviceOk == false) //{ // istate = (int)FormState.关闭; //} //else //{ // istate = (int)FormState.开放; //} scpRcvDetail = new TB_ARRIVE_DETAIL(); scpRcvDetail.ArrvBillNum = detail.ReceiveNbr;//收货单号 scpRcvDetail.PoBillNum = detail.PurchaseOrder.Trim();//采购单 scpRcvDetail.PoLine = detail.Line;//订单行 scpRcvDetail.PartCode = detail.PartCode;//零件号 scpRcvDetail.Batch = detail.Lot;//批次 scpRcvDetail.VendBatch = detail.SupplierLot;//供应商批号 scpRcvDetail.PoUnit = detail.Um;//采购单位 scpRcvDetail.LocUnit = detail.logisticsUm;//物流单位 scpRcvDetail.Qty = detail.ReceiveQuantity;//收货总量 //DockCode = ?,//收货口 scpRcvDetail.State = 1;// (int)FormState.关闭, scpRcvDetail.Remark = detail.Remark; scpRcvDetail.CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime;//创建日期 scpRcvDetail.CreateUser = detail.CreateUser;//创建用户 scpRcvDetail.IsDeleted = false; scpRcvDetail.GUID = detail.TaskID; scpRcvDetail.BillType = 0; scpRcvDetail.SubSite = detail.Site; scpRcvDetail.Site = detail.Domain; scpRcveDetailList.Add(scpRcvDetail); } } var _str = JsonHelper.GetJson>(scpRcveDetailList); scpdb.TB_ARRIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray()); _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("到货单更新{0}任务编号{1}", _reciveDetailList.Count().ToString(), p_entity.TaskID)); _ret.Result = true; // var retDetail=UpdateReciveDetail(db, scpdb, p_entity); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateRecive", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); _ret.MessageList.Add(string.Format("到货单更新失败任务编号{0}", p_entity.TaskID)); throw e; } return _ret; } public static ResultObject UpdateInvoiceDetail(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsnDetail", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject UpdateInvoice(ExchangeCenterContext db, ScpEntities scpdb, List p_invoiceList, Guid p_taskId) { ResultObject _ret = new ResultObject(); List _mstList = new List(); List _detList = new List(); // List _addList = new List(); try { if (p_invoiceList.FirstOrDefault() != null) { var _api = p_invoiceList.FirstOrDefault(); #region 发票主表 TED_INVOICE_MSTR _invMast = new TED_INVOICE_MSTR(); var _vinvoice = JsonConvert.DeserializeObject(_api.Extend1); _invMast.GUID = Guid.NewGuid(); _invMast.Status = "0"; _invMast.Invoice_ID = 1000; _invMast.InvoiceReference = _vinvoice.InvoiceNum; _invMast.CreateInvoice = true; _invMast.Supplier = _vinvoice.VendId.Trim(); _invMast.SupplierName = _vinvoice.VendName.Trim(); _invMast.Rowid = Guid.NewGuid().ToString(); _invMast.InvoiceIsTaxable = true; _invMast.InvoiceHoldAmountTC = _vinvoice.Amount.Value; _invMast.InvoiceVoucher = 0; _invMast.InvoiceRegistrationNbr = 1000; _invMast.PostingDate = _vinvoice.PostingDate == null ? DateTime.Now : _vinvoice.PostingDate.Value; _invMast.Currency = "CNY"; _invMast.InvoiceDate = _vinvoice.UpdateTime == null ? DateTime.Now : _vinvoice.UpdateTime.Value; _invMast.GUID = Guid.NewGuid(); _invMast.Invoice_ID = 1000; _invMast.CreateInvoice = true; _invMast.PaymentCondCode = "90"; _invMast.InvoiceDueDate = _invMast.InvoiceDate.AddDays(int.Parse(_invMast.PaymentCondCode)); _invMast.InvoiceIsStatusFinal = true; _invMast.InvoicePostingYear = _vinvoice.PostingDate == null ? DateTime.Now.Year : _vinvoice.PostingDate.Value.Year; _invMast.APMatchingIsStatusFinal = true; _invMast.InvoiceRemark = _vinvoice.InvcBillNum;//发票编号 _invMast.CreateWithAmountIsTax = true; _invMast.InvoiceAmountTC = _vinvoice.TaxAmount == null ? 0 : _vinvoice.TaxAmount.Value; _invMast.InvoiceIsTaxable = true; _invMast.CreateUser = _vinvoice.CreateUser; _invMast.CreateTime = DateTime.Now; _invMast.Remark = _vinvoice.Remark; _invMast.TaskID = p_taskId; _invMast.CommandType = "A"; _invMast.DataID = Guid.NewGuid(); _invMast.Domain = _vinvoice.Site; _invMast.Site = _vinvoice.SubSite; _invMast.CInvoiceCostCenterCode = _vinvoice.CInvoiceCostCenterCode; _invMast.CInvoiceReference = _vinvoice.InvoiceNum; _invMast.CInvoiceDescription = _vinvoice.CInvoiceDescription; _invMast.CInvoiceType = _vinvoice.CInvoiceType; _invMast.CInvoiceDivisionCode = _vinvoice.CInvoiceDivisionCode; _mstList.Add(_invMast); #endregion #region 发票差异 if ((_vinvoice.ContractPrice != null && _vinvoice.ContractPrice.Value != 0)) { _invMast.InvoiceHoldAmountTC = _vinvoice.Amount.Value + _vinvoice.ContractPrice.Value; //_add.VatDebitCC = _vinvoice.ContractPrice.Value;//折扣 //_add.VatDebitLC = _vinvoice.BlancePrice.Value;//税额调整 //_add.VatDebitTC = _vinvoice.ContractPrice.Value; // _addList.Add(_add); } if ((_vinvoice.BlancePrice != null && _vinvoice.BlancePrice.Value != 0)) { _invMast.InvoiceAmountTC = (_vinvoice.TaxAmount == null ? 0 : _vinvoice.TaxAmount.Value) + _vinvoice.BlancePrice.Value; } #endregion #region 发票明细 foreach (var detail in p_invoiceList) { TED_INVOICE_DET _entity = new TED_INVOICE_DET(); var _invDetail = JsonConvert.DeserializeObject(detail.Extend2); _entity.CommandType = "A"; _entity.GUID = _invDetail.GUID; _entity.Status = _invMast.Status; _entity.PurchaseOrder = _invDetail.PoBillNum; _entity.Line = _invDetail.PoLineNum; _entity.ReceiveNbr = _invDetail.RecvBillNum; _entity.MatchQuantity = _invDetail.Qty; _entity.MatchPrice = _invDetail.Price + ((_invDetail.BlancePrice == null) ? 0 : _invDetail.BlancePrice.Value); _entity.IsPvodFinished = true; _entity.UsageDate = DateTime.Now; _entity.IsRecalculateTaxes = true; _entity.ParentRowid = _invMast.Rowid; _entity.CreateUser = _invDetail.CreateUser; _entity.CreateTime = _invDetail.CreateTime; _entity.Remark = _invDetail.Remark; _entity.TaskID = p_taskId; _entity.CommandType = "A"; _entity.DataID = Guid.NewGuid(); _entity.Domain = _invDetail.Site.Trim(); _entity.Site = _invDetail.SubSite.Trim(); _entity.PartCode = _invDetail.PartCode; _entity.Tax = _invDetail.Tax.ToString(); _detList.Add(_entity); detail.State = (int)BillState.Finish; detail.PutTime = DateTime.Now; } #endregion var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() { DataCount = p_invoiceList.Count, TaskID = p_taskId, TableName = "TED_INVOICE_MSTR", Site = _vinvoice.SubSite.Trim(), Domain = _vinvoice.Site, CreateTime = _api.CreateTime, CreateUser = _api.CreateOper, Creator = "SCP", }); } db.TED_INVOICE_MSTR.AddOrUpdate(_mstList.ToArray()); db.TED_INVOICE_DET.AddOrUpdate(_detList.ToArray()); //db.TED_INVOICE_ADD.AddOrUpdate(_addList.ToArray()); var str = JsonHelper.GetJson(_mstList.ToArray()); var str1 = JsonHelper.GetJson(_detList.ToArray()); _ret.State = ReturnStatus.Succeed; _ret.Result = new LogModel() { LogMessage = string.Format("成功发布发票信息{0}条", _detList.Count), LogTime = DateTime.Now.ToString(), TaskId = p_taskId.ToString(), TableName = "TED_INVOICE_MSTR" }; } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateInvoice", e.Message); _ret.Result = new LogModel() { LogMessage = "发布发票信息失败", LogTime = DateTime.Now.ToString(), TaskId = p_taskId.ToString(), TableName = "TED_INVOICE_MSTR" }; ; _ret.ErrorList.Add(e); throw e; } return _ret; } //public static ResultObject UpdateReturnDetail(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) //{ // ResultObject _ret = new ResultObject(); // try // { // var scpRcveDetailList = new List(); // var _reciveDetailList = db.TED_RETURN_DET.Where(p => p.TaskID == p_entity.TaskID).ToList(); // foreach (var detail in _reciveDetailList) // { // var poLineNum = Convert.ToInt32(detail.Line); // var scpRcvDetail = // scpdb.TB_RECEIVE_DETAIL.SingleOrDefault( // p => p.RecvBillNum == detail.ReturnNbr && // p.PoBillNum == detail.PurchaseOrder && // p.PoLine == detail.Line && // p.PartCode == detail.PartCode && // p.Batch == detail.Lot // ); // if (scpRcvDetail == null) // { // //int istate = 0; // //if (isRerviceOk == false) // //{ // // istate = (int)FormState.关闭; // //} // //else // //{ // // istate = (int)FormState.开放; // //} // scpRcvDetail = new TB_RECEIVE_DETAIL // { // RecvBillNum = detail.ReturnNbr,//收货单号 // PoBillNum = detail.PurchaseOrder,//采购单 // PoLine = detail.Line,//订单行 // PartCode = detail.PartCode,//零件号 // Batch = detail.PartCode,//批次 // VendBatch = detail.SupplierLot,//供应商批号 // PoUnit = detail.Um,//采购单位 // LocUnit = detail.logisticsUm,//物流单位 // Qty = detail.ReturnQuantity,//收货总量 //DockCode = ?,//收货口 // State = 0,// (int)FormState.关闭, // Remark = detail.Remark, // CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime,//创建日期 // CreateUser = detail.CreateUser,//创建用户 // IsDeleted = false, // GUID = System.Guid.NewGuid(), // BillType = 0 // }; // scpRcveDetailList.Add(scpRcvDetail); // } // } // } // catch (Exception e) // { // _ret.State = ReturnStatus.Failed; // LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateAsnDetail", e.Message); // _ret.Result = false; // _ret.ErrorList.Add(e); // throw e; // } // return _ret; //} public static ResultObject UpdateReturn(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _reciveList = db.TED_RETURN_MSTR.Where(p => p.TaskID == p_entity.TaskID && !string.IsNullOrEmpty(p.ReturnNbr)).ToList(); var _scpPoDetailList = new List(); foreach (var detail in _reciveList) { var scpRcv = scpdb.TB_ARRIVE.SingleOrDefault(p => p.ArrvBillNum != null && p.ArrvBillNum == detail.ReturnNbr && p.Site == detail.Domain && p.SubSite == detail.Site); var scpRcvList = new List(); bool isRerviceOk = false; if (!string.IsNullOrEmpty(detail.Site) && !string.IsNullOrEmpty(detail.Domain)) { string _domain = detail.Domain; string _site = detail.Site; List configs = scpdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == _domain).ToList(); foreach (TA_FACTORY_CONFIG cfg in configs) { TA_CONFIG tacfg = scpdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault(); if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核") { if ("允许" == tacfg.ParamValue) { isRerviceOk = true; } } } } if (scpRcv == null) { int istate = 0; if (isRerviceOk == false) { istate = (int)FormState.关闭; } else { istate = (int)FormState.开放; } scpRcv = new TB_ARRIVE { ArrvBillNum = detail.ReturnNbr,//收货单号 State = istate, Remark = "", CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime,//创建日期 CreateUser = detail.CreateUser,//创建用户 IsDeleted = false, GUID = detail.TaskID, BillType = 1 }; scpRcvList.Add(scpRcv); } scpRcv.PoBillNum = detail.PurchaseOrder;//采购单 scpRcv.AsnBillNum = detail.ASN;//发货单号 if (!string.IsNullOrEmpty(detail.ASN)) { var _entity = scpdb.TB_ASN.Where(p => p.AsnBillNum == detail.ASN).FirstOrDefault(); if (_entity != null) { _entity.State = 4; } } scpRcv.Site = detail.Domain;//地点 scpRcv.VendId = detail.Supplier;//供货商名称 scpRcv.ShipTime = detail.ReturnDate;//收货日期 scpRcv.SubSite = detail.Site; scpdb.TB_ARRIVE.AddOrUpdate(scpRcvList.ToArray()); } var scpRcveDetailList = new List(); var _reciveDetailList = db.TED_RETURN_DET.Where(p => p.TaskID == p_entity.TaskID).ToList(); var _recive = db.TED_RETURN_MSTR.Where(p => p.TaskID == p_entity.TaskID && !string.IsNullOrEmpty(p.ReturnNbr)).FirstOrDefault(); if (_recive != null) { foreach (var detail in _reciveDetailList) { detail.ReturnNbr = _recive.ReturnNbr; var poLineNum = Convert.ToInt32(detail.Line); var scpRcvDetail = scpdb.TB_ARRIVE_DETAIL.SingleOrDefault( p => p.ArrvBillNum == detail.ReturnNbr && p.PoBillNum == detail.PurchaseOrder && p.PoLine == detail.Line && p.PartCode == detail.PartCode && p.Batch == detail.Lot && p.SubSite == detail.Site ); if (scpRcvDetail == null) { //int istate = 0; //if (isRerviceOk == false) //{ // istate = (int)FormState.关闭; //} //else //{ // istate = (int)FormState.开放; //} scpRcvDetail = new TB_ARRIVE_DETAIL(); scpRcvDetail.ArrvBillNum = detail.ReturnNbr;//收货单号 scpRcvDetail.PoBillNum = detail.PurchaseOrder;//采购单 scpRcvDetail.PoLine = detail.Line;//订单行 scpRcvDetail.PartCode = detail.PartCode;//零件号 scpRcvDetail.Batch = detail.Lot;//批次 scpRcvDetail.VendBatch = detail.SupplierLot;//供应商批号 scpRcvDetail.PoUnit = detail.Um;//采购单位 scpRcvDetail.LocUnit = detail.logisticsUm;//物流单位 scpRcvDetail.Qty = detail.ReturnQuantity;//收货总量 //DockCode = ?,//收货口 scpRcvDetail.State = 1;// (int)FormState.关闭, scpRcvDetail.Remark = detail.Remark; scpRcvDetail.CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime;//创建日期 scpRcvDetail.CreateUser = detail.CreateUser;//创建用户 scpRcvDetail.IsDeleted = false; scpRcvDetail.GUID = detail.TaskID; scpRcvDetail.BillType = 1; scpRcvDetail.SubSite = detail.Site; scpRcvDetail.Site = detail.Domain; scpRcveDetailList.Add(scpRcvDetail); } } var _str = JsonHelper.GetJson>(scpRcveDetailList); scpdb.TB_ARRIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray()); } _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("退货单更新{0}任务编号{1}", _reciveDetailList.Count().ToString(), p_entity.TaskID)); _ret.Result = true; // var retDetail=UpdateReciveDetail(db, scpdb, p_entity); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateRecive", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); _ret.MessageList.Add(string.Format("退货单更新失败任务编号{0}", p_entity.TaskID)); throw e; } return _ret; } public static ResultObject UpdatePoDetail(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _poDetailList = db.TED_POD_DET.Where(p => p.TaskID == p_entity.TaskID).ToList(); var _scpPoDetailList = new List(); foreach (var detail in _poDetailList) { var lineNum = Convert.ToInt32(detail.Line); var PoDetail = scpdb.TB_PO_DETAIL.SingleOrDefault( p => p.PoBillNum == detail.PurchaseOrder && p.PoLine == lineNum && p.SubSite == detail.Site && p.Site == detail.Domain); if (PoDetail == null) { PoDetail = new TB_PO_DETAIL { PoBillNum = detail.PurchaseOrder,//订单号 PoLine = lineNum,//订单行 IsDeleted = false, GUID = detail.TaskID }; _scpPoDetailList.Add(PoDetail); } PoDetail.PartCode = detail.PartCode;//零件号-物料号 PoDetail.PlanQty = detail.Qty;//订货数量-采购量 PoDetail.PoUnit = detail.PoUm;//采购单位 PoDetail.LocUnit = detail.LocUm;//存储单位 PoDetail.Price = ScpCache.Config.项目名称 == ProjectName.重庆北汽模塑.ToString() ? 0 : detail.Price; PoDetail.Currency = detail.Currency;//币种 PoDetail.PackQty = detail.PackQty;//标包数量 PoDetail.UnConv = detail.Conv;//转换率 PoDetail.State = Convert.ToInt32(detail.Status);//状态 PoDetail.Remark = detail.Remark;//备注 PoDetail.CreateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime;//创建日期 PoDetail.CreateUser = detail.CreateUser;//创建用户 PoDetail.UpdateTime = detail.CreateTime == null ? DateTime.Now : (DateTime)detail.CreateTime;//创建日期 PoDetail.UpdateUser = detail.CreateUser;//创建用户 } scpdb.TB_PO_DETAIL.AddOrUpdate(_scpPoDetailList.ToArray()); //Console.WriteLine($"更新 采购订单 数据:{qadPoDetailList.Count}"); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "Save_TEA_TASK_SUB", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject UpdatePo(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _poList = db.TED_PO_MSTR.Where(p => p.TaskID == p_entity.TaskID).ToList(); var _scpPolist = new List(); foreach (var po in _poList) { var _po = scpdb.TB_PO.SingleOrDefault(p => p.ErpBillNum == po.PurchaseOrder && p.Site == po.Domain && p.SubSite == po.Site); if (_po == null) { int temp; _po = new TB_PO { PoBillNum = po.PurchaseOrder,//订单号 ErpBillNum = po.PurchaseOrder,//ERP订单号 VendId = po.Supplier,//供应商编号 ModType = Int32.TryParse(po.ModeType, out temp) ? temp : (int?)null, //单据类型(1:日程单,2:离散订单) Contacter = po.Contact,//联系人 Site = po.Domain,//地点 State = (int)FormState.开放,//状态 Remark = po.Remark,//说明 CreateTime = po.CreateTime == null ? DateTime.Now : (DateTime)po.CreateTime,//创建日期 CreateUser = po.CreateUser,//创建用户 IsDeleted = false, GUID = po.TaskID, BeginTime = po.OrderDate == null ? DateTime.Now : po.OrderDate,//创建日期 EndTime = po.DueDate//收货结束时间 }; int _count = _scpPolist.Count(p => p.ErpBillNum == po.PurchaseOrder && p.Site == po.Domain && p.SubSite == po.Site); if (_count == 0) { _scpPolist.Add(_po); } } _po.Contacter = po.Contact; _po.Buyer = _po.Buyer; _po.BuyerPhone = _po.BuyerPhone; _po.UpdateTime = _po.UpdateTime;//更新日期 _po.UpdateUser = _po.UpdateUser;//更新用户 } scpdb.TB_PO.AddOrUpdate(_scpPolist.ToArray()); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "Save_TEA_TASK_SUB", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } /// /// 更新供应商 /// /// /// /// /// public static ResultObject UpdateSupplier(List p_list, ScpEntities scpdb, AppBoxContext authdb, TEA_TASK_SUB p_entity) { Dictionary _dic = new Dictionary(); _dic.Add("BJBMPT", "BJ01"); _dic.Add("CQBMPT", "CQ01"); _dic.Add("ZZBMPT", "ZZ01"); _dic.Add("HFBMPT", "HF01"); _dic.Add("CDBMPT", "CD01"); ResultObject _ret = new ResultObject(); try { var _tavenderlist = scpdb.TA_VENDER.ToList(); var addlist = new List(); var uplist = new List(); foreach (var supplier in p_list) { foreach (var item in _dic) { var _supplier = _tavenderlist.FirstOrDefault(p => p.VendId == supplier.SupplierCode && p.Site == item.Key); if (_supplier == null) { _supplier = new TA_VENDER { VendId = supplier.SupplierCode.ToUpper(), VendAbbCode = "0", State = 1, }; _supplier.VendName = string.IsNullOrEmpty(supplier.SupplierName) ? supplier.SupplierName : supplier.SupplierName; _supplier.SubSite = item.Value;//地点 _supplier.Site = item.Key;//域 _supplier.Remark = supplier.TaskID.ToString();//任务ID addlist.Add(_supplier); } else { _supplier.VendName = string.IsNullOrEmpty(supplier.SupplierName) ? supplier.SupplierName : supplier.SupplierName; _supplier.SubSite = item.Value;//地点 _supplier.Site = item.Key;//域 _supplier.Remark = supplier.TaskID.ToString();//任务ID uplist.Add(_supplier); } # region 取消自动创建 //var vendname = string.Format("{0}@{1}", _supplier.VendId.ToUpper(), _supplier.Site.ToUpper()); // //var _first = authdb.Users.Where(p => p.Name == vendname).FirstOrDefault(); //var _vend = authdb.Roles.Where(p => p.Name == "供应商").FirstOrDefault(); //var _factory = authdb.TA_FACTORY.Where(p => p.ErpDomain == _supplier.Site.ToUpper()).FirstOrDefault(); //if (_first == null && _vend != null && _factory != null) //{ // User _entity = new User(); // _entity.Name = vendname; // _entity.Remark = _supplier.Site.ToUpper(); // // 随机密码 // _entity.Password = GenerateComplexPassword(); //PasswordUtil.CreateDbPassword("99999999"); // _entity.ChineseName = _supplier.VendName; // _entity.Email = _supplier.VendId + "@163.com"; // _entity.Gender = "男"; // _entity.Enabled = true; // _entity.Roles = new List(); // Role t = authdb.Set().Local.Where(x => x.ID == _vend.ID).FirstOrDefault(); // if (t == null) // { // t = new Role { ID = _vend.ID }; // authdb.Set().Attach(t); // } // _entity.Roles.Add(t); // _entity.TA_FACTORY = new List(); // TA_FACTORY f = authdb.Set().Local.Where(x => x.ID == _factory.ID).FirstOrDefault(); // if (f == null) // { // f = new TA_FACTORY { ID = _factory.ID }; // authdb.Set().Attach(f); // } // _entity.TA_FACTORY.Add(f); // authdb.Users.Add(_entity); //} //_venderlist.Add(_supplier); #endregion } } scpdb.BulkInsert(addlist); scpdb.BulkUpdate(uplist); //scpdb.TA_VENDER.AddOrUpdate(q => q.UID, _venderlist.ToArray()); _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("更新表{0}任务ID{1}成功!", "TES_SUPPLIER", p_entity.TaskID)); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateSupplier", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } private static void UpdateSupplierExtend(List p_vendList) { var _ls = new List(); using (var db = EntitiesFactory.CreateAppBoxInstance()) { foreach (var qadData in p_vendList) { try { //var vendname = string.Format("{0}@{1}", qadData.SupplierCode.ToUpper(), qadData.Domain.ToUpper()); string vendtoup = qadData.SupplierCode.ToUpper(); var _first = db.Users.Where(p => p.Name.Contains(vendtoup)).ToList(); if (_first != null) { foreach (var item in _first) { var count = db.VenderUsers.Count(p => p.VenderId == qadData.SupplierCode && p.UserId == item.ID); if (count == 0) { var _ef = new VenderUsers() { UserId = item.ID, VenderId = qadData.SupplierCode.ToUpper() }; _ls.Add(_ef); } else { var _ef = db.VenderUsers.FirstOrDefault(p => p.VenderId == qadData.SupplierCode && p.UserId == item.ID); _ef.UserId = item.ID; _ef.VenderId = qadData.SupplierCode.ToUpper(); _ls.Add(_ef); } } } } catch(Exception EX) { throw EX; } db.VenderUsers.AddOrUpdate(q=>q.Id,_ls.ToArray()); db.BulkSaveChanges(); } } } /// /// 更新供应商零件 /// /// /// /// /// /// public static ResultObject UpdateSupplierPart(DataCenterContext dc, ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _supplierpartlist = db.TES_SUPPLIER_PART.Where(p => p.TaskID == p_entity.TaskID).ToList(); var _venderpartlist = new List(); decimal _packqty = 1; foreach (var supplierpart in _supplierpartlist) { var _supplierpart = scpdb.TA_VEND_PART.SingleOrDefault(p => p.VendId == supplierpart.Supplier && p.PartCode == supplierpart.PartCode && p.VendPartCode == supplierpart.SupplierPart && p.Site == supplierpart.Domain); if (_supplierpart == null) { var _pack = dc.TS_PACK.SingleOrDefault(p => p.PartCode == supplierpart.PartCode && p.Site == supplierpart.Domain && p.Site == supplierpart.Site); if (_pack != null) { } _supplierpart = new TA_VEND_PART { VendId = supplierpart.Supplier.ToUpper(),//供应商编号 PartCode = supplierpart.PartCode.ToUpper(),//对应物料号 VendPartCode = supplierpart.SupplierPart.ToUpper(),//供应商物料号 VendPackQty = _packqty,//供应商物料号 State = 1,//状态(0:失效 1:有效) Remark = "", CreateTime = supplierpart.CreateTime == null ? DateTime.Now : (DateTime)supplierpart.CreateTime,//创建日期 CreateUser = supplierpart.CreateUser,//创建用户 TransportationTime = 1, IsDeleted = false, GUID = new Guid() }; } _supplierpart.Site = string.IsNullOrEmpty(_supplierpart.Site) ? supplierpart.Domain : _supplierpart.Site; _supplierpart.SubSite = string.IsNullOrEmpty(_supplierpart.SubSite) ? supplierpart.Site : _supplierpart.SubSite; _supplierpart.VendPartCode = supplierpart.SupplierPart?.ToUpper() ?? supplierpart.PartCode.ToUpper(); _supplierpart.VendPackQty = _packqty; _supplierpart.TransportationTime = 1; _supplierpart.UpdateTime = DateTime.Now;//更新日期 _supplierpart.UpdateUser = supplierpart.CreateUser;//更新用户 _supplierpart.Remark = supplierpart.TaskID.ToString();//任务ID _venderpartlist.Add(_supplierpart); } scpdb.TA_VEND_PART.AddOrUpdate(_venderpartlist.ToArray()); _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("更新表{0}任务ID{1}成功!", "TES_SUPPLIER_PART", p_entity.TaskID)); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateSupplierPart", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } /// /// 更新零件 /// /// /// /// /// public static ResultObject UpdatePart(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _partmstrlist = db.TES_PART_MSTR.Where(p => p.TaskID == p_entity.TaskID && p.CommandType != "D").ToList(); var _partmstrlistD = db.TES_PART_MSTR.Where(p => p.TaskID == p_entity.TaskID && p.CommandType == "D").ToList(); var _partlist = new List(); var _partlistD = new List(); foreach (var part in _partmstrlist) { var _part = scpdb.TA_PART.SingleOrDefault(p => p.PartCode == part.PartCode && p.Site == part.Domain); if (_part == null) { _part = new TA_PART { PartCode = part.PartCode.ToUpper(), ErpPartCode = part.PartCode.ToUpper(), }; } _part.PartDesc1 = part.Desc1; _part.PartDesc2 = string.IsNullOrEmpty(part.Desc2) ? string.Empty : part.Desc2; if (!string.IsNullOrEmpty(part.Group)) { _part.ProjectId = part.Group; } else { _part.ProjectId = "public"; } _part.Unit = !string.IsNullOrEmpty(part.Um) ? part.Um.ToUpper() : "EA"; _part.State = part.Status; if (part.InspectType != null) { _part.Ischeck = (part.InspectType == 0) ? true : false; } if (!string.IsNullOrEmpty(part.PartType)) { if (part.PartType.Substring(0, 2) == "12") { _part.PartGroup = "AST"; } else { _part.PartGroup = "其他"; } } _part.Qlevel = string.IsNullOrEmpty(part.Qgrade) ? string.Empty : part.Qgrade; _part.State = part.Status; _part.Site = part.Domain; // _part.SubSite = part.Site; _part.Remark = part.TaskID.ToString(); _partlist.Add(_part); } if (_partmstrlistD.Count() > 0) { foreach (var depart in _partmstrlistD) { var _part = scpdb.TA_PART.FirstOrDefault(p => p.PartCode == depart.PartCode && p.Site == depart.Domain); if (_part != null) { _partlistD.Add(_part); } } } var str = JsonHelper.GetJson>(_partlist); scpdb.TA_PART.AddOrUpdate(_partlist.ToArray()); if (_partlistD.Count() > 0) { scpdb.TA_PART.DeleteRangeByKey(_partlistD.ToArray()); } _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("更新表{0}任务ID{1}成功!", "TES_PART_MSTR", p_entity.TaskID)); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdatePart", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject UpdateFactory(ExchangeCenterContext db, ScpEntities scpdb, AppBoxContext appscpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _factorylist = db.TES_SITE.Where(p => p.TaskID == p_entity.TaskID).ToList(); var _appboxfactorylist = new List(); var _scpfactorylist = new List(); foreach (var factory in _factorylist) { var item1 = appscpdb.TA_FACTORY.SingleOrDefault(p => p.ErpDomain == factory.Domain && p.ErpSite == factory.Site); if (item1 == null) { item1 = new TA_FACTORY { ErpDomain = factory.Domain, ErpSite = factory.Site, GUID = Guid.NewGuid(), State = 1, CreateTime = DateTime.Now, CreateUser = factory.CreateUser }; } item1.FactoryId = factory.Domain; item1.ZipCode = factory.Domain; item1.FactoryName = factory.Desc; item1.Address = ""; item1.Remark = factory.Remark; item1.Tel = ""; item1.Fax = ""; item1.UpdateTime = DateTime.Now; item1.UpdateUser = factory.CreateUser; _appboxfactorylist.Add(item1); var item2 = scpdb.TB_FACTORY.SingleOrDefault(p => p.ErpDomain == factory.Domain && p.ErpSite == factory.Site); if (item2 == null) { item2 = new TB_FACTORY { ErpDomain = factory.Domain, ErpSite = factory.Site, GUID = Guid.NewGuid(), State = 1, CreateTime = DateTime.Now, CreateUser = factory.CreateUser }; } item2.FactoryId = factory.Domain; item2.ZipCode = factory.Domain; item2.FactoryName = factory.Desc; item2.Address = ""; item2.Remark = factory.Remark; item2.Tel = ""; item2.Fax = ""; item2.UpdateTime = DateTime.Now; item2.UpdateUser = factory.CreateUser; _scpfactorylist.Add(item2); } appscpdb.TA_FACTORY.AddOrUpdate(_appboxfactorylist.ToArray()); scpdb.TB_FACTORY.AddOrUpdate(_scpfactorylist.ToArray()); if (appscpdb.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpdateFactory", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public static ResultObject UpdateTES_PURCHASE_PRICE(List p_list, string domain, string site, string name, bool flag, int ConfirmState) { ResultObject _ret = new ResultObject(); if (ConfirmState != (int)PriceState.FConfirm) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; return _ret; } try { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); List _teslist = new List(); var _ls = scpdb.V_TB_PRICE.Where(p => p_list.Contains(p.UID)).ToList(); foreach (var _price in _ls) { Guid _taskguid = Guid.NewGuid(); TS_UNI_API _item = new TS_UNI_API(); var _vend = _price.VendId.Trim(); var _partCode = _price.PartCode.Trim(); var _domain = _price.Site.Trim(); var _site = _price.SubSite.Trim(); if (_site == "CD01") { _item.BillNum = (_vend + _site.Substring(0, 1) + _site.Substring(3, 1)).Trim(); } else { _item.BillNum = (_vend + _site.Substring(1, 1) + _site.Substring(3, 1)).Trim(); } _item.InterfaceType = "Price"; if (_price.Extend2 == "是") { _item.Batch = "Yes"; } else if (_price.Extend2 == "否") { _item.Batch = "No"; } _item.Qty = _price.Amt + _price.SharingPrice; _item.Price = _price.Amt; _item.State = 1; _item.ValidDate = DateTime.Now; _item.ErpLineNum = 1; _item.PartCode = _partCode;//零件编号 _item.Domain = _domain;//域 _item.Site = _site;//地点 _item.Extend1 = _price.Remarks; _item.CreateTime = Convert.ToDateTime(_price.StartTime);//开始时间 _item.PutTime = Convert.ToDateTime(_price.EndTime);//结束时间 _item.CreateOper = _price.Creator; _item.Currency = _price.Curr;//货币 var _first = scpdb.TA_PART.Where(itm => itm.PartCode == _partCode).FirstOrDefault(); if (_first != null) { _item.PoUnit = _first.Unit; } else { _item.PoUnit = _price.Unit;//单位 } if (_domain == "BJBMPT") { var po = scpdb.V_TB_PO_DETAIL.Count(p => p.PartCode == _partCode && p.Site == "BJBMPT" && p.VendId == _vend.Trim()); if (po > 0) { var _list = scpdb.V_TB_PO_DETAIL.Where(p => p.PartCode == _partCode && p.Site == "BJBMPT" && p.VendId == _vend.Trim()).ToList(); foreach (var b in _list) { var PP = scpdb.TB_PO_DETAIL.FirstOrDefault(p => p.PartCode == b.PartCode && p.Site == "BJBMPT" && p.PoBillNum == b.PoBillNum); PP.Price = _item.Price; scpdb.TB_PO_DETAIL.AddOrUpdate(PP); } } } _teslist.Add(_item); } scpdb.TS_UNI_API.AddOrUpdate(_teslist.ToArray()); if (scpdb.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = "数据更新失败!"; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = e.InnerException.Message; } return _ret; } public static ResultObject UpdateTES_PURCHASE_PRICE_TemporaryPrice(List p_list, string domain, string site, string name, bool flag) { ResultObject _ret = new ResultObject(); try { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); List _teslist = new List(); var _ls = scpdb.V_TB_PRICE_TemporaryPrice.Where(p => p_list.Contains(p.UID)).ToList(); foreach (var _price in _ls) { Guid _taskguid = Guid.NewGuid(); TS_UNI_API _item = new TS_UNI_API(); var _vend = _price.VendId.Trim(); var _partCode = _price.PartCode.Trim(); var _domain = _price.Site.Trim(); var _site = _price.SubSite.Trim(); _item.BillNum = (_vend + _site.Substring(1, 1) + _site.Substring(3, 1)).Trim(); _item.InterfaceType = "Price"; _item.Batch = "No"; _item.Qty = _price.Amt + _price.SharingPrice; _item.Price = _price.Amt; _item.State = 1; _item.ValidDate = DateTime.Now; _item.ErpLineNum = 1; _item.PartCode = _partCode;//零件编号 _item.Domain = _domain;//域 _item.Site = _site;//地点 _item.Extend1 = _price.Remarks; _item.CreateTime = Convert.ToDateTime(_price.StartTime);//开始时间 _item.PutTime = Convert.ToDateTime(_price.EndTime);//结束时间 _item.CreateOper = _price.Creator; _item.Currency = _price.Curr;//货币 var _first = scpdb.TA_PART.Where(itm => itm.PartCode == _partCode).FirstOrDefault(); if (_first != null) { _item.PoUnit = _first.Unit; } else { _item.PoUnit = _price.Unit;//单位 } _teslist.Add(_item); } scpdb.TS_UNI_API.AddOrUpdate(_teslist.ToArray()); if (scpdb.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = "数据更新失败!"; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = e.InnerException.Message; } return _ret; } public static ResultObject WritePo(List p_order_list, string site, string p_creator, DateTime p_time, BillModType p_modtype, string subsite, string p_chineseName, string p_buyerPhone) { ResultObject _ret = new ResultObject(); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.Serializable, Timeout = new TimeSpan(0, 20, 0) })) { try { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); var OrderList = p_order_list.GroupBy(p => p.订单编号).ToList(); string _polist = ""; int _num = 1; OrderList.ForEach((p) => { var list = p.ToList(); if (list.Count > 0) { #region 日程单 if (p_modtype == BillModType.Contract) { var _entity = list.FirstOrDefault(); var _po = scpdb.TB_PO.SingleOrDefault(t => t.PoBillNum == _entity.订单编号/* && t.State == state*/ && t.Site == site && t.SubSite == subsite && t.VendId == _entity.供应商编号.ToUpper()); if (_po == null) { _po = new TB_PO { GUID = Guid.NewGuid(), PoBillNum = _entity.订单编号.ToUpper(), State = (int)PoState.Open, Site = site, SubSite = subsite, VendId = _entity.供应商编号.Trim().ToUpper() }; } _po.ErpBillNum = _entity.订单编号.Trim().ToUpper(); ; _po.ModType = (int)p_modtype; _po.Contacter = p_chineseName;// _entity.联系人; _po.Buyer = p_chineseName;// _entity.联系人; _po.Site = site.Trim().ToUpper(); _po.BuyerPhone = p_buyerPhone; _po.Remark = _entity.备注; _po.IsDeleted = false; _po.State = (int)PoState.Open; _po.CreateTime = DateTime.Now; _po.CreateUser = p_creator; _po.BeginTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.EndTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.要求到货日期); _po.Pricelist = _entity.供应商编号.Trim().ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; _po.SubSite = subsite.Trim().ToUpper(); scpdb.TB_PO.AddOrUpdate(_po); list.ForEach((itm) => { TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL(); _PO_Detail.Currency = "CNY"; _PO_Detail.PoBillNum = _po.PoBillNum; _PO_Detail.PartCode = itm.零件号.Trim(); var part = scpdb.TA_PART.FirstOrDefault(t => t.PartCode == itm.零件号.Trim() && t.Site == _po.Site); _PO_Detail.PoLine = int.Parse(itm.行号); _PO_Detail.PoUnit = part.Unit; _PO_Detail.CreateTime = DateTime.Now; _PO_Detail.CreateUser = p_creator; _PO_Detail.BeginTime = string.IsNullOrEmpty(itm.订单创建时间) ? DateTime.Now : DateTime.Parse(itm.订单创建时间); _PO_Detail.EndTime = string.IsNullOrEmpty(itm.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(itm.要求到货日期); _PO_Detail.PlanQty = decimal.Parse(itm.数量); _PO_Detail.IsDeleted = false; _PO_Detail.LocUnit = part.Unit; _PO_Detail.UnConv = 1; _PO_Detail.State = (int)PoState.Open; _PO_Detail.Remark = itm.备注; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号); _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.Site = site.Trim().ToUpper(); _PO_Detail.SubSite = subsite.Trim().ToUpper(); TS_UNI_API Ts = new TS_UNI_API(); Ts.InterfaceType = "PO"; Ts.TableName = "TS_UNI_API"; Ts.Batch = _entity.供应商编号.Trim().ToUpper(); Ts.BillType = 702; Ts.SubBillType = 1; Ts.BillNum = _entity.订单编号.Trim().ToUpper(); Ts.PartCode = _PO_Detail.PartCode.Trim(); Ts.Qty = decimal.Parse(_entity.数量); Ts.State = 1; Ts.CreateOper = _entity.联系人; Ts.CreateTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); Ts.PutTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); Ts.VendId = _entity.供应商编号.Trim().ToUpper(); Ts.PoUnit = part.Unit; Ts.LocUnit = part.Unit; Ts.ValidDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); Ts.ErpBillNum = _entity.订单编号; Ts.Buyer = _entity.采购员; Ts.BuyerPhone = _entity.采购员电话; Ts.Price = decimal.Parse(_entity.单价); Ts.Site = subsite.Trim().ToUpper(); Ts.Domain = site.Trim().ToUpper(); Ts.Extend1 = _entity.税率; Ts.Extend2 = _entity.备注; Ts.CreateOper = _entity.采购员; Ts.VendBatch = p_creator; Ts.ErpLineNum = _PO_Detail.PoLine; if (_entity.订单类型.ToUpper() == "S") { Ts.ModType = _entity.订单类型.ToUpper(); } scpdb.TB_PO_DETAIL.AddOrUpdate(_PO_Detail); scpdb.TS_UNI_API.Add(Ts); }); _polist = _polist + _po.PoBillNum + ","; } #endregion #region 离散单 (离散单只增加不修改) if (p_modtype == BillModType.Non_Contract) { var _entity = list.FirstOrDefault(); TB_PO _po = new TB_PO(); _po.GUID = Guid.NewGuid(); _po.PoBillNum = SCP_BILLCODE_CONTROLLER.MakePoNum(_num); _po.State = (int)PoState.Open; _po.Site = site.Trim().ToUpper(); _po.SubSite = subsite.Trim().ToUpper(); _po.VendId = _entity.供应商编号.Trim().ToUpper(); _po.ErpBillNum = _po.PoBillNum; _po.ModType = (int)p_modtype; _po.Contacter = p_chineseName;// _entity.联系人; _po.Buyer = p_chineseName;// _entity.联系人; _po.BuyerPhone = p_buyerPhone; _po.Site = site.Trim().ToUpper(); _po.Remark = _entity.备注; _po.IsDeleted = false; _po.CreateTime = DateTime.Now; _po.CreateUser = p_creator; _po.BeginTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.EndTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.要求到货日期); _po.Pricelist = _entity.供应商编号.ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; scpdb.TB_PO.AddOrUpdate(_po); TB_ASK _ask = new TB_ASK(); _ask.AskBillNum = SCP_BILLCODE_CONTROLLER.MakeASKCode_BJBQ(_num); _ask.GUID = Guid.NewGuid(); _ask.PoBillNum = _po.PoBillNum; _ask.VendId = _entity.供应商编号.Trim().ToUpper(); _ask.IsDeleted = false; _ask.CreateTime = DateTime.Now; _ask.CreateUser = p_creator; _ask.Site = site.Trim().ToUpper(); _ask.ReceivedPort = "";//交货口 _ask.State = (int)AskState.New; _ask.Remark = _entity.备注; _ask.ModType = (int)p_modtype; _ask.ErpBillNum = _po.PoBillNum; _ask.BeginTime = p_time; _ask.EndTime = DateTime.Parse(_entity.要求到货日期); _ask.Buyer = p_chineseName; _ask.BuyerPhone = p_buyerPhone; _ask.SubSite = subsite; scpdb.TB_ASK.Add(_ask); int _number = 1; list.ForEach((itm) => { TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL(); _PO_Detail.GUID = Guid.NewGuid(); _PO_Detail.PartCode = itm.零件号.Trim().ToUpper(); var part = scpdb.TA_PART.FirstOrDefault(t => t.PartCode == itm.零件号.Trim() && t.Site == _po.Site); _PO_Detail.PoLine = _number; _PO_Detail.PoBillNum = _po.PoBillNum; _PO_Detail.State = (int)PoState.Open; _PO_Detail.Site = site.Trim().ToUpper(); _PO_Detail.SubSite = subsite.Trim().ToUpper(); _PO_Detail.Currency = "CNY"; _PO_Detail.PoUnit = part.Unit; _PO_Detail.Remark = itm.备注; _PO_Detail.CreateTime = DateTime.Now; _PO_Detail.CreateUser = p_creator; _PO_Detail.BeginTime = string.IsNullOrEmpty(itm.订单创建时间) ? DateTime.Now : DateTime.Parse(itm.订单创建时间); _PO_Detail.EndTime = string.IsNullOrEmpty(itm.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(itm.要求到货日期); _PO_Detail.PlanQty = decimal.Parse(itm.数量); _PO_Detail.IsDeleted = false; _PO_Detail.LocUnit = part.Unit; _PO_Detail.UnConv = 1; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号); _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.TempQty = decimal.Parse(itm.数量); //_PO_Detail.Extend = itm.供应商编号; TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL(); _tDetail.Remark = itm.备注; _tDetail.PoBillNum = _po.PoBillNum; _tDetail.AskBillNum = _ask.AskBillNum; _tDetail.PoLine = _number; _tDetail.PoUnit = part.Unit; _tDetail.CreateTime = DateTime.Now; _tDetail.CreateUser = p_creator; _tDetail.PartCode = itm.零件号.ToUpper().Trim(); _tDetail.ReceivedPort = ""; _tDetail.BeginTime = p_time; _tDetail.EndTime = Convert.ToDateTime(itm.要求到货日期); _tDetail.TempQty = 0; _tDetail.AskQty = Decimal.Parse(itm.数量); _tDetail.IsDeleted = false; _tDetail.LocUnit = part.Unit; _tDetail.UnConv = 1; _tDetail.State = (int)PoState.Open; _tDetail.SubSite = subsite.Trim().ToUpper(); _tDetail.Site = site.Trim().ToUpper(); _tDetail.Price = Decimal.Parse(itm.单价); _tDetail.GUID = Guid.NewGuid(); _tDetail.Currency = itm.币种; TS_UNI_API Ts = new TS_UNI_API(); Ts.InterfaceType = "PO"; Ts.TableName = "TS_UNI_API"; Ts.Batch = _entity.供应商编号.Trim().ToUpper(); Ts.BillType = 702; Ts.SubBillType = 2; Ts.BillNum = _po.PoBillNum.Trim().ToUpper(); Ts.PartCode = _tDetail.PartCode.Trim().ToUpper(); Ts.Qty = _tDetail.AskQty; Ts.State = 1; Ts.CreateOper = _entity.联系人; Ts.CreateTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); Ts.PutTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); Ts.VendId = _entity.供应商编号.Trim().ToUpper(); Ts.PoUnit = part.Unit; Ts.LocUnit = part.Unit; Ts.ValidDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); Ts.Buyer = _entity.采购员; Ts.BuyerPhone = _entity.采购员电话; Ts.Price = _tDetail.Price; Ts.Site = subsite.Trim().ToUpper(); Ts.Domain = site.Trim().ToUpper(); Ts.Extend1 = _entity.税率; Ts.Extend2 = _entity.备注; Ts.CreateOper = _entity.采购员; Ts.VendBatch = p_creator; Ts.ErpBillNum = _po.PoBillNum; Ts.ErpLineNum = _PO_Detail.PoLine; if (!string.IsNullOrEmpty(_entity.订单类型)) { if (_entity.订单类型.ToUpper() == "S") { Ts.ModType = _entity.订单类型.ToUpper(); } } scpdb.TB_ASK_DETAIL.Add(_tDetail); scpdb.TB_PO_DETAIL.AddOrUpdate(_PO_Detail); scpdb.TS_UNI_API.Add(Ts); _number++; }); _polist = _polist + _po.PoBillNum + ","; } #endregion } //var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() //{ // DataCount = 1, // TaskID = taskid, // TableName = "TED_PO_MSTR", // Site = subsite.Trim().ToUpper(), // Domain = site.Trim().ToUpper(), // CreateTime = p_time, // CreateUser = p_creator, // Creator = "SCP", //}); _num++; Thread.Sleep(10); } ); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); scope.Complete(); _ret.State = ReturnStatus.Succeed; _ret.Result = true; _ret.Message = _polist; } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "InsterPo", e.Message); _ret.Result = false; _ret.Message = e.InnerException != null ? e.Message + e.InnerException.Message : e.Message; scope.Dispose(); } } return _ret; } public static ResultObject WritePo_PO(List p_order_list, string site, string p_creator, DateTime p_time, BillModType p_modtype, string subsite, string p_chineseName, string p_buyerPhone) { ResultObject _ret = new ResultObject(); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.Serializable, Timeout = new TimeSpan(0, 20, 0) })) { try { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); var OrderList = p_order_list.GroupBy(p => p.订单编号).ToList(); string _polist = ""; int _num = 1; OrderList.ForEach((p) => { var list = p.ToList(); if (list.Count > 0) { #region 日程单 if (p_modtype == BillModType.Contract) { var _entity = list.FirstOrDefault(); var _po = scpdb.TB_PO.SingleOrDefault(t => t.PoBillNum == _entity.订单编号/* && t.State == state*/ && t.Site == site && t.SubSite == subsite && t.VendId == _entity.供应商编号.ToUpper()); if (_po == null) { _po = new TB_PO { GUID = Guid.NewGuid(), PoBillNum = _entity.订单编号.ToUpper(), State = (int)PoState.Open, Site = site, SubSite = subsite, VendId = _entity.供应商编号.Trim().ToUpper() }; } _po.ErpBillNum = _entity.订单编号.Trim().ToUpper(); ; _po.ModType = (int)p_modtype; _po.Contacter = p_chineseName;// _entity.联系人; _po.Buyer = p_chineseName;// _entity.联系人; _po.Site = site.Trim().ToUpper(); _po.State = (int)PoState.Open; _po.BuyerPhone = p_buyerPhone; _po.Remark = _entity.备注; _po.IsDeleted = false; _po.CreateTime = DateTime.Now; _po.CreateUser = p_creator; _po.BeginTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.EndTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.要求到货日期); _po.Pricelist = _entity.供应商编号.Trim().ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; _po.SubSite = subsite.Trim().ToUpper(); scpdb.TB_PO.AddOrUpdate(_po); list.ForEach((itm) => { TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL(); _PO_Detail.Currency = "CNY"; _PO_Detail.PoBillNum = _po.PoBillNum; _PO_Detail.PartCode = itm.零件号.Trim(); var part = scpdb.TA_PART.FirstOrDefault(t => t.PartCode == itm.零件号.Trim() && t.Site == _po.Site); _PO_Detail.PoLine = int.Parse(itm.行号); _PO_Detail.PoUnit = part.Unit; _PO_Detail.CreateTime = DateTime.Now; _PO_Detail.CreateUser = p_creator; _PO_Detail.BeginTime = string.IsNullOrEmpty(itm.订单创建时间) ? DateTime.Now : DateTime.Parse(itm.订单创建时间); _PO_Detail.EndTime = string.IsNullOrEmpty(itm.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(itm.要求到货日期); _PO_Detail.PlanQty = decimal.Parse(itm.数量); _PO_Detail.IsDeleted = false; _PO_Detail.LocUnit = part.Unit; _PO_Detail.UnConv = 1; _PO_Detail.Remark = itm.备注; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号); _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.Site = site.Trim().ToUpper(); _PO_Detail.State = (int)PoState.Open; _PO_Detail.SubSite = subsite.Trim().ToUpper(); TS_UNI_API Ts = new TS_UNI_API(); Ts.InterfaceType = "PO"; Ts.TableName = "TS_UNI_API"; Ts.Batch = _entity.供应商编号.Trim(); Ts.BillType = 702; Ts.SubBillType = 1; Ts.BillNum = _entity.订单编号.Trim().ToUpper(); Ts.PartCode = _PO_Detail.PartCode.Trim(); Ts.Qty = decimal.Parse(_entity.数量); Ts.State = 1; Ts.CreateOper = _entity.联系人; Ts.CreateTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); Ts.PutTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); Ts.VendId = _entity.供应商编号.Trim(); Ts.PoUnit = part.Unit; Ts.LocUnit = part.Unit; Ts.ValidDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); Ts.ErpBillNum = _entity.订单编号.Trim(); Ts.Buyer = _entity.采购员; Ts.BuyerPhone = _entity.采购员电话; Ts.Price = decimal.Parse(_entity.单价); Ts.Site = subsite.Trim().ToUpper(); Ts.Domain = site.Trim().ToUpper(); Ts.Extend1 = _entity.税率; Ts.Extend2 = _entity.备注; Ts.CreateOper = _entity.采购员; Ts.VendBatch = p_creator; Ts.ErpLineNum = _PO_Detail.PoLine; scpdb.TB_PO_DETAIL.AddOrUpdate(_PO_Detail); scpdb.TS_UNI_API.Add(Ts); }); _polist = _polist + _po.PoBillNum + ","; } #endregion #region 离散单 (离散单只增加不修改) if (p_modtype == BillModType.Non_Contract) { var _entity = list.FirstOrDefault(); TB_PO _po = new TB_PO(); _po.GUID = Guid.NewGuid(); _po.PoBillNum = SCP_BILLCODE_CONTROLLER.MakePoNum(_num); _po.State = (int)PoState.Open; _po.Site = site.Trim().ToUpper(); _po.SubSite = subsite.Trim().ToUpper(); _po.VendId = _entity.供应商编号.Trim().ToUpper(); _po.ErpBillNum = _po.PoBillNum; _po.ModType = (int)p_modtype; _po.Contacter = p_chineseName;// _entity.联系人; _po.Buyer = p_chineseName;// _entity.联系人; _po.BuyerPhone = p_buyerPhone; _po.Site = site.Trim().ToUpper(); _po.Remark = _entity.备注; _po.IsDeleted = false; _po.CreateTime = DateTime.Now; _po.CreateUser = p_creator; _po.BeginTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.EndTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.要求到货日期); _po.Pricelist = _entity.供应商编号.ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; scpdb.TB_PO.AddOrUpdate(_po); int _number = 1; list.ForEach((itm) => { TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL(); _PO_Detail.GUID = Guid.NewGuid(); _PO_Detail.PartCode = itm.零件号.Trim().ToUpper(); var part = scpdb.TA_PART.FirstOrDefault(t => t.PartCode == itm.零件号.Trim() && t.Site == _po.Site); _PO_Detail.PoLine = _number; _PO_Detail.PoBillNum = _po.PoBillNum.Trim(); _PO_Detail.State = (int)PoState.Open; _PO_Detail.Site = site.Trim().ToUpper(); _PO_Detail.SubSite = subsite.Trim().ToUpper(); _PO_Detail.Currency = "CNY"; _PO_Detail.PoUnit = part.Unit; _PO_Detail.Remark = itm.备注; _PO_Detail.CreateTime = DateTime.Now; _PO_Detail.CreateUser = p_creator; _PO_Detail.BeginTime = string.IsNullOrEmpty(itm.订单创建时间) ? DateTime.Now : DateTime.Parse(itm.订单创建时间); _PO_Detail.EndTime = string.IsNullOrEmpty(itm.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(itm.要求到货日期); _PO_Detail.PlanQty = decimal.Parse(itm.数量); _PO_Detail.IsDeleted = false; _PO_Detail.LocUnit = part.Unit; _PO_Detail.UnConv = 1; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号); _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.TempQty = decimal.Parse(itm.数量); //_PO_Detail.Extend = itm.供应商编号; TS_UNI_API Ts = new TS_UNI_API(); Ts.InterfaceType = "PO"; Ts.TableName = "TS_UNI_API"; Ts.Batch = _entity.供应商编号.Trim(); Ts.BillType = 702; Ts.SubBillType = 2; Ts.BillNum = _po.PoBillNum.Trim().ToUpper(); Ts.PartCode = _PO_Detail.PartCode.Trim(); Ts.Qty = _PO_Detail.PlanQty; Ts.State = 1; Ts.CreateOper = _entity.联系人; Ts.CreateTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); Ts.PutTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); Ts.VendId = _entity.供应商编号.Trim(); Ts.PoUnit = part.Unit; Ts.LocUnit = part.Unit; Ts.ValidDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); Ts.Buyer = _entity.采购员; Ts.BuyerPhone = _entity.采购员电话; Ts.Price = _PO_Detail.Price; Ts.Site = subsite.Trim().ToUpper(); Ts.Domain = site.Trim().ToUpper(); Ts.Extend1 = _entity.税率; Ts.Extend2 = _entity.备注; Ts.CreateOper = _entity.采购员; Ts.VendBatch = p_creator; Ts.ErpBillNum = _po.PoBillNum.Trim(); Ts.ErpLineNum = _number; scpdb.TB_PO_DETAIL.AddOrUpdate(_PO_Detail); scpdb.TS_UNI_API.Add(Ts); _number++; }); _polist = _polist + _po.PoBillNum.Trim() + ","; } #endregion } //var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() //{ // DataCount = 1, // TaskID = taskid, // TableName = "TED_PO_MSTR", // Site = subsite.Trim().ToUpper(), // Domain = site.Trim().ToUpper(), // CreateTime = p_time, // CreateUser = p_creator, // Creator = "SCP", //}); _num++; Thread.Sleep(10); } ); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); scope.Complete(); _ret.State = ReturnStatus.Succeed; _ret.Result = true; _ret.Message = _polist; } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "InsterPo", e.Message); _ret.Result = false; _ret.Message = e.InnerException.Message; scope.Dispose(); } } return _ret; } public static ResultObject WritePo_PO_PO(List p_order_list, string site, string p_creator, DateTime p_time, BillModType p_modtype, string subsite, string p_chineseName, string p_buyerPhone) { ResultObject _ret = new ResultObject(); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.Serializable, Timeout = new TimeSpan(0, 20, 0) })) { try { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); var OrderList = p_order_list.GroupBy(p => p.订单编号).ToList(); string _polist = ""; int _num = 1; OrderList.ForEach((p) => { var list = p.ToList(); if (list.Count > 0) { #region 日程单 if (p_modtype == BillModType.Contract) { var _entity = list.FirstOrDefault(); var _po = scpdb.TB_PO.SingleOrDefault(t => t.PoBillNum == _entity.订单编号/* && t.State == state*/ && t.Site == site && t.SubSite == subsite && t.VendId == _entity.供应商编号.ToUpper()); if (_po == null) { _po = new TB_PO { GUID = Guid.NewGuid(), PoBillNum = _entity.订单编号.ToUpper(), State = (int)PoState.Open, Site = site, SubSite = subsite, VendId = _entity.供应商编号.Trim().ToUpper() }; } _po.ErpBillNum = _entity.订单编号.Trim().ToUpper(); ; _po.ModType = (int)p_modtype; _po.Contacter = p_chineseName;// _entity.联系人; _po.Buyer = p_chineseName;// _entity.联系人; _po.Site = site.Trim().ToUpper(); _po.BuyerPhone = p_buyerPhone; _po.Remark = _entity.备注; _po.IsDeleted = false; _po.CreateTime = DateTime.Now; _po.CreateUser = p_creator; _po.BeginTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.EndTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.要求到货日期); _po.Pricelist = _entity.供应商编号.Trim().ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; _po.SubSite = subsite.Trim().ToUpper(); scpdb.TB_PO.AddOrUpdate(_po); list.ForEach((itm) => { TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL(); _PO_Detail.Currency = "CNY"; _PO_Detail.PoBillNum = _po.PoBillNum; _PO_Detail.PartCode = itm.零件号.Trim(); _PO_Detail.PoLine = int.Parse(itm.行号); _PO_Detail.PoUnit = itm.单位; _PO_Detail.CreateTime = DateTime.Now; _PO_Detail.CreateUser = p_creator; _PO_Detail.BeginTime = string.IsNullOrEmpty(itm.订单创建时间) ? DateTime.Now : DateTime.Parse(itm.订单创建时间); _PO_Detail.EndTime = string.IsNullOrEmpty(itm.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(itm.要求到货日期); _PO_Detail.PlanQty = decimal.Parse(itm.数量); _PO_Detail.IsDeleted = false; _PO_Detail.LocUnit = itm.单位; _PO_Detail.PoUnit = itm.单位; _PO_Detail.UnConv = 1; _PO_Detail.Remark = itm.备注; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号); _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.Site = site.Trim().ToUpper(); _PO_Detail.SubSite = subsite.Trim().ToUpper(); TS_UNI_API Ts = new TS_UNI_API(); Ts.InterfaceType = "PO"; Ts.TableName = "TS_UNI_API"; Ts.Batch = _entity.供应商编号; Ts.BillType = 702; Ts.SubBillType = 1; Ts.BillNum = _entity.订单编号; Ts.PartCode = _PO_Detail.PartCode; Ts.Qty = decimal.Parse(_entity.数量); Ts.State = 1; Ts.CreateOper = _entity.联系人; Ts.CreateTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); Ts.PutTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); Ts.VendId = _entity.供应商编号; Ts.PoUnit = _entity.单位; Ts.LocUnit = _entity.单位; Ts.ValidDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); Ts.ErpBillNum = _entity.订单编号; Ts.Buyer = _entity.采购员; Ts.BuyerPhone = _entity.采购员电话; Ts.Price = decimal.Parse(_entity.单价); Ts.Site = subsite.Trim().ToUpper(); Ts.Domain = site.Trim().ToUpper(); Ts.Extend1 = _entity.税率; Ts.Extend2 = _entity.备注; Ts.CreateOper = _entity.采购员; Ts.VendBatch = p_creator; Ts.ErpLineNum = _PO_Detail.PoLine; scpdb.TB_PO_DETAIL.AddOrUpdate(_PO_Detail); scpdb.TS_UNI_API.Add(Ts); }); _polist = _polist + _po.PoBillNum + ","; } #endregion #region 离散单 (离散单只增加不修改) if (p_modtype == BillModType.Non_Contract) { var _entity = list.FirstOrDefault(); TB_PO _po = new TB_PO(); _po.GUID = Guid.NewGuid(); _po.PoBillNum = _entity.订单编号; _po.State = (int)PoState.Open; _po.Site = site.Trim().ToUpper(); _po.SubSite = subsite.Trim().ToUpper(); _po.VendId = _entity.供应商编号.Trim().ToUpper(); _po.ErpBillNum = _po.PoBillNum; _po.ModType = (int)p_modtype; _po.Contacter = p_chineseName;// _entity.联系人; _po.Buyer = p_chineseName;// _entity.联系人; _po.BuyerPhone = p_buyerPhone; _po.Site = site.Trim().ToUpper(); _po.Remark = _entity.备注; _po.IsDeleted = false; _po.CreateTime = DateTime.Now; _po.CreateUser = p_creator; _po.BeginTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.EndTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.要求到货日期); _po.Pricelist = _entity.供应商编号.ToUpper() + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; scpdb.TB_PO.AddOrUpdate(_po); int _number = 1; list.ForEach((itm) => { TB_PO_DETAIL _PO_Detail = new TB_PO_DETAIL(); _PO_Detail.GUID = Guid.NewGuid(); _PO_Detail.PartCode = itm.零件号.Trim().ToUpper(); _PO_Detail.PoLine = int.Parse(itm.行号); _PO_Detail.PoBillNum = _po.PoBillNum; _PO_Detail.State = (int)PoState.Open; _PO_Detail.Site = site.Trim().ToUpper(); _PO_Detail.SubSite = subsite.Trim().ToUpper(); _PO_Detail.Currency = "CNY"; _PO_Detail.PoUnit = itm.单位; _PO_Detail.Remark = itm.备注; _PO_Detail.CreateTime = DateTime.Now; _PO_Detail.CreateUser = p_creator; _PO_Detail.BeginTime = string.IsNullOrEmpty(itm.订单创建时间) ? DateTime.Now : DateTime.Parse(itm.订单创建时间); _PO_Detail.EndTime = string.IsNullOrEmpty(itm.要求到货日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(itm.要求到货日期); _PO_Detail.PlanQty = decimal.Parse(itm.数量); _PO_Detail.IsDeleted = false; _PO_Detail.LocUnit = itm.单位; _PO_Detail.PoUnit = itm.单位; _PO_Detail.UnConv = 1; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.Workorderlot = string.IsNullOrEmpty(itm.加工单号) ? 0 : int.Parse(itm.加工单号); _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.TempQty = decimal.Parse(itm.数量); //_PO_Detail.Extend = itm.供应商编号; TS_UNI_API Ts = new TS_UNI_API(); Ts.InterfaceType = "PO"; Ts.TableName = "TS_UNI_API"; Ts.Batch = _entity.供应商编号; Ts.BillType = 702; Ts.SubBillType = 2; Ts.BillNum = _po.PoBillNum; Ts.PartCode = _PO_Detail.PartCode; Ts.Qty = _PO_Detail.PlanQty; Ts.State = 1; Ts.CreateOper = _entity.联系人; Ts.CreateTime = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); Ts.PutTime = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); Ts.VendId = _entity.供应商编号; Ts.PoUnit = _entity.单位; Ts.LocUnit = _entity.单位; Ts.ValidDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); Ts.Buyer = _entity.采购员; Ts.BuyerPhone = _entity.采购员电话; Ts.Price = _PO_Detail.Price; Ts.Site = subsite.Trim().ToUpper(); Ts.Domain = site.Trim().ToUpper(); Ts.Extend1 = _entity.税率; Ts.Extend2 = _entity.备注; Ts.CreateOper = _entity.采购员; Ts.VendBatch = p_creator; Ts.ErpBillNum = _po.PoBillNum; Ts.ErpLineNum = int.Parse(itm.行号); scpdb.TB_PO_DETAIL.AddOrUpdate(_PO_Detail); scpdb.TS_UNI_API.Add(Ts); _number++; }); _polist = _polist + _po.PoBillNum + ","; } #endregion } //var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() //{ // DataCount = 1, // TaskID = taskid, // TableName = "TED_PO_MSTR", // Site = subsite.Trim().ToUpper(), // Domain = site.Trim().ToUpper(), // CreateTime = p_time, // CreateUser = p_creator, // Creator = "SCP", //}); _num++; Thread.Sleep(10); } ); EntitiesFactory.SaveDb(scpdb); EntitiesFactory.SaveDb(db); scope.Complete(); _ret.State = ReturnStatus.Succeed; _ret.Result = true; _ret.Message = _polist; } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "InsterPo", e.Message); _ret.Result = false; _ret.Message = e.InnerException.Message; scope.Dispose(); } } return _ret; } public static ResultObject InsterPo(List p_order_list, string site, string p_creator, DateTime p_time, BillModType p_modtype, string subsite) { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); ResultObject _ret = new ResultObject(); try { var OrderList = p_order_list.GroupBy(p => p.订单编号).ToList(); OrderList.ForEach((p) => { Guid taskid = Guid.NewGuid(); var list = p.ToList(); if (list.Count > 0) { var _entity = list.FirstOrDefault(); // int state = (int)PoState.Open; var update_po = scpdb.TB_PO.FirstOrDefault(t => t.PoBillNum == _entity.订单编号/* && t.State == state*/ && t.Site == site && t.SubSite == subsite && t.VendId == _entity.供应商编号.ToUpper()); TED_PO_MSTR _po = new TED_PO_MSTR(); _po.GUID = Guid.NewGuid(); _po.PurchaseOrder = _entity.订单编号; _po.Supplier = _entity.供应商编号.ToUpper(); _po.Contact = _entity.联系人; _po.ShipTo = subsite.Trim().ToUpper();//发往 _po.OrderDate = string.IsNullOrEmpty(_entity.订单创建时间) ? DateTime.Now : DateTime.Parse(_entity.订单创建时间); _po.DueDate = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); _po.StartDate = string.IsNullOrEmpty(_entity.订单开始时间) ? DateTime.Now : DateTime.Parse(_entity.订单开始时间);//订单日期 _po.EndDate = string.IsNullOrEmpty(_entity.订单截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.订单截至日期); _po.MadeIn = ""; _po.Confirm = true; _po.Buyer = _entity.采购员; _po.BuyerPhone = _entity.采购员电话; _po.Status = (int)PoState.Open; if (p_modtype == BillModType.Contract) { _po.ScheduledOrder = true; } else { _po.ScheduledOrder = false; } _po.CreateUser = p_creator; _po.CreateTime = p_time; _po.Remark = _entity.备注; ; _po.TaskID = taskid; if (update_po != null) { _po.CommandType = "U"; } else { _po.CommandType = "A"; } _po.Domain = site.Trim().ToUpper(); _po.ModeType = ((int)p_modtype).ToString(); _po.Site = subsite.Trim().ToUpper(); _po.DataID = Guid.NewGuid(); _po.Pricelist = _entity.供应商编号 + subsite.Substring(1, 1) + subsite.Substring(3, 1); _po.Taxclass = _entity.税率; db.TED_PO_MSTR.Add(_po); list.ForEach((itm) => { int _poline = Int32.Parse(itm.行号); var update_po_detail = scpdb.TB_PO_DETAIL.FirstOrDefault(t => t.PartCode == itm.零件号 && t.PoLine == _poline && t.PoBillNum == itm.订单编号 /*&& t.State == state*/ && t.Site == site && t.SubSite == subsite); TED_PO_DET _PO_Detail = new TED_PO_DET(); _PO_Detail.GUID = Guid.NewGuid(); _PO_Detail.PurchaseOrder = itm.订单编号; _PO_Detail.Line = Int32.Parse(itm.行号); _PO_Detail.Currency = "CNY"; _PO_Detail.PoType = itm.订单类型; _PO_Detail.PartCode = itm.零件号.ToUpper(); _PO_Detail.Qty = decimal.Parse(itm.数量); _PO_Detail.QtyOpen = 0; _PO_Detail.PackQty = 1; _PO_Detail.Currency = itm.币种; _PO_Detail.Price = string.IsNullOrEmpty(itm.单价) ? 0 : decimal.Parse(itm.单价); _PO_Detail.PoUm = itm.单位; _PO_Detail.LocUm = itm.单位; _PO_Detail.Conv = 1; _PO_Detail.DueDate = string.IsNullOrEmpty(_entity.要求到货日期) ? DateTime.Now : DateTime.Parse(_entity.要求到货日期); _PO_Detail.Status = (int)PoState.Open; _PO_Detail.CreateTime = DateTime.Parse(itm.订单创建时间); _PO_Detail.StartDate = string.IsNullOrEmpty(_entity.零件开始时间) ? p_time : DateTime.Parse(_entity.零件开始时间); _PO_Detail.EndDate = string.IsNullOrEmpty(_entity.零件截至日期) ? DateTime.Now.AddYears(10) : DateTime.Parse(_entity.零件截至日期); _PO_Detail.CreateUser = p_creator; _PO_Detail.TaskID = taskid; if (update_po_detail != null) { _PO_Detail.CommandType = "U"; } else { _PO_Detail.CommandType = "A"; } _PO_Detail.DataID = Guid.NewGuid(); _PO_Detail.Domain = site.Trim().ToUpper(); _PO_Detail.Site = subsite.Trim().ToUpper(); _PO_Detail.Workorderlot = itm.加工单号; _PO_Detail.PoType = itm.订单类型; _PO_Detail.Operation = string.IsNullOrEmpty(itm.工序) ? 0 : int.Parse(itm.工序); _PO_Detail.Location = itm.库位; _PO_Detail.Firmdays = string.IsNullOrEmpty(itm.固定天数) ? 7 : int.Parse(itm.固定天数); _PO_Detail.Scheduledays = string.IsNullOrEmpty(itm.日程天数) ? 7 : int.Parse(itm.日程天数); _PO_Detail.Scheduleweeks = string.IsNullOrEmpty(itm.日程周数) ? 2 : int.Parse(itm.日程周数); _PO_Detail.Schedulemonth = string.IsNullOrEmpty(itm.日程月数) ? 1 : int.Parse(itm.日程月数); _PO_Detail.Supplieritem = itm.供应商零件; _PO_Detail.Dliverypatterncode = itm.发货样式; _PO_Detail.Deliverytimecode = itm.发货时间样式; _PO_Detail.Transportdays = string.IsNullOrEmpty(itm.运输周期) ? 0 : int.Parse(itm.运输周期); _PO_Detail.Pricelist = _entity.供应商编号 + subsite.Substring(1, 1) + subsite.Substring(3, 1); db.TED_POD_DET.Add(_PO_Detail); }); } var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() { DataCount = 1, TaskID = taskid, TableName = "TED_PO_MSTR", Site = subsite.Trim().ToUpper(), Domain = site.Trim().ToUpper(), CreateTime = p_time, CreateUser = p_creator, Creator = "SCP", }); }); if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = "数据更新失败!"; } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "InsterPo", e.Message); _ret.Result = false; _ret.Message = e.InnerException.Message; //throw e; } return _ret; } public static ResultObject UpdatePo(List p_po_list, string site, string p_creator, DateTime p_time, string subsite) { ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); ResultObject _ret = new ResultObject(); try { foreach (var _num in p_po_list) { Guid taskid = Guid.NewGuid(); TED_PO_MSTR item = new TED_PO_MSTR(); var _mstr = scpdb.TB_PO.FirstOrDefault(t => t.PoBillNum == _num && t.State == (int)PoState.Open); if (_mstr != null) { // var uid = oldpolist.Select(p => p.UID).Max(); // var _mstr = db.TED_PO_MSTR.FirstOrDefault(t => t.UID == uid); var oldpodetaillist = scpdb.TB_PO_DETAIL.Where(q => q.PoBillNum == _num && q.State == (int)PoState.Open).ToList(); item.CommandType = "U"; item.GUID = Guid.NewGuid(); item.DataID = _mstr.GUID; item.Status = (int)PoState.Close; item.TaskID = taskid; item.PurchaseOrder = _mstr.PoBillNum; item.Supplier = _mstr.VendId; item.Contact = _mstr.Buyer; item.ShipTo = _mstr.SubSite;//发往 item.OrderDate = _mstr.CreateTime;//订单日期 item.DueDate = Convert.ToDateTime(_mstr.EndTime); item.StartDate = _mstr.CreateTime;//订单日期 item.EndDate = Convert.ToDateTime(_mstr.EndTime); item.MadeIn = ""; item.Confirm = true; item.Buyer = _mstr.Buyer; item.BuyerPhone = _mstr.BuyerPhone; item.ScheduledOrder = _mstr.ModType == 1 ? true : false; item.CreateUser = _mstr.CreateUser; item.CreateTime = _mstr.CreateTime; item.Remark = "订单关闭"; item.Domain = _mstr.Site; item.ModeType = _mstr.ModType.ToString(); item.Site = _mstr.SubSite; item.Pricelist = _mstr.Pricelist; item.Taxclass = _mstr.Taxclass; db.TED_PO_MSTR.Add(item); if (oldpodetaillist.Count > 0) { foreach (var po_detail in oldpodetaillist) { TED_PO_DET _PO_Detail = new TED_PO_DET(); _PO_Detail.GUID = Guid.NewGuid(); _PO_Detail.PurchaseOrder = po_detail.PoBillNum; _PO_Detail.Line = po_detail.PoLine; _PO_Detail.Currency = po_detail.Currency; _PO_Detail.PoType = po_detail.PoType; _PO_Detail.PartCode = po_detail.PartCode.ToUpper(); _PO_Detail.Qty = po_detail.PlanQty; _PO_Detail.QtyOpen = po_detail.ShippedQty; _PO_Detail.PackQty = po_detail.PackQty; _PO_Detail.Currency = po_detail.Currency; _PO_Detail.Price = po_detail.Price; _PO_Detail.PoUm = po_detail.PoUnit; _PO_Detail.LocUm = po_detail.PoUnit; _PO_Detail.Conv = 1; _PO_Detail.Status = (int)PoState.Close; _PO_Detail.CreateTime = po_detail.CreateTime; _PO_Detail.StartDate = Convert.ToDateTime(po_detail.BeginTime); _PO_Detail.EndDate = Convert.ToDateTime(po_detail.EndTime); _PO_Detail.CreateUser = po_detail.CreateUser; _PO_Detail.TaskID = taskid; _PO_Detail.CommandType = "U"; _PO_Detail.DataID = po_detail.GUID; _PO_Detail.Domain = po_detail.Site; _PO_Detail.Site = po_detail.SubSite; _PO_Detail.Workorderlot = po_detail.Workorderlot.ToString(); _PO_Detail.PoType = po_detail.PoType; _PO_Detail.Operation = po_detail.Operation; _PO_Detail.Location = po_detail.Location; _PO_Detail.Firmdays = po_detail.Firmdays; _PO_Detail.Scheduledays = po_detail.Scheduledays; _PO_Detail.Scheduleweeks = po_detail.Scheduleweeks; _PO_Detail.Schedulemonth = po_detail.Schedulemonth; _PO_Detail.Supplieritem = po_detail.Supplieritem; _PO_Detail.Dliverypatterncode = po_detail.Dliverypatterncode; _PO_Detail.Deliverytimecode = po_detail.Deliverytimecode; _PO_Detail.Transportdays = po_detail.Transportdays; db.TED_POD_DET.Add(_PO_Detail); } } var ret = CREATE_TEA_TASK_SUB(db, true, new TEA_TASK_SUB() { DataCount = 1, TaskID = taskid, TableName = "TED_PO_MSTR", Site = subsite, Domain = site, CreateTime = p_time, CreateUser = p_creator, Creator = "SCP", }); } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "InsterPo", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.Message = "数据更新失败!"; } return _ret; } /// /// 作废发货单 /// /// /// /// /// public static ResultObject UpApAsn(ExchangeCenterContext db, ScpEntities scpdb, TEA_TASK_SUB p_entity) { ResultObject _ret = new ResultObject(); try { var _SCPAPASNlist = db.TED_SCRAPASN.Where(p => p.TaskID == p_entity.TaskID && string.IsNullOrEmpty(p.Remark)).ToList(); var Asnlist = new List(); var AsnDetailslist = new List(); foreach (var asn in _SCPAPASNlist) { TB_ASN b_ASN = new TB_ASN(); b_ASN = scpdb.TB_ASN.FirstOrDefault(q => q.SubSite == "BJ02" && q.AsnBillNum == asn.BillNum); b_ASN.Reason = asn.Reason; b_ASN.State = (int)AskState.Reject; b_ASN.IsDeleted = true; List asn_details = scpdb.TB_ASN_DETAIL.Where(q => q.AsnBillNum == asn.BillNum).ToList(); if (asn_details != null) { asn_details.ForEach(itm => { itm.IsDeleted = true; itm.State = (int)AskState.Reject; }); AsnDetailslist.AddRange(asn_details); } Asnlist.Add(b_ASN); asn.Remark = "SCPREAD"; } scpdb.TB_ASN.BulkUpdate(Asnlist); scpdb.TB_ASN_DETAIL.BulkUpdate(AsnDetailslist); db.TED_SCRAPASN.BulkUpdate(_SCPAPASNlist); _ret.State = ReturnStatus.Succeed; _ret.MessageList.Add(string.Format("更新表{0}任务ID{1}成功!", "TED_SCPAPASN", p_entity.TaskID)); } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TEA_TASK_SUB), "UpApAsn", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } } }