public static String GetMealInsertQuery(Meal meal)
 {
     String query = "insert into meal(nationID,mealTypeID,festivalID,mealNameVN,mealPicture,descriptionVN,tutorialVN,insertedByEmail,dietID)"
     + "values('" + meal.NationID + "','" + meal.MealTypeID + "','" + meal.FesID + "','" + meal.MealName
     + "','" + meal.MealPic + "','" + meal.Description + "','" + meal.Tutorial + "','" + meal.InsertedBy + "','"  + meal.DietID
     + "');";
     return query;
 }
 public void InsertMeal(Meal meal)
 {
     try
     {
         MySqlCommand cmd = mySqlConnection.CreateCommand();
         cmd.CommandText = "insert into meal(mealTypeID,mealNameVN,mealPicture,descriptionVN,tutorialVN,dietID)"
                                + "values (@mealTypeID,@mealName,@mealPic,@description,@tutorial,@dietID)";
         cmd.Parameters.AddWithValue("@mealTypeID", meal.MealTypeID);
         cmd.Parameters.AddWithValue("@mealName", meal.MealName);
         cmd.Parameters.AddWithValue("@mealPic", meal.MealPic);
         cmd.Parameters.AddWithValue("@description", meal.Description);
         cmd.Parameters.AddWithValue("@tutorial", meal.Tutorial);
         cmd.Parameters.AddWithValue("@dietID", meal.DietID);
         cmd.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         MessageBox.Show("Error: " + e.Message);
         throw;
     }
 }
Esempio n. 3
0
        private void btnUpdateMeal_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to update this(these) row(s)", "Update row", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                Meal meal = new Meal();
                meal.MealName = txtMealName.Text;
                meal.MealTypeID = cbbMealTypeID.SelectedIndex + 1;
                meal.DietID = cbbDiet.SelectedIndex + 1;
                meal.MealPic = txtMealPicture.Text;
                meal.Description = txtDescription.Text;
                meal.Tutorial = txtTutorial.Text;
                foreach (DataGridViewRow row in this.dgvMeal.SelectedRows)
                {

                    DataGridViewCell cell = row.Cells[0];
                    int id = int.Parse(cell.Value.ToString());
                    mysqlConectionService.UpdateMeal(meal,id);
                }

                MessageBox.Show("Updating successfull!");
                this.LoadMealData();
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
Esempio n. 4
0
        private void btnInsertMeal_Click(object sender, EventArgs e)
        {
            if (txtMealName.Text == "")
            {
                MessageBox.Show("Tên món ăn ko được để trống");
                return;
            }

            Meal meal = new Meal();
            meal.MealName = txtMealName.Text;
            meal.MealTypeID = cbbMealTypeID.SelectedIndex + 1;
            meal.DietID = cbbDiet.SelectedIndex + 1;
            string url = txtMealPicture.Text;
            string file = "" ;
            if (  url.Contains("http://"))
            {
                file  = FileUtil.DownLoadFile(url);

                meal.MealPic = file;
            }

            meal.Description = txtDescription.Text;
            meal.Tutorial = txtTutorial.Text;

            mysqlConectionService.InsertMeal(meal);
            string query = DatabaseUtil.GetMealInsertQuery(meal);
            // Export File Query
            FileUtil.ExportQueryFile(query);
            MessageBox.Show("Inserting successfull!");
            flagInsert = 1;
            this.LoadMealData();
        }
 public void UpdateMeal(Meal meal, int id)
 {
     try
     {
         MySqlCommand cmd = mySqlConnection.CreateCommand();
         cmd.CommandText = "update meal set mealTypeID=@mealTypeID,"
                           + "mealNameVN=@mealName,mealPicture=@mealPic,descriptionVN=@description,tutorialVN=@tutorial,dietID=@dietID"
                             + " where mealID=" + id;
         cmd.Parameters.AddWithValue("@mealTypeID", meal.MealTypeID);
         cmd.Parameters.AddWithValue("@mealName", meal.MealName);
         cmd.Parameters.AddWithValue("@mealPic", meal.MealPic);
         cmd.Parameters.AddWithValue("@description", meal.Description);
         cmd.Parameters.AddWithValue("@tutorial", meal.Tutorial);
         cmd.Parameters.AddWithValue("@dietID", meal.DietID);
         cmd.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         MessageBox.Show("Error: " + e.Message);
         throw;
     }
 }