Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to add a supplier?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    name = textBoxName.Text;
                    address = textBoxAddress.Text;
                    email = textBoxEmail.Text;
                    phone = textBoxPhone.Text;
                    birthday = textBoxBirthday.Text;
                    ingredient_id = textBoxProductId.Text;

                    sup = new Supplier(name, address, email, phone, birthday, ingredient_id);
                    if (sup.repOK())
                    {
                        //MessageBox.Show(sup.toString());
                        supMan = new SupplierManager();
                        supMan.saveSupplier(sup);

                        //write text file
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                        file.WriteLine("Add supplier{" + sup.toStringInfo() + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Add supplier successfully.");
                    }
                    else
                    {
                        MessageBox.Show("Invalid Supplier.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to delete a supplier?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        String id = table1.Rows[selectedIndex].Cells[0].Value.ToString();
                        //MessageBox.Show(id);

                        supMan = new SupplierManager();
                        supMan.deleteSupplier(id);

                        //write text file
                        sup = new Supplier();
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                        file.WriteLine("Delete supplier{" + id + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Delete supplier successfully.");
                    }
                    else
                        MessageBox.Show("Select a supplier to delete.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }