Beispiel #1
0
        private string ExtractTransMode(PdfXmlMapper mapping)
        {
            foreach (var page in mapping.Pages)
            {
                foreach (var table in page.Tables)
                {
                    if (table.Rows.Count > 1)
                    {
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            var row = table.Rows[i];

                            for (int j = 0; j < row.Cells.Count; j++)
                            {
                                var cell = row.Cells[j];
                                if (cell.Equals(Constants.Common.TransMode))
                                {
                                    var nextRow = table.Rows[i + 1];
                                    return(nextRow.Cells[j]);
                                }
                            }
                        }
                    }
                }
            }

            return("");
        }
Beispiel #2
0
        private Dictionary <string, string> ExtractSizes(PdfXmlMapper mapping)
        {
            Dictionary <string, string> sizeModels = new Dictionary <string, string>();

            //the first line is not a column, it is a line, so we have to extract it in ugly way. :D
            if (mapping.Pages.Count > 0 &&
                mapping.Pages[0].Tables.Count > 1 &&
                mapping.Pages[0].Tables[1].Rows.Count > 0 &&
                mapping.Pages[0].Tables[1].Rows[mapping.Pages[0].Tables[1].Rows.Count - 1].Cells.Count > 0)
            {
                string   firstSizeRow = mapping.Pages[0].Tables[1].Rows[mapping.Pages[0].Tables[1].Rows.Count - 1].Cells[0];
                string[] splits       = firstSizeRow.Split(' ');
                string   sizeType     = splits[splits.Length - 7];
                string   sizeValue    = splits[splits.Length - 3];
                sizeModels.Add(sizeType, sizeValue);
            }

            //extract other tables.
            if (mapping.Pages.Count > 0 &&
                mapping.Pages[0].Tables.Count > 1 &&
                mapping.Pages[0].Tables[0].Rows.Count > 0)
            {
                foreach (var row in mapping.Pages[0].Tables[0].Rows)
                {
                    if (row.Cells.Count > 20)
                    {
                        string sizeType  = row.Cells[10];
                        string sizeValue = row.Cells[18];
                        sizeModels.Add(sizeType, sizeValue);
                    }
                }
            }

            return(sizeModels);
        }
Beispiel #3
0
        private Dictionary <string, string> ExtractSizes(PdfXmlMapper mapping)
        {
            Dictionary <string, string> sizeModels = new Dictionary <string, string>();

            foreach (var page in mapping.Pages)
            {
                foreach (var table in page.Tables)
                {
                    if (table.Rows.Count > 1)
                    {
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            var row = table.Rows[i];

                            for (int j = 0; j < row.Cells.Count; j++)
                            {
                                var cell = row.Cells[j];
                                if (cell.Trim().Equals(Constants.Common.ScheduledLine))
                                {
                                    var   sizeRow = table.Rows[table.Rows.Count - 1];
                                    Regex regex   = new Regex("[ ]{2,}", RegexOptions.None);

                                    string sizeLine = sizeRow.Cells[3];
                                    sizeLine = sizeLine.Replace("-", "").Trim();
                                    sizeLine = regex.Replace(sizeLine, " ");
                                    var sizes = sizeLine.Split(' ');

                                    string sizeValueLine = sizeRow.Cells[4];
                                    sizeValueLine = sizeValueLine.Replace("-", "").Trim();
                                    sizeValueLine = regex.Replace(sizeValueLine, " ");
                                    var sizeValues = sizeValueLine.Split(' ');

                                    if (sizes.Length == sizeValues.Length)
                                    {
                                        for (int sizeIndex = 0; sizeIndex < sizes.Length; sizeIndex++)
                                        {
                                            sizeModels.Add(sizes[sizeIndex], sizeValues[sizeIndex]);
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("The sizes count and values count are different.");
                                    }

                                    return(sizeModels);
                                }
                            }
                        }
                    }
                }
            }

            throw new Exception("Cannot find Sizes.");
        }
Beispiel #4
0
        private string ExtractPlannedDelDate(PdfXmlMapper mapping)
        {
            if (mapping.Pages.Count > 0 &&
                mapping.Pages[0].Tables.Count > 1 &&
                mapping.Pages[0].Tables[0].Rows.Count > 0 &&
                mapping.Pages[0].Tables[0].Rows[0].Cells.Count > 13)
            {
                return(mapping.Pages[0].Tables[0].Rows[0].Cells[14]);
            }

            return("");
        }
