// 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());
        }
        /// <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);
        }
Esempio n. 3
0
        public static Int32 SaveDropLine(ShipmentDropLine line)
        {
            TDCShipmentLine tdcShipmentLine;

            //if (line.ShipmentLineId == Null.NullInteger)
            //{
            //    //get shipment id

            tdcShipmentLine = TDCShipmentLineController.GetLine(line.LineCode, line.OpcoCode, line.ShipmentNumber, line.DespatchNumber);
            if (tdcShipmentLine == null)
            {
                throw new Exception(
                          string.Format("When importing Drop Line data the related Shipment Line could not be found. The line code was '{3}', Opco Code was '{0}', the Shipment Number was '{1}', and the Despatch Number was '{2}'.",
                                        line.OpcoCode, line.ShipmentNumber, line.DespatchNumber, line.LineCode));
            }

            //if (line.ShipmentLineId == Null.NullInteger)
            //{
            //    throw new Exception(
            //        string.Format("When importing Drop Line data the related Shipment Line could not be found. The Opco Code was '{0}', the Shipment Number was '{1}', and the Despatch Number was '{2}' and the Line Code was '{3}'.",
            //                      line.OpcoCode, line.ShipmentNumber, line.DespatchNumber, line.LineCode));
            //}
            line.ShipmentLineId = tdcShipmentLine.Id;


            if (!line.Split)
            {
            }
            else
            {
                //optrak split this line
                //  tdcShipment.SplitShipment()
            }

            //}

            if (line.DropId == Null.NullInteger)
            {
                //get warehouse id which will be used to find the trip id
                int       warehouseId;
                Warehouse relatedWarehouse = WarehouseController.GetWarehouse(line.Depot);
                if (relatedWarehouse == null)
                {
                    throw new Exception(
                              string.Format("When importing Drop Line data the related warehouse could not be found. The Warehouse number was '{0}'.",
                                            line.Depot));
                }
                warehouseId = relatedWarehouse.Id;

                //get the related trip id
                Trip relatedTrip = TripController.GetTripByWarehouseDateAndNumber(line.TripNumber, line.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  = line.TripNumber;
                    relatedTrip.StartDate   = line.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}'.",
                                            line.TripNumber, line.DeliveryDate.ToShortDateString(), warehouseId));
                }


                //get drop id this line relates to
                ShipmentDrop relatedShipmentDrop = GetDrop(tdcShipmentLine.ShipmentId, relatedTrip.Id, line.OrderSequence, line.DropSequence);
                if (relatedShipmentDrop == null)
                {
                    //a related shipment drop could not be found
                    //this could be because that file has not been proced yet so create
                    //a blank one to relate to
                    relatedShipmentDrop            = new ShipmentDrop();
                    relatedShipmentDrop.ShipmentId = tdcShipmentLine.ShipmentId;
                    relatedShipmentDrop.TripId     = relatedTrip.Id;
                    // relatedShipmentDrop.OrderSequence = line.OrderSequence;
                    relatedShipmentDrop.DropSequence = line.DropSequence;
                    relatedShipmentDrop.Id           = SaveDrop(relatedShipmentDrop, line.Depot);
                }
                if (relatedShipmentDrop.Id == -1)
                {
                    throw new Exception(
                              string.Format("When importing Drop Line data a related Drop could not be created with details, Shipment Id: '{0}', Trip Id: '{1}', and Order OrderSequence: '{2}' and Drop OrderSequence '{3}'.",
                                            tdcShipmentLine.ShipmentId, relatedTrip.Id, line.OrderSequence, line.DropSequence));
                }

                line.DropId = relatedShipmentDrop.Id;
            }

            try
            {
                if (line.IsValid)
                {
                    // Save entity
                    //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
                    ShipmentDropLine existingShipmentDropLine = null;// DropController.GetDropLine(line.ShipmentLineId);
                    if (existingShipmentDropLine != null)
                    {
                        //just overwite with this new data
                        //log?
                        line.Id       = existingShipmentDropLine.Id;
                        line.CheckSum = existingShipmentDropLine.CheckSum;
                    }
                    line.OriginalShipmentLineId = line.ShipmentLineId;
                    line.Id = DataAccessProvider.Instance().SaveDropLine(line);
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(line);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(line.Id);
        }
        // *************************************************************
        // **
        // ** Printing Support
        // **
        // *************************************************************

        /// <summary>
        /// Prints the specified shipments.
        /// </summary>
        /// <param name="shipments">The shipments.</param>
        /// <param name="numberOfCopies">The number of copies.</param>
        public static void Print(
            List <TDCShipmentPrintable> shipments,
            int numberOfCopies,
            TDCShipment.ReportTypeEnum reportType)
        {
            try
            {
                // Make sure we have something to do
                if (shipments != null && numberOfCopies > 0)
                {
                    // Create the report instance
                    ReportDocument theReport = null;

                    // Our list of one shipment for data binding
                    List <TDCShipmentPrintable> printableShipment = new List <TDCShipmentPrintable>(1);

                    // Warehouse code where we are trying to print to
                    string printerWarehouse = "";

                    // Load the correct crystal report
                    switch (reportType)
                    {
                    case TDCShipment.ReportTypeEnum.DeliveryNote:
                    {
                        // Create an instance of the report
                        theReport = new DeliveryNote();
                        // Done
                        break;
                    }

                    case TDCShipment.ReportTypeEnum.ConversionNote:
                    case TDCShipment.ReportTypeEnum.TransferNote:
                    case TDCShipment.ReportTypeEnum.ExBranchSalesOrder:
                    {
                        // Create an instance of the report
                        theReport = new DeliveryNote();
                        // Done
                        break;
                    }
                    }

                    // Specify report options
                    theReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
                    theReport.PrintOptions.PaperSize        = CrystalDecisions.Shared.PaperSize.PaperA4;

                    // Iterate over the shipments and print (this is the order they are in the collection)
                    foreach (TDCShipmentPrintable shipment in shipments)
                    {
                        // Clear the list of shipments
                        printableShipment.Clear();

                        // Add the shipment to the list
                        printableShipment.Add(shipment);

                        // Bind main shipment data
                        theReport.SetDataSource(printableShipment);

                        // Bind the shipment lines data
                        theReport.Subreports[0].SetDataSource(TDCShipmentLineController.GetLines(shipment.Id));

                        // Specify the correct printer
                        switch (reportType)
                        {
                        case TDCShipment.ReportTypeEnum.DeliveryNote:
                        {
                            // Store the warehouse code
                            printerWarehouse = shipment.DeliveryWarehouseCode;
                            // Specify the printer name/ip
                            theReport.PrintOptions.PrinterName = shipment.DeliveryWarehouse.PrinterName;
                            // Specify the report title
                            theReport.SetParameterValue("reportTitle", "Delivery Note");
                            // Done
                            break;
                        }

                        case TDCShipment.ReportTypeEnum.ConversionNote:
                        {
                            // Store the warehouse code
                            printerWarehouse = shipment.StockWarehouseCode;
                            // Specify the printer name/ip
                            theReport.PrintOptions.PrinterName = shipment.StockWarehouse.PrinterName;
                            // Specify the report title
                            theReport.SetParameterValue("reportTitle", "Conversion Note");
                            // Done
                            break;
                        }

                        case TDCShipment.ReportTypeEnum.TransferNote:
                        {
                            // Store the warehouse code
                            printerWarehouse = shipment.StockWarehouseCode;
                            // Specify the printer name/ip
                            theReport.PrintOptions.PrinterName = shipment.StockWarehouse.PrinterName;
                            // Specify the report title
                            theReport.SetParameterValue("reportTitle", "Transfer Note");
                            // Done
                            break;
                        }

                        case TDCShipment.ReportTypeEnum.ExBranchSalesOrder:
                        {
                            // Store the warehouse code
                            printerWarehouse = shipment.StockWarehouseCode;
                            // Specify the printer name/ip
                            theReport.PrintOptions.PrinterName = shipment.StockWarehouse.PrinterName;
                            // Specify the report title
                            theReport.SetParameterValue("reportTitle", "Ex-Branch Sales Order");
                            // Done
                            break;
                        }
                        }

                        // Make sure we have a printer name
                        if (!string.IsNullOrEmpty(theReport.PrintOptions.PrinterName))
                        {
                            // Print the delivery note
                            theReport.PrintToPrinter(numberOfCopies, true, 0, 0);
                        }
                        else
                        {
                            // No printer for the specified warehouse
                            throw new Exception(string.Format("The warehouse '{0}' does not have a printer specified."));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Log an throw if configured to do so (should not by default)
                ExceptionPolicy.HandleException(ex, "Printing");
            }
        }