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); } }
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; } }