Esempio n. 1
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                //Yes/No dialog to confirm Delete action
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete row with id " + rowId, "Delete " + rowId, MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    //hide former options form
                    this.Hide();
                    //search the row with the id in the dataset and delete it

                    //connect to the DB
                    connect(); //---> we now have the data in the dataset, access it
                    //count the row we have in our dataset (dataTable)..... count-1 xq empieza en zero
                    int numRowCount = dataset.Tables["Friends"].Rows.Count;

                    //itereate the rows to find the one with the id of the selected and delete it
                    for (int i = 0; i < numRowCount; i++)
                    {
                        //define Row (fila) to use iterate the Rows[i]
                        DataRow fila;
                        fila = dataset.Tables["Friends"].Rows[i];
                        //Check if the "id" column of each row (fila) is == id
                        if (Convert.ToInt32(fila["id"]) == rowId)
                        {
                            //row found
                            //delete row
                            fila.Delete();
                            //actualise dataset dataTable ---> adapter Update()
                            adapter.Update(dataset, "Friends");
                            //refresh list View
                            MainForm2 f2 = new MainForm2();

                            MessageBox.Show("Friend data Deleted!, refreshed");
                            f2.refreshdata();
                        }
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    //close former Options form and the dialogForm
                    this.Hide();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
 private void Enterbutton_Click(object sender, EventArgs e)
 {
     if (nomtextBox.Text.ToString() == "")
     {
         MessageBox.Show("Please, Enter your name");
     }
     else
     {
         //hide first form when this button is clicked
         this.Hide();
         //get username
         nom = nomtextBox.Text;
         //instantiate new for (form2--->Mainpage)
         //form2 f2 = new form2(); form2--> Mainpage
         MainForm2 f2 = new MainForm2();
         //assign the user name to the username attribute in form 2
         f2.username = nom;
         //open new form
         f2.ShowDialog();
     }
 }