protected void TDCShipmentDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e) { try { // Entity as will be saved to the db Discovery.BusinessObjects.TDCShipment tdcShipment = e.InputParameters[0] as Discovery.BusinessObjects.TDCShipment; // OpCo contact details tdcShipment.OpCoContact.Name = GetControl <TextBox>("txtOpCoContactName", TDCShipmentFormView.Row).Text; tdcShipment.OpCoContact.Email = GetControl <TextBox>("txtOpCoContactEmail", TDCShipmentFormView.Row).Text; // Shipment contact details tdcShipment.ShipmentContact.Name = GetControl <TextBox>("txtShipmentContactName", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentContact.Email = GetControl <TextBox>("txtShipmentContactEmail", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentContact.TelephoneNumber = GetControl <TextBox>("txtShipmentContactTelephone", TDCShipmentFormView.Row).Text; // Customer address details tdcShipment.CustomerAddress.Line1 = GetControl <TextBox>("txtCustomerAddress1", TDCShipmentFormView.Row).Text; tdcShipment.CustomerAddress.Line2 = GetControl <TextBox>("txtCustomerAddress2", TDCShipmentFormView.Row).Text; tdcShipment.CustomerAddress.Line3 = GetControl <TextBox>("txtCustomerAddress3", TDCShipmentFormView.Row).Text; tdcShipment.CustomerAddress.Line4 = GetControl <TextBox>("txtCustomerAddress4", TDCShipmentFormView.Row).Text; tdcShipment.CustomerAddress.Line5 = GetControl <TextBox>("txtCustomerAddress5", TDCShipmentFormView.Row).Text; tdcShipment.CustomerAddress.PostCode = GetControl <TextBox>("txtCustomerAddressPostCode", TDCShipmentFormView.Row).Text; // Shipment address details tdcShipment.ShipmentAddress.Line1 = GetControl <TextBox>("txtShipmentAddress1", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line2 = GetControl <TextBox>("txtShipmentAddress2", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line3 = GetControl <TextBox>("txtShipmentAddress3", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line4 = GetControl <TextBox>("txtShipmentAddress4", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line5 = GetControl <TextBox>("txtShipmentAddress5", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.PostCode = GetControl <TextBox>("txtShipmentAddressPostCode", TDCShipmentFormView.Row).Text; // PAF address details tdcShipment.PAFAddress.Easting = Convert.ToInt32(GetControl <TextBox>("txtPAFEasting", TDCShipmentFormView.Row).Text); tdcShipment.PAFAddress.Northing = Convert.ToInt32(GetControl <TextBox>("txtPAFNorthing", TDCShipmentFormView.Row).Text); tdcShipment.PAFAddress.DPS = GetControl <TextBox>("txtPAFDPS", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line1 = GetControl <TextBox>("txtPAFAddress1", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line2 = GetControl <TextBox>("txtPAFAddress2", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line3 = GetControl <TextBox>("txtPAFAddress3", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line4 = GetControl <TextBox>("txtPAFAddress4", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line5 = GetControl <TextBox>("txtPAFAddress5", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.PostCode = GetControl <TextBox>("txtPAFAddressPostCode", TDCShipmentFormView.Row).Text; // tdcShipment.PAFAddress.Status = GetControl<TextBox>("txtPAFStatus", TDCShipmentFormView.Row).Text; //need to persist match value // Who's making the update tdcShipment.UpdatedBy = User.Identity.Name; } catch (Exception ex) { // Display error message DisplayMessage(string.Format("Please ensure that all form values have been entered correctly. The error was, <i>\"{0}\"</i>", ex.Message), DiscoveryMessageType.Error); // Don't alow update, etc e.Cancel = true; } }
protected void btnAddLine_Click(object sender, EventArgs e) { try { // Load the shipment we're adding the line to Discovery.BusinessObjects.TDCShipment tdcShipment = TDCShipmentController.GetShipment( Convert.ToInt32(Request.QueryString["Id"])); // Create a new shipment line TDCShipmentLine tdcLine = new TDCShipmentLine(); tdcLine.Id = -1; tdcLine.ShipmentId = tdcShipment.Id; tdcLine.UpdatedBy = Page.User.Identity.Name; tdcLine.ConversionInstructions = txtConversionInstructions.Text; tdcLine.ConversionQuantity = Convert.ToInt32(txtConversionQuantity.Text); tdcLine.CustomerReference = txtCustomerReference.Text; tdcLine.Description1 = txtDescription1.Text; tdcLine.Description2 = txtDescription2.Text; tdcLine.Grammage = Convert.ToInt32(txtGrammage.Text); tdcLine.NetWeight = Convert.ToDecimal(txtNetWeight.Text); tdcLine.IsISO9000Approved = chkIsISO9000Approved.Checked; tdcLine.IsPanel = chkIsPanel.Checked; tdcLine.Length = Convert.ToInt32(txtLength.Text); tdcLine.LineNumber = tdcShipment.ShipmentLines.Count + 1; tdcLine.LoadCategoryCode = ddlLoadCategory.SelectedValue; tdcLine.Microns = Convert.ToInt32(txtMicrons.Text); tdcLine.Packing = txtPacking.Text; tdcLine.ProductCode = tdcShipment.Type.ToString(); tdcLine.ProductGroup = txtProductGroup.Text; tdcLine.Quantity = Convert.ToInt32(txtQuantity.Text); tdcLine.QuantityUnit = txtQuantityUnit.Text; tdcLine.Volume = Convert.ToDecimal(txtVolume.Text); tdcLine.Width = Convert.ToInt32(txtWidth.Text); // Add the shipment line to the shipment TDCShipmentLineController.SaveLine(tdcLine); // 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("Line #{0} product code {1} was added to shipment {2}.", tdcLine.LineNumber, tdcLine.ProductCode, tdcShipment.ShipmentNumber), DiscoveryMessageType.Success); } catch (Exception ex) { // Display message ((DiscoveryPage)Page).DisplayMessage(String.Concat("There was an error saving the shipment line. ", ex.Message), DiscoveryMessageType.Error); } }
/// <summary> /// Routings the populate shipment line fields. /// </summary> /// <param name="schema">The schema.</param> /// <param name="parentShipment">The parent shipment.</param> public void RoutingPopulateShipmentLineFields(TextFieldCollection schema, TDCShipment parentShipment) { schema["Order"].Value = string.Concat(parentShipment.OpCoCode, "-", parentShipment.ShipmentNumber, "-", parentShipment.DespatchNumber); schema["LineCode"].Value = LineNumber.ToString(); schema["Product"].Value = ProductCode; schema["MaximumUnits"].Value = Quantity.ToString(); schema["MaximumWeight"].Value = GrossWeight.ToString("######0.##"); schema["MaximumVolume"].Value = Volume.ToString("###0.###"); schema["Width"].Value = Width.ToString();; schema["Length"].Value = Length.ToString(); }
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; } }
protected void btnTDCShipmentDetails_Click(object sender, System.EventArgs e) { // Get the opco code, shipment number and the despatch number string[] shipmentParams = ((System.Web.UI.WebControls.IButtonControl)sender).CommandArgument.Split('|'); // Get the tdc shipment Discovery.BusinessObjects.TDCShipment tdcShipment = TDCShipmentController.GetShipment(shipmentParams[0], shipmentParams[1], shipmentParams[2]); if (null != tdcShipment) { // Redirect to the tdc shipment page Response.Redirect(string.Concat("~/Shipments/TDCShipment.aspx?Id=", tdcShipment.Id)); } }
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 TDCShipmentDataSource_Inserting(Object sender, ObjectDataSourceMethodEventArgs e) { try { // Entity as will be saved to the db Discovery.BusinessObjects.TDCShipment tdcShipment = e.InputParameters[0] as Discovery.BusinessObjects.TDCShipment; // Get the shipment type string shipmentType = GetControl <DropDownList>("ddlType", TDCShipmentFormView.Row).SelectedItem.Value; // Store the shipment type tdcShipment.Type = (Shipment.TypeEnum)Enum.Parse(typeof(Shipment.TypeEnum), shipmentType); // Generate the shipment number tdcShipment.ShipmentNumber = String.Concat( shipmentType.ToUpper(), SequenceController.GetNextSequence(String.Concat(shipmentType, "SHIPMENT")).ToString()); // Specify the despatch number tdcShipment.DespatchNumber = "1"; // Specify the customer name tdcShipment.CustomerName = string.Concat(shipmentType.ToUpper(), " ad-hoc order"); // Specify the customer number tdcShipment.CustomerNumber = "Ad-hoc"; // Specify the customer reference tdcShipment.CustomerReference = "Ad-hoc"; // Specify opco contact details tdcShipment.OpCoContact.Name = "NA"; tdcShipment.OpCoContact.Email = "NA"; // Specify the shipment name tdcShipment.ShipmentName = tdcShipment.CustomerName; // Shipment contact details tdcShipment.ShipmentContact.Name = GetControl <TextBox>("txtShipmentContactName", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentContact.Email = GetControl <TextBox>("txtShipmentContactEmail", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentContact.TelephoneNumber = GetControl <TextBox>("txtShipmentContactTelephone", TDCShipmentFormView.Row).Text; // Shipment address details tdcShipment.ShipmentAddress.Line1 = GetControl <TextBox>("txtShipmentAddress1", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line2 = GetControl <TextBox>("txtShipmentAddress2", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line3 = GetControl <TextBox>("txtShipmentAddress3", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line4 = GetControl <TextBox>("txtShipmentAddress4", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.Line5 = GetControl <TextBox>("txtShipmentAddress5", TDCShipmentFormView.Row).Text; tdcShipment.ShipmentAddress.PostCode = GetControl <TextBox>("txtShipmentAddressPostCode", TDCShipmentFormView.Row).Text; // PAF address details //tdcShipment.PAFAddress.Easting = Convert.ToInt32(GetControl<TextBox>("txtPAFEasting", TDCShipmentFormView.Row).Text); //tdcShipment.PAFAddress.Northing = Convert.ToInt32(GetControl<TextBox>("txtPAFNorthing", TDCShipmentFormView.Row).Text); //tdcShipment.PAFAddress.DPS = GetControl<TextBox>("txtPAFDPS", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line1 = GetControl <TextBox>("txtPAFAddress1", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line2 = GetControl <TextBox>("txtPAFAddress2", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line3 = GetControl <TextBox>("txtPAFAddress3", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line4 = GetControl <TextBox>("txtPAFAddress4", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.Line5 = GetControl <TextBox>("txtPAFAddress5", TDCShipmentFormView.Row).Text; tdcShipment.PAFAddress.PostCode = GetControl <TextBox>("txtPAFAddressPostCode", TDCShipmentFormView.Row).Text; //tdcShipment.PAFAddress.Status = GetControl<TextBox>("txtPAFStatus", TDCShipmentFormView.Row).Text; // Updated by tdcShipment.UpdatedBy = User.Identity.Name; // Update the back url so that we can add lines,ase class redirects to this url BackUrl = String.Format("~/Shipments/TdcShipment.aspx?Id={0}&AddLines=True&Type={1}", "{0}", shipmentType);; } catch (Exception ex) { // Display error message DisplayMessage(string.Format("Please ensure that all form values have been entered correctly. The error was, <i>\"{0}\"</i>", ex.Message), DiscoveryMessageType.Error); // Failed e.Cancel = true; } }
/// <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); } }