public Job(PrintItem PrintItem)
        {
            PrintItems = new List <PrintItem>();
            JobTotal   = 0;

            this.Id = PrintItem.JobId;
            PrintItems.Add(PrintItem);
        }
Пример #2
0
        /// <summary>
        /// Accepts a csv file to get job that need to be processed.
        /// </summary>
        public void ReadInputFile()
        {
            try
            {
                string[] AllLines = File.ReadAllLines(rootFolder + "BatchJobFile.csv");

                foreach (string line in AllLines.Skip(1))
                {
                    string[] tokens = line.Split('\t', StringSplitOptions.None);

                    PrintItem printItem = new PrintItem
                    {
                        JobId             = Convert.ToInt32(tokens[0].ToString()),
                        Description       = tokens[1].ToString().Trim(),
                        Cost              = Convert.ToDecimal(tokens[2].ToString()),
                        ChargeExtraMargin = Convert.ToBoolean(Convert.ToInt32(tokens[3].ToString())),
                        ChargeSaleTax     = Convert.ToBoolean(Convert.ToInt32(tokens[4].ToString()))
                    };

                    //Check if print item needs to be add a existing Job based on job id
                    //or to a new one.
                    if (Jobs.Select(o => o.Id).ToList().Any(o => o == printItem.JobId))
                    {
                        Job job = Jobs.Where(o => o.Id == printItem.JobId).FirstOrDefault();
                        job.PrintItems.Add(printItem);
                    }
                    else
                    {
                        Jobs.Add(new Job(printItem));
                    }
                }
            }
            catch (Exception WhatHappen)
            {
                Console.WriteLine("Error reading input file.");
                Console.WriteLine($"The error message is { WhatHappen.Message }");
                Console.WriteLine("Please check the input file.");
                Console.WriteLine("We are looking for the input file 'BatchJobFile.csv' at " + rootFolder);
                Console.WriteLine("Retry application again.");
                Console.ReadLine();
            }
        }