예제 #1
0
        public MealSearcher(int idDiet)
        {
            InitializeComponent();
            this.ClientSize = new System.Drawing.Size(815, 570);


            /// FoodType load
            foodTypeDict  = LoadDB.LoadDBByte("FoodTypes", "IdFoodTypes", "Type");
            foodStyleDict = LoadDB.LoadDBByte("FoodStyle", "IdStyle", "Style");
            foodDietDict  = LoadDB.LoadDBByte("FoodDiet", "IdDiet", "Diet");

            /// CheckBoxLoad
            LoadCheckListBox(chLBFoodType, foodTypeDict);
            LoadCheckListBox(chLBDiet, foodDietDict);
            LoadCheckListBox(chLBStyle, foodStyleDict);

            /// Ingridients load
            LoadIngridients();
            Search();


            this.idDiet = idDiet;


            datTimPickDate.Value        = DateTime.Today.Date + new TimeSpan(12, 00, 00);
            datTimPickDate.CustomFormat = "HH:mm - dddd d MMMM yyyy";
        }
예제 #2
0
파일: Diet.cs 프로젝트: CzarqR/reapEAT
        public Diet()
        {
            InitializeComponent();
            this.ClientSize        = new System.Drawing.Size(324, 155);
            dateTPMin.CustomFormat = "ddd d.MM.yyyy";
            dateTPMax.CustomFormat = "ddd d.MM.yyyy";



            LoadDietsToLV();
            UserDiets = LoadDB.LoadDInt("[" + X.IdUser + "_diets]", "IdDiet", "Name");
            LoadUserDietsToCheckB();
        }
예제 #3
0
        public AddNewRecipe()
        {
            InitializeComponent();
            LoadIngridients();
            /// FoodType/Style/Diet load
            foodTypeDict  = LoadDB.LoadDBByte("FoodTypes", "IdFoodTypes", "Type");
            foodStyleDict = LoadDB.LoadDBByte("FoodStyle", "IdStyle", "Style");
            foodDietDict  = LoadDB.LoadDBByte("FoodDiet", "IdDiet", "Diet");

            LoadComboBox(comBDiet, foodDietDict);
            LoadComboBox(comBStyle, foodStyleDict);
            LoadComboBox(comBType, foodTypeDict);

            LoadMeasureTypes();
        }
예제 #4
0
        public Main()
        {
            InitializeComponent();
            this.ClientSize = new System.Drawing.Size(818, 575);


            /// FoodType load
            foodTypeDict  = LoadDB.LoadDBByte("FoodTypes", "IdFoodTypes", "Type");
            foodStyleDict = LoadDB.LoadDBByte("FoodStyle", "IdStyle", "Style");
            foodDietDict  = LoadDB.LoadDBByte("FoodDiet", "IdDiet", "Diet");

            /// CheckBoxLoad
            LoadCheckListBox(chLBFoodType, foodTypeDict);
            LoadCheckListBox(chLBDiet, foodDietDict);
            LoadCheckListBox(chLBStyle, foodStyleDict);

            /// Ingridients load
            LoadIngridients();
            Search();
        }
예제 #5
0
파일: Diet.cs 프로젝트: CzarqR/reapEAT
        /// Delete diet
        private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete " + listVDiets.SelectedItems[0].SubItems[0].Text + " diet?", "Delete Diet", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                using (SqlConnection sqlConnection = new SqlConnection(X.ConnectionString("DB")))
                {
                    SqlCommand sqlCommandDelDiet = new SqlCommand("DELETE FROM [" + X.IdUser + "_diets] WHERE IdDiet = " + listVDiets.SelectedItems[0].SubItems[1].Text, sqlConnection)
                    {
                        CommandType = CommandType.Text
                    };


                    SqlCommand sqlCommandDropDiet = new SqlCommand("DROP TABLE [" + X.IdUser + "_" + listVDiets.SelectedItems[0].SubItems[1].Text + "_diet];", sqlConnection)
                    {
                        CommandType = CommandType.Text
                    };


                    sqlConnection.Open();
                    sqlCommandDelDiet.ExecuteNonQuery();
                    sqlCommandDropDiet.ExecuteNonQuery();
                    sqlConnection.Close();

                    sqlCommandDelDiet.Dispose();
                    sqlCommandDropDiet.Dispose();
                }
            }

            if (idDiet == int.Parse(listVDiets.SelectedItems[0].SubItems[1].Text))
            {
                listVDiet.Items.Clear();
            }

            UserDiets.Clear();
            UserDiets = LoadDB.LoadDInt("[" + X.IdUser + "_diets]", "IdDiet", "Name");
            LoadUserDietsToCheckB();
            LoadDietsToLV();
        }
예제 #6
0
파일: Diet.cs 프로젝트: CzarqR/reapEAT
        private void ButConfirm_Click(object sender, EventArgs e)
        {
            ///Number of diets check
            if (UserDiets.Count == MaxDietsPerUser)
            {
                lblNameInfo.Text    = "You have the maximum number of diets";
                lblNameInfo.Visible = true;
                return;
            }

            ///Name validation
            string name = txtName.Text.ToString().Trim();

            if (name.Length == 0)
            {
                lblNameInfo.Text    = "Give correct name";
                lblNameInfo.Visible = true;
                return;
            }

            /// checking same name in DB
            using (SqlConnection sqlConnection = new SqlConnection(X.ConnectionString("DB")))
            {
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from [" + X.IdUser + "_diets] where name = '" + name + "'", sqlConnection);
                DataTable      dataTable      = new DataTable();
                sqlDataAdapter.Fill(dataTable);
                sqlDataAdapter.Dispose();
                if (dataTable.Rows.Count == 1)
                {
                    lblNameInfo.Text    = "There already is a diet with same name";
                    lblNameInfo.Visible = true;
                    return;
                }
            }



            /// adding diet to user diet list
            using (SqlConnection sqlConnection = new SqlConnection(X.ConnectionString("DB")))
            {
                SqlCommand sqlCommandAddDiet = new SqlCommand("Insert into [" + X.IdUser + "_diets] (Name) values ('" + name + "') ", sqlConnection)
                {
                    CommandType = CommandType.Text
                };
                sqlConnection.Open();
                sqlCommandAddDiet.ExecuteNonQuery();
                sqlConnection.Close();
                sqlCommandAddDiet.Dispose();
            }

            /// adding diet DB
            using (SqlConnection sqlConnection = new SqlConnection(X.ConnectionString("DB")))
            {
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from [" + X.IdUser + "_diets] where name = '" + name + "'", sqlConnection);
                DataTable      dataTable      = new DataTable();
                sqlDataAdapter.Fill(dataTable);
                sqlDataAdapter.Dispose();
                SqlCommand sqlCommandAddNewDietDB = new SqlCommand("CreateDiet", sqlConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                sqlCommandAddNewDietDB.Parameters.AddWithValue("@IdDiet", dataTable.Rows[0].Field <int>("IdDiet"));
                sqlCommandAddNewDietDB.Parameters.AddWithValue("@IdUser", X.IdUser);
                sqlConnection.Open();
                sqlCommandAddNewDietDB.ExecuteNonQuery();
                sqlConnection.Close();
            }
            UserDiets.Clear();
            UserDiets = LoadDB.LoadDInt("[" + X.IdUser + "_diets]", "IdDiet", "Name");
            LoadDietsToLV();
            LoadUserDietsToCheckB();
            lblName.Visible     = false;
            txtName.Visible     = false;
            butConfirm.Visible  = false;
            lblNameInfo.Visible = false;
            txtName.Text        = "";
        }