private void toolStripMenuItem1_Click(object sender, EventArgs e) { string username = null; switch (lvUsers.SelectedItems.Count) { case 0: MessageBox.Show(getDisplayMember("changedPassword{oneuserrequired}", "Please select at least one user to change a password for.")); return; case 1: username = lvUsers.SelectedItems[0].Text; break; default: username = "******"; break; } var f = new frmSetPassword(); if (f.ShowDialog(this, username) == DialogResult.OK) { using (new AutoCursor(this)) { foreach (ListViewItem lvi in lvUsers.SelectedItems) { AdminProxy.ChangePassword(Toolkit.ToInt32(lvi.Tag, -1), f.Password); } MainFormUpdateStatus(getDisplayMember("changedPassword{done}", "Changed password for {0} user(s)", lvUsers.SelectedItems.Count.ToString("###,##0")), true); MainFormRefreshData(); } } }
private void btnChangePassword_Click(object sender, EventArgs e) { var f = new frmSetPassword(); if (f.ShowDialog(this, MainFormCurrentNodeText(txtUserName.Text)) == DialogResult.OK) { if (ID < 1) { // new user, can't change it yet. remember it for when we save the user _password = f.Password; lblPasswordNotSet.Visible = String.IsNullOrEmpty(_password); btnSave.Enabled = String.IsNullOrEmpty(_password); MarkDirty(); } else { using (new AutoCursor(this)) { AdminProxy.ChangePassword(ID, f.Password); if (txtUserName.Text.ToLower() == AdminProxy.Connection.GrinGlobalUserName.ToLower()) { AdminProxy.Connection.GrinGlobalPassword = f.Password; if (AdminProxy.Connection.GrinGlobalRememberPassword) { MainFormSaveConnections(AdminProxy.Connection); } } MainFormUpdateStatus(getDisplayMember("changePassword{done}", "Changed password for user {0}", MainFormCurrentNodeText(txtUserName.Text)), true); } } } }
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); }