Esempio n. 1
0
        public static void MenuStart(int userName)


        {
            int    UsersID = userName;
            string query;
            bool   running = true;

            do
            {
                bool        run       = true;
                int         selection = Validations.GetInt("1. Enter an Activity \r\n2. View Tracked Data\r\n3. Run Calculations");
                int         subSelection;
                string      value;
                ActivityLog Activity = new ActivityLog();
                Console.WriteLine(UsersID);
                switch (selection)



                {
                case 1:


                {
                    do
                    {
                        Activity.User_ID = UsersID;

                        query = @"select * from activity_categories ;";
                        DataTable table = DatabaseConnection.queryDatabase(query);
                        Dictionary <int, string> keyValues = DatabaseConnection.DataList(table, "activity_category_id", "category_description");
                        DatabaseConnection.PrintDictionary(keyValues);
                        subSelection = Validations.GetInt();
                        if (keyValues.TryGetValue(subSelection, out value))
                        {
                            Activity.CatDescr = subSelection;
                        }
                        query     = @"select * from activity_descriptions ;";
                        table     = DatabaseConnection.queryDatabase(query);
                        keyValues = DatabaseConnection.DataList(table, "activity_description_id", "activity_description");
                        DatabaseConnection.PrintDictionary(keyValues);
                        subSelection = Validations.GetInt();
                        if (keyValues.TryGetValue(subSelection, out value))
                        {
                            Activity.ActDescr = subSelection;
                        }

                        query     = @"select * from days_of_week ;";
                        table     = DatabaseConnection.queryDatabase(query);
                        keyValues = DatabaseConnection.DataList(table, "day_id", "day_name");
                        DatabaseConnection.PrintDictionary(keyValues);
                        subSelection = Validations.GetInt();
                        if (keyValues.TryGetValue(subSelection, out value))
                        {
                            Activity.DayName = subSelection;
                        }
                        query     = @"select * from tracked_calendar_days ;";
                        table     = DatabaseConnection.queryDatabase(query);
                        keyValues = DatabaseConnection.DataList(table, "calendar_day_id", "calendar_numerical_day");
                        DatabaseConnection.PrintDictionary(keyValues);
                        subSelection = Validations.GetInt();
                        if (keyValues.TryGetValue(subSelection, out value))
                        {
                            Activity.DateTime = subSelection;
                        }
                        query     = @"select * from activity_times ;";
                        table     = DatabaseConnection.queryDatabase(query);
                        keyValues = DatabaseConnection.DataList(table, "activity_time_id", "time_spent_on_activity");
                        DatabaseConnection.PrintDictionary(keyValues);
                        subSelection = Validations.GetInt();
                        if (keyValues.TryGetValue(subSelection, out value))
                        {
                            Activity.TimeSpent = subSelection;
                        }
                        query     = @"select * from tracked_calendar_dates ;";
                        table     = DatabaseConnection.queryDatabase(query);
                        keyValues = DatabaseConnection.DataList(table, "calendar_date_id", "calendar_date");
                        DatabaseConnection.PrintDictionary(keyValues);
                        subSelection = Validations.GetInt();
                        if (keyValues.TryGetValue(subSelection, out value))
                        {
                            Activity.CalendarDate = subSelection;
                        }
                        string queryadd = UsersID + " ," + Activity.ToString();

                        query = $@"INSERT INTO activity_log (user_id,calendar_day,day_name,category_description,activity_description,time_spent_on_activity,calendar_date) VALUES ({queryadd});";
                        Console.Write(query);
                        DatabaseConnection.queryDataInsert(query);

                        Utility.Pause();
                        run = Validations.GetBool("Do you want to add another activity? : ");
                    } while (run);
                }
                break;

                case 2:

                {
                    List <ActivityLog> activities = null;

                    Activity.User_ID = UsersID;
                    query            = @"select * from activity_categories ;";
                    DataTable table = DatabaseConnection.queryDatabase(query);
                    Dictionary <int, string> keyValues = DatabaseConnection.DataList(table, "activity_category_id", "category_description");
                    DatabaseConnection.PrintDictionary(keyValues);
                    subSelection = Validations.GetInt();
                    if (keyValues.TryGetValue(subSelection, out value))

                    {
                        Activity.DateTime = subSelection;
                        string category = "category_description";
                        query      = $@"Select * from activity_log where user_id = {userName} and {category} = {subSelection};";
                        activities = ActivityLog.AllActivities(query);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Entry");
                    }
                    List <Activities> descriptActivities = new List <Activities>();
                    foreach (ActivityLog log in activities)
                    {
                        int i = log.SetID; Activities activity = new Activities(i); descriptActivities.Add(activity);
                    }
                    foreach (Activities log in descriptActivities)
                    {
                        Console.WriteLine(log.ToString());
                    }
                    Utility.Pause();
                } break;

                case 3:
                {
                } break;

                case 4: { running = false; } break;

                default: { } break;
                }
            } while (running);
        }