private Boolean formFilledCorrectly(ref string plantaList) { String mensaje = String.Empty; if (hdIdItem.Value.Equals(String.Empty)) { if (txtCuenta.Text.Equals(String.Empty)) { mensaje += (string)GetLocalResourceObject("CuentaRequerido") + Environment.NewLine; } else { if (isThereTheUser(txtCuenta.Text, txtEmail.Text)) { mensaje += (string)GetLocalResourceObject("existeUsuario") + Environment.NewLine; } } try { if (cbxActiveDirectory.Checked) { String exception = String.Empty; if (!DGActiveDirectory.userExistOnActiveDirectory(txtCuenta.Text.Trim(), "GDL|USA", ref exception)) { if (exception.Length == 0) { mensaje += (string)GetLocalResourceObject("NoexisteUsuario") + Environment.NewLine; return(false); } else { Log.Error(exception); ltNombreUsuario.Text = string.Empty; return(false); } } } } catch (ConfigurationErrorsException cEE) { Log.Error(cEE.ToString()); } } if (ddlTipo.SelectedIndex < 1) { mensaje += (string)GetLocalResourceObject("TipoRequerido") + Environment.NewLine; } foreach (ListItem item in ddlPlanta.Items) { if (item.Selected && !plantaList.Contains(item.Text + "|")) { plantaList += item.Value + "|"; } } if (plantaList.Length == 0) { mensaje += (string)GetLocalResourceObject("AtLeastOnePlant") + Environment.NewLine; } if (!string.IsNullOrEmpty(txtEmail.Text.Trim())) { string[] emails = txtEmail.Text.Split(';'); foreach (string email in emails) { try { new MailAddress(email); if (email.Contains(" ")) { mensaje += String.Format((string)GetLocalResourceObject("CorreoMal"), email) + Environment.NewLine; } } catch (Exception) { mensaje += String.Format((string)GetLocalResourceObject("CorreoMal"), email) + Environment.NewLine; } } } else { mensaje += String.Format((string)GetLocalResourceObject("CorreoMal"), "") + Environment.NewLine; } if (mensaje.Length > 0) { popUpMessageControl1.setAndShowInfoMessage(mensaje, Comun.MESSAGE_TYPE.Error); return(false); } return(true); }
protected void btnGuardar_Click(object sender, EventArgs e) { try { string mensaje = ""; //Valida correo try { if (!string.IsNullOrEmpty(ltEmail.Text)) { new MailAddress(ltEmail.Text); } } catch (FormatException) { mensaje += (string)GetLocalResourceObject("CorreoMal"); } //Valida campos obligatorios... if ("" == hdIdItem.Value) { if ((null == txtCuenta.Text) || ("" == txtCuenta.Text)) { mensaje += (string)GetLocalResourceObject("CuentaRequerido"); } /*if ((null == txtPassword.Text) || ("" == txtPassword.Text)) * { * mensaje += "El campo Contraseña, es requerido <br/>"; * } * * if ((null == txtNombre.Text) || ("" == txtNombre.Text)) * { * mensaje += "El campo Nombre, es requerido <br/>"; * } * */ } if (ddlTipo.SelectedIndex <= 0) { mensaje += (string)GetLocalResourceObject("TipoRequerido"); } string plantaList = string.Empty; foreach (ListItem item in ddlPlanta.Items) { if (item.Selected) { plantaList += item.Value + "|"; } } //if ((string.IsNullOrEmpty(plantaList)) && ("RECEPCION" != ddlTipo.SelectedItem.Text)) //{ // mensaje += "El campo Planta, es requerido para usuarios de PLANTA o APOYO <br/>"; //} if ("" == hdIdItem.Value) { //Valida no existencia de otro usuario igual... if (this.existeUsuario(true, txtCuenta.Text)) { mensaje += (string)GetLocalResourceObject("existeUsuario"); } bool autenticated = false; //Valida que exista en el LDAP #if DEBUG if (txtCuenta.Text.Trim().CompareTo("recepcion") == 0) { autenticated = true; } else if (txtCuenta.Text.Trim().CompareTo("planta") == 0) { autenticated = true; } else if (txtCuenta.Text.Trim().CompareTo("planta2") == 0) { autenticated = true; } else if (txtCuenta.Text.Trim().CompareTo("apoyo") == 0) { autenticated = true; } else if (txtCuenta.Text.Trim().CompareTo("apoyo2") == 0) { autenticated = true; } else if (txtCuenta.Text.Trim().CompareTo("apoyo3") == 0) { autenticated = true; } else if (txtCuenta.Text.Trim().CompareTo("apoyo4") == 0) { autenticated = true; } #endif if (!autenticated) { autenticated = DGActiveDirectory.userExistOnActiveDirectory(txtCuenta.Text.Trim()); } //autenticated = true; if (!autenticated) { mensaje += (string)GetLocalResourceObject("NoexisteUsuario"); } } //Muestra PopUp con mensaje(s), si hubo... if (mensaje.Trim().Length > 0) { popUpMessageControl1.setAndShowInfoMessage(mensaje, Common.MESSAGE_TYPE.Error); mensaje = ""; return; } else { if ("" == hdIdItem.Value) { // Es INSERT this.guardaUsuario(ltNombreUsuario.Text, txtCuenta.Text, ltEmail.Text, ddlTipo.SelectedValue, plantaList, checkActivo.Checked); } else { // Es UPDATE int id = 0; Int32.TryParse(hdIdItem.Value.ToString(), out id); this.actualizaUsuario(id, ltEmail.Text, ddlTipo.SelectedValue, plantaList, checkActivo.Checked); } } this.limpiaCampos(); Response.Redirect(this.Page.Request.Path); } catch (Exception ex) { Log.Error(ex.ToString()); } }