Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to add an ingredient?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    name = textBoxName.Text;
                    quantity = double.Parse(textBoxQuantity.Text);
                    price = double.Parse(textBoxPrice.Text);
                    status = textBoxStatus.Text;
                    Ing = new Ingredient(name, quantity, price, status);

                    if (Ing.repOK() && Ing.validatePrice(price))
                    {
                        IngMan = new IngredientManager();
                        IngMan.saveIngredient(Ing);

                        //write text file
                        //MessageBox.Show(cus.toString());
                        DateTime now = DateTime.Now;
                        date = now.ToString("yyyy-MM-dd");
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"property.txt", true);
                        file.WriteLine("Add Ingredient{" + Ing.toString() + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Add Ingredient successfully.");

                    }
                    else
                    {
                        MessageBox.Show("Invalid Ingredient.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to update an ingredient?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        id = table1.Rows[selectedIndex].Cells[0].Value.ToString();
                        name = textBoxName.Text;
                        quantity = double.Parse(textBoxQuantity.Text);
                        price = double.Parse(textBoxPrice.Text);
                        status = textBoxStatus.Text;
                        Ing = new Ingredient(id, name, quantity, price, status);
                        if (Ing.repOK() && Ing.validatePrice(price))
                        {
                            IngMan = new IngredientManager();
                            IngMan.updateIngredient(Ing);

                            //write text file
                            DateTime now = DateTime.Now;
                            date = now.ToString("yyyy-MM-dd");
                            System.IO.StreamWriter file = new System.IO.StreamWriter(@"property.txt", true);
                            file.WriteLine("Update Ingredient{" + Ing.toString() + "}" + "    " + now);
                            file.Close();
                            tableGetData();
                            MessageBox.Show("Update Ingredient successfully.");

                        }
                        else
                        {
                            MessageBox.Show("Invalid Ingredient.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select an ingredient to update.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }