protected void btnGuardar_Click(object sender, EventArgs e) { #region ValidarCampos if (txtIdentificador.EmptyTextBox()) { lblValidar.Text = "El campo Identificador es obligatorio"; return; } if (txtNombre.EmptyTextBox()) { lblValidar.Text = "El campo Nombre es obligatorio"; return; } if (txtApePaterno.EmptyTextBox()) { lblValidar.Text = "El campo Apellido Paterno es obligatorio"; return; } if (txtApeMaterno.EmptyTextBox()) { lblValidar.Text = "El campo Apellido Materno es obligatorio"; return; } if (txtMatricula.EmptyTextBox()) { lblValidar.Text = "El campo Matricula es obligatorio"; return; } if (bool.Parse(ddlBeca.SelectedValue)) { if (txtBeca.EmptyTextBox()) { lblValidar.Text = "El campo Beca es obligatorio"; return; } if (ddlTipoBeca.SelectedValue == "PORCENTAJE") { if (decimal.Parse(txtBeca.Text) > 100) { lblValidar.Text = "Cuando la selección es PORCENTAJE, Solo se admite hasta 100"; txtBeca.BackColor = System.Drawing.Color.FromName("#f2dede"); return; } } } else { txtBeca.Text = "0"; } if (ddlEstatus.EmptyDropDownList()) { lblValidar.Text = "El campo Estatus es obligatorio"; return; } if (!string.IsNullOrEmpty(lblValidar.Text)) { lblValidar.Text = string.Empty; } #endregion List <PermisosMenuModel> permisosMenuModels = (List <PermisosMenuModel>)Session["lsAccesosPermitidos"]; permisosMenuModels = permisosMenuModels.Where(x => x.UidSegModulo == Guid.Parse("C1E64F99-F72E-4C68-89DE-6E32BD5C0525")).ToList(); foreach (var item in permisosMenuModels) { txtMatricula.BackColor = System.Drawing.Color.Transparent; if (ViewState["Accion"].ToString() == "Guardar") { if (item.Agregar) { Guid UidAlumno = Guid.NewGuid(); if (validacionesServices.ExisteMatricula(txtMatricula.Text)) { txtMatricula.BackColor = System.Drawing.Color.FromName("#f2dede"); lblValidar.Text = "La matricula ingresado ya existe por favor intente con otro."; } else { if (alumnosServices.RegistrarAlumno(UidAlumno, txtIdentificador.Text.Trim().ToUpper(), txtNombre.Text.Trim().ToUpper(), txtApePaterno.Text.Trim().ToUpper(), txtApeMaterno.Text.Trim().ToUpper(), txtMatricula.Text.Trim().ToUpper(), txtCorreo.Text.Trim().ToUpper(), bool.Parse(ddlBeca.SelectedValue), ddlTipoBeca.SelectedValue, decimal.Parse(txtBeca.Text), txtNumero.Text.Trim(), Guid.Parse(ddlPrefijo.SelectedValue), Guid.Parse(ViewState["UidClienteLocal"].ToString()))) { pnlAlert.Visible = true; lblMensajeAlert.Text = "<strong>¡Felicidades! </strong> se ha registrado exitosamente."; divAlert.Attributes.Add("class", "alert alert-success alert-dismissible fade show"); ViewState["NewPageIndex"] = null; alumnosServices.CargarAlumnos(Guid.Parse(ViewState["UidClienteLocal"].ToString())); gvAlumnos.DataSource = alumnosServices.lsAlumnosGridViewModel; gvAlumnos.DataBind(); ScriptManager.RegisterStartupScript(this, this.GetType(), "FormScript", "hideModal()", true); } } } else { pnlAlert.Visible = true; lblMensajeAlert.Text = "<strong>Lo sentimos,</strong> no tiene permisos para esta acción."; divAlert.Attributes.Add("class", "alert alert-danger alert-dismissible fade show"); ScriptManager.RegisterStartupScript(this, this.GetType(), "FormScript", "hideModal()", true); } } else if (ViewState["Accion"].ToString() == "Actualizar") { if (item.Actualizar) { bool Actualizar = true; if (ViewState["ActualizarMatricula"].ToString() != txtMatricula.Text) { if (validacionesServices.ExisteMatricula(txtMatricula.Text)) { txtMatricula.BackColor = System.Drawing.Color.FromName("#f2dede"); lblValidar.Text = "La matricula que desea actualizar ya existe por favor intente con otro."; Actualizar = false; } } if (Actualizar) { if (alumnosServices.ActualizarAlumno(Guid.Parse(ViewState["UidRequerido"].ToString()), txtIdentificador.Text.Trim().ToUpper(), txtNombre.Text.Trim().ToUpper(), txtApePaterno.Text.Trim().ToUpper(), txtApeMaterno.Text.Trim().ToUpper(), txtMatricula.Text.Trim().ToUpper(), txtCorreo.Text.Trim().ToUpper(), bool.Parse(ddlBeca.SelectedValue), ddlTipoBeca.SelectedValue, decimal.Parse(txtBeca.Text), Guid.Parse(ddlEstatus.SelectedValue), txtNumero.Text.Trim(), Guid.Parse(ddlPrefijo.SelectedValue))) { pnlAlert.Visible = true; lblMensajeAlert.Text = "<strong>¡Felicidades! </strong> se ha actualizado exitosamente."; divAlert.Attributes.Add("class", "alert alert-success alert-dismissible fade show"); ViewState["NewPageIndex"] = null; alumnosServices.CargarAlumnos(Guid.Parse(ViewState["UidClienteLocal"].ToString())); gvAlumnos.DataSource = alumnosServices.lsAlumnosGridViewModel; gvAlumnos.DataBind(); ScriptManager.RegisterStartupScript(this, this.GetType(), "FormScript", "hideModal()", true); } } } else { pnlAlert.Visible = true; lblMensajeAlert.Text = "<strong>Lo sentimos,</strong> no tiene permisos para esta acción."; divAlert.Attributes.Add("class", "alert alert-danger alert-dismissible fade show"); ScriptManager.RegisterStartupScript(this, this.GetType(), "FormScript", "hideModal()", true); } } } }