示例#1
0
        //Main function
        static void Main(string[] args)
        {
            int start_day_offset = 1;
            int end_day_offset   = 91;

            //Initialise our 3 Structures
            List <string> DailyList = new List <string>();
            MonthDay      MDay      = new MonthDay();
            WeekDay       WDay      = new WeekDay();

            //Populate the Structurs and decide on output stream
            bool to_txt = My_Input.Get_input(DailyList, WDay, MDay);

            //Conduct output string
            string output = "";

            for (int i = start_day_offset; i < end_day_offset; i++)
            {
                var    current_date = DateTime.Now.AddDays(i);
                int    date_number  = current_date.Day;
                string date_weekday = current_date.ToString("ddd");

                List <string> customers = new List <string>();
                customers.AddRange(MDay.mdayList[date_number - 1]);
                customers.AddRange(WDay.wdayDict[date_weekday.ToLower()]);
                customers.AddRange(DailyList);

                output += current_date.ToString("ddd, dd MMMM yyyy") + ": " + String.Join(", ", customers.ToArray()) + System.Environment.NewLine;
            }

            if (to_txt)
            {
                My_Output.Print_file(output);
            }
            else
            {
                My_Output.Print_console(output);
            }
        }
示例#2
0
        //Function to help receive the input and populate the structures if format is appropriate
        internal static bool Get_input(List <string> Daily_list, WeekDay WDay, MonthDay MDay)
        {
            Print_Initial_Message();
            Print_Valid_Input_Format();

            bool end = false;

            while (!end)
            {
                Console.WriteLine();
                Console.WriteLine("Please, enter 'Q' if you want to stop providing customer data");
                Console.WriteLine("Or any other input to keep on");
                string end_choice = Console.ReadLine();

                if (string.Equals(end_choice, "Q"))
                {
                    end = true;
                }
                else
                {
                    bool          valid         = true;
                    string        customer_name = Get_customer();
                    string        preference    = Get_preference(customer_name);
                    int           isDate        = checkMonthDay(preference);
                    List <string> cust_weekdays = checkWeekDay(preference);

                    if (string.Equals(preference.ToLower(), "every day"))
                    {
                        Daily_list.Add(customer_name);
                    }
                    else if (cust_weekdays.Count != 0)
                    {
                        foreach (string wday in cust_weekdays)
                        {
                            WDay.dayAdd(wday, customer_name);
                        }
                    }
                    else if (isDate > 0)
                    {
                        MDay.dateAdd(isDate, customer_name);
                    }
                    else if (string.Equals(preference.ToLower(), "never"))
                    {
                    }
                    else
                    {
                        valid = false;
                        Console.WriteLine();
                        Console.WriteLine("Sorry, the provided preference input is not valid");
                        Console.WriteLine("You would need to re-attempt providing input for customer '{0}'", customer_name);
                        Console.WriteLine("Reminding the valid preference input format");
                        Console.WriteLine();
                        Print_Valid_Input_Format();
                    }
                    if (valid)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Customer '{0}' was added to the System.", customer_name);
                        Console.WriteLine();
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("Now please, enter 'P' if you want the output written in a txt file");
            Console.WriteLine("Or any other input if you want it displayed in the console:");
            string out_choice = Console.ReadLine();

            Console.WriteLine();

            return(string.Equals(out_choice, "P"));
        }