Beispiel #1
0
 private void LoadComboBox()
 {
     memberIDs = MemberDB.GetMemberIDs();
     if (memberIDs.Count > 0) // if there are members
     {
         cboMemberID.DataSource    = memberIDs;
         cboMemberID.SelectedIndex = 0; // triggers SelectedIndexChanged
     }
     else // no members
     {
         MessageBox.Show("There are no members. " +
                         "Add some members in the database, and restart the application ", "Empty Load");
         Application.Exit();
     }
 }
Beispiel #2
0
        // member selection  changes
        private void cboMemberID_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedID = (int)cboMemberID.SelectedValue;

            try
            {
                current = MemberDB.GetMemberByID(selectedID);
                DisplayCurrentMemberData();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while retrieving member with selected ID: " + ex.Message,
                                ex.GetType().ToString());
            }
        }
Beispiel #3
0
        // user wants to update DateEnded of the current member
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            frmUpdate secondForm = new frmUpdate();

            secondForm.current = current;                  // set current member on the second form
            DialogResult result = secondForm.ShowDialog(); // display second form modal

            if (result == DialogResult.OK)
            {
                current = secondForm.current; // receive current member from the second form
            }
            else if (result == DialogResult.Retry)
            {
                current = MemberDB.GetMemberByID(current.MemberID);
            }
            DisplayCurrentMemberData();
        }
Beispiel #4
0
        // accepts changes
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (IsValidDateEnded())
            {
                // build Member object with the new data
                Member newMember = new Member();
                newMember.MemberID    = current.MemberID;
                newMember.MemberName  = current.MemberName;
                newMember.DateStarted = current.DateStarted;
                if (txtDateEnded.Text == "")
                {
                    newMember.DateEnded = null;
                }
                else
                {
                    newMember.DateEnded = Convert.ToDateTime(txtDateEnded.Text);
                }

                try                                                 // try to update
                {
                    if (!MemberDB.UpdateMember(current, newMember)) //failed
                    {
                        MessageBox.Show("Another user has updated or " +
                                        "deleted current member", "Concurrency Error");
                        this.DialogResult = DialogResult.Retry;
                    }
                    else
                    {
                        current           = newMember;
                        this.DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while updating: " + ex.Message, ex.GetType().ToString());
                }
            }
        }