public bool AddDependent(DependentModel dependent)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    // Set the command object properties
                    cmd.Connection = conn;
                    cmd.CommandText = Scripts.SqlInsertDependent;

                    // Add the input parameters to the parameter collection
                    cmd.Parameters.AddWithValue("@Name", dependent.NameOfChild);
                    cmd.Parameters.AddWithValue("@Relationship", dependent.Relationship);
                    cmd.Parameters.AddWithValue("@LivesWith", dependent.ChildLivesWith);
                    cmd.Parameters.AddWithValue("@PersonID", dependent.PersonID);
                    cmd.Parameters.AddWithValue("@BirthDate", dependent.BirthDate);

                    // Open the connection, execute the query and close the connection
                    cmd.Connection.Open();
                    var rowsAffected = cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                    return rowsAffected > 0;
                }

            }
        }
 public bool RegisterDependent(DependentModel dependent)
 {
     return this.memberAccess.AddDependent(dependent);
 }
Exemple #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
            {

                //string clubMemberId = dgv.SelectedRows[0].Cells[0].Value.ToString();
                // Check if the validation passes
                if (this.ValidateRegistration())
                {
                    List<DependentModel> depList = new List<DependentModel>();
                    //loop through all dependents datagrid view
                    foreach (DataGridViewRow row in dataGridViewDependents.Rows)
                    {
                        if (row.IsNewRow) continue;
                        DependentModel dependentModel = new DependentModel()
                        {
                            DependentID = 0,
                            NameOfChild = row.Cells["NameofChild"].Value.ToString(),
                            BirthDate = Convert.ToDateTime(row.Cells["BirthDate"].Value.ToString()),
                            //BirthDate = Convert.ToDateTime(_datePicker.Value.ToShortDateString()),
                            ChildLivesWith = row.Cells["LivesWith"].Value.ToString(),
                            Relationship = row.Cells["Relationship"].Value.ToString(),
                            PersonID = 0
                        };

                        //this.clubMemberService.RegisterDependent(dependentModel);

                        depList.Add(dependentModel);
                    }

                    string phone = string.Empty;
                    if (!(txtContactNumber.Text == "(   )    -"))
                        phone = txtContactNumber.Text;

                    bool guardianFlag = false;
                    if (rdoGuardian1.Checked)
                        guardianFlag = true;

                    bool churchHomeFlag = false;
                    if (rdoChurchHome1.Checked)
                        churchHomeFlag = true;

                    bool leaveMessageFlag = false;
                    if (rdoLeaveMessage1.Checked)
                        leaveMessageFlag = true;

                    // Assign the values to the model
                    PersonModel clubMemberModel = new PersonModel()
                    {
                        PersonID = 0,
                        FirstName = txtFirstName.Text.Trim(),
                        LastName = txtLastName.Text.Trim(),
                        MiddleIntial = txtMiddleInitial.Text.Trim(),
                        Address = txtAddress.Text.Trim(),
                        PhoneNumber = phone.Trim(),
                        DateOfBirth = dtDateOfBirth.Value,
                        ChurchHome = bool.Parse(rdoChurchHome1.Checked.ToString()),
                        ChurchName = txtAttend.Text.Trim(),
                        Opinion = txtOpinion.Text.Trim(),
                        LeaveMessage = bool.Parse(rdoLeaveMessage1.Checked.ToString()),
                        City = txtCity.Text.Trim(),
                        State = txtState.Text.Trim(),
                        Zip = txtZip.Text.Trim(),
                        ExportFlag = 0,
                        ProofGuardianFlag = bool.Parse(rdoGuardian1.Checked.ToString()),
                        LockItemsFlag = false,
                        DependentModelList = depList
                    };

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

                    // if status of success variable is true then display a information else display the error message
                    if (success)
                    {

                        //List<DependentModel> depList = new List<DependentModel>();
                        //loop through all dependents datagrid view
                        //while (success)
                        //{
                        //    foreach (DataGridViewRow row in dataGridViewDependents.Rows)
                        //    {
                        //        if (row.IsNewRow) continue;
                        //        DependentModel dependentModel = new DependentModel()
                        //        {
                        //            DependentID = 0,
                        //            NameOfChild = row.Cells["NameofChild"].Value.ToString(),
                        //            BirthDate = Convert.ToDateTime(row.Cells["Birthdate"].Value.ToString()),
                        //            ChildLivesWith = row.Cells["LivesWith"].Value.ToString(),
                        //            Relationship = row.Cells["Relationship"].Value.ToString(),
                        //            PersonID = 0
                        //        };

                        //        this.clubMemberService.RegisterDependent(dependentModel);

                        //        //depList.Add(dependentModel);
                        //    }
                        //}
                        //success = this.clubMemberService.RegisterDependent(depList);
                        //this.clubMemberService.RegisterDependent()
                        // 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);
            }
        }
Exemple #4
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())
                {
                    List<DependentModel> depList = new List<DependentModel>();
                    //loop through all dependents datagrid view
                    foreach (DataGridViewRow row in dataGridViewDependents.Rows)
                    {
                        if (row.IsNewRow) continue;
                        DependentModel dependentModel = new DependentModel()
                        {
                            NameOfChild = row.Cells["Name of Child"].Value.ToString(),
                            BirthDate = Convert.ToDateTime(row.Cells["BirthDate"].Value.ToString()),
                            //BirthDate = Convert.ToDateTime(_datePicker.Value.ToShortDateString()),
                            ChildLivesWith = row.Cells["LivesWith"].Value.ToString(),
                            Relationship = row.Cells["Relationship"].Value.ToString(),
                            PersonID = this.memberId//,
                            //DependentID = Convert.ToInt32(row.Cells["DependentID"].Value.ToString())
                        };
                        depList.Add(dependentModel);
                    }
                    //if
                    //var lockDate = Convert.ToDateTime(row.Cells["LockItemsDate"].Value.ToString());

                    List<ItemModel> itemList = new List<ItemModel>();
                    //loop through all dependents datagrid view
                    foreach (DataGridViewRow row in dataGridViewItems.Rows)
                    {
                        if (row.IsNewRow) continue;

                        //DateTime lockDate = Convert.ToDateTime(_datePicker.Value.ToShortDateString());
                        //if (!(string.IsNullOrEmpty(row.Cells["LockItemsDate"].Value.ToString())))
                        //lockDate = Convert.ToDateTime(row.Cells["LockItemsDate"].Value.ToString());

                        ItemModel itemModel = new ItemModel()
                        {
                            Description = row.Cells["Description"].Value.ToString(),
                            //Date = Convert.ToDateTime(row.Cells["Date"].Value.ToString()),
                            Date = Convert.ToDateTime(row.Cells["Date"].Value.ToString()),
                            //Date = Convert.ToDateTime(_datePicker.Value.ToShortDateString()),
                            Comments = row.Cells["Comments"].Value.ToString(),
                            Initials = row.Cells["Initials"].Value.ToString(),
                            PersonID = this.memberId
                        };
                        itemList.Add(itemModel);
                    }

                    string phone = string.Empty;
                    if (!(txtContactNumber.Text == "(   )    -"))
                        phone = txtContactNumber.Text;

                    //DateTime? start = (txtStartDate.Text == DateTime.MinValue.ToString()) ? null : (DateTime?)txtStartDate.Text;
                    //DBNull.Value
                    // <Nullable>DateTime start = lockItemDate == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(lockItemDate);

                    //DateTime? start = lockItemDate ?? (DateTime?)DBNull.Value;
                    DataRow dataRow = this.clubMemberService.GetFullClubMemberById(memberId);
                    //Person personObject = new Person();
                    DateTime? dt = dataRow["LockItemDate"] == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(dataRow["LockItemDate"]);
                    //personObject.LockItemsFlag = Convert.ToBoolean(dataRow["LockItemFlag"].ToString());

                    if ((!dt.HasValue) && (itemList.Count > 0))
                        dt = DateTime.Today;

                    //if (dt.HasValue)
                    //{
                    //    var date = Convert.ToDateTime(dataRow["LockItemDate"]);
                    //    //if it has been more than a year reset date
                    //    //bool resetLockDate = this.clubMemberService.GetClubMemberLockDate(dt, memberId);
                    //    var matchFound = (date - DateTime.Now).TotalDays > 365;
                    //    dt = DateTime.Today;
                    //}
                    //if (!dt.HasValue)

                    PersonModel clubMemberModel = new PersonModel()
                    {
                        PersonID = this.memberId,
                        FirstName = txtFirstName.Text.Trim(),
                        LastName = txtLastName.Text.Trim(),
                        MiddleIntial = txtMiddleInitial.Text.Trim(),
                        Address = txtAddress.Text.Trim(),
                        PhoneNumber = phone.Trim(),
                        DateOfBirth = dtDateOfBirth.Value,
                        ChurchHome = bool.Parse(rdoChurchHome1.Checked.ToString()),
                        ChurchName = txtChurchName.Text.Trim(),
                        Opinion = txtOpinion.Text.Trim(),
                        LeaveMessage = bool.Parse(rdoLeaveMessage1.Checked.ToString()),
                        City = txtCity.Text.Trim(),
                        State = txtState.Text.Trim(),
                        Zip = txtZip.Text.Trim(),
                        DateUpdated = DateTime.Now,
                        ProofGuardianFlag = bool.Parse(rdoGuardian1.Checked.ToString()),
                        LockItemsDate = dt,//lockItemDate,
                        LockItemsFlag = lockItemFlag,
                        DependentModelList = depList,
                        ItemModelList = itemList
                    };

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

                    if (flag)
                    {
                        MessageBox.Show(
                            Resources.Update_Successful_Message,
                            Resources.Update_Successful_Message_Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

                        _manage.PerformRefresh();
                    }
                }
                else
                {
                    MessageBox.Show(
                        this.errorMessage,
                        Resources.Registration_Error_Message_Title,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                this.ShowErrorMessage(ex);
            }
        }