private void btnSave_Click(object sender, EventArgs e)
        {
            CurrentAdvisor.Notes = txtNotes.Text;
            CurrentAdvisor.SaveRecordToDatabase(frmMain_Parent.CurrentUser.UserId);

            // loop through dgvservices, and update productservice records for record keeper product
            if (dgvServices.Rows.Count > 0)
            {
                DataTable planAdvisorServices = AdvisorService.GetAssociated(CurrentAdvisor);

                foreach (DataGridViewRow dr in dgvServices.Rows)
                {
                    Guid serviceId = new Guid(dr.Cells["ServiceId"].Value.ToString());

                    bool serviceOffered = false;
                    if (dr.Cells["ServiceOffered"].Value.ToString() != "")
                    {
                        serviceOffered = bool.Parse(dr.Cells["ServiceOffered"].Value.ToString());
                    }

                    var ps = planAdvisorServices.AsEnumerable().Where(x => x.Field <Guid>("ServiceId") == serviceId);
                    if (ps.Any()) // rk product already has service record, so update it
                    {
                        Guid           productServiceId = new Guid(ps.CopyToDataTable().Rows[0]["PlanAdvisorServiceId"].ToString());
                        ProductService productService   = new ProductService(productServiceId);
                        productService.ServiceOffered = serviceOffered;
                        productService.SaveRecordToDatabase(frmMain_Parent.CurrentUser.UserId);
                    }
                    else // rk product does not have service record, so create on
                    {
                        AdvisorService planAdvisorService = new AdvisorService();
                        planAdvisorService.ServiceId      = serviceId;
                        planAdvisorService.PlanAdvisorId  = CurrentAdvisor.Id;
                        planAdvisorService.ServiceOffered = serviceOffered;
                        planAdvisorService.SaveRecordToDatabase(frmMain_Parent.CurrentUser.UserId);
                    }
                }
            }

            //this.Close();
        }
        private void LoadDgvServices(bool refresh = false)
        {
            DataTable dataTable = new DataTable();

            /// Set the datatable based on the SelectedIndex of <see cref="cboServicesView"/>.
            switch (cboServicesView.SelectedIndex)
            {
            case 0:
                dataTable = Service.GetActive();
                break;

            case 1:
                dataTable = Service.GetInactive();
                break;

            default:
                return;
            }

            dataTable = dataTable.AsEnumerable().Where(x => x["Type"].ToString() == "Advisor").CopyToDataTable();

            dataTable.Columns.Add("ServiceOffered", typeof(bool));

            dgvServices.DataSource = dataTable;

            // Display/order the columns.
            dgvServices.Columns["ServiceId"].Visible  = false;
            dgvServices.Columns["Type"].Visible       = false;
            dgvServices.Columns["CreatedBy"].Visible  = false;
            dgvServices.Columns["CreatedOn"].Visible  = false;
            dgvServices.Columns["ModifiedBy"].Visible = false;
            dgvServices.Columns["ModifiedOn"].Visible = false;
            dgvServices.Columns["StateCode"].Visible  = false;

            dgvServices.Columns["Name"].DisplayIndex           = 0;
            dgvServices.Columns["Name"].ReadOnly               = true;
            dgvServices.Columns["Category"].DisplayIndex       = 1;
            dgvServices.Columns["Category"].ReadOnly           = true;
            dgvServices.Columns["ServiceOffered"].DisplayIndex = 2;
            dgvServices.Columns["ServiceOffered"].ReadOnly     = false;


            // set service offered values
            if (refresh == true)
            {
                DataTable planAdvisorServices = AdvisorService.GetAssociated(CurrentPlanAdvisor);
                int       rowIndex            = 0;

                foreach (DataGridViewRow drServices in dgvServices.Rows)
                {
                    Guid serviceId = new Guid(drServices.Cells["ServiceId"].Value.ToString());
                    var  ps        = planAdvisorServices.AsEnumerable().Where(x => x.Field <Guid>("ServiceId") == serviceId);
                    if (ps.Any()) // rk product already has service record, so update it
                    {
                        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dgvServices.Rows[rowIndex].Cells["ServiceOffered"];
                        var serviceOffered           = SqlBoolean.Parse(ps.CopyToDataTable().Rows[0]["ServiceOffered"].ToString()).IsTrue;
                        dgvServices.Rows[rowIndex].Cells["ServiceOffered"].Value = serviceOffered.ToString();
                    }

                    rowIndex++;
                }
            }
        }