Example #1
0
        private bool save()
        {
            if (txtUserName.Text.Trim().Length == 0)
            {
                tcUser.SelectedTab = tpGeneral;
                Application.DoEvents();
                MessageBox.Show(getDisplayMember("save{usernamerequired}", "You must set a username for this user before saving."));
                txtUserName.Focus();
                return(false);
            }
            if (String.IsNullOrEmpty(_password) && ID == -1)
            {
                tcUser.SelectedTab = tpGeneral;
                Application.DoEvents();
                MessageBox.Show(getDisplayMember("save{passwordrequired}", "You must set a password for this user before saving."));
                btnChangePassword.Focus();
                return(false);
            }
            if (_cooperatorID < 1 && (txtFirstName.Text.Trim().Length == 0 || txtLastName.Text.Trim().Length == 0))
            {
                tcUser.SelectedTab       = tpGeneral;
                tcCooperator.SelectedTab = tpCoopGeneral;
                Application.DoEvents();
                MessageBox.Show(getDisplayMember("save{cooperatorrequired}", "You must select a cooperator or enter a new one for this user before saving.\nA new cooperator must have its First Name and Last Name specified."));
                txtFirstName.Focus();
                return(false);
            }

            if (_geographyID < 1)
            {
                tcUser.SelectedTab       = tpGeneral;
                tcCooperator.SelectedTab = tpCoopGeographic;
                Application.DoEvents();
                MessageBox.Show(getDisplayMember("save{geographyrequired}", "You must specify a geographic location for this user before saving."));
                btnGeography.Focus();
                return(false);
            }

            var discCode      = getSelectedValue(ddlDisciplineCode) + string.Empty;
            var catCode       = getSelectedValue(ddlCategoryCode) + string.Empty;
            var orgRegionCode = getSelectedValue(ddlOrganizationRegionCode) + string.Empty; //.SelectedValue == null ? null : ((DataRowView)ddlOrganizationRegionCode.SelectedValue).Row[ddlOrganizationRegionCode.ValueMember] + string.Empty;


            var newID = -1;

            try {
                newID = AdminProxy.SaveUser(ID,
                                            txtUserName.Text,
                                            chkEnabled.Checked,
                                            _cooperatorID,
                                            _currentCooperatorID,
                                            _webCooperatorID,
                                            txtTitle.Text,
                                            txtFirstName.Text,
                                            //txtInitials.Text,
                                            txtLastName.Text,
                                            //                    txtFullName.Text,
                                            txtJob.Text,
                                            discCode,
                                            txtOrganization.Text,
                                            txtOrganizationAbbreviation.Text,
                                            Toolkit.ToInt32(ddlLanguage.SelectedValue, -1),
                                            chkIsActive.Checked,
                                            txtAddressLine1.Text,
                                            txtAddressLine2.Text,
                                            txtAddressLine3.Text,
                                            txtCity.Text,
                                            txtPostalIndex.Text,
                                            txtEmail.Text,
                                            txtPrimaryPhone.Text,
                                            txtSecondaryPhone.Text,
                                            txtFax.Text,
                                            Toolkit.ToInt32(ddlSiteCode.SelectedValue, -1),
                                            orgRegionCode,
                                            catCode,
//                        txtRegionCode.Text,
//                        txtCategoryCode.Text,
                                            _geographyID,
                                            //                    Toolkit.ToInt32(ddlGeography.SelectedValue, 0),
                                            txtNote.Text
                                            );
            } catch (InvalidOperationException ioe) {
                if (ioe.Message.Contains("duplicate"))
                {
                    MessageBox.Show(this, getDisplayMember("save{duplicateuser_body}", "A user with that user name already exists.\r\nYou must choose a different one."),
                                    getDisplayMember("save{duplicateuser_title}", "User Name Taken"));
                }
                else
                {
                    throw;
                }
            }

            if (newID != ID)
            {
                // every user is added to the all users group. always.
                var groups  = AdminProxy.ListGroups(-1).Tables["list_groups"];
                var groupID = -1;
                foreach (DataRow dr in groups.Rows)
                {
                    if (dr["group_tag"].ToString().ToLower() == "allusers")
                    {
                        groupID = Toolkit.ToInt32(dr["sys_group_id"], -1);
                        break;
                    }
                }
                if (groupID > -1)
                {
                    var userIDs = new List <int>();
                    userIDs.Add(newID);
                    AdminProxy.AddUsersToGroup(groupID, userIDs);
                }
            }

            ID = newID;

            if (!String.IsNullOrEmpty(_password))
            {
                AdminProxy.ChangePassword(ID, _password);
                _password = null;
            }
            return(true);
        }
Example #2
0
        public override void RefreshData()
        {
            this.Text = "Group - " + MainFormCurrentNodeText("") + " - " + this.AdminProxy.Connection.ServerName + (Toolkit.IsProcessElevated() ? " - Administrator " : "");

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

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

            foreach (DataRow dr in ds.Tables["list_groups"].Rows)
            {
                txtName.Text = dr["group_name"].ToString();
                txtTag.Text  = dr["group_tag"].ToString();

                if (AdminProxy.IsReservedGroupTagValue(txtTag.Text))
                {
                    txtTag.Enabled = false;
                }
                else
                {
                    txtTag.Enabled = true;
                }

                txtDescription.Text = dr["description"].ToString();

                DataRow[] drPerms = ds.Tables["permissions_by_group"].Select("sys_group_id = " + dr["sys_group_id"]);
                if (drPerms != null && drPerms.Length > 0)
                {
                    foreach (DataRow drp in drPerms)
                    {
                        var lvi = new ListViewItem(drp["title"].ToString(), 0);
                        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);
                            }
                        }
                        lvi.SubItems.Add(drp["perm_is_enabled"].ToString().ToUpper());
                        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["group_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);
                    }
                }


                lvUsers.Items.Clear();
                var dtUsers = ds.Tables["users_by_group"];
                if (dtUsers != null)
                {
                    var drUsers = dtUsers.Select("sys_group_id = " + dr["sys_group_id"]);

                    foreach (DataRow drUser in drUsers)
                    {
                        var lvi = new ListViewItem(new string[] {
                            drUser["user_name"].ToString(),
                            drUser["full_name"].ToString(),
                            drUser["is_enabled"].ToString()
                        });
                        lvi.ImageIndex = 1;
                        lvi.Tag        = drUser["sys_user_id"];
                        lvUsers.Items.Add(lvi);
                    }
                }
            }

            MarkClean();
        }
Example #3
0
        public override void RefreshData()
        {
            //lvPerms.MultiSelect = !Modal;

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

            // 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.ListGroups(ID);

            initHooksForMdiParent(ds.Tables["list_groups"], "group_name", "sys_group_id");
            lvGroups.Items.Clear();
            foreach (DataRow dr in ds.Tables["list_groups"].Rows)
            {
                var lvi = new ListViewItem(dr["group_name"].ToString(), 0);
                lvi.Tag = Toolkit.ToInt32(dr["sys_group_id"], -1);
                lvi.SubItems.Add(dr["description"].ToString());
                DataRow[] drPerms = ds.Tables["permissions_by_group"].Select("sys_group_id = " + dr["sys_group_id"]);
                var       perms   = new List <string>();
                foreach (DataRow drp in drPerms)
                {
                    perms.Add(drp["permission_name"].ToString());
                }
                if (perms.Count == 0)
                {
                    lvi.SubItems.Add("(None)");
                }
                else
                {
                    lvi.SubItems.Add("(" + perms.Count + ") - " + Toolkit.Join(perms.ToArray(), ", ", "-"));
                }

                DataRow[] drUsers = ds.Tables["users_by_group"].Select("sys_group_id = " + dr["sys_group_id"]);
                var       users   = new List <string>();
                foreach (DataRow dru in drUsers)
                {
                    users.Add(dru["user_name"].ToString());
                }

                if (users.Count == 0)
                {
                    lvi.SubItems.Add("(None)");
                }
                else
                {
                    lvi.SubItems.Add("(" + users.Count + ") - " + Toolkit.Join(users.ToArray(), ", ", "-"));
                }

                lvi.Tag = dr["sys_group_id"];
                lvGroups.Items.Add(lvi);
            }

            selectRememberedTags(lvGroups, tags);

            MainFormUpdateStatus(getDisplayMember("RefreshData{done}", "Refreshed Groups"), false);
        }