public void saveSupplier(Supplier sup)
 {
     cmd.CommandText = "INSERT INTO supplier(name, address, email, phone, birthday, ingredient_id)" +
                 " values(@name, @address, @email, @phone, @birthday, @ingredient_id)";
     cmd.Parameters.AddWithValue("@name", sup.getName());
     cmd.Parameters.AddWithValue("@address", sup.getAddress());
     cmd.Parameters.AddWithValue("@email", sup.getEmail());
     cmd.Parameters.AddWithValue("@phone", sup.getPhone());
     cmd.Parameters.AddWithValue("@birthday", sup.getBirthday());
     cmd.Parameters.AddWithValue("@ingredient_id", sup.getIngredientid());
     cmd.ExecuteNonQuery();
     conn.Close();
 }
 public void updateSupplier(Supplier sup)
 {
     cmd.CommandText = " UPDATE supplier SET name = @name, address=@address, " +
                       " email = @email, phone = @phone, birthday=@birthday, ingredient_id = @ingredient_id " +
                       " where id = @id ";
     cmd.Parameters.AddWithValue("@name", sup.getName());
     cmd.Parameters.AddWithValue("@address", sup.getAddress());
     cmd.Parameters.AddWithValue("@email", sup.getEmail());
     cmd.Parameters.AddWithValue("@phone", sup.getPhone());
     cmd.Parameters.AddWithValue("@birthday", sup.getBirthday());
     cmd.Parameters.AddWithValue("@ingredient_id", sup.getIngredientid());
     cmd.Parameters.AddWithValue("@id", sup.getId());
     cmd.ExecuteNonQuery();
     conn.Close();
 }
Exemple #3
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 #4
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());
            }
        }