protected void btnMapToTdc_Click(object sender, System.EventArgs e) { // Get the opco shipment Discovery.BusinessObjects.OpCoShipment opCoShipment = OpCoShipmentController.GetShipment(Convert.ToInt32((sender as System.Web.UI.WebControls.IButtonControl).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 Discovery.BusinessObjects.TDCShipment tdcShipment; try { // Map opco shipment tdcShipment = opCoShipment.MapToTDC(null, Page.User.Identity.Name, false); // Update the status of the opco shipment to mapped opCoShipment.Status = Shipment.StatusEnum.Mapped; // 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 OpCoShipmentFormView.DataBind(); } } }
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; } } }
/// <summary> /// Maps to TDC. /// </summary> /// <returns></returns> public TDCShipment MapToTDC(TDCShipment existingTDCShipment, string updatedBy, bool raiseAddressException) { try { // Create an instance of a tdc shipment TDCShipment tdcShipment = new TDCShipment(); // Map the opco shipment to a tdc shipment Mapper.Map(this, tdcShipment, this.OpCoCode, "TDC", null, new string[] { "Id" }); // Update the opco shipment id in the tdc shipment tdcShipment.OpCoShipmentId = this.Id; // Map the opcoshipmentlines to tdcshipment lines via the mapper class List <ShipmentLine> tdcShipmentLines = new List <ShipmentLine>(this.ShipmentLines.Count); // Map the lines from opcoshipmentlines to tdcshipmentlines foreach (ShipmentLine opCoShipmentLine in this.ShipmentLines) { // The new tdc shipment line TDCShipmentLine tdcShipmentLine = new TDCShipmentLine(); // Map the opco shipment to a tdc shipment Mapper.Map(opCoShipmentLine, tdcShipmentLine, this.OpCoCode, "TDC", null, new string[] { "Id" }); //store the original quantity for later validation which stops the user from //increasing the quantity past this original quantity. tdcShipmentLine.OriginalQuantity = tdcShipmentLine.Quantity; // Add the tdcshipmentline to the tdcshipmentlines list tdcShipmentLines.Add(tdcShipmentLine); } // Store the new tdc shipment lines in the tdcshipment tdcShipment.ShipmentLines = tdcShipmentLines; // ******************************** // ** UPDATE EXISTING TDC SHIPMENT // ******************************** if (null != existingTDCShipment) { // Update the existing tdc shipment with the one just mapped tdcShipment = (TDCShipment)existingTDCShipment.UpdateFromShipment(tdcShipment); } // Update the status of the tdc shipment to mapped tdcShipment.Status = StatusEnum.Mapped; // See if the tdc shipment has been cancelled if (0 == tdcShipment.TotalLineQuantity) { // Cancel the shipment tdcShipment.Status = Shipment.StatusEnum.Cancelled; } // If the tdc shipment is valid and not cancelled, execute remaining business logic if (tdcShipment.IsValid) { // ********************************************************************************* // ** Tec Spec 5.3, Calculate the estimated delivery date of the tdc shipment // ********************************************************************************* tdcShipment.CalculateDeliveryDate(); // ********************************************************************************* // ** Tec Spec 5.4, Check the address // ********************************************************************************* tdcShipment.CheckAddress(); // Specify that the shipment was update tdcShipment.UpdatedBy = updatedBy; // Save the tdc shipment TDCShipmentController.SaveShipment(tdcShipment); //if an invalid address should be logged or emailed then call the NotifyIfPoorAddressMatch method. //This method will check if there was a poor match an pass an exception to the exception handling if (raiseAddressException) { tdcShipment.NotifyIfPoorAddressMatch(); } // ******************************** // ** UPDATE THIS OPCO SHIPMENT // ******************************** // Update the opco shipment status if the shipment is NOTMAPPED if (this.Status == Shipment.StatusEnum.NotMapped) { // Update the status of the opco shipment to mapped this.Status = Shipment.StatusEnum.Mapped; // Update the opco shipment status OpCoShipmentController.UpdateShipmentStatus(this); } } else { // The tdc shipment was is invalid throw new InValidBusinessObjectException(tdcShipment); } // Return the new tdc shipment return(tdcShipment); } catch (Exception ex) { // Generate a new exception ex = new FailedShipmentMappingException( this.OpCoCode, this.OpCoContact.Email, string.Format("Failed to map OpCo shipment {0} - {1} for OpCo {2}. {3}", this.ShipmentNumber, this.DespatchNumber, this.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(null); } }