Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to update 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();
                        name = textBoxName.Text;
                        address = textBoxAddress.Text;
                        email = textBoxEmail.Text;
                        phone = textBoxPhone.Text;
                        birthday = textBoxBirthday.Text;
                        ingredient_id = textBoxProductId.Text;

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

                            //write text file
                            DateTime now = DateTime.Now;
                            System.IO.StreamWriter file = new System.IO.StreamWriter(@"person.txt", true);
                            file.WriteLine("Update supplier{" + sup.toStringInfo() + "}" + "    " + now);
                            file.Close();
                            tableGetData();
                            MessageBox.Show("Update supplier successfully.");

                        }
                        else
                        {
                            MessageBox.Show("Invalid Supplier.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select a supplier to update.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }