예제 #1
0
        /// <summary>
        /// Method to add new member
        /// </summary>
        /// <param name="clubMember">club member model</param>
        /// <returns>true or false</returns>
        public bool AddClubMember(ClubMemberModel clubMember)
        {
            using (OleDbCommand oleDbCommand = new OleDbCommand())
            {
                // Set the command object properties
                oleDbCommand.Connection = new OleDbConnection(this.ConnectionString);
                oleDbCommand.CommandType = CommandType.Text;
                oleDbCommand.CommandText = Scripts.SqlInsertClubMember;

                // Add the input parameters to the parameter collection
                oleDbCommand.Parameters.AddWithValue("@Name", clubMember.Name);
                oleDbCommand.Parameters.AddWithValue("@DateOfBirth", clubMember.DateOfBirth.ToShortDateString());
                oleDbCommand.Parameters.AddWithValue("@Occupation", (int)clubMember.Occupation);
                oleDbCommand.Parameters.AddWithValue("@MaritalStatus", (int)clubMember.MaritalStatus);
                oleDbCommand.Parameters.AddWithValue("@HealthStatus", (int)clubMember.HealthStatus);
                oleDbCommand.Parameters.AddWithValue("@Salary", clubMember.Salary);
                oleDbCommand.Parameters.AddWithValue("@NumberOfChildren", clubMember.NumberOfChildren);

                // Open the connection, execute the query and close the connection
                oleDbCommand.Connection.Open();
                var rowsAffected = oleDbCommand.ExecuteNonQuery();
                oleDbCommand.Connection.Close();

                return rowsAffected > 0;
            }
        }
예제 #2
0
        /// <summary>
        /// Click event to update the data
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">event args</param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ValidateUpdate())
                {
                    ClubMemberModel clubMemberModel = new ClubMemberModel()
                    {
                        Id = this.memberId,
                        Name = txt2Name.Text.Trim(),
                        DateOfBirth = dt2DateOfBirth.Value,
                        Occupation = (Occupation)cmb2Occupation.SelectedValue,
                        HealthStatus = (HealthStatus)cmb2HealthStatus.SelectedValue,
                        MaritalStatus = (MaritalStatus)cmb2MaritalStatus.SelectedValue,
                        Salary = txt2Salary.Text.Trim() == string.Empty ? 0 : Convert.ToDecimal(txt2Salary.Text),
                        NumberOfChildren = txt2NoOfChildren.Text.Trim() == string.Empty ? 0 : Convert.ToInt16(txt2NoOfChildren.Text)
                    };

                    var flag = this.clubMemberService.UpdateClubMember(clubMemberModel);

                    if (flag)
                    {
                        DataTable data = this.clubMemberService.GetAllClubMembers();
                        this.LoadDataGridView(data);

                        MessageBox.Show(
                            Resources.Update_Successful_Message,
                            Resources.Update_Successful_Message_Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);                        
                    }
                }
                else
                {
                    MessageBox.Show(
                        this.errorMessage,
                        Resources.Registration_Error_Message_Title,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                this.ShowErrorMessage(ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Click event to handle registration
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">event data</param>
        private void Register_Click(object sender, EventArgs e)
        {
            try
            {
                // Check if the validation passes
                if (this.ValidateRegistration())
                {
                    // Assign the values to the model
                    ClubMemberModel clubMemberModel = new ClubMemberModel()
                    {
                        Id = 0,
                        Name = txtName.Text.Trim(),
                        DateOfBirth = dtDateOfBirth.Value,
                        Occupation = (Occupation)cmbOccupation.SelectedValue,
                        HealthStatus = (HealthStatus)cmbHealthStatus.SelectedValue,
                        MaritalStatus = (MaritalStatus)cmbMaritalStatus.SelectedValue,
                        Salary = txtSalary.Text.Trim() == string.Empty ? 0 : Convert.ToDecimal(txtSalary.Text),
                        NumberOfChildren = txtNoOfChildren.Text.Trim() == string.Empty ? 0 : Convert.ToInt16(txtNoOfChildren.Text)
                    };

                    // Call the service method and assign the return status to variable
                    var success = this.clubMemberService.RegisterClubMember(clubMemberModel);

                    // if status of success variable is true then display a information else display the error message
                    if (success)
                    {
                        // display the message box
                        MessageBox.Show(
                            Resources.Registration_Successful_Message,
                            Resources.Registration_Successful_Message_Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

                        // Reset the screen
                        this.ResetRegistration();
                    }
                    else
                    {
                        // display the error messge
                        MessageBox.Show(
                            Resources.Registration_Error_Message,
                            Resources.Registration_Error_Message_Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
                else
                {
                    // Display the validation failed message
                    MessageBox.Show(
                        this.errorMessage, 
                        Resources.Registration_Error_Message_Title, 
                        MessageBoxButtons.OK, 
                        MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                this.ShowErrorMessage(ex);
            }
        }
예제 #4
0
 /// <summary>
 /// Service method to update club member
 /// </summary>
 /// <param name="clubMember">club member</param>
 /// <returns>true / false</returns>
 public bool UpdateClubMember(ClubMemberModel clubMember)
 {
     return this.memberAccess.UpdateClubMember(clubMember);
 }
예제 #5
0
 /// <summary>
 /// Service method to create new member
 /// </summary>
 /// <param name="clubMember">club member model</param>
 /// <returns>true or false</returns>
 public bool RegisterClubMember(ClubMemberModel clubMember)
 {
     return this.memberAccess.AddClubMember(clubMember);
 }