Пример #1
0
    public static void Main()
    {
        List <SamsungOrderRow> List = new List <SamsungOrderRow>();

        SamsungOrderRow orderRow = new SamsungOrderRow();

        SamsungOrder samsungOrder = new SamsungOrder();


        var orderTxt = @"Purchase Order PO No : 5299649779 Date : 2020.06.25 Supplier Name & Address Buyer Name & Address L10IU1 : ECONOCOM INTERNATIONAL ITALIA S.P.A Samsung Electronics Italia S.p.A Via Marcello Nizzoli, 8 Via Mike Bongiorno, 9 MILANO 20124 Sales Person : 2061971 ESPRI Purchse Group : QSW Payment Terms : S160 Purchaser : AAAAA Currency : EUR Plant : S425 Destination : CIF / MILANO [SEI]Plant TO SITE : Use Code : I Material Qty Price Per Unit Amount Delivery Material Description Commercial-Code 1 MI-SCBEXT36TH 1 7.41 1 PC 7.41 2020.06.29 MI-SCBEXT36TH,, MI-SCBEXT36TH Amount : 7.41 Remark 1 / 1";
        var results  = orderTxt.Split(new string[] { "Purchase Order" }, StringSplitOptions.None);

        foreach (string result in results)
        {
            if (!string.IsNullOrEmpty(result))
            {
                //Console.WriteLine(result.Trim());
                //PO NO
                var OrderNumber = Regex.Match(result, @"(?<=PO No :)(\s\d{10}\s)(?=Date :)");
                //Console.WriteLine(OrderNumber.ToString().Trim());

                samsungOrder.OrderNumber = OrderNumber.ToString().Trim();

                //Date
                var OrderDate = Regex.Match(result, @"(?<=Date :)(\s\d{4}[.]\d{2}[.]\d{2}\s)(?=Supplier)");

                samsungOrder.OrderDate = OrderDate.ToString().Trim().Replace(".", "-");

                //Console.WriteLine(Date.ToString().Trim());
                ////Supplier
                //var Supplier = Regex.Match(result, @"(?<=L10IU1 :)(.*)(?=Sales Person :)");
                //Console.WriteLine(Supplier.ToString().Trim());

                //Sales Person
                var SalesPerson = Regex.Match(result, @"(?<=Sales Person :)(\s\d{7}\s\w{5}\s)(?=Purchse Group :)");

                samsungOrder.DistributorCode = SalesPerson.ToString().Trim();


                //Console.WriteLine(SalesPerson.ToString().Trim());

                //OrderItemRow
                var OrderItemRowOne = Regex.Match(result, @"(?<=Commercial-Code)(.*)(?=Amount)");

                //Console.WriteLine(OrderItemRowOne.ToString().Trim());

                string[] OrderItem = OrderItemRowOne.ToString().Trim().Split(' ');

                orderRow.ArticleCode  = OrderItem[1];
                orderRow.Quantity     = Convert.ToInt32(OrderItem[2]);
                orderRow.Price        = OrderItem[3];
                orderRow.Amount       = OrderItem[6];
                orderRow.DeliveryDate = OrderItem[7].Replace(".", "-");

                List.Add(orderRow);


                orderRow.getSetOrderRow = List;

                samsungOrder.GetSetOrderRows = orderRow.getSetOrderRow;

                samsungOrder.OrderDetails();
            }
        }
    }
Пример #2
0
        static void Main(string[] args)
        {
            string fileName = @"C:\Temp\emails\20A1035736.txt";

            var skipLine = 0;

            List <SamsungOrderRow> Lst = new List <SamsungOrderRow>();

            SamsungOrderRow orderRow = new SamsungOrderRow();

            //orderRow.ArticleCode = "F-SCBSMT36TM";
            //orderRow.Price = "69.02";
            //orderRow.Quantity = 1;
            //orderRow.Amount = "69.02";
            //orderRow.DeliveryDate = "2019.09.26".Replace(".","-");

            //Lst.Add(orderRow);



            //orderRow = new SamsungOrderRow();

            //orderRow.ArticleCode = "F-SCBSMT36TM";
            //orderRow.Price = "69.02";
            //orderRow.Quantity = 1;
            //orderRow.Amount = "69.02";
            //orderRow.DeliveryDate = "2019.09.26".Replace(".", "-");

            //Lst.Add(orderRow);

            //orderRow.getSetOrderRow = Lst;



            SamsungOrder m = new SamsungOrder();

            //m.OrderNumber = "5282196578";
            //m.OrderDate = "2019.09.25".Replace(".","-");
            //m.DistributorCode = "2061971 ESPRI";
            //m.ExternelReference = "19a1114551";


            //m.GetSetOrderRows = orderRow.getSetOrderRow;

            //m.Print();



            /// Now  try with dynamic data

            //- Open the text file
            using (StreamReader sr = new StreamReader(fileName))
            {
                string line;    //- Holds the entire line

                //- Cycle thru the text file 1 line at a time pulling
                //- substrings into the variables initialized above
                while ((line = sr.ReadLine()) != null)
                {
                    //- Pulling substrings.  If there is a problem
                    //- with the start index and/or the length values
                    //- an exception is thrown
                    try
                    {
                        if (skipLine > 0)
                        {
                            skipLine -= 1;
                            continue;
                        }

                        if (line.Trim().StartsWith("Purchase"))
                        {
                            continue;
                        }

                        if (line.Trim().StartsWith("Supplier"))
                        {
                            skipLine = 3;
                            continue;
                        }


                        if (line.Trim().StartsWith("Payment"))
                        {
                            skipLine = 5;
                            continue;
                        }


                        if (line.Trim().Contains("PO No"))
                        {
                            m.OrderNumber = line.Substring(8, 10).Trim();
                            m.OrderDate   = line.Substring(26, 10).Trim().Replace(".", "-");
                        }

                        if (line.Trim().Contains("Sales Person"))
                        {
                            m.DistributorCode = line.Substring(15, 14).Trim();
                        }

                        if (line.Trim().StartsWith("1"))
                        {
                            orderRow.ArticleCode  = line.Substring(2, 14).Trim();
                            orderRow.Quantity     = Convert.ToInt32(line.Substring(16, 2).Trim());
                            orderRow.Price        = line.Substring(18, 5).Trim();
                            orderRow.DeliveryDate = line.Substring(33, 10).Trim().Replace(".", "-");
                            orderRow.Amount       = line.Substring(23, 2).Trim();


                            Lst.Add(orderRow);
                        }

                        if (line.Trim().StartsWith("2"))
                        {
                            orderRow = new SamsungOrderRow();

                            orderRow.ArticleCode  = line.Substring(2, 14).Trim();
                            orderRow.Quantity     = Convert.ToInt32(line.Substring(16, 2).Trim());
                            orderRow.Price        = line.Substring(18, 5).Trim();
                            orderRow.DeliveryDate = line.Substring(33, 10).Trim().Replace(".", "-");
                            orderRow.Amount       = line.Substring(23, 2).Trim();


                            Lst.Add(orderRow);
                        }

                        if (line.Trim().Contains("Remark"))
                        {
                            orderRow.getSetOrderRow = Lst;

                            m.GetSetOrderRows = orderRow.getSetOrderRow;

                            m.Print();
                            break;
                        }
                    }

                    catch (Exception ex)
                    {
                        Console.Write(ex.ToString());
                    }
                }
                sr.Close();
            }



            Console.ReadLine();
        }