/// <summary> /// Prints the specified shipment via id. /// </summary> /// <param name="shipmentid">The shipment id.</param> /// <param name="numberOfCopies">The number of copies.</param> public static void Print( int shipmentId, int numberOfCopies, TDCShipment.ReportTypeEnum reportType) { // Load the shipment and print Print(GetShipment(shipmentId), numberOfCopies, reportType); }
/// <summary> /// Prints the specified shipment. /// </summary> /// <param name="shipment">The shipment.</param> /// <param name="numberOfCopies">The number of copies.</param> public static void Print( TDCShipmentPrintable shipment, int numberOfCopies, TDCShipment.ReportTypeEnum reportType) { // Create a list of shipments List <TDCShipmentPrintable> shipments = new List <TDCShipmentPrintable>(); // Add the shipment to the list shipments.Add(shipment); // Print the shipment Print(shipments, numberOfCopies, reportType); }
/// <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); }
// ************************************************************* // ** // ** 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"); } }