LoadBatch |
This topic describes the ShipExec Server LoadBatch Business Rule
A business rule hook that loads a batch
public BatchRequest LoadBatch(string batchReference, SerializableDictionary userParams) { // string connectionString = BusinessRuleSettings[0].Value; DataSet batchItems = new DataSet(); BatchRequest batchReq = new BatchRequest(); using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand()) { cmd.CommandText = "SPGetBatchItem"; cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Batch", batchReference.Trim()); conn.Open(); System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(cmd); adapter.Fill(batchItems); conn.Close(); } } DataTable dt = batchItems.Tables[0]; if (dt.Rows.Count > 0) { batchReq.BatchItems = new List<BatchItem>(); long seq = 1; foreach (DataRow row in dt.Rows) { string order = row.Field<string>("BatchOrder").Trim(); ShipmentRequest shipmentRequest = new ShipmentRequest(); shipmentRequest.PackageDefaults = new Package(); shipmentRequest.Packages = new List<PackageRequest>(); shipmentRequest.Packages.Add(new PackageRequest()); shipmentRequest.PackageDefaults.Shipdate = new Date(DateTime.Now); shipmentRequest = Load(order, shipmentRequest, userParams); BatchItem batchItem = new BatchItem() { BatchItemReference = order, BatchReference = batchReference, CreateDate = new Date(DateTime.Now), //Id = 1, //IsShipped = false, //Packages = new List<Package>(), //ProcessedDate = new Date(DateTime.Now), SequenceNumber = seq, ShipmentRequest = shipmentRequest }; seq++; batchReq.BatchItems.Add(batchItem); if (batchReq.BatchReference == null || batchReq.BatchReference.Trim() == "") batchReq.BatchReference = row.Field<string>("BatchName").Trim() + " - " + DateTime.Now.ToLocalTime().ToString(); } } return batchReq; }