Example #1
0
        private void btnLisaa_Click(object sender, EventArgs e)
        {
            try
            {
                string UusiHSuku = tbSukunimi.Text;
                string UusiHEtu  = tbEtunimi.Text;
                if (string.IsNullOrWhiteSpace(UusiHSuku) || string.IsNullOrWhiteSpace(UusiHEtu) || !cbKayttoehdot.Checked)
                {
                    MessageBox.Show("Anna vähintään etu- ja sukunimi sekä hyväksy käyttöehdot\nja valitse osallistuminen");
                }
                else
                {
                    // Add New person to database

                    string Email = tbEmail.Text;
                    string City  = tbCity.Text;
                    string Club  = tbClub.Text;

                    // first create new object
                    objConnect = new DatabaseConnection();
                    // then give SQL as a parameter
                    objConnect.Sql = "INSERT INTO Person (EventID, LastName, FirstName, Email, City, Acceptance, Club)" +
                                     " VALUES ('" + EventID + "', '" + UusiHSuku + "', '" + UusiHEtu + "', '" + Email + "', '" + City + "', '1', '" + Club + "')";
                    // Run
                    ds = objConnect.GetConnection;

                    // Get PersonID

                    // Call DatabaseConnection Class
                    // first create new object
                    objConnect = new DatabaseConnection();
                    // then give SQL as a parameter
                    objConnect.Sql = "SELECT MAX(PersonID) AS PersonID From Person";
                    ds             = objConnect.GetConnection;
                    dt             = new DataTable();
                    dt             = ds.Tables["Table"];
                    foreach (DataRow dr in dt.Rows)
                    {
                        PersonID = dr["PersonID"].ToString();
                    }

                    Osallistuminen t = new Osallistuminen(PersonID, UusiHSuku, UusiHEtu, EventID);
                    t.FormClosed += (s, args) => this.Close();
                    t.ShowDialog();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Example #2
0
        private void btnRemoveParti_Click(object sender, EventArgs e)
        {
            try
            {
                if (lbListPersons.SelectedIndex == -1)
                {
                    // Do nothing - nothing selected
                }
                else
                {
                    string toRemove  = lbListPersons.SelectedItem.ToString();
                    string LastName  = toRemove.Split(',')[0];
                    string FirstName = toRemove.Split(',')[1];
                    string PersonID  = "";
                    FirstName = FirstName.TrimStart();
                    // first create new object
                    objConnect = new DatabaseConnection();
                    // then give SQL as a parameter - Device table fist
                    objConnect.Sql = "SELECT * FROM Person WHERE LastName = '" + LastName + "' AND FirstName = '" + FirstName + "' AND EventID = '" + EventID + "'";
                    ds             = objConnect.GetConnection;
                    dt             = new DataTable();
                    dt             = ds.Tables["Table"];
                    // Update params and call Osallistuminen form
                    foreach (DataRow dr in dt.Rows)
                    {
                        PersonID = dr["PersonID"].ToString();
                    }

                    // Form calling
                    Osallistuminen t = new Osallistuminen(PersonID, LastName, FirstName, EventID);
                    t.ShowDialog();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }