// 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());
        }
        // *************************************************************
        // **
        // ** 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");
            }
        }