Exemplo n.º 1
0
 /// <summary>
 /// Attempts to display a C-Access user in a new <see cref="UserAccountForm"/>.
 /// </summary>
 /// <param name="username">The username of the account to display.</param>
 private void ShowUserAccount(string username)
 {
     this.Cursor = Cursors.WaitCursor;
     new MethodInvoker(() =>
     {
         CPUser user = CPSecurity.Provider.GetUser(username);
         this.BeginInvoke(new MethodInvoker(() =>
         {
             try
             {
                 if (user == null)
                 {
                     MessageBox.Show(this, string.Format("User \"{0}\" could not be found.", username), "User Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     UserAccountForm.ShowExistingAccountForm(user, this.MdiParent);
                 }
             }
             finally
             {
                 this.Cursor = Cursors.Default;
             }
         }));
     }).BeginInvoke(null, null);
 }
Exemplo n.º 2
0
        private void _newAccountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ActiveCandidate ac = _treeView.SelectedNode.Tag as ActiveCandidate;

            if (ac != null)
            {
                UserAccountForm.CreateNewAccountForm(null, ac.ID, ac.ElectionCycle, null).ShowAsOwnedBy(this);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a user account form for displaying an existing user account.
        /// </summary>
        /// <param name="user">The user to display.</param>
        /// <returns>A <see cref="UserAccountForm"/> purposed for displaying user <paramref name="user"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="user"/> is null.</exception>
        public static UserAccountForm CreateExistingAccountForm(CPUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user", "User cannot be null.");
            }
            UserAccountForm form = new UserAccountForm();

            form.SetUser(user);
            return(form);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Shows a form for displaying an existing user account.
 /// </summary>
 /// <param name="user">The user to display.</param>
 /// <param name="owner">The existing form that should own the new form.</param>
 public static void ShowExistingAccountForm(CPUser user, Form owner = null)
 {
     if (owner != null)
     {
         // find already-open form and, if found, show that instead of a new one
         var existing = (from f in owner.OwnedForms
                         where f is UserAccountForm && f.Tag is CPUser && ((CPUser)f.Tag).UserName == user.UserName
                         select f).FirstOrDefault();
         if (existing != null)
         {
             existing.BringToFront();
             return;
         }
     }
     UserAccountForm.CreateExistingAccountForm(user).ShowAsOwnedBy(owner);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a user account form for creating a new user account.
        /// </summary>
        /// <param name="entity">The entity to create a user account for.</param>
        /// <param name="candidateID">The ID of the candidate to associate with the new account.</param>
        /// <param name="electionCycle">The election cycle for which the new account is registered.</param>
        /// <param name="entityKey">The campaign-relative unique account analysis identifier for the entity.</param>
        /// <returns>A <see cref="UserAccountForm"/> purposed for creating a new user account for <paramref name="entity"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="entity"/> is null.</exception>
        public static UserAccountForm CreateNewAccountForm(Entity entity, string candidateID, string electionCycle, string entityKey)
        {
            UserAccountForm form = new UserAccountForm()
            {
                Text = CreateFormText
            };

            form._mainTabControl.TabPages.Remove(form._generalTabPage);
            form._mainTabControl.TabPages.Remove(form._securityTabPage);
            form._mainTabControl.TabPages.Remove(form._electionsTabPage);
            form.IsCreateMode  = true;
            form._initializing = true;
            form.SetCandidate(candidateID);
            form._initializing = false;
            // set CFIS entity context
            form.SetEntity(entity, AccountAnalysis.ParseEntityType(entityKey), candidateID, electionCycle, AccountAnalysis.ParseCommitteeID(entityKey), AccountAnalysis.ParseLiaisonID(entityKey));
            return(form);
        }
Exemplo n.º 6
0
 private void _listView_ItemActivate(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     try
     {
         ListViewItem item = this.SelectedItem;
         if (item == null)
         {
             return;
         }
         ActiveCandidate ac = null;
         if (_treeView.SelectedNode != null)
         {
             ac = _treeView.SelectedNode.Tag as ActiveCandidate;
         }
         var user = this.SelectedUser;
         if (user != null || item.Text.EndsWith("*"))
         {
             var status = this.SelectedIneligibilityStatus;
             if (status != null)
             {
                 // other cycle user, prompt for open or update
                 user = status.MatchedUser;
                 if (user != null)
                 {
                     if (MessageBox.Show(this, string.Format("{0} already has an account from EC{1}. Would you like to associate this account with the EC{2} data before opening it?", user.DisplayName, user.SourceElectionCycle, ac.ElectionCycle), "Update Account?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                     {
                         // remap account
                         Entity entity    = status.Entity;
                         string contactID = status.ContactID;
                         if (entity != null && contactID != null)
                         {
                             char?sourceCommitteeID = AccountAnalysis.ParseCommitteeID(contactID);
                             byte?sourceLiaisonID   = AccountAnalysis.ParseLiaisonID(contactID);
                             if (sourceCommitteeID.HasValue)
                             {
                                 user.SourceCommitteeID = sourceCommitteeID;
                             }
                             if (sourceLiaisonID.HasValue)
                             {
                                 user.SourceLiaisonID = sourceLiaisonID;
                             }
                             if (ac != null)
                             {
                                 user.SourceElectionCycle = ac.ElectionCycle;
                             }
                             user.SourceType = entity.Type;
                             user.ElectionCycles.Add(ac.ElectionCycle);
                         }
                         if (!user.Save())
                         {
                             MessageBox.Show(this, string.Format("An error occurred attempting to update {0}'s account. Please try again, or contact an administrator for further assistance.", user.DisplayName), "Account Update Failed", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                             return;
                         }
                         _refreshToolStripButton.PerformClick();
                     }
                 }
             }
             if (user != null)
             {
                 // show existing user account properties
                 UserAccountForm.ShowExistingAccountForm(user, this.MdiParent);
             }
         }
         else
         {
             // create new user
             if (ac != null)
             {
                 Entity entity = this.SelectedEntity;
                 if (entity != null)
                 {
                     UserAccountForm.CreateNewAccountForm(entity, ac.ID, ac.ElectionCycle, item.Name).ShowAsOwnedBy(this.MdiParent);
                     _refreshToolStripButton.PerformClick();
                 }
                 else
                 {
                     var status = this.SelectedIneligibilityStatus;
                     if (status != null)
                     {
                         entity = status.Entity;
                         MessageBox.Show(this, string.Format("A C-Access user account cannot be created for {0} for the following reason:\n\n{1}", entity != null ? entity.Name : this.SelectedItem.Name, status.Status.GetDescription()), "Ineligible Contact", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                 }
             }
             else
             {
                 // does not match a leaf node, so expand tree
                 lock (_listViewClickedLock)
                 {
                     _listViewClicked = true;
                 }
                 if (!_treeView.SelectedNode.IsExpanded)
                 {
                     _treeView.SelectedNode.Expand();
                 }
                 var nodes = _treeView.SelectedNode.Nodes.Find(item.Name, false);
                 if (nodes.Length > 0 && nodes[0].TreeView != null)
                 {
                     nodes[0].EnsureVisible();
                     _treeView.SelectedNode = nodes[0];
                 }
             }
         }
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }