Beispiel #1
0
        public static string FindNamesOfDate(List <NameDate> nameDates, DateTime date)
        {
            NameDate name = nameDates.FirstOrDefault(nd => nd.Day == date.Day && nd.Month == date.Month);

            string namesOfTheDate = name != null ? name.Names : $"No names found from file for the date {date}";

            return(namesOfTheDate);
        }
Beispiel #2
0
        public static List <NameDate> LoadCSV(string filename)
        {
            string whole_file;

            try
            {
                // Get the file's text.
                whole_file = System.IO.File.ReadAllText(filename);
            }
            catch (System.IO.FileNotFoundException)
            {
                throw new System.IO.FileNotFoundException($"inserted file name from path: {filename} is not found");
            }

            // Split into lines.
            whole_file = whole_file.Replace('\n', '\r');

            string[] lines = whole_file.Split(new char[] { '\r' },
                                              StringSplitOptions.RemoveEmptyEntries);

            // See how many rows and columns there are.
            int num_rows = lines.Length;

            int num_cols = lines[0].Split(';').Length;

            if (num_cols != 2)
            {
                throw new Exception($"inserted file name from path: {filename} is not in correct format 2 columns separeted with semicolumn");
            }

            // Generate List for All name dates
            List <NameDate> nameDates = new List <NameDate>();
            int             row       = 0;

            // Load the array.
            try
            {
                for (row = 0; row < num_rows; row++)
                {
                    string[] columns  = lines[row].Split(';');
                    NameDate nameDate = new NameDate(columns, row);
                    nameDates.Add(nameDate);
                }
            }
            catch
            {
                throw new Exception($"Data in row {row} is not correct. Please check the date is in correct format \"dd.MM\".");
            }

            return(nameDates);
        }