private void fGrid2_BeforeCommitEdit(object sender, iGBeforeCommitEditEventArgs e)
 {
     if (e.ColIndex == 3)
     {
         if (fGrid2.Rows[e.RowIndex].Cells[e.ColIndex].AuxValue == null)
         {
             m_prev_role = null;
             return;
         }
         m_prev_role = (fGrid2.Rows[e.RowIndex].Cells[e.ColIndex].AuxValue as fnn.iGComboItemEX).Tag as ic.RoleC;
     }
 }
        private void UpdateRoles(ic.church_groupC _gp)
        {
            if (_gp == null)
            {
                return;
            }
            var nlist = from k in m_LDATA[_gp.cg_id].Items.Cast <fnn.iGComboItemEX>()
                        where k.Visible
                        select k;

            ic.RoleC   _role = null;
            List <int> _ids  = new List <int>();

            foreach (var k in nlist)
            {
                _role = k.Tag as ic.RoleC;
                if (datam.DATA_ROLES.Keys.IndexOf(_role.role_id) == -1)
                {
                    k.Visible = false; continue;
                }
                k.Value   = _role.role_name;
                k.Visible = true;
                _ids.Add(_role.role_id);
            }
            var new_list = from k in datam.DATA_ROLES.Values
                           where k.gp_type == em.role_gp_typeS.church_group & k.gp_id == _gp.cg_id
                           & _ids.IndexOf(k.role_id) == -1
                           select k;

            foreach (var r in new_list)
            {
                m_LDATA[_gp.cg_id].Items.Add(new fnn.iGComboItemEX()
                {
                    Tag   = r,
                    Value = r.role_name,
                });
            }
        }
        private void fGrid2_AfterCommitEdit_1(object sender, iGAfterCommitEditEventArgs e)
        {
            if (string.IsNullOrEmpty(fGrid2.Rows[e.RowIndex].Key))
            {
                #region new member
                if (e.ColIndex == 1)
                {
                    if (fGrid2.Rows[e.RowIndex].Cells[1].AuxValue != null)
                    {
                        var _mem = (fGrid2.Rows[e.RowIndex].Cells[1].AuxValue as fnn.iGComboItemEX).Tag as ic.memberC;
                        _mem.ChurchGroupCollection.Add(m_cgroup);
                        fGrid2.Rows[e.RowIndex].Tag = _mem.mem_id.ToStringNullable();
                        fGrid2.Rows[e.RowIndex].Key = _mem.mem_id.ToStringNullable();
                        dbh.SingleInsertCommandTSP("church_group_members_tb", new string[]
                        {
                            "mem_id",
                            "cg_id",
                            "cg_type_id",
                            "mem_status",
                            "start_date",
                            "end_date",
                            "exp_type",
                            "lch_id",
                            "lch_type_id",
                            "fs_time_stamp"
                        },
                                                   new object[]
                        {
                            _mem.mem_id,
                            m_cgroup.cg_id,
                            m_cgroup.cg_type_id,
                            1,
                            datam.CURR_DATE.Date,
                            null, 33,
                            datam.LCH_ID,
                            datam.LCH_TYPE_ID, 0//time_stamp
                        });
                        fGrid2.Rows[e.RowIndex].ReadOnly = iGBool.True;
                        fGrid2.Rows[e.RowIndex].Cells[1].DropDownControl = null;
                        fGrid2.Rows[e.RowIndex].Cells["_pic"].TypeFlags  = iGCellTypeFlags.HasEllipsisButton;
                        fGrid2.Rows[e.RowIndex].Cells["_pic"].ReadOnly   = iGBool.False;
                        fGrid2.Rows[e.RowIndex].Tag = _mem.mem_id;
                        fGrid2.Rows[e.RowIndex].Cells["desig"].DropDownControl = m_LDATA[m_cgroup.cg_id];
                        fGrid2.Rows[e.RowIndex].Cells["desig"].ReadOnly        = iGBool.False;
                        fGrid2.Rows[e.RowIndex].Cells["desig"].TypeFlags       = iGCellTypeFlags.HideComboButton;
                        count_Rows();
                        fGrid.Rows[m_cgroup.cg_id.ToString()].Cells[1].Value = m_cgroup.MemberCount;
                        buttonX1.PerformClick();
                    }
                    else
                    {
                        fGrid2.Rows[e.RowIndex].Cells[1].AuxValue = null;
                        fGrid2.Rows[e.RowIndex].Cells[1].Value    = null;
                    }
                }

                #endregion
                return;
            }
            if (e.ColIndex == 3)
            {
                if (fGrid2.Rows[e.RowIndex].Cells[3].AuxValue != null)
                {
                    var _role = (fGrid2.Rows[e.RowIndex].Cells[3].AuxValue as fnn.iGComboItemEX).Tag as ic.RoleC;
                    var _mem  = datam.DATA_MEMBER[fGrid2.Rows[e.RowIndex].Key.ToInt32()];
                    if (_role != null & _mem != null)
                    {
                        using (var xd = new xing())
                        {
                            #region previous role
                            if (m_prev_role != null)
                            {
                                //delete previous role

                                if (_mem != null)
                                {
                                    var mem_role = (from c in _mem.RolesCollection
                                                    where c.Is_valid & c.role_id == m_prev_role.role_id
                                                    select c).FirstOrDefault();
                                    if (mem_role != null)
                                    {
                                        mem_role.Is_valid = false;

                                        if (sdata.CURR_DATE.Subtract(mem_role.start_date).Days > 30)
                                        {
                                            xd.SingleUpdateCommandETS("roles_mem_tb", new string[]
                                            {
                                                "is_valid",
                                                "end_date",
                                                "end_fs_id",
                                                "un_id",
                                            }, new object[]
                                            {
                                                0,
                                                sdata.CURR_DATE,
                                                sdata.CURR_FS.fs_id,
                                                mem_role.un_id
                                            }, 1);
                                        }
                                        else
                                        {
                                            xd.SingleDeleteCommandExp("roles_mem_tb", new string[] { "un_id", "lch_id" }, new int[] { mem_role.un_id, sdata.ChurchID });
                                            _mem.RolesCollection.Remove(mem_role);
                                        }
                                    }
                                }
                                m_prev_role = null;
                            }
                            #endregion
                            //
                            ic.MemRoleC _mem_role = new ic.MemRoleC();
                            _mem_role.start_date  = sdata.CURR_DATE;
                            _mem_role.start_fs_id = sdata.CURR_FS.fs_id;
                            _mem_role.objRole     = _role;
                            _mem_role.Is_valid    = true;
                            _mem_role.role_id     = _role.role_id;
                            _mem_role.mem_id      = _mem.mem_id;
                            _mem_role.un_id       = xd.SingleInsertCommandInt("roles_mem_tb", new string[]
                            {
                                "mem_id",
                                "role_id",
                                "start_date",
                                "end_date",
                                "start_fs_id",
                                "end_fs_id",
                                "is_valid",
                                "exp_type",
                                "lch_id",
                            }, new object[]
                            {
                                _mem_role.mem_id,
                                _mem_role.role_id,
                                _mem_role.start_date,
                                null,       //end date
                                _mem_role.start_fs_id,
                                _mem_role.end_fs_id,
                                1,
                                33, sdata.ChurchID
                            });
                            xd.CommitTransaction();
                            _mem.RolesCollection.Add(_mem_role);
                            _mem_role = null;
                        }
                    }
                    return;
                }
                if (fGrid2.Rows[e.RowIndex].Cells[3].AuxValue == null)
                {
                    using (var xd = new xing())
                    {
                        var _mem = datam.DATA_MEMBER[fGrid2.Rows[e.RowIndex].Key.ToInt32()];
                        #region previous role
                        if (m_prev_role != null & _mem != null)
                        {
                            var mem_role = (from c in _mem.RolesCollection
                                            where c.Is_valid & c.role_id == m_prev_role.role_id
                                            select c).FirstOrDefault();
                            if (mem_role != null)
                            {
                                mem_role.Is_valid = false;

                                if (sdata.CURR_DATE.Subtract(mem_role.start_date).Days > 30)
                                {
                                    xd.SingleUpdateCommandETS("roles_mem_tb", new string[]
                                    {
                                        "is_valid",
                                        "end_date",
                                        "end_fs_id",
                                        "un_id",
                                    }, new object[]
                                    {
                                        0,
                                        sdata.CURR_DATE,
                                        sdata.CURR_FS.fs_id,
                                        mem_role.un_id
                                    }, 1);
                                }
                                else
                                {
                                    xd.SingleDeleteCommandExp("roles_mem_tb", new string[] { "un_id", "lch_id" }, new int[] { mem_role.un_id, sdata.ChurchID });
                                    _mem.RolesCollection.Remove(mem_role);
                                }
                                xd.CommitTransaction();
                            }

                            m_prev_role = null;
                        }
                        #endregion
                    }
                    fGrid2.Rows[e.RowIndex].Cells[3].Value = null;
                }
            }
        }
        private void LoadMainGrid2(ic.church_groupC _gp)
        {
            if (m_LDATA.Keys.IndexOf(_gp.cg_id) == -1)
            {
                m_LDATA.Add(_gp.cg_id, new iGDropDownList());
                m_LDATA[_gp.cg_id] = fnn.CreateCombo();
                m_LDATA[_gp.cg_id].MaxVisibleRowCount = 5;
                var nlist = from k in datam.DATA_ROLES.Values
                            where k.gp_type == em.role_gp_typeS.church_group &
                            k.gp_id == _gp.cg_id
                            select k;
                foreach (var n in nlist)
                {
                    m_LDATA[_gp.cg_id].Items.Add(new fnn.iGComboItemEX()
                    {
                        Text  = n.role_name,
                        Value = n.role_name,
                        Tag   = n
                    });
                }
            }
            m_prev_role = null;
            fGrid2.Cols["_pic"].Width = 20;
            fGrid2.Rows.Clear();
            buttonX1.Visible = false;
            buttonX2.Visible = false;
            buttonR.Visible  = false;
            if (_gp == null)
            {
                return;
            }
            iGRow _row = null;

            _row                         = CreateNewRow2();
            _row.Key                     = "othersxxx";
            _row.ForeColor               = Color.Blue;
            _row.Cells["mem"].Value      = "Member Names";
            _row.Cells["mem"].TextAlign  = iGContentAlignment.MiddleCenter;
            _row.BackColor               = Color.Lavender;
            _row.ReadOnly                = iGBool.False;
            _row.Selectable              = false;
            _row.Cells["type"].Value     = null;
            _row.Cells["type"].TextAlign = iGContentAlignment.MiddleRight;
            //
            _row.Cells["desig"].Value     = "Member Role(s)";
            _row.Cells["desig"].TextAlign = iGContentAlignment.MiddleCenter;
            // fGrid2.Rows["othersxxx"].Cells["_pic"].TypeFlags = iGCellTypeFlags.HasEllipsisButton;

            buttonX1.Visible = true;
            buttonX2.Visible = true;
            buttonR.Visible  = true;
            if (_gp == null)
            {
                fGrid2.EndUpdate(); return;
            }
            int _cnt = 0;

            ic.RoleC _role = null;
            if (_gp.MemberCount > 0)
            {
                foreach (var r in _gp.MemberEnumerable.OrderBy(l => l.mem_name))
                {
                    _cnt++;
                    _row          = fGrid2.Rows.Add();
                    _row.ReadOnly = iGBool.True;
                    _row.Font     = new Font("verdana", 10, FontStyle.Bold);
                    _row.Cells["type"].Col.Width = 30;
                    _row.Cells["type"].Value     = _cnt;
                    _row.Cells["type"].TextAlign = iGContentAlignment.MiddleCenter;
                    _row.Cells["mem"].ValueType  = typeof(string);
                    _row.Tag = r.mem_id.ToStringNullable();
                    _row.Cells["mem"].Value      = r.mem_name;
                    _row.Cells["_pic"].TypeFlags = iGCellTypeFlags.HasEllipsisButton;
                    _row.Cells["_pic"].ReadOnly  = iGBool.False;
                    //
                    _role = r.RolesCollection.Where(k => k.Is_valid & k.objRole.gp_type == em.role_gp_typeS.church_group & k.objRole.gp_id == _gp.cg_id).Select(k => k.objRole).FirstOrDefault();
                    _row.Cells["desig"].DropDownControl = m_LDATA[_gp.cg_id];
                    _row.Cells["desig"].Value           = null;
                    if (_role != null)
                    {
                        _row.Cells["desig"].Value = _role.role_name;
                    }
                    //
                    _row.Cells["desig"].ReadOnly  = iGBool.False;
                    _row.Cells["desig"].TypeFlags = iGCellTypeFlags.HideComboButton;
                    _row.Key = r.mem_id.ToStringNullable();
                    _row.AutoHeight();
                }
            }
            fGrid2.Cols.AutoWidth();
            fGrid2.AutoResizeCols = false;
            fGrid2.EndUpdate();
            position_button_controller();
        }