protected void lnklPrivGroupItem_Click(object sender, EventArgs e)
        {
            LinkButton lnk = (LinkButton)sender;

            try
            {
                PRIVGROUP privGroup = SQMModelMgr.LookupPrivGroup(new PSsqmEntities(), lnk.CommandArgument.ToString(), false);
                if (privGroup != null)
                {
                    hfPrivGroupID.Value     = privGroup.PRIV_GROUP;
                    tbEditPrivGroup.Text    = privGroup.PRIV_GROUP;
                    tbEditPrivGroup.Enabled = false;
                    tbEditDescription.Text  = privGroup.DESCRIPTION;
                    if (ddlPrivGroupStatus.FindItemByValue(privGroup.STATUS) != null)
                    {
                        ddlPrivGroupStatus.SelectedValue = privGroup.STATUS;
                    }
                    ddlEdit_OnIndexChanged(null, null);
                    //btnDelete.Visible = true;
                }

                string script = "function f(){OpenPrivGroupEditWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
            }
            catch
            {
            }
        }
        private void SavePrivGroupItem()
        {
            PSsqmEntities ctx       = new PSsqmEntities();
            PRIVGROUP     privGroup = null;
            bool          isNew     = false;

            if (string.IsNullOrEmpty(hfPrivGroupID.Value))              // add new item
            {
                privGroup = new PRIVGROUP();

                isNew = true;
            }
            else
            {
                privGroup = SQMModelMgr.LookupPrivGroup(ctx, hfPrivGroupID.Value.ToString(), false);
            }

            privGroup.PRIV_GROUP  = tbEditPrivGroup.Text.ToString().Trim();
            privGroup.DESCRIPTION = tbEditDescription.Text.ToString().Trim();
            privGroup.STATUS      = ddlPrivGroupStatus.SelectedValue.ToString().Trim();

            if ((privGroup = SQMModelMgr.UpdatePrivGroup(ctx, privGroup)) != null)
            {
                if (isNew)
                {
                    // We need to add the default privs
                    PRIVLIST privList = null;
                    if (defaultPrivs == null)
                    {
                        defaultPrivs = SQMSettings.SelectSettingsGroup("DEFAULT_PRIVS", "");
                    }
                    if (defaultPrivs.Count > 0)
                    {
                        foreach (SETTINGS setting in defaultPrivs)
                        {
                            try
                            {
                                priv   = Convert.ToInt16(setting.SETTING_CD.ToString());
                                scopes = setting.VALUE.ToString().Split(',');
                                for (int i = 0; i < scopes.Count(); i++)
                                {
                                    privList            = SQMModelMgr.LookupPrivList(privGroup.PRIV_GROUP, priv, scopes[i], true);
                                    privList.PRIV_GROUP = privGroup.PRIV_GROUP;
                                    privList.PRIV       = priv;
                                    privList.SCOPE      = scopes[i].Trim();
                                    privList            = SQMModelMgr.UpdatePrivList(ctx, privList);
                                }
                            }
                            catch
                            { }
                        }
                    }
                    else
                    {
                        // if there are no defult settings, we are going to force dashboard, inbox and incident
                    }
                    if (OnPrivGroupCommand != null)
                    {
                        OnPrivGroupCommand("add");
                    }
                }
                else
                {
                    foreach (GridDataItem item in rgPrivGroup.Items)
                    {
                        LinkButton lnk = (LinkButton)item.FindControl("lnkPrivGroupItem");
                        if (lnk.CommandArgument == hfPrivGroupID.Value)
                        {
                            // update the list item without doing a complete refresh of the list
                            Label lbl = new Label();
                            lbl      = (Label)item.FindControl("lblDescription");
                            lbl.Text = privGroup.DESCRIPTION;

                            lbl      = (Label)item.FindControl("lblGroupStatus");
                            lbl.Text = XLATList.Where(x => x.XLAT_GROUP == "ACTIVE_STATUS" && x.XLAT_CODE == privGroup.STATUS.ToString()).FirstOrDefault().DESCRIPTION_SHORT;
                        }
                    }
                }
            }
        }