// Custom object hydration /// <summary> /// Customs the shipment fill. /// </summary> /// <param name="shipment">The shipment.</param> /// <param name="dataReader">The data reader.</param> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> public static void CustomShipmentFill(TDCShipment shipment, IDataReader dataReader, bool fullyPopulate) { // See if we fully populate this entity if (fullyPopulate) { // Populate shipment lines List <TDCShipmentLine> tdcLines = TDCShipmentLineController.GetLines(shipment.Id); // The total number of lines int TotalLines = tdcLines.Count; // Clear existing lines shipment.ShipmentLines.Clear(); // Add new lines foreach (TDCShipmentLine tdcLine in tdcLines) { // Specify any derived columns that we need tdcLine.TotalLines = TotalLines; // Add the line shipment.ShipmentLines.Add(tdcLine); } } // Populate opco contact shipment.OpCoContact.Email = dataReader["OpCoContactEmail"].ToString(); shipment.OpCoContact.Name = dataReader["OpCoContactName"].ToString(); // Populate shipment contact shipment.ShipmentContact.Email = dataReader["ShipmentContactEmail"].ToString(); shipment.ShipmentContact.Name = dataReader["ShipmentContactName"].ToString(); shipment.ShipmentContact.TelephoneNumber = dataReader["ShipmentContactTel"].ToString(); // Populate shipment address shipment.ShipmentAddress.Line1 = dataReader["ShipmentAddress1"].ToString(); shipment.ShipmentAddress.Line2 = dataReader["ShipmentAddress2"].ToString(); shipment.ShipmentAddress.Line3 = dataReader["ShipmentAddress3"].ToString(); shipment.ShipmentAddress.Line4 = dataReader["ShipmentAddress4"].ToString(); shipment.ShipmentAddress.Line5 = dataReader["ShipmentAddress5"].ToString(); shipment.ShipmentAddress.PostCode = dataReader["ShipmentPostCode"].ToString(); // Populate customer address shipment.CustomerAddress.Line1 = dataReader["CustomerAddress1"].ToString(); shipment.CustomerAddress.Line2 = dataReader["CustomerAddress2"].ToString(); shipment.CustomerAddress.Line3 = dataReader["CustomerAddress3"].ToString(); shipment.CustomerAddress.Line4 = dataReader["CustomerAddress4"].ToString(); shipment.CustomerAddress.Line5 = dataReader["CustomerAddress5"].ToString(); shipment.CustomerAddress.PostCode = dataReader["CustomerPostCode"].ToString(); // Populate paf address shipment.PAFAddress.DPS = dataReader["PAFDPS"].ToString(); shipment.PAFAddress.Easting = Convert.ToInt32(dataReader["PAFEasting"].ToString()); shipment.PAFAddress.Northing = Convert.ToInt32(dataReader["PAFNorthing"].ToString()); shipment.PAFAddress.Line1 = dataReader["PAFAddress1"].ToString(); shipment.PAFAddress.Line2 = dataReader["PAFAddress2"].ToString(); shipment.PAFAddress.Line3 = dataReader["PAFAddress3"].ToString(); shipment.PAFAddress.Line4 = dataReader["PAFAddress4"].ToString(); shipment.PAFAddress.Line5 = dataReader["PAFAddress5"].ToString(); shipment.PAFAddress.PostCode = dataReader["PAFPostCode"].ToString(); shipment.PAFAddress.Location = Convert.ToInt32(dataReader["PAFLocation"].ToString()); shipment.PAFAddress.Match = dataReader["PAFMatch"].ToString(); //shipment.PAFAddress.Status = (PAFAddress.PAFStatusEnum)Enum.Parse(typeof(PAFAddress.PAFStatusEnum), dataReader["PAFStatus"].ToString()); }
public void CalculateDeliveryDate() { using (TransactionScope scope = new TransactionScope()) { TDCShipment tdcShipment = new TDCShipment(); //set-up two warehouses Warehouse stockWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(stockWarehouse); tdcShipment.StockWarehouseCode = stockWarehouse.Code; Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(deliveryWarehouse); tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code; //set-up trunker days TrunkerDay trunkerDay = new TrunkerDay(); trunkerDay.Days = 3; trunkerDay.SourceWarehouseId = tdcShipment.StockWarehouse.Id; trunkerDay.DestinationWarehouseId = tdcShipment.DeliveryWarehouse.Id; trunkerDay.UpdatedBy = "me"; trunkerDay.Id = TrunkerDaysController.SaveTrunkerDay(trunkerDay); tdcShipment.RequiredShipmentDate = new DateTime(2006, 07, 24); tdcShipment.OpCoCode = "HSP"; tdcShipment.StockWarehouseCode = tdcShipment.StockWarehouse.Code; tdcShipment.DeliveryWarehouseCode = tdcShipment.DeliveryWarehouse.Code; tdcShipment.CalculateDeliveryDate(); Assert.IsTrue(tdcShipment.EstimatedDeliveryDate == new DateTime(2006, 07, 27)); } }
public void CalculateDeliveryDateSameWarehouseSameDay() { using (TransactionScope scope = new TransactionScope()) { //set-up two warehouses TDCShipment tdcShipment = new TDCShipment(); Warehouse stockWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(stockWarehouse); tdcShipment.StockWarehouseCode = stockWarehouse.Code; tdcShipment.DeliveryWarehouseCode = stockWarehouse.Code; tdcShipment.RequiredShipmentDate = new DateTime(2006, 07, 24); tdcShipment.OpCoCode = "HSP"; Route route = RouteTests.PopulateNewItem(); route.IsNextDay = false; route.IsSameDay = true; RouteTests.SaveItem(route); tdcShipment.RouteCode = route.Code; tdcShipment.CalculateDeliveryDate(); Assert.IsTrue(tdcShipment.EstimatedDeliveryDate == new DateTime(2006, 07, 24)); } }
protected void discoveryShipments_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Get the shipment we're bound to TDCShipment shipment = (TDCShipment)e.Item.DataItem; // Find the TDC shipment details button and hide it if we dont't have permission e.Item.FindControl("btnTDCShipmentDetails").Visible = (( shipment.Type == Shipment.TypeEnum.WHS && DiscoveryPage.HasRule( "Shipment: View Warehouse Order Detail", Context.User) ) || ( shipment.Type == Shipment.TypeEnum.ADH && DiscoveryPage.HasRule( "Shipment: View Ad-Hoc Order Detail", Context.User) ) || ( shipment.Type == Shipment.TypeEnum.OPCO && DiscoveryPage.HasRule( "Shipment: View TDC Shipment Detail", Context.User) ) ); // Find the OpCo shipment details button and hide it if we dont't have permission e.Item.FindControl("btnOpCoShipmentDetail").Visible = (( shipment.Type == Shipment.TypeEnum.OPCO && DiscoveryPage.HasRule( "Shipment: View OpCo Shipment Detail", Context.User) )); // See if we have permission to print (also it has a status other than not mapped) e.Item.FindControl("btnPrintTransConv").Visible = (DiscoveryPage.HasRule("Shipment: Print Orders", Context.User) && shipment.IsTransferOrConversion && shipment.Status != Shipment.StatusEnum.Mapped); e.Item.FindControl("btnPrintDelColl").Visible = (DiscoveryPage.HasRule("Shipment: Print Orders", Context.User) && shipment.Status != Shipment.StatusEnum.Mapped); // Se if we can view the audit messages e.Item.FindControl("btnAuditDetail").Visible = (DiscoveryPage.HasRule("Admin: View Message Audits", Context.User)); // If we've been routed, see if the estimated delivery date is outside the required window if (shipment.IsEstimatedDeliveryLate) { // Change the header style (e.Item.FindControl("panelHeader") as Panel).CssClass = "shipmentHeaderEstLate"; } else if (shipment.IsActualDeliveryLate) { // Change the header style (e.Item.FindControl("panelHeader") as Panel).CssClass = "shipmentHeaderActLate"; } else if (shipment.IsTransferOrConversion) { // If non of the above, see if we're a conversion (e.Item.FindControl("panelHeader") as Panel).CssClass = "shipmentHeaderTransConv"; } } }
/// <summary> /// Updates the shipment status if business rules allow it. /// </summary> /// <param name="shipmentToUpdate">The shipment to update.</param> /// <param name="newStatus">The new status.</param> /// <param name="updatedBy">The updated by.</param> /// <returns></returns> public static bool UpdateShipmentStatus(TDCShipment shipmentToUpdate, Shipment.StatusEnum newStatus, string updatedBy) { bool success = false; try { bool update = false; switch (newStatus) { case Shipment.StatusEnum.Mapped: { if (shipmentToUpdate.Status == Shipment.StatusEnum.Routing) { update = true; } break; } case Shipment.StatusEnum.Routing: { if (shipmentToUpdate.Status == Shipment.StatusEnum.Mapped) { update = true; } break; } default: { throw new Exception( string.Format("Cannot change status from {0} to {1}, it breaks business rules", shipmentToUpdate.Status.ToString(), newStatus.ToString())); } } if (update) { // Update the status of the shipment in the db success = DataAccessProvider.Instance().UpdateTDCShipmentStatus(shipmentToUpdate, newStatus, updatedBy); if (!success) { throw new Exception("Failed to Update Status."); } } } catch (Exception ex) { // Log an throw if configured to do so if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } return(success); }
protected void btnSplitConfirm_Click(object sender, EventArgs e) { try { // Load the shipment we need to split Discovery.BusinessObjects.TDCShipment tdcShipment = TDCShipmentController.GetShipment(Convert.ToInt32(Request.QueryString["Id"])); // Reset the split shipment splitShipment = null; // Get the lines and quantities, etc and split the shipment splitShipment = tdcShipment.SplitShipment( GetLineSplits(), AlterSourceQuantities, AlterWeightsAndVolumes, Page.User.Identity.Name); // See if we've got something to do if (null != splitShipment) { // Re-bind the data dataSourceShipmentLines.DataBind(); // Update the UI if (null != SaveComplete) { // Notify others that we've split the shipment SaveComplete(this, new EventArgs()); } // Display message ((DiscoveryPage)Page).DisplayMessage(String.Format("Shipment {0}-{1} was split creating shipment <a href=\"TDCShipment.aspx?Id={4}\">{2}-{3}</a>.", tdcShipment.ShipmentNumber, tdcShipment.DespatchNumber, splitShipment.ShipmentNumber, splitShipment.DespatchNumber, splitShipment.Id), DiscoveryMessageType.Success); } else { // Display message ((DiscoveryPage)Page).DisplayMessage("The shipment was <b>not</b> split as no quantities greater than 0 (zero) were specified.", DiscoveryMessageType.Information); } } catch (Exception ex) { // Display message ((DiscoveryPage)Page).DisplayMessage(String.Concat("There was a problem splitting the shipment. ", ex.Message), DiscoveryMessageType.Error); // We failed to split the shipment splitShipment = null; } }
public void CalculateDeliveryDateWithWeekend() { using (TransactionScope scope = new TransactionScope()) { //set-up two warehouses TDCShipment tdcShipment = new TDCShipment(); Warehouse stockWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(stockWarehouse); tdcShipment.StockWarehouseCode = stockWarehouse.Code; Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(deliveryWarehouse); tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code; //set-up non working days //saturday NonWorkingDay nonWorkingDay = new NonWorkingDay(); nonWorkingDay.NonWorkingDate = new DateTime(2006, 07, 29); nonWorkingDay.Description = "sat"; nonWorkingDay.UpdatedBy = "me"; nonWorkingDay.WarehouseId = tdcShipment.DeliveryWarehouse.Id; NonWorkingDayController.SaveNonWorkingDay(nonWorkingDay); //sunday nonWorkingDay = new NonWorkingDay(); nonWorkingDay.NonWorkingDate = new DateTime(2006, 07, 30); nonWorkingDay.Description = "sun"; nonWorkingDay.UpdatedBy = "me"; nonWorkingDay.WarehouseId = tdcShipment.DeliveryWarehouse.Id; NonWorkingDayController.SaveNonWorkingDay(nonWorkingDay); //set-up trunker days TrunkerDay trunkerDay = new TrunkerDay(); trunkerDay.Days = 3; trunkerDay.SourceWarehouseId = tdcShipment.StockWarehouse.Id; trunkerDay.DestinationWarehouseId = tdcShipment.DeliveryWarehouse.Id; trunkerDay.UpdatedBy = "me"; trunkerDay.Id = TrunkerDaysController.SaveTrunkerDay(trunkerDay); tdcShipment.RequiredShipmentDate = new DateTime(2006, 07, 26); tdcShipment.OpCoCode = "HSP"; tdcShipment.StockWarehouseCode = tdcShipment.StockWarehouse.Code; tdcShipment.DeliveryWarehouseCode = tdcShipment.DeliveryWarehouse.Code; tdcShipment.CalculateDeliveryDate(); Assert.IsTrue(tdcShipment.EstimatedDeliveryDate == new DateTime(2006, 07, 31)); } }
/// <summary> /// Prints the specified shipment. /// </summary> /// <param name="shipment">The shipment.</param> /// <param name="numberOfCopies">The number of copies.</param> public static void Print( TDCShipment shipment, int numberOfCopies, TDCShipment.ReportTypeEnum reportType) { // Print the shipment TDCShipmentPrintable printableShipment = new TDCShipmentPrintable(); // Map this shipment to a printable one, we could have gone off the the DB Mapper.Map(shipment, printableShipment, "NA", "NA", null, null); // Print the shipment Print(printableShipment, numberOfCopies, reportType); }
/// <summary> /// Saves the shipment. /// </summary> /// <param name="shipment">The shipment.</param> /// <returns></returns> public static int SaveShipment(TDCShipment shipment) { try { // Make sure the shipment is valid if (shipment.IsValid) { // Save the shipment to the db and update the id, this will update the shipment lines if required shipment.Id = DataAccessProvider.Instance().SaveTDCShipment(shipment); // Get the checksum for the entity FrameworkController.GetChecksum(shipment, "Shipment"); // Save the shipment lines to the db foreach (TDCShipmentLine tdcShipmentLine in shipment.ShipmentLines) { // Save the shipment line and update the shipment line id if required tdcShipmentLine.Id = TDCShipmentLineController.SaveLine(tdcShipmentLine); } } else { // Entity is not valid throw new InValidBusinessObjectException(shipment); } } catch (Exception ex) { // Generate a new exception ex = new Exception( string.Format("Failed to save TDC shipment {0} - {1} for OpCo {2}. {3}", shipment.ShipmentNumber, shipment.DespatchNumber, shipment.OpCoCode, ex.Message)); // Log an throw if configured to do so if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw ex; } // We failed to save the shipment return(-1); } // Done return(shipment.Id); }
/// <summary> /// Saves the commander orders. /// </summary> /// <param name="requestMessage">The request message.</param> /// <returns></returns> private SubscriberStatusEnum SaveCommanderOrders(RequestMessage requestMessage) { foreach (CommanderSalesOrder salesOrder in salesOrders) { //check to see if a commander order already exists for this order reference CommanderSalesOrder previousRecord = CommanderController.GetSalesOrder(salesOrder.OrderReference, false); if (previousRecord != null) { //check to see if the related shipment exists and if it has been sent to the warehouse yet TDCShipment relatedShipment = TDCShipmentController.GetShipment(requestMessage.SourceSystem, previousRecord.OrderReference, "NA"); if (relatedShipment != null) { if (Null.NullDate != relatedShipment.SentToWMS) { ////log //LogEntry logEntry=new LogEntry(); //logEntry.Message = "blah"; //Logger.Write(logEntry); // throw new Exception("This message has already been sent to the warehouse."); return(SubscriberStatusEnum.Processed); } } salesOrder.Id = previousRecord.Id; foreach (CommanderSalesOrderLine commanderSalesOrderLine in salesOrder.Lines) { commanderSalesOrderLine.CommanderSalesOrderId = previousRecord.Id; } } //save salesOrder and lines try { int savedId = CommanderController.SaveSalesOrder(salesOrder, true); } catch (InValidBusinessObjectException ex) { //log exception } } return(SubscriberStatusEnum.Processed); }
protected void Remove_Click(object sender, EventArgs e) { List <TDCShipment> shipmentsToRemoveFromRouting = new List <TDCShipment>(); foreach (int shipmentId in ShipmentIdsToRemoveFromRouting) { TDCShipment tdcShipment = new TDCShipment(); tdcShipment.Id = shipmentId; tdcShipment.Status = Shipment.StatusEnum.Routing; shipmentsToRemoveFromRouting.Add(tdcShipment); } if (RemoveItemsFromRouting(shipmentsToRemoveFromRouting)) { GridViewShipmentsToRefine.DataBind(); GridViewShipmentsToRefine.PageIndex = 0; } }
static internal TDCShipment PopulateItem() { TDCShipment tdcShipment = new TDCShipment(); OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem(); try { tdcShipment.OpCoShipmentId = OpCoShipmentController.SaveShipment(opCoShipment); } catch (InValidBusinessObjectException e) { Console.Write(e.ValidatableObject.ValidationMessages); } tdcShipment.OpCoCode = opCoShipment.OpCoCode; tdcShipment.OpCoSequenceNumber = 1; tdcShipment.OpCoContact.Email = "Email"; tdcShipment.OpCoContact.Name = "Name"; tdcShipment.DespatchNumber = "Number"; tdcShipment.RequiredShipmentDate = DateTime.Now; tdcShipment.CustomerNumber = "CustNo"; tdcShipment.CustomerName = "CustomerName"; tdcShipment.CustomerReference = "ref"; tdcShipment.CustomerAddress.Line1 = "Line1"; tdcShipment.CustomerAddress.PostCode = "NN8 1NB"; tdcShipment.ShipmentNumber = "ShipNo"; tdcShipment.ShipmentName = "ShipmentName"; tdcShipment.ShipmentAddress.Line1 = "Line1"; tdcShipment.ShipmentAddress.PostCode = "NN8 1NB"; tdcShipment.SalesBranchCode = "BranchCode"; tdcShipment.AfterTime = "11:11"; tdcShipment.BeforeTime = "10:10"; tdcShipment.TailLiftRequired = false; tdcShipment.CheckInTime = 1; tdcShipment.DivisionCode = "Div"; tdcShipment.GeneratedDateTime = DateTime.Now; tdcShipment.Status = Shipment.StatusEnum.Mapped; tdcShipment.IsRecurring = false; tdcShipment.IsValidAddress = false; tdcShipment.PAFAddress.Line1 = "Line1"; tdcShipment.PAFAddress.PostCode = "PostCode"; tdcShipment.UpdatedBy = "UpdatedBy"; tdcShipment.Instructions = "Instructions"; tdcShipment.VehicleMaxWeight = (decimal)1.1; OpCoDivision division = OpcoDivisionTests.PopulateNewItem(); OpcoDivisionTests.SaveItem(division); tdcShipment.DivisionCode = division.Code; Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(deliveryWarehouse); tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code; Warehouse stockWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(stockWarehouse); tdcShipment.StockWarehouseCode = stockWarehouse.Code; Route route = RouteTests.PopulateNewItem(); RouteTests.SaveItem(route); tdcShipment.RouteCode = route.Code; TransactionType transactionType = TransactionTypeTests.PopulateNewItem(); TransactionTypeTests.SaveItem(transactionType); tdcShipment.TransactionTypeCode = transactionType.Code; TransactionSubType transactionSubType = TransactionSubTypeTests.PopulateNewItem(); TransactionSubTypeTests.SaveItem(transactionSubType); tdcShipment.TransactionSubTypeCode = transactionSubType.Code; return(tdcShipment); }
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e) { try { if (e.CurrentStepIndex == (int)StepsEnum.Define_Criteria && e.NextStepIndex == (int)StepsEnum.Refine_Shipments) { if (ListBoxRegions.SelectedValue == "") { DisplayMessage("Please Select a Region."); RoutingHistoryId = null; e.Cancel = true; return; } else { try { RoutingHistoryId = RoutingController.SetOptrakLocks(User.Identity.Name, ListBoxRegions.SelectedValue, (RoutingController.PeriodEnum)RadioButtonListPeriod.SelectedIndex); if (RoutingHistoryId == -2) { //there are no shipments matching the criteria to lock so display message to user DisplayMessage("No shipments were found to Route."); RoutingHistoryId = null; e.Cancel = true; return; } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, "User Interface"); } if (RoutingHistoryId == null) { DisplayMessage( "There was a problem locking the Shipments which match the specified criteria for Routing.", DiscoveryMessageType.Error); e.Cancel = true; } else { GridViewShipmentsToRefine.Sort("ShipmentName,pafpostcode,estimateddeliverydate", SortDirection.Ascending); } } } else if (e.CurrentStepIndex == (int)StepsEnum.Refine_Shipments && e.NextStepIndex == (int)StepsEnum.Merge_Delivery_Points) { List <TDCShipment> shipmentsToRemoveFromRouting = new List <TDCShipment>(); foreach (int shipmentId in ShipmentIdsToRemoveFromRouting) { TDCShipment tdcShipment = new TDCShipment(); tdcShipment.Id = shipmentId; tdcShipment.Status = Shipment.StatusEnum.Routing; shipmentsToRemoveFromRouting.Add(tdcShipment); } e.Cancel = !RemoveItemsFromRouting(shipmentsToRemoveFromRouting); if (!e.Cancel) { //merge their delivery points using Customer Name and PAF postcode bool mergeWorked = false; try { mergeWorked = RoutingController.MergeDeliveryPointsAutomatically(RoutingHistoryId.Value); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, "User Interface"); } if (!mergeWorked) { DisplayMessage("Merging of Delivery points failed."); e.Cancel = true; } MultiView1.ActiveViewIndex = 0; GridViewMergedPoints.DataBind(); } } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "User Interface")) { DisplayMessage(ex); } } }
/// <summary> /// Deletes the shipment. /// </summary> /// <param name="shipment">The TDC shipment.</param> /// <returns></returns> public static bool DeleteShipment(TDCShipment shipment) { return(DeleteShipment(shipment.Id)); }
public void Map() { using (TransactionScope scope = new TransactionScope()) { if (MappingController.DeleteAllMappings()) { if (MappingController.DeleteAllMappingSystems()) { if (MappingController.DeleteAllMappingPropertyAssociations()) { if (MappingController.DeleteAllMappingClassAssociations()) { //add a mapping for route code Mapping mapping; mapping = PopulateMappingItem(); mapping.SourceValue = "OpcoValue"; mapping.DestinationValue = "TDCValue"; MappingController.SaveMapping(mapping); //set up source object to map to destination OpCoShipment sourceObject = OpcoShipmentTests.PopulateNewItem(); sourceObject.RouteCode = mapping.SourceValue; //set up a new instance of a TDC shipment to map the new values into TDCShipment destinationObject = new TDCShipment(); //perform the mapping MappingController.Map(sourceObject, destinationObject, mapping.SourceSystem.Name, mapping.DestinationSystem.Name, DoLines); Assert.IsTrue ( destinationObject.GetType().GetProperty(mapping.MappingPropertyAssociation.DestinationProperty). GetValue(destinationObject, null).Equals( mapping.DestinationValue) && ((sourceObject.ShipmentLines == null || sourceObject.ShipmentLines.Count == 0) || destinationObject.ShipmentLines.Count > 0) && ((destinationObject.ShipmentLines == null || destinationObject.ShipmentLines.Count == 0) || destinationObject.ShipmentLines[0] is TDCShipmentLine) && ((sourceObject.ShipmentLines == null || sourceObject.ShipmentLines.Count == 0) || sourceObject.ShipmentLines[0].ConversionQuantity == destinationObject.ShipmentLines[0].ConversionQuantity) && sourceObject.CustomerAddress != null && sourceObject.OpCoContact != null && sourceObject.AfterTime == destinationObject.AfterTime && sourceObject.BeforeTime == destinationObject.BeforeTime && sourceObject.CheckInTime == destinationObject.CheckInTime && sourceObject.CustomerAddress.Line1 == destinationObject.CustomerAddress.Line1 && sourceObject.CustomerName == destinationObject.CustomerName && sourceObject.CustomerNumber == destinationObject.CustomerNumber && sourceObject.CustomerReference == destinationObject.CustomerReference && sourceObject.DeliveryWarehouseCode == destinationObject.DeliveryWarehouseCode && sourceObject.DespatchNumber == destinationObject.DespatchNumber && sourceObject.DivisionCode == destinationObject.DivisionCode && sourceObject.GeneratedDateTime == destinationObject.GeneratedDateTime && sourceObject.Instructions == destinationObject.Instructions && sourceObject.OpCoCode == destinationObject.OpCoCode && sourceObject.OpCoContact.Email == destinationObject.OpCoContact.Email && sourceObject.OpCoHeld == destinationObject.OpCoHeld && sourceObject.OpCoSequenceNumber == destinationObject.OpCoSequenceNumber && sourceObject.RequiredShipmentDate == destinationObject.RequiredShipmentDate && // sourceObject.RouteCode == destinationObject.RouteCode && sourceObject.SalesBranchCode == destinationObject.SalesBranchCode && sourceObject.ShipmentName == destinationObject.ShipmentName && sourceObject.ShipmentNumber == destinationObject.ShipmentNumber && sourceObject.Status == destinationObject.Status && sourceObject.StockWarehouseCode == destinationObject.StockWarehouseCode && sourceObject.TailLiftRequired == destinationObject.TailLiftRequired && sourceObject.TotalLineQuantity == destinationObject.TotalLineQuantity && sourceObject.TransactionTypeCode == destinationObject.TransactionTypeCode && sourceObject.VehicleMaxWeight == destinationObject.VehicleMaxWeight ); } } } } } }
/// <summary> /// Processes the request. /// </summary> /// <param name="requestMessage">The request message.</param> public override void ProcessRequest(RequestMessage requestMessage) { try { // Get the opco shipment from the request processor if (!RequestProcessor.RequestDictionary.ContainsKey("OpCoShipment") || RequestProcessor.RequestDictionary["OpCoShipment"] == null) { // Failed to retrieve the opco shipment from the processor throw new Exception("Attempting to map an Op Co Shipment but it was not found in the Request Processor. Make sure that the shipment parser has been subscribed before the shipment mapper."); } // Get the cached opco shipment from the processor opCoShipment = (OpCoShipment)RequestProcessor.RequestDictionary["OpCoShipment"]; // Get the audit entry from the processor if we have one (optional) if (RequestProcessor.RequestDictionary.ContainsKey("AuditEntry") && RequestProcessor.RequestDictionary["AuditEntry"] != null) { // Get the cached audit entry from the processor auditEntry = (MessageAuditEntry)RequestProcessor.RequestDictionary["AuditEntry"]; } // ***************************************************************** // ** SEE IF WE HAVE AN EXISTING OPCO SHIPMENT // ***************************************************************** // See if we already have the shipment in the db existingOpCoShipment = OpCoShipmentController.GetShipment( opCoShipment.OpCoCode, opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber); // Did we find an existing opco shipment if (null != existingOpCoShipment) { // We've found the shipment, make sure that our sequence number is later if (existingOpCoShipment.OpCoSequenceNumber >= opCoShipment.OpCoSequenceNumber) { // Consume the message as it's old Status = SubscriberStatusEnum.Processed; // Log that the shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Format("Unable to update existing opco shipment {0} - {1} for for opco {2}. The request sequence number is {3} but sequence {4} has already been processed.", opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber, opCoShipment.OpCoCode, opCoShipment.OpCoSequenceNumber, existingOpCoShipment.OpCoSequenceNumber), "Request Management", 0, 0, TraceEventType.Information, "Request Management", null); // Write to the log Logger.Write(logEntry); // done return; } else { // See if we need to update the tdc shipment if (existingOpCoShipment.Status == Shipment.StatusEnum.Mapped) { // ***************************************************************** // ** SEE IF WE HAVE AN EXISTING TDC SHIPMENT // ***************************************************************** // Get the existing tdc shipment existingTDCShipment = TDCShipmentController.GetShipment( opCoShipment.OpCoCode, opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber); // Did we find an existing tdc shipment? if (null != existingTDCShipment) { // See if the tdc shipment can be updated if (existingTDCShipment.Status != Shipment.StatusEnum.Mapped) { // Consume the message, we can't make the update Status = SubscriberStatusEnum.Consumed; // Log that the shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Format("Unable to update existing tdc shipment {0} - {1} for for opco {2}. The status of the existing tdc shipment is {3} disallowing this update.", existingTDCShipment.ShipmentNumber, existingTDCShipment.DespatchNumber, existingTDCShipment.OpCoCode, existingTDCShipment.Status), "Request Management", 0, 0, TraceEventType.Information, "Request Management", null); // Write to the log Logger.Write(logEntry); // done return; } } else { // We should have found the tdc shipment Status = SubscriberStatusEnum.Failed; // Log that the tdc shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Concat("Unable to update tdc shipment ", opCoShipment.ShipmentNumber, "-", opCoShipment.DespatchNumber, " for opco ", opCoShipment.OpCoCode, ". The tdc shipment was not found."), "Request Management", 0, 0, TraceEventType.Error, "Request Management", null); // Write to the log Logger.Write(logEntry); // done return; } } } } // ***************************************************************** // ** SAVE OR UPDATE THE OPCO SHIPMENT // ***************************************************************** // See if we have an existing opco shipment if (null != existingOpCoShipment) { // Update existing opco shipment opCoShipment = (OpCoShipment)existingOpCoShipment.UpdateFromShipment(opCoShipment); } // Specify that the shipment was updated by this subscriber opCoShipment.UpdatedBy = this.GetType().FullName; // See if the shipment has been cancelled if (0 == opCoShipment.TotalLineQuantity) { // Cancel the shipment opCoShipment.Status = Shipment.StatusEnum.Cancelled; } else if (opCoShipment.OpCoHeld) { // Hold the shipment opCoShipment.Status = Shipment.StatusEnum.Held; } // See if we have an audit entry (not required) if (null != auditEntry) { // Store the audit entry id opCoShipment.AuditId = auditEntry.Id; } // Save the opco shipment to the db if (-1 != OpCoShipmentController.SaveShipment(opCoShipment)) { // Cache the opco shipment for other subscribers RequestProcessor.RequestDictionary["OpCoShipment"] = opCoShipment; // ***************************************************************** // ** MAP AND SAVE THE TDC SHIPMENT // ***************************************************************** // We only create the TDC Shipment if the OpCo Shipment has not been cancelled // If it has been cancelled and we have an existing TDC Shipment we still update it if (opCoShipment.Status != Shipment.StatusEnum.Cancelled || null != existingTDCShipment) { try { // Map the opco shipment to a new tdc shipment tdcShipment = opCoShipment.MapToTDC(existingTDCShipment, this.GetType().FullName, true); // Store the tdc shipment for other subscribers RequestProcessor.RequestDictionary["TDCShipment"] = tdcShipment; } catch (Exception ex) { // Log that the shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Format("The opco shipment {0} - {1} for opco {2} has a status of NOTMAPPED. The error was {3}", opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber, opCoShipment.OpCoCode, ex.Message), "Request Management", 0, 0, TraceEventType.Error, "Request Management", null); // Write to the log Logger.Write(logEntry); } } // Processed Status = SubscriberStatusEnum.Processed; } else { // We failed to save the op co shipment } } catch (Exception ex) { // Store the exception LastError = ex; // Failed Status = SubscriberStatusEnum.Failed; } finally { // Cleanup existingOpCoShipment = null; existingTDCShipment = null; } }
/// <summary> /// Saves the shipmentDrop. /// </summary> /// <param name="shipmentDrop">The shipmentDrop.</param> /// <param name="depotCode">The depot code.</param> /// <returns></returns> public static Int32 SaveDrop(ShipmentDrop shipmentDrop, string depotCode) { if (shipmentDrop.TripId == Null.NullInteger) { //get warehouse id which will be used to find the trip id int warehouseId; Warehouse relatedWarehouse = WarehouseController.GetWarehouse(depotCode); if (relatedWarehouse == null) { throw new Exception( string.Format("When importing ShipmentDrop data the related warehouse could not be found. The Warehouse number was '{0}'.", depotCode)); } warehouseId = relatedWarehouse.Id; shipmentDrop.OriginalDepotId = warehouseId; //get and set the related trip id Trip relatedTrip = TripController.GetTripByWarehouseDateAndNumber(shipmentDrop.TripNumber, shipmentDrop.DeliveryDate, warehouseId); if (relatedTrip == null) { //the trip file hasn't bee recieved yet so add a record to relate to for now relatedTrip = new Trip(); relatedTrip.TripNumber = shipmentDrop.TripNumber; relatedTrip.StartDate = shipmentDrop.DeliveryDate; relatedTrip.WarehouseId = warehouseId; relatedTrip.Id = TripController.SaveTrip(relatedTrip); } if (relatedTrip.Id == -1) { throw new Exception( string.Format("When importing ShipmentDrop data a related trip could not be created with details, Trip Number: '{0}', Search Date: '{1}', and WarehouseId: '{2}'.", shipmentDrop.TripNumber, shipmentDrop.DeliveryDate.ToShortDateString(), warehouseId)); } shipmentDrop.TripId = relatedTrip.Id; } if (shipmentDrop.ShipmentId == Null.NullInteger && shipmentDrop.CallType != ShipmentDrop.CallTypeEnum.Depot) { //get shipment id TDCShipment tdcShipment = TDCShipmentController.GetShipment(shipmentDrop.OpcoCode, shipmentDrop.ShipmentNumber, shipmentDrop.DespatchNumber); if (tdcShipment == null) { throw new Exception( string.Format("When importing ShipmentDrop data the related shipment could not be found. The Opco Code was '{0}', the Shipment Number was '{1}', and the Despatch Number was '{2}'.", shipmentDrop.OpcoCode, shipmentDrop.ShipmentNumber, shipmentDrop.DespatchNumber)); } else if (tdcShipment.Status == Shipment.StatusEnum.Routed) { //TODO: Log that this shipment has already been routed, etc } //update the related shipments estimated date with the time now that optrak has calculated it for us string[] arriveTime = shipmentDrop.ArriveTime.Split(':'); tdcShipment.EstimatedDeliveryDate.AddHours(Convert.ToDouble(arriveTime[0])); tdcShipment.EstimatedDeliveryDate.AddMinutes(Convert.ToDouble(arriveTime[1])); TDCShipmentController.SaveShipment(tdcShipment); shipmentDrop.ShipmentId = tdcShipment.Id; } try { if (shipmentDrop.IsValid) { //check to see if we've had this data before or we have recieved a TRIPPART file that needed us to //add a record to maintain referential integrity ShipmentDrop existingShipmentDrop = GetDrop(shipmentDrop.ShipmentId, shipmentDrop.TripId, shipmentDrop.OrderSequence, shipmentDrop.DropSequence); if (existingShipmentDrop != null) { //just overwite with this new data //log? shipmentDrop.Id = existingShipmentDrop.Id; shipmentDrop.CheckSum = existingShipmentDrop.CheckSum; } // Save entity shipmentDrop.Id = DataAccessProvider.Instance().SaveDrop(shipmentDrop); if (shipmentDrop.Id == -1) { throw new Exception( string.Format("A Drop could not be saved. The Opco Code was '{0}', the Shipment Number was '{1}', and the Despatch Number was '{2}'.", shipmentDrop.OpcoCode, shipmentDrop.ShipmentNumber, shipmentDrop.DespatchNumber)); } } else { // Entity is not valid throw new InValidBusinessObjectException(shipmentDrop); } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } return(shipmentDrop.Id); }
/// <summary> /// Increments the print count. /// </summary> /// <param name="tdcShipment">The TDC shipment.</param> /// <returns></returns> internal static int IncrementPrintCount(TDCShipment tdcShipment) { return(1); }
protected void discoveryShipments_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "Sort": { // Bind data discoveryShipments.DataBind(); // Done break; } case "OpCoDetail": { if (null != Redirecting) { OpCoRedirectEventArg redirectEventArgs = new OpCoRedirectEventArg(); Redirecting(ref redirectEventArgs); if (!redirectEventArgs.CancelRedirect) { // Redirect to the details page Response.Redirect(string.Format("~/Shipments/OpCoShipment.aspx?Id={0}&{1}", e.CommandArgument.ToString(), Discovery.Utility.UIHelper.GenerateUrlReferrer(HttpContext.Current, new string[] { redirectEventArgs.QueryParams, string.Concat("PageIndex=", discoveryPager.PageIndex.ToString()), string.Concat("PageSize=", discoveryPager.PageSize.ToString()), string.Concat("SortExpression=", string.Concat(discoveryShipments.SortExpression, " ", discoveryShipments.SortDirection.ToString())) }))); } } // Done; break; } case "TDCDetail": { if (null != Redirecting) { OpCoRedirectEventArg redirectEventArgs = new OpCoRedirectEventArg(); Redirecting(ref redirectEventArgs); if (!redirectEventArgs.CancelRedirect) { // Get the opco code, shipment number and the despatch number for the tdc shipment string[] shipmentParams = e.CommandArgument.ToString().Split('|'); // Get the tdc shipment Discovery.BusinessObjects.TDCShipment tdcShipment = TDCShipmentController.GetShipment(shipmentParams[0], shipmentParams[1], shipmentParams[2]); if (null != tdcShipment) { // Redirect to the details page Response.Redirect(string.Format("~/Shipments/TDCShipment.aspx?Id={0}&{1}", tdcShipment.Id, Discovery.Utility.UIHelper.GenerateUrlReferrer(HttpContext.Current, new string[] { redirectEventArgs.QueryParams, string.Concat("PageIndex=", discoveryPager.PageIndex.ToString()), string.Concat("PageSize=", discoveryPager.PageSize.ToString()), string.Concat("SortExpression=", string.Concat(discoveryShipments.SortExpression, " ", discoveryShipments.SortDirection.ToString())) }))); } } } // Done; break; } case "AuditDetail": { if (null != Redirecting) { OpCoRedirectEventArg redirectEventArgs = new OpCoRedirectEventArg(); Redirecting(ref redirectEventArgs); if (!redirectEventArgs.CancelRedirect) { // Redirect to the details page Response.Redirect(string.Format("~/Admin/MessageAudit.aspx?Id={0}&{1}", e.CommandArgument.ToString(), Discovery.Utility.UIHelper.GenerateUrlReferrer(HttpContext.Current, new string[] { redirectEventArgs.QueryParams, string.Concat("PageIndex=", discoveryPager.PageIndex.ToString()), string.Concat("PageSize=", discoveryPager.PageSize.ToString()), string.Concat("SortExpression=", string.Concat(discoveryShipments.SortExpression, " ", discoveryShipments.SortDirection.ToString())) }))); } } // Done break; } case "MapToTdc": { // Get the opco shipment Discovery.BusinessObjects.OpCoShipment opCoShipment = OpCoShipmentController.GetShipment(Convert.ToInt32(e.CommandArgument)); // Make sure that we found the shipment if (null != opCoShipment && opCoShipment.Id != -1) { // We have the shipment, now map it to a tdc shipment if not mapped if (opCoShipment.Status == Shipment.StatusEnum.NotMapped) { // The new shipment TDCShipment tdcShipment; try { //see if there is an existing TDCShipment TDCShipment existingTDCShipment = TDCShipmentController.GetShipment( opCoShipment.OpCoCode, opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber); // Map opco shipment tdcShipment = opCoShipment.MapToTDC(existingTDCShipment, Page.User.Identity.Name, false); // Update the opco shipment status OpCoShipmentController.UpdateShipmentStatus(opCoShipment); // Display message DiscoveryPage.DisplayMessage(string.Format("The OpCo shipment was mapped to a new TDC shipment <a href=\"TDCShipment.aspx?Id={0}\">{1}-{2}</a>.", tdcShipment.Id, tdcShipment.ShipmentNumber, tdcShipment.DespatchNumber), DiscoveryMessageType.Success, Page.Master); } catch (Exception ex) { DiscoveryPage.DisplayMessage(ex.Message, DiscoveryMessageType.Error, Page.Master); } // Status changed, re bind the data discoveryShipments.DataBind(); } } // Done; break; } } }
protected void TDCShipmentLineFormView_OnDataBound(object sender, EventArgs e) { // If we're in read only mode see if we can switch to edit mode if (((FormView)sender).CurrentMode == FormViewMode.ReadOnly) { // Find the edit button ImageButton editButton = DiscoveryPage.GetControl <ImageButton>("ButtonEdit", (FormView)sender); // See if we found the edit button (depends when we're data binding) if (editButton != null) { // Do we already have the shipment if (shipment == null) { // Seed can edit canEdit = false; // Make sure we have a query string value if (null != Request.QueryString["id"]) { // Get the shipment shipment = TDCShipmentController.GetShipment(Convert.ToInt32(Request.QueryString["id"])); // Now we have the shipment, load the load category codes // See if we can edit the line if (null != shipment && shipment.Id > 0) { canEdit = ( /* Not Complete */ ( shipment.Status != Shipment.StatusEnum.Completed ) && ( ( shipment.Type == Shipment.TypeEnum.WHS && DiscoveryPage.HasRule("Shipment: Edit Warehouse Order Detail", Context.User) ) || ( shipment.Type == Shipment.TypeEnum.ADH && DiscoveryPage.HasRule("Shipment: Edit Ad-Hoc Order Detail", Context.User) ) || ( shipment.Type == Shipment.TypeEnum.OPCO && DiscoveryPage.HasRule("Shipment: Edit TDC Shipment Detail", Context.User) ) ) ); } } } // Update the visibility editButton.Visible = canEdit; } } }