Beispiel #5
0
        private string ExtractPOUnitPrice(PdfXmlMapper mapping)
        {
            if (mapping.Pages.Count > 0 &&
                mapping.Pages[0].Tables.Count > 1 &&
                mapping.Pages[0].Tables[0].Rows.Count > 0 &&
                mapping.Pages[0].Tables[0].Rows[0].Cells.Count > 19)
            {
                return(mapping.Pages[0].Tables[0].Rows[0].Cells[20]);
            }

            return("");
        }
Beispiel #6
0
        private string ExtractMaterialDescription(PdfXmlMapper mapping)
        {
            if (mapping.Pages.Count > 0 &&
                mapping.Pages[0].Tables.Count > 1 &&
                mapping.Pages[0].Tables[0].Rows.Count > 0 &&
                mapping.Pages[0].Tables[0].Rows[0].Cells.Count > 1)
            {
                return(mapping.Pages[0].Tables[0].Rows[0].Cells[2]);
            }

            return("");
        }
Beispiel #7
0
        private ExtractedRowModel ExtractFile(string fileName, string fileXmlContent)
        {
            ExtractedRowModel model = new ExtractedRowModel();

            XmlSerializer serializer = new XmlSerializer(typeof(PdfXmlMapper));
            PdfXmlMapper  mapping    = null;

            using (TextReader reader = new StringReader(fileXmlContent))
            {
                mapping = (PdfXmlMapper)serializer.Deserialize(reader);
            }

            if (mapping != null)
            {
                try
                {
                    // Extract PO Number
                    model.PONumber            = ExtractPONumber(mapping);
                    model.SeasonCode          = ExtractSeasonCode(mapping);
                    model.Manufacturer        = ExtractManufacturer(mapping);
                    model.Material            = ExtractMaterial(mapping);
                    model.MaterialDescription = ExtractMaterialDescription(mapping);
                    model.Plan_ExFTY          = ExtractPlannedDelDate(mapping);
                    model.Original_ExFTY      = "";
                    model.TotalPOQty          = ExtractTotalPOQty(mapping);
                    model.POUnitPrice         = ExtractPOUnitPrice(mapping);
                    model.DeliveryAddress     = ExtractDeliveryAddress(mapping);
                    model.TransMode           = ExtractTransMode(mapping);
                    model.Sizes = ExtractSizes(mapping);
                }
                catch (Exception ex)
                {
                    model.HasErrors = true;
                    model.Error     = ex.Message;

                    this.RejectedFiles.Add(fileName);
                }
            }

            return(model);
        }
Beispiel #8
0
        private string ExtractTotalPOQty(PdfXmlMapper mapping)
        {
            foreach (var page in mapping.Pages)
            {
                foreach (var table in page.Tables)
                {
                    foreach (var row in table.Rows)
                    {
                        for (int i = 0; i < row.Cells.Count; i++)
                        {
                            var cell = row.Cells[i];
                            if (cell.Equals(Constants.Brazil.TotalPOQty))
                            {
                                string poQty = row.Cells[i + 1];
                                return(poQty);
                            }
                        }
                    }
                }
            }

            return("");
        }
Beispiel #9
0
        private string ExtractManufacturer(PdfXmlMapper mapping)
        {
            foreach (var page in mapping.Pages)
            {
                foreach (var table in page.Tables)
                {
                    foreach (var row in table.Rows)
                    {
                        for (int i = 0; i < row.Cells.Count; i++)
                        {
                            var cell = row.Cells[i];
                            if (cell.Equals(Constants.Common.Manufacturer))
                            {
                                string manufacturer = row.Cells[i + 1];
                                return(manufacturer);
                            }
                        }
                    }
                }
            }

            return("");
        }
Beispiel #10
0
        private string ExtractSeasonCode(PdfXmlMapper mapping)
        {
            foreach (var page in mapping.Pages)
            {
                foreach (var table in page.Tables)
                {
                    foreach (var row in table.Rows)
                    {
                        for (int i = 0; i < row.Cells.Count; i++)
                        {
                            var cell = row.Cells[i];
                            if (cell.Equals(Constants.Common.SeasonCode))
                            {
                                string code = row.Cells[i + 1];
                                return(code);
                            }
                        }
                    }
                }
            }

            return("");
        }
Beispiel #11
0
        private string ExtractTransMode(PdfXmlMapper mapping)
        {
            foreach (var page in mapping.Pages)
            {
                foreach (var table in page.Tables)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var row = table.Rows[i];

                        for (int j = 0; j < row.Cells.Count; j++)
                        {
                            var cell = row.Cells[j];
                            if (cell.Contains(Constants.Brazil.TransMode))
                            {
                                return(cell.Replace(Constants.Brazil.TransMode, "").Trim());
                            }
                        }
                    }
                }
            }

            return("");
        }