public override void RefreshData()
        {
            //lvPerms.MultiSelect = !Modal;

            this.Text = "Permission Templates - " + this.AdminProxy.Connection.ServerName + (Toolkit.IsProcessElevated() ? " - Administrator " : "");
            var tags = rememberSelectedTags(lvPermissionTemplates);

            // this form has multiple uses, as does the underlying ListPermissions method.
            // it can:
            // List all permissions (0,[0])
            // List permission info for a single permission (37,[0])
            // List permissions that are NOT in a list (0, [2,3,4,5,6])


            var ds = AdminProxy.ListPermissionTemplates(ID);

            initHooksForMdiParent(ds.Tables["list_permission_templates"], "template_name", "sys_perm_template_id");
            lvPermissionTemplates.Items.Clear();
            foreach (DataRow dr in ds.Tables["list_permission_templates"].Rows)
            {
                var lvi = new ListViewItem(dr["template_name"].ToString(), 0);
                lvi.Tag = Toolkit.ToInt32(dr["sys_perm_template_id"], -1);
                DataRow[] drPerms = ds.Tables["permissions_by_template"].Select("sys_perm_template_id = " + dr["sys_perm_template_id"]);
                var       perms   = new List <string>();
                foreach (DataRow drp in drPerms)
                {
                    perms.Add(drp["perm_name"].ToString());
                }
                lvi.SubItems.Add(Toolkit.Join(perms.ToArray(), ", ", "-"));
                lvi.Tag = dr["sys_perm_template_id"];
                lvPermissionTemplates.Items.Add(lvi);
            }

            selectRememberedTags(lvPermissionTemplates, tags);

            MainFormUpdateStatus("Refreshed Permission Templates ", false);
        }
        public override void RefreshData()
        {
            this.Text = "Permission Template - " + MainFormCurrentNodeText("") + " - " + this.AdminProxy.Connection.ServerName + (Toolkit.IsProcessElevated() ? " - Administrator " : "");

            var ds = AdminProxy.ListPermissionTemplates(ID < 0 ? int.MaxValue : ID);

            // fill permissions tab
            lvPermissions.Items.Clear();

            foreach (DataRow dr in ds.Tables["list_permission_templates"].Rows)
            {
                txtName.Text        = dr["template_name"].ToString();
                txtDescription.Text = dr["description"].ToString();

                DataRow[] drPerms = ds.Tables["permissions_by_template"].Select("sys_perm_template_id = " + dr["sys_perm_template_id"]);
                if (drPerms != null && drPerms.Length > 0)
                {
                    foreach (DataRow drp in drPerms)
                    {
                        var lvi = new ListViewItem(drp["perm_name"].ToString());
                        lvi.Tag = Toolkit.ToInt32(drp["sys_permission_id"], -1);
                        lvi.UseItemStyleForSubItems = false;
                        string dv  = drp["dataview_name"].ToString();
                        string tbl = drp["table_name"].ToString();
                        if (String.IsNullOrEmpty(dv) && String.IsNullOrEmpty(tbl))
                        {
                            lvi.SubItems.Add("-- any resource --");
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(dv))
                            {
                                lvi.SubItems.Add(dv + " (dataview)");
                            }
                            else
                            {
                                lvi.SubItems.Add(tbl);
                            }
                        }
                        addPermItem(lvi, drp["create_permission_text"].ToString());
                        addPermItem(lvi, drp["read_permission_text"].ToString());
                        addPermItem(lvi, drp["update_permission_text"].ToString());
                        addPermItem(lvi, drp["delete_permission_text"].ToString());

                        // get restriction info...
                        var drFields = ds.Tables["template_perm_field_info"].Select("sys_permission_id = " + drp["sys_permission_id"]);
                        if (drFields == null || drFields.Length == 0)
                        {
                            lvi.SubItems.Add("-");
                        }
                        else
                        {
                            // pull perm field info into english-like display...
                            var sb = new StringBuilder();
                            foreach (var drField in drFields)
                            {
                                if (sb.Length > 0)
                                {
                                    sb.Append(" and ");
                                }
                                if (drField["compare_mode"].ToString() == "parent")
                                {
                                    sb.Append(drField["parent_table_name"] + "." + drField["parent_table_field_name"] + " " + drField["parent_compare_operator"] + " " + drField["parent_compare_value"] + " (for all children)");
                                }
                                else
                                {
                                    if (Toolkit.ToInt32(drField["sys_dataview_field_id"], -1) > -1)
                                    {
                                        sb.Append(drField["dataview_name"] + "." + drField["dataview_field_name"] + " " + drField["compare_operator"] + " " + drField["compare_value"] + " (dataview)");
                                    }
                                    else if (Toolkit.ToInt32(drField["sys_table_field_id"], -1) > -1)
                                    {
                                        sb.Append(drField["table_name"] + "." + drField["table_field_name"] + " " + drField["compare_operator"] + " " + drField["compare_value"] + " ");
                                    }
                                    else
                                    {
                                        sb.Append("INVALID -- must map a field from either Data View or Table!!!");
                                    }
                                }
                            }
                            lvi.SubItems.Add(sb.ToString());
                        }
                        lvPermissions.Items.Add(lvi);
                    }
                }
            }

            MarkClean();
        }