コード例 #1
0
        public Form1()
        {
            InitializeComponent();


            listView1.View = View.Details;

            listView1.Columns.Add("Name");
            listView1.Columns.Add("Meal");
            listView1.Columns.Add("Category");
            listView1.Columns.Add("Day");
            listView1.Columns.Add("Day Num");

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("We cannot connect to the database", ex.Message);
                return;
            }
            Updates.updateSource(conn);
            Updates.updateDays(conn);
            Updates.updateCuisine(conn);
            Updates.updateMeal(conn);
            Updates.updateCategory(conn);
            Updates.updateSeason(conn);
            Updates.updateUnits(conn);
            Updates.updateIngredients(conn);
        }
コード例 #2
0
        // Adds ingredient
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Ingredient ing in Updates.getIngredients())
            {
                if (ing.name == textBox1.Text)
                {
                    MessageBox.Show("This ingredient is already in the list");
                    textBox1.Text        = null;
                    radioButton1.Checked = false;
                    button1.Enabled      = false;
                    numericUpDown1.Value = 0;
                    comboBox1.Text       = "";
                    comboBox2.Text       = "";
                    textBox1.Select();
                    return;
                }
            }

            if (comboBox1.Text != String.Empty)
            {
                bool inList = false;

                foreach (string s in Updates.getCatagories())
                {
                    if (s == comboBox1.Text)
                    {
                        inList = true;
                        break;
                    }
                }

                if (!inList)
                {
                    category = null;
                    MessageBox.Show("You must select a category from the list or add it.");
                    comboBox1.Select();
                    return;
                }
                if (inList)
                {
                    category = comboBox1.Text;
                }
            }
            else
            {
                category = null;
            }

            if (comboBox2.Text != String.Empty)
            {
                bool inList = false;

                foreach (string s in Updates.getStores())
                {
                    if (s == comboBox2.Text)
                    {
                        inList = true;
                        break;
                    }
                }

                if (!inList)
                {
                    source = null;
                    MessageBox.Show("You must select a store from the list or add it.");
                    comboBox2.Select();
                    return;
                }

                if (inList)
                {
                    source = comboBox2.Text;
                }
            }
            else
            {
                source = null;
            }


            if (radioButton1.Checked)
            {
                staple = "true";
            }
            else
            {
                staple = "false";
            }

            string cmdText = "SET TRANSACTION READ WRITE;";

            cmd = new MySqlCommand(cmdText, conn);
            cmd.ExecuteNonQuery();
            cmdText = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;";
            cmd     = new MySqlCommand(cmdText, conn);
            cmd.ExecuteNonQuery();
            cmdText = "START TRANSACTION;";
            cmd     = new MySqlCommand(cmdText, conn);
            cmd.ExecuteNonQuery();
            string theCmd = "CALL addIngredient(\'" + textBox1.Text + "\', \'" + category + "\', \'" + source + "\', " + staple + ", " + numericUpDown1.Value.ToString() + ");";

            cmd = new MySqlCommand(theCmd, conn);
            cmd.ExecuteNonQuery();
            cmdText = "COMMIT;";
            cmd     = new MySqlCommand(cmdText, conn);
            cmd.ExecuteNonQuery();

            Updates.updateIngredients(conn);
            MessageBox.Show("This ingredient is added to the list");
            textBox1.Text        = null;
            button1.Enabled      = false;
            numericUpDown1.Value = 0;
            comboBox1.Text       = "";
            comboBox2.Text       = "";
            radioButton1.Checked = false;
            textBox1.Select();
        }