Ejemplo n.º 1
0
        public bool AddLineItem(ExportLineItem item, string orderNumber, int orderQty, string batchItemName, string currentProduct)
        {
            try
            {
                XmlFileName = (AppSettings.Get("ExportFilePath").ToString()) + (AppSettings.Get("DailyScheduleData").ToString());

                string batchName = orderNumber;
                // are we processing an order or a batch?
                bool isBatch = false;
                if (orderNumber.IndexOf("batch", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    isBatch     = true;
                    orderNumber = batchItemName;
                }

                if (item.PlantID == "")
                {
                    item.PlantID = AppSettings.Get("LocalPlantName").ToString();
                }

                AggregateLineItem searchLineItem = AggregateLineItemList.Find(i => i.Number == item.Number && i.IsStock == item.IsStock && i.PlantID == item.PlantID);
                if (searchLineItem == null)
                {
                    // add a new line to the list
                    AggregateLineItem newAggregateLineItem = new AggregateLineItem(item, orderNumber, orderQty);
                    AggregateLineItemList.Add(newAggregateLineItem);
                    PrintLineItem(newAggregateLineItem, isBatch, batchItemName, currentProduct, batchName);
                }
                else
                {
                    // add a new order record to associated orders of the existing line
                    OrderData newOrder = new OrderData(orderNumber, item.Qty, orderQty);

                    //update existing info
                    searchLineItem.Category          = item.Category;
                    searchLineItem.Number            = item.Number;
                    searchLineItem.HasPdf            = item.HasPdf;
                    searchLineItem.ItemDescription   = item.ItemDescription;
                    searchLineItem.Material          = item.Material;
                    searchLineItem.MaterialThickness = item.MaterialThickness;
                    searchLineItem.Parent            = item.Parent;
                    searchLineItem.Title             = item.Title;
                    searchLineItem.Operations        = item.Operations;

                    // add new order information
                    searchLineItem.AssociatedOrders.Add(newOrder);
                    PrintLineItem(searchLineItem, isBatch, batchItemName, currentProduct, batchName);
                }


                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public static string CalculateSubFolder(string pdfInputPath, string rootOutputPath, AggregateLineItem item, bool isBatch)
        {
            string inputPdfName  = pdfInputPath + item.Number + ".pdf";
            string outputPdfPath = rootOutputPath;


            if (item.StructCode != "")
            {
                item.StructCode = item.StructCode.Replace('/', '-');
            }

            // route to the proper plant
            if (item.Category == "Part")
            {
                if (item.PlantID == "Plant 2")
                {
                    outputPdfPath += "\\Plant 2\\";
                }
                else if (item.PlantID == "Plant 1&2")
                {
                    outputPdfPath += "\\Plant 1&2\\";
                }
                else    // default to plant 1
                {
                    outputPdfPath += "\\Plant 1\\";
                }
            }

            if (!isBatch)
            {
                // route to stock or make to order folders for part items on orders
                if (item.Category == "Part")
                {
                    if (item.IsStock == true)
                    {
                        outputPdfPath += "\\Stock\\";
                    }
                    else
                    {
                        outputPdfPath += "\\Make To Order\\";
                    }
                }
            }
            else
            {
                // route to stock or make to order folders for part items on batches
                if (item.Category == "Part")
                {
                    if (item.IsStock == true)
                    {
                        outputPdfPath += "\\Parts To Make for Batch\\";
                    }
                    else
                    {
                        outputPdfPath += "\\Parts To Make as Ordered\\";
                    }
                }
            }

            System.IO.Directory.CreateDirectory(outputPdfPath);

            // sort out laser parts
            if (item.Operations == "Laser")
            {
                outputPdfPath = outputPdfPath + "\\" + item.Operations + "\\";
                if (item.MaterialThickness == "")
                {
                    item.MaterialThickness = "Unknown Thickness";
                }
                outputPdfPath += item.MaterialThickness.ToString();
                System.IO.Directory.CreateDirectory(outputPdfPath);
                outputPdfPath += "\\" + item.Number + ".pdf";
            }

            // sort out bandsaw parts
            else if (item.Operations == "Bandsaw" || item.Operations == "Iron Worker")
            {
                outputPdfPath = outputPdfPath + "\\" + item.Operations + "\\";
                if (item.StructCode == "")
                {
                    item.StructCode = "Unknown Material Type";
                }
                outputPdfPath += item.StructCode;
                System.IO.Directory.CreateDirectory(outputPdfPath);
                outputPdfPath += "\\" + item.Number + ".pdf";
            }

            // sort out machine shop parts
            else if (item.Operations == "Machine Shop")
            {
                outputPdfPath = outputPdfPath + "\\" + item.Operations + "\\";
                if (item.StructCode == "")
                {
                    item.StructCode = "Unknown Material Type";
                }
                outputPdfPath += item.StructCode;
                System.IO.Directory.CreateDirectory(outputPdfPath);
                outputPdfPath += "\\" + item.Number + ".pdf";
            }

            // sort out sheared parts
            else if (item.Operations == "Shear")
            {
                outputPdfPath = outputPdfPath + "\\" + item.Operations + "\\";
                if (item.StructCode == "")
                {
                    item.StructCode = "Unknown Material Type";
                }
                outputPdfPath += item.StructCode;
                System.IO.Directory.CreateDirectory(outputPdfPath);
                outputPdfPath += "\\" + item.Number + ".pdf";
            }

            // assemblies should drop through above logic down into here...
            else
            {
                outputPdfPath += "\\" + item.Number + ".pdf";
            }

            return(outputPdfPath);
        }
Ejemplo n.º 3
0
        private bool PrintLineItem(AggregateLineItem item, bool isBatch, string batchItemName, string currentProduct, string batchName = "")
        {
            try
            {
                string outputPdfPath = ProcessPDF.CalculateSubFolder(PdfInputPath, Path.GetDirectoryName(XmlFileName), item, isBatch);

                string watermark = "";
                if (isBatch)
                {
                    watermark = "Batch Name: " + batchName + "\n";
                }

                if (item.Category == "Part")  // only process parts at this level
                {
                    string itemNumber = "";
                    if (item.Keywords != "")
                    {
                        itemNumber = item.Keywords;
                    }
                    else
                    {
                        itemNumber = item.Number;
                    }

                    watermark += "Item Number: " + itemNumber + "      Desc: " + item.ItemDescription + "\n";
                    if (item.Category == "Part")
                    {
                        watermark += "Material: " + item.StructCode + "\n";
                        watermark += "Operation: " + item.Operations + "\n";
                    }
                    int totalQty = 0;

                    if (item.Notes != "")
                    {
                        watermark += "Notes: " + item.Notes + "\n";
                    }

                    foreach (var order in item.AssociatedOrders)
                    {
                        int lineTotalQty = order.UnitQty * order.OrderQty;
                        if (!isBatch)
                        {
                            string productName = GetProductNumberOfOrderNumber(order.OrderNumber);
                            watermark += order.OrderNumber + "--" + productName + "--" + " Ordr Qty: " + order.OrderQty + " x unit Qty: " + order.UnitQty + "---Line Ttl Qty: " + lineTotalQty + "\n";
                        }
                        else
                        {
                            watermark += "Batch Line: " + order.OrderNumber + "----- Line Qty: " + order.OrderQty + " x per unit Qty: " + order.UnitQty + "---Line Total Qty: " + lineTotalQty + "\n";
                        }
                        totalQty += lineTotalQty;
                    }

                    watermark += "Total Quantity: " + totalQty + "\n";

                    string fileNameToCopy = item.Number + ".pdf";
                    string outputFolder   = Path.GetDirectoryName(outputPdfPath) + "\\";

                    if (ProcessPDF.CopyPDF(PdfInputPath, new List <string> {
                        fileNameToCopy
                    }, new List <string> {
                        watermark
                    }, outputFolder))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in Processing PDFs.\n" + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 4
0
        public static bool CreateCoverPageWithCutList(string fileName, AggregateLineItem item, List <AggregateLineItem> cutList)
        {
            try
            {
                string tempDir = System.IO.Path.GetTempPath() + @"\VaultItemProcessor\";

                Document document = new Document();
                document.Info.Title = "Order Cover Page";

                // item information
                Section itemSection = document.AddSection();
                itemSection.AddParagraph("Item Information", "Heading2");

                itemSection.PageSetup.PageFormat = PageFormat.A4;
                itemSection.PageSetup.PageWidth  = Unit.FromInch(8.5);
                itemSection.PageSetup.PageHeight = Unit.FromInch(11.0);

                Table itemTable = new Table();
                itemTable.Borders.Width = 0.75;

                Column column = itemTable.AddColumn(Unit.FromInch(2));
                column.Format.Alignment = ParagraphAlignment.Center;

                itemTable.AddColumn(Unit.FromInch(4));

                Row row = itemTable.AddRow();
                row.Shading.Color = Colors.PaleGoldenrod;
                Cell cell = row.Cells[0];
                cell.AddParagraph("Item Number");
                cell = row.Cells[1];
                cell.AddParagraph("Description");

                row  = itemTable.AddRow();
                cell = row.Cells[0];
                cell.AddParagraph(item.Number);
                cell = row.Cells[1];
                cell.AddParagraph(item.ItemDescription);

                itemSection.Add(itemTable);

                // order information
                //Section orderSection = document.AddSection();

                Table orderTable = new Table();
                orderTable.Borders.Width = 0.75;

                Column orderColumn = orderTable.AddColumn(Unit.FromInch(1));    // blank column to indent
                orderTable.AddColumn(Unit.FromInch(1.5));                       // order number text
                orderTable.AddColumn(Unit.FromInch(1.5));                       // order number actual value
                orderTable.AddColumn(Unit.FromInch(1));                         // quantity text
                orderTable.AddColumn(Unit.FromInch(1));                         // actual quantity
                orderColumn.Format.Alignment = ParagraphAlignment.Center;



                int index = 0;
                foreach (OrderData order in item.AssociatedOrders)
                {
                    Row orderRow = orderTable.AddRow();
                    orderRow.Shading.Color = Colors.BlanchedAlmond;
                    Cell orderCell = orderRow.Cells[0];

                    orderCell = orderRow.Cells[1];
                    orderCell.AddParagraph("Order Number");
                    orderCell = orderRow.Cells[2];
                    orderCell.AddParagraph(item.AssociatedOrders[index].OrderNumber);
                    orderCell = orderRow.Cells[3];
                    orderCell.AddParagraph("Qty");
                    orderCell = orderRow.Cells[4];
                    orderCell.AddParagraph(item.AssociatedOrders[index].OrderQty.ToString());

                    index++;
                }

                //orderTable.SetEdge(0, 0, index-2, 3, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.Black);

                itemSection.Add(orderTable);


                if (cutList.Count > 0)
                {
                    itemSection.AddParagraph("", "Heading2");
                    itemSection.AddParagraph("Cut List of Non-Stock Saw and Iron Worker Parts without Drawings.", "Heading2");
                }

                foreach (AggregateLineItem cutItem in cutList)
                {
                    Table cutListTable = new Table();
                    cutListTable.Borders.Width = 0.75;

                    Column cutListcolumn = cutListTable.AddColumn(Unit.FromInch(1.5));
                    column.Format.Alignment = ParagraphAlignment.Center;

                    cutListTable.AddColumn(Unit.FromInch(2.0));
                    cutListTable.AddColumn(Unit.FromInch(2.0));
                    cutListTable.AddColumn(Unit.FromInch(1.0));

                    Row cutListRow = cutListTable.AddRow();
                    cutListTable.Shading.Color = Colors.PaleGoldenrod;
                    Cell cutListCell = cutListRow.Cells[0];
                    cutListCell.AddParagraph("Item Number");
                    cutListCell = cutListRow.Cells[1];
                    cutListCell.AddParagraph("Description");
                    cutListCell = cutListRow.Cells[2];
                    cutListCell.AddParagraph("Material");
                    cutListCell = cutListRow.Cells[3];
                    cutListCell.AddParagraph("Operations");

                    cutListRow  = cutListTable.AddRow();
                    cutListCell = cutListRow.Cells[0];
                    cutListCell.AddParagraph(cutItem.Number);
                    cutListCell = cutListRow.Cells[1];
                    cutListCell.AddParagraph(cutItem.ItemDescription);
                    cutListCell = cutListRow.Cells[2];
                    cutListCell.AddParagraph(cutItem.StructCode);
                    cutListCell = cutListRow.Cells[3];
                    cutListCell.AddParagraph(cutItem.Operations);

                    itemSection.Add(cutListTable);

                    int index2 = 0;
                    orderTable = new Table();
                    orderTable.Borders.Width = 0.75;

                    orderColumn = orderTable.AddColumn(Unit.FromInch(1.5));         // blank column to indent
                    orderTable.AddColumn(Unit.FromInch(1.5));                       // order number text
                    orderTable.AddColumn(Unit.FromInch(1.5));                       // order number actual value
                    orderTable.AddColumn(Unit.FromInch(1));                         // quantity text
                    orderTable.AddColumn(Unit.FromInch(1));                         // actual quantity
                    orderColumn.Format.Alignment = ParagraphAlignment.Center;

                    foreach (OrderData order in cutItem.AssociatedOrders)
                    {
                        Row orderRow = orderTable.AddRow();
                        orderRow.Shading.Color = Colors.BlanchedAlmond;
                        Cell orderCell = orderRow.Cells[0];
                        orderCell = orderRow.Cells[1];
                        orderCell.AddParagraph("Order Number");
                        orderCell = orderRow.Cells[2];
                        orderCell.AddParagraph(cutItem.AssociatedOrders[index2].OrderNumber);
                        orderCell = orderRow.Cells[3];
                        orderCell.AddParagraph("Qty");
                        orderCell = orderRow.Cells[4];
                        int cutQty = cutItem.AssociatedOrders[index2].OrderQty * cutItem.AssociatedOrders[index2].UnitQty;
                        orderCell.AddParagraph(cutQty.ToString());

                        index2++;
                    }
                    itemSection.Add(orderTable);
                }

                if (item.Notes != "")
                {
                    itemSection.AddParagraph("");
                    itemSection.AddParagraph(item.Notes);
                }

                //if (item.Notes != "")
                //{
                //    Section notesSection = document.AddSection();
                //    notesSection.AddParagraph(item.Notes);
                //}


                var pdfRenderer = new PdfDocumentRenderer(false);
                pdfRenderer.Document = document;
                //pdfRenderer.RenderDocument();


                var tempDocument = document.Clone();
                tempDocument.BindToRenderer(null);
                var pdfRenderer3 = new PdfDocumentRenderer(true);
                pdfRenderer3.Document = tempDocument;
                pdfRenderer3.RenderDocument();
                int pageCount = pdfRenderer3.PdfDocument.PageCount;


                if (!(pageCount % 2 == 0))  // add a filler page if we have an odd number of pages.
                {
                    Section blankSection = document.AddSection();
                    blankSection.PageSetup.PageFormat = PageFormat.A4;
                    blankSection.PageSetup.PageWidth  = Unit.FromInch(8.5);
                    blankSection.PageSetup.PageHeight = Unit.FromInch(11);

                    pdfRenderer.RenderDocument();
                    //blankSection.AddParagraph("This page intentionally left blank.");
                    pdfRenderer.PdfDocument.Save(fileName);
                }
                else
                {
                    pdfRenderer.RenderDocument();
                    pdfRenderer.PdfDocument.Save(fileName);
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }