protected void btnSave_ServerClick(object sender, System.EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } string sGroups = iGroups.Value; ArrayList alGroups = new ArrayList(); while (sGroups.Length > 0) { alGroups.Add(Int32.Parse(sGroups.Substring(0, sGroups.IndexOf(",")))); sGroups = sGroups.Remove(0, sGroups.IndexOf(",") + 1); } foreach (ListItem liRole in lbSecurityRoles.Items) { if (liRole.Selected) { alGroups.Add(Int32.Parse(liRole.Value)); } } string filename = ""; System.IO.Stream strres = new System.IO.MemoryStream(); if (fPhoto.PostedFile != null && fPhoto.PostedFile.ContentLength > 0) { System.Drawing.Image img; string extension = ""; img = Mediachase.Ibn.Web.UI.Images.ProcessImage(fPhoto.PostedFile, out extension); string photoid = Guid.NewGuid().ToString().Substring(0, 6); filename = photoid + extension; img.Save(strres, img.RawFormat); strres.Position = 0; } try { int imgroup = int.Parse(ddlIMGroup.SelectedItem.Value); bool bApprovePending = false; if (UID > 0) { if (User.CheckUserGroup(Security.CurrentUser.UserID, (int)InternalSecureGroups.Administrator)) { if (tdWindowsLoginTextBox.Visible) { User.UpdateWindowsLogin(UID, tbWindowsLogin.Text.Trim()); } } if ((bool)ViewState[UID + "IsPending"]) { User.ApprovePending(UID, (lblLogin.Text != "") ? lblLogin.Text : txtLogin.Text, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, alGroups, imgroup, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, filename, strres, int.Parse(ProfileList.SelectedValue)); ViewState[UID + "IsPending"] = false; bApprovePending = true; } else if ((bool)ViewState[UID + "IsExternal"]) { User.CreateFromExternal(UID, txtLogin.Text, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, alGroups, imgroup, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, int.Parse(lstTimeZone.SelectedItem.Value), int.Parse(lstLang.SelectedItem.Value), filename, strres); ViewState[UID + "IsExternal"] = false; } else { User.UpdateUserInfo(UID, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, alGroups, imgroup, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, filename, strres, cbDelete.Checked, int.Parse(ProfileList.SelectedValue)); } } else { UID = User.Create(txtLogin.Text, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, alGroups, imgroup, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, int.Parse(lstTimeZone.SelectedItem.Value), int.Parse(lstLang.SelectedItem.Value), filename, strres, int.Parse(ProfileList.SelectedValue)); } if (UID != Security.CurrentUser.UserID) { if (!bApprovePending) { Response.Redirect("../Directory/UserView.aspx?UserID=" + UID); } else { Util.CommonHelper.ReloadTopFrame("ActiveWork.ascx", "../Directory/UserView.aspx?UserID=" + UID, Response); } } else { Picture.Visible = false; Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "window.top.location.href='../Directory/UserView.aspx?UserID=" + UID.ToString() + "';", true); } } catch (MaxUsersCountException) { lblError.Text = LocRM.GetString("MaxUsersCount"); lblError.Visible = true; } catch (EmailDuplicationException) { int iUserId = User.GetUserByEmail(txtEmail.Text); string sUserName = String.Empty; if (iUserId > 0) { sUserName = CommonHelper.GetUserStatusPureName(iUserId); } lblError.Text = LocRM.GetString("EmailDuplicate") + " (" + sUserName + ")"; lblError.Visible = true; } catch (LoginDuplicationException) { lblError.Text = LocRM.GetString("DuplicatedLogin"); lblError.Visible = true; } catch (PasswordRequiredException) { for (int i = 0; i < alGroups.Count; i++) { using (IDataReader reader = SecureGroup.GetGroup((int)alGroups[i])) { if (reader.Read()) { lbSelectedGroups.Items.Add(new ListItem(CommonHelper.GetResFileString(reader["GroupName"].ToString()), ((int)alGroups[i]).ToString())); ListItem li = lbAvailableGroups.Items.FindByValue(((int)alGroups[i]).ToString()); if (li != null) { lbAvailableGroups.Items.Remove(li); } } } } PasswordValidator1.Validate(); PasswordValidator1.Enabled = true; lblError.Text = LocRM.GetString("PasswordRequest"); lblError.Visible = true; } }
protected void btnSave_ServerClick(object sender, System.EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } string sGroups = iGroups.Value; ArrayList alGroups = new ArrayList(); if (ddUserType.SelectedItem.Value != "1") //non partner { while (sGroups.Length > 0) { alGroups.Add(Int32.Parse(sGroups.Substring(0, sGroups.IndexOf(",")))); sGroups = sGroups.Remove(0, sGroups.IndexOf(",") + 1); } if (ddUserType.SelectedItem.Value == "0") //regular { foreach (ListItem liRole in lbSecurityRoles.Items) { if (liRole.Selected) { alGroups.Add(Int32.Parse(liRole.Value)); } } } if (alGroups.Count <= 0) { GroupValidator.IsValid = false; return; } } string filename = ""; System.IO.Stream strres = new System.IO.MemoryStream(); if (fPhoto.PostedFile != null && fPhoto.PostedFile.ContentLength > 0) { System.Drawing.Image img; string extension = ""; img = Mediachase.Ibn.Web.UI.Images.ProcessImage(fPhoto.PostedFile, out extension); string photoid = Guid.NewGuid().ToString().Substring(0, 6); filename = photoid + extension; img.Save(strres, img.RawFormat); strres.Position = 0; } try { int imgroup = int.Parse(ddlIMGroup.SelectedItem.Value); switch (ddUserType.SelectedItem.Value) { case "0": UID = User.Create(txtLogin.Text, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, alGroups, imgroup, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, int.Parse(lstTimeZone.SelectedItem.Value), int.Parse(lstLang.SelectedItem.Value), "", filename, strres, txtWinLogin.Text, int.Parse(ProfileList.SelectedValue)); break; case "1": UID = User.CreatePartnerUser(txtLogin.Text, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, int.Parse(ddPartnerGroups.SelectedItem.Value), txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, int.Parse(lstTimeZone.SelectedItem.Value), int.Parse(lstLang.SelectedItem.Value), filename, strres, int.Parse(ProfileList.SelectedValue)); break; case "2": UID = User.CreateExternal(txtFirstName.Text, txtLastName.Text, txtEmail.Text, alGroups, chbIsActive.Checked, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, int.Parse(lstTimeZone.SelectedItem.Value), int.Parse(lstLang.SelectedItem.Value), "", filename, strres); break; case "3": UID = User.CreatePending(txtLogin.Text, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, alGroups, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, int.Parse(lstTimeZone.SelectedItem.Value), int.Parse(lstLang.SelectedItem.Value), "", filename, strres); break; } if (!cbOneMore.Checked) { Response.Redirect("~/Directory/UserView.aspx?UserID=" + UID); } else { Response.Redirect("~/Directory/MultipleUserEdit.aspx"); } } catch (MaxUsersCountException) { lblError.Text = LocRM.GetString("MaxUsersCount"); lblError.Visible = true; } catch (LoginDuplicationException) { if (ddUserType.SelectedItem.Value == "2") { int iUserId = User.GetUserByEmail(txtEmail.Text); string sUserName = String.Empty; if (iUserId > 0) { sUserName = CommonHelper.GetUserStatusPureName(iUserId); } lblError.Text = LocRM.GetString("EmailDuplicate") + " (" + sUserName + ")"; } else { lblError.Text = LocRM.GetString("DuplicatedLogin"); } lblError.Visible = true; } catch (EmailDuplicationException) { int iUserId = User.GetUserByEmail(txtEmail.Text); string sUserName = String.Empty; if (iUserId > 0) { sUserName = CommonHelper.GetUserStatusPureName(iUserId); } lblError.Text = LocRM.GetString("EmailDuplicate") + " (" + sUserName + ")"; lblError.Visible = true; } catch (PasswordRequiredException) { for (int i = 0; i < alGroups.Count; i++) { using (IDataReader reader = SecureGroup.GetGroup((int)alGroups[i])) { if (reader.Read()) { lbSelectedGroups.Items.Add(new ListItem(CommonHelper.GetResFileString(reader["GroupName"].ToString()), ((int)alGroups[i]).ToString())); ListItem li = lbAvailableGroups.Items.FindByValue(((int)alGroups[i]).ToString()); if (li != null) { lbAvailableGroups.Items.Remove(li); } } } } PasswordValidator1.Validate(); PasswordValidator1.Enabled = true; lblError.Text = LocRM.GetString("PasswordRequest"); lblError.Visible = true; } }
protected void btnSave_ServerClick(object sender, System.EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } string filename = ""; System.IO.Stream strres = new System.IO.MemoryStream(); if (fPhoto.PostedFile != null && fPhoto.PostedFile.ContentLength > 0) { System.Drawing.Image img; string extension = ""; img = Mediachase.Ibn.Web.UI.Images.ProcessImage(fPhoto.PostedFile, out extension); string photoid = Guid.NewGuid().ToString().Substring(0, 6); filename = photoid + extension; img.Save(strres, img.RawFormat); strres.Position = 0; } try { if (UID > 0) { User.UpdatePartnerUser(UID, txtPassword.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, chbIsActive.Checked, txtPhone.Text, txtFax.Text, txtMobile.Text, txtJobTitle.Text, txtDepartment.Text, txtCompany.Text, txtLocation.Text, filename, strres, int.Parse(ProfileList.SelectedValue)); Response.Redirect("../Directory/UserView.aspx?UserID=" + UID); } else { Response.Redirect("../Directory/Directory.aspx"); } } catch (MaxUsersCountException) { lblError.Text = LocRM.GetString("MaxUsersCount"); lblError.Visible = true; } catch (EmailDuplicationException) { int iUserId = User.GetUserByEmail(txtEmail.Text); string sUserName = String.Empty; if (iUserId > 0) { sUserName = CommonHelper.GetUserStatusPureName(iUserId); } lblError.Text = LocRM.GetString("EmailDuplicate") + " (" + sUserName + ")"; lblError.Visible = true; } catch (LoginDuplicationException) { lblError.Text = LocRM.GetString("DuplicatedLogin"); lblError.Visible = true; } catch (PasswordRequiredException) { PasswordValidator1.Validate(); PasswordValidator1.Enabled = true; lblError.Text = LocRM.GetString("PasswordRequest"); lblError.Visible = true; } }