Exemplo n.º 1
0
        public static VehicleSale FromTextLine(string dataline)
        {
            if (string.IsNullOrWhiteSpace(dataline))
            {
                return(null);
            }


            var vs = new VehicleSale();


            var regexObj = new Regex(@"""[^""]+""|'[^']+'|[^,]+");
            var columns  = new List <string>();

            foreach (Match m in regexObj.Matches(dataline))
            {
                columns.Add(m.Value);
            }


            for (var i = 0; i < columns.Count; i++)
            {
                var val = columns[i].Trim();

                switch (i)
                {
                case 0:
                    int dnum;
                    Int32.TryParse(val, out dnum);
                    vs.DealNumber = dnum;

                    break;

                case 1:
                    vs.CustomerName = val;
                    break;

                case 2:
                    vs.DealershipName = val;
                    break;

                case 3:
                    vs.Vehicle = val;
                    break;

                case 4:
                    val = val.Trim('"').Replace(",", "");
                    decimal pr;
                    decimal.TryParse(val, out pr);
                    vs.Price = pr;
                    break;

                case 5:
                    vs.Date = val;
                    break;
                }
            }

            return(vs);
        }
Exemplo n.º 2
0
        public void ReadSalesFromText(string raw)
        {
            var lines = raw.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            if (lines.Length < 2)
            {
                return;
            }


            Sales = new List <VehicleSale>(lines.Length - 1);

            for (var i = 1; i < lines.Length; i++)
            {
                var sale = VehicleSale.FromTextLine(lines[i]);

                if (sale != null)
                {
                    Sales.Add(sale);
                }
            }
        }