public bool AddCompleteOrderTaskAndDetails(CompleteOrderTaskInfo info, List <CompleteOrderTaskDetailsInfo> detailsList) { var taskId = Guid.NewGuid(); using (SqlConnection conn = Databases.GetSqlConnection(GlobalConfig.ERP_DB_NAME, false)) { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (var trans = conn.BeginTransaction()) { try { //添加完成订单任务 AddCompleteOrderTask(trans, taskId, info); //添加完成订单任务明细 AddCompleteOrderTaskDetails(trans, taskId, detailsList); //订单记录设置任务编号ID AddCompleteOrderTaskRecord(trans, taskId, detailsList.Select(w => w.OrderId).ToList()); trans.Commit(); } catch (SqlException ex) { trans.Rollback(); throw new ApplicationException(ex.Message); } } } return(true); }
private void AddCompleteOrderTask(SqlTransaction trans, Guid taskId, CompleteOrderTaskInfo info) { var strbSql = new StringBuilder(); strbSql.AppendLine(@" INSERT INTO [CompleteOrderTask]([ID],[CreateTime],[ExpressId],[WarehouseId],[TaskState],[TotalQuantity],[Operationer],[OperationId]) VALUES(@ID,GETDATE(),@ExpressId,@WarehouseId,@TaskState,@TotalQuantity,@Operationer,@OperationId) "); trans.Connection.Execute(strbSql.ToString(), new { ID = taskId, ExpressId = info.ExpressId, WarehouseId = info.WarehouseId, TaskState = (int)CompleteOrderTaskState.Wait, TotalQuantity = info.TotalQuantity, Operationer = info.Operationer, OperationId = info.OperationId, }, trans); }
public static void CreateTask(Guid warehouseId, Guid expressId, Guid operationId, string operationer, out string errorMsg) { errorMsg = string.Empty; var goodsOrderRecordList = DAL.CompleteOrderTask.Instance.GetWaitConsignmentedList(warehouseId, expressId).ToList(); if (!goodsOrderRecordList.Any()) { errorMsg = "目前没有待完成的订单"; } else { var completeOrderTaskInfo = new CompleteOrderTaskInfo { ID = Guid.NewGuid(), CreateTime = DateTime.Now, WarehouseId = warehouseId, ExpressId = expressId, OperationId = operationId, Operationer = operationer, StartTime = DateTime.Now, EndTime = DateTime.Now, TotalQuantity = goodsOrderRecordList.Count, TaskState = (int)CompleteOrderTaskState.Wait, Description = string.Empty }; var details = goodsOrderRecordList.Select(goodsOrderRecordInfo => new CompleteOrderTaskDetailsInfo { TaskId = completeOrderTaskInfo.ID, OrderId = goodsOrderRecordInfo.OrderId, OrderNo = goodsOrderRecordInfo.OrderNo, SaleFilialeId = goodsOrderRecordInfo.SaleFilialeId, SalePlatformId = goodsOrderRecordInfo.SalePlatformId, }).ToList(); var isSuccess = DAL.CompleteOrderTask.Instance.AddCompleteOrderTaskAndDetails(completeOrderTaskInfo, details); if (!isSuccess) { errorMsg = "生成任务繁忙,请稍后重试"; } } }