Esempio n. 1
0
        public void _WhatYouEat()
        {
            // connect to the database.
            var             dbDirect    = "Server=localhost;Database=Kalculator3;Uid=root;Pwd=theBigBang!23;";
            MySqlConnection connecttoDB = new MySqlConnection(dbDirect);

            connecttoDB.Open();

            //ask user to choose if he wants to make new table.
            Console.WriteLine();
            Console.WriteLine("You can input the data of what you ate in the table whose is username.");
            Console.Write("Do you want to make a new table? (y/n) : ");
            var userInput = Console.ReadLine();

            if (userInput == "y")
            {
                Console.WriteLine("let's make a new table");
                Console.WriteLine("What's your name?");
                Console.Write(" : ");
                var newUserName = Console.ReadLine();

                string sql_newUser = $"CREATE TABLE {newUserName} (ITEM VARCHAR(45), UNIT INT(11), CALORIES INT(11), CARB INT(11), PROTEIN INT(11), FAT INT(11));";

                MySqlCommand cmd_newUser = new MySqlCommand(sql_newUser, connecttoDB);
                cmd_newUser.ExecuteNonQuery();

                Console.WriteLine("new data table has made.");

                //but here is a problem.
                //I cannot check if the command is implemented or not because there is no exception control.
                //and I can't get the error message here.
            }

            Console.WriteLine();
            Console.WriteLine("Give me your name to find your table");
            var userName = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine("Hello, {0}", userName);

            Console.WriteLine("input the name of item you want to add in the table. IT HAS TO BE ON THE LIST.");
            Console.Write(" : ");
            var nameofitem = Console.ReadLine();

            //check if the item exists in the table.
            var findTheItem = new SelectUsingReader();

            var datasetFromWholeList = findTheItem.SelectUsingReader_(nameofitem);

            //datasetFromWholeList.Read();

            var temporal_ITEM = datasetFromWholeList.GetString(datasetFromWholeList.GetOrdinal("ITEM"));

            var temporal_UNIT = datasetFromWholeList.GetInt32(datasetFromWholeList.GetOrdinal("UNIT"));

            var temporal_CALORIES = datasetFromWholeList.GetInt32(datasetFromWholeList.GetOrdinal("CALORIES"));
            var temporal_CARB     = datasetFromWholeList.GetInt32(datasetFromWholeList.GetOrdinal("CARB"));
            var temporal_PROTEIN  = datasetFromWholeList.GetInt32(datasetFromWholeList.GetOrdinal("PROTEIN"));
            var temporal_FAT      = datasetFromWholeList.GetInt32(datasetFromWholeList.GetOrdinal("FAT"));

            Console.WriteLine("so far so good?");


            string sql = $"INSERT INTO {userName} (ITEM, UNIT, CALORIES, CARB, PROTEIN, FAT) VALUE ('{temporal_ITEM}', {temporal_UNIT}, {temporal_CALORIES}, {temporal_CARB}, {temporal_PROTEIN}, {temporal_FAT});";

            MySqlCommand cmd = new MySqlCommand(sql, connecttoDB);

            cmd.ExecuteNonQuery();

            Console.WriteLine("so far so good 2");

            Console.WriteLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("This is the main menu");
            Console.WriteLine("You can move on the menu by number.");
            Console.WriteLine("----------------------------------");
            Console.WriteLine("1. Check your goal");
            Console.WriteLine("2. Input what you ate");
            Console.WriteLine("3. Input new nutrition info");
            Console.WriteLine("4. see the list of foods info");
            Console.WriteLine("5. Terminate the program");
            Console.WriteLine("6. test for developer");
            Console.WriteLine("----------------------------------");
            Console.Write("Type a number : ");

            int menu_select = Int32.Parse(Console.ReadLine());

            if (menu_select == 2)
            {
                var inputFoodEaten = new WhatYouEat();
                inputFoodEaten._WhatYouEat();

                /*
                 * var inputFoodEaten = new whatyouate();
                 * inputFoodEaten.whatyouate_();
                 */
            }
            else if (menu_select == 3)
            {
                var inputNewinfo = new ItemAddition();
                inputNewinfo.ItemAddition_();
                Console.WriteLine(inputNewinfo.Name);
                inputNewinfo.Add_Data_to_MySQL();
                Console.WriteLine(inputNewinfo.Name);
            }
            else if (menu_select == 4)
            {
                var reading = new SelectUsingReader();

                //if a parameter is input, it will show the details of it, otherwise all of items.
                Console.WriteLine("if you want to look up the information of the food, type the name of it. otherwise show whole list");
                Console.Write(" : ");
                var targetSearch = Console.ReadLine();

                if (targetSearch == null)
                {
                    reading.SelectUsingReader_();
                }
                reading.SelectUsingReader_(targetSearch);
            }

            else if (menu_select == 5)
            {
            }

            else if (menu_select == 6)
            {
                var numberTesting = new List <int>()
                {
                    1, 2, 3, 4, 5
                };
                foreach (int a in numberTesting)
                {
                    Console.WriteLine(a);
                }

                for (int i = 0; i < 5; i++)
                {
                    numberTesting[i] = numberTesting[i] * 2;
                    Console.WriteLine(numberTesting[i]);
                }



                /*
                 * var dbDirect = "Server=localhost;Database=Kalculator3;Uid=root;Pwd=theBigBang!23;";
                 *
                 * using (MySqlConnection connecttoDB = new MySqlConnection(dbDirect))
                 * {
                 *  connecttoDB.Open();
                 *
                 *  string sql = "SELECT ITEM FROM FoodList";
                 *
                 *  MySqlCommand cmd = new MySqlCommand(sql, connecttoDB);
                 *  MySqlDataReader rdr = cmd.ExecuteReader();
                 *
                 *  var nameofItems = new List<string>();
                 *
                 *  while (rdr.Read())
                 *  {
                 *      nameofItems.Add(Convert.ToString(rdr["ITEM"]));
                 *  }
                 *
                 *  foreach (string prime in nameofItems)
                 *  {
                 *      Console.WriteLine(prime);
                 *  }
                 *
                 *  var a = nameofItems.IndexOf("tesajenfting");
                 *  Console.WriteLine(a);
                 *  /*
                 *  while (rdr.Read())
                 *  {
                 *      Console.WriteLine("ITEM : {0}", rdr["ITEM"]);
                 *  }
                 */

                /*
                 * while (rdr.Read())
                 * {
                 *  Console.WriteLine("ITEM : {0}", rdr["ITEM"]);
                 *  Console.WriteLine("UNIT : {0}", rdr["UNIT"]);
                 *  Console.WriteLine("CALORIES : {0}", rdr["CALORIES"]);
                 *  Console.WriteLine("CARB : {0}", rdr["CARB"]);
                 *  Console.WriteLine("PROTEIN : {0}", rdr["PROTEIN"]);
                 *  Console.WriteLine("FAT : {0}", rdr["FAT"]);
                 *  Console.WriteLine();
                 * }
                 */
            }
        }