public DeliveryMoveResponse HandleDeliveryMoveRequest(DeliveryMoveRequest request) { SqlCommand com = new SqlCommand ($"select * from Delivery inner join Tranc on Delivery.TransactionId = Tranc.TransactionId where DeliverymanId={(int)request.DelivererId} and Delivery.TransactionId={(int)request.GUID}" , Connect.Connection); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds, "DeliveryMove"); if (ds.Tables[0].Rows.Count == 0) { return(new DeliveryMoveResponse() { Check = 3 //表示其它错误 }); } int secureId; int quantity = (int)ds.Tables[0].Rows[0]["MaterialQuantity"]; int materialId = (int)ds.Tables[0].Rows[0]["MaterialId"]; if ((DeliveryState)ds.Tables[0].Rows[0]["DeliveryState"] == DeliveryState.Waiting) { if ((TransactionType)ds.Tables[0].Rows[0]["TransactionType"] == TransactionType.DONATION) { secureId = (int)ds.Tables[0].Rows[0]["UserId"]; if (request.SecureId == secureId) { SqlCommand cmd2 = new SqlCommand( $"update Delivery " + $"set DeliveryState = {(int)DeliveryState.Processing}" + $", DeliveryBeginDate = '{DateTime.Now}'" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd2.ExecuteNonQuery(); SqlCommand cmd3 = new SqlCommand( $"update Tranc " + $"set TransactionState = {(int)ApplicationState.Delivering}" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd3.ExecuteNonQuery(); return(new DeliveryMoveResponse() { Check = 0 //表示成功 }); } } else { secureId = (int)ds.Tables[0].Rows[0]["DeliveryAdminId"]; if (request.SecureId == secureId) { SqlCommand cmd = new SqlCommand( $"update Materials " + $"set MaterialQuantity = MaterialQuantity - {quantity}" + $"where MaterialId = {materialId}", Connect.Connection); cmd.ExecuteNonQuery(); SqlCommand cmd2 = new SqlCommand( $"update Delivery " + $"set DeliveryState = {(int)DeliveryState.Processing}" + $", DeliveryBeginDate = '{DateTime.Now}'" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd2.ExecuteNonQuery(); SqlCommand cmd3 = new SqlCommand( $"update Tranc " + $"set TransactionState = {(int)ApplicationState.Delivering}" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd3.ExecuteNonQuery(); return(new DeliveryMoveResponse() { Check = 0 //表示成功 }); } } } else if ((DeliveryState)ds.Tables[0].Rows[0]["DeliveryState"] == DeliveryState.Processing) { if ((TransactionType)ds.Tables[0].Rows[0]["TransactionType"] == TransactionType.DONATION) { secureId = (int)ds.Tables[0].Rows[0]["DeliveryAdminId"]; if (request.SecureId == secureId) { SqlCommand cmd = new SqlCommand( $"update Materials " + $"set MaterialQuantity = MaterialQuantity + {quantity}" + $"where MaterialId = {materialId}", Connect.Connection); cmd.ExecuteNonQuery(); SqlCommand cmd2 = new SqlCommand( $"update Delivery " + $"set DeliveryState = {(int)DeliveryState.Finished}" + $", DeliveryEndDate = '{DateTime.Now}'" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd2.ExecuteNonQuery(); SqlCommand cmd3 = new SqlCommand( $"update Tranc " + $"set TransactionState = {(int)ApplicationState.Received}" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd3.ExecuteNonQuery(); return(new DeliveryMoveResponse() { Check = 0 //表示成功 }); } } else { secureId = (int)ds.Tables[0].Rows[0]["UserId"]; SqlCommand cmd2 = new SqlCommand( $"update Delivery " + $"set DeliveryState = {(int)DeliveryState.Finished}" + $", DeliveryEndDate = '{DateTime.Now}'" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd2.ExecuteNonQuery(); SqlCommand cmd3 = new SqlCommand( $"update Tranc " + $"set TransactionState = {(int)ApplicationState.Received}" + $"where TransactionId = {request.GUID}", Connect.Connection); cmd3.ExecuteNonQuery(); if (request.SecureId == secureId) { return(new DeliveryMoveResponse() { Check = 0 //表示成功 }); } } } else { return(new DeliveryMoveResponse() { Check = 2 //表示订单状态非Waiting或Processing }); } return(new DeliveryMoveResponse() { Check = 1 //表示验证ID错误 }); }
public static DeliveryMoveResponse HandleDeliveryMoveRequest(DeliveryMoveRequest request) { //TODO:数据库 return(new DeliveryMoveResponse()); }