Beispiel #1
0
        public static List <Lunch> GetAllLunch()
        {
            List <Lunch> allDatas = new List <Lunch> {
            };
            MySqlConnection conn  = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = @"SELECT * FROM lunch;";
            MySqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int      lunchId    = rdr.GetInt32(0);
                string   food       = rdr.GetString(1);
                DateTime stampTimeB = rdr.GetDateTime(2);
                float    sugar      = rdr.GetFloat(3);
                float    carb       = rdr.GetFloat(4);
                int      user_id    = rdr.GetInt32(5);
                Lunch    newLunch   = new Lunch(food, stampTimeB, sugar, carb, user_id, lunchId);
                allDatas.Add(newLunch);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allDatas);
        }
Beispiel #2
0
        public static Lunch Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM lunch WHERE id = (@searchId);";
            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);
            var      rdr       = cmd.ExecuteReader() as MySqlDataReader;
            int      LunchId   = 0;
            string   food      = "";
            DateTime stampTime = new DateTime();
            float    sugar     = 0;
            float    carb      = 0;
            int      userId    = 0;

            while (rdr.Read())
            {
                LunchId   = rdr.GetInt32(0);
                food      = rdr.GetString(1);
                stampTime = rdr.GetDateTime(2);
                sugar     = rdr.GetFloat(3);
                carb      = rdr.GetFloat(4);
                userId    = rdr.GetInt32(5);
            }
            Lunch newLunch = new Lunch(food, stampTime, sugar, carb, userId, LunchId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newLunch);
        }
Beispiel #3
0
        public List <Lunch> GetLunchs()
        {
            List <Lunch> allLoginLunchs = new List <Lunch> {
            };
            MySqlConnection conn        = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM lunch WHERE user_id = @user_id;";
            MySqlParameter userId = new MySqlParameter();

            userId.ParameterName = "@user_id";
            userId.Value         = this._id;
            cmd.Parameters.Add(userId);
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int      lunchId   = rdr.GetInt32(0);
                string   food      = rdr.GetString(1);
                DateTime stampTime = rdr.GetDateTime(2);
                float    sugar     = rdr.GetFloat(3);
                float    carb      = rdr.GetFloat(4);
                int      user_id   = rdr.GetInt32(5);
                Lunch    newLunch  = new Lunch(food, stampTime, sugar, carb, user_id);

                allLoginLunchs.Add(newLunch);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allLoginLunchs);
        }