コード例 #1
0
        protected void btn_guardar_ServerClick(object sender, EventArgs e)
        {
            try
            {
                if (FormAccion == "Agregar")
                {
                    if (txt_contrasena.Value == txt_confirmacion.Value)
                    {
                        WSGestion.WSGestion wsgest = new WSGestion.WSGestion();
                        wsgest.Url = ConfigurationManager.AppSettings.Get("dirWs");
                        WSGestion.MOD_Usuario obj = new WSGestion.MOD_Usuario();

                        obj.USU_nombre = txt_nombre.Value;
                        obj.USU_primapellido = txt_apellido1.Value;
                        obj.USU_segapellido = txt_apellido2.Value;
                        obj.USU_telefono = txt_telefono.Value;
                        obj.USU_contrasena = txt_contrasena.Value;
                        obj.USU_direccion = txt_Direccion.Value;
                        obj.USU_email = txt_email.Value;
                        obj.USU_id_puesto = Convert.ToInt32(dlPuesto.SelectedValue.ToString());
                        obj.USU_id_perfil = Convert.ToInt32(dl_perfil.SelectedValue.ToString());
                        if (chk_activo.Checked)
                        {
                            obj.USU_id_estado_usuario = 1;
                        }
                        else
                        {
                            obj.USU_id_estado_usuario = 0;
                        }
                        obj.USU_id_centro_atencion = Convert.ToInt32(txt_codigocentro.Value.ToString());

                        int cant_usu = wsgest.SEL_Usuario_By_Email(txt_email.Value);

                        if (cant_usu <= 0)
                        {
                            if (wsgest.CRE_Usuario(obj))
                            {
                                Response.Redirect("frm_Grid_Usuario.aspx");
                            }
                            else
                            {
                                Alert_Mensaje.Attributes["class"] = "alert alert-danger";
                                mensaje_alerta = "Procedimiento almacenado no aceptado";
                                titulo_mensaje_alerta = "Error: ";
                                Alert_Mensaje.Visible = true;
                            }
                        }
                        else
                        {
                            Alert_Mensaje.Attributes["class"] = "alert alert-danger";
                            mensaje_alerta = "Correo electrónico ya existe, favor ponerse en contacto con el administrador";
                            titulo_mensaje_alerta = "Error: ";
                            Alert_Mensaje.Visible = true;
                        }
                    }
                    else
                    {
                        Alert_Mensaje.Attributes["class"] = "alert alert-danger";
                        mensaje_alerta = "La contraseña y su confirmación no son las mismas";
                        titulo_mensaje_alerta = "Error: ";
                        Alert_Mensaje.Visible = true;
                    }
                }
                if (FormAccion == "Editar")
                {
                    WSGestion.WSGestion wsgest = new WSGestion.WSGestion();
                    wsgest.Url = ConfigurationManager.AppSettings.Get("dirWs");
                    WSGestion.MOD_Usuario obj = new WSGestion.MOD_Usuario();
                    obj.USU_id_usuario = codigo_seleccionado;
                    obj.USU_nombre = txt_nombre.Value;
                    obj.USU_primapellido = txt_apellido1.Value;
                    obj.USU_segapellido = txt_apellido2.Value;
                    obj.USU_telefono = txt_telefono.Value;
                    obj.USU_contrasena = contrasena;
                    obj.USU_direccion = txt_Direccion.Value;
                    obj.USU_email = txt_email.Value;
                    obj.USU_id_puesto = Convert.ToInt32(dlPuesto.SelectedValue.ToString());
                    obj.USU_id_perfil = Convert.ToInt32(dl_perfil.SelectedValue.ToString());
                    if (chk_activo.Checked)
                    {
                        obj.USU_id_estado_usuario = 1;
                    }
                    else
                    {
                        obj.USU_id_estado_usuario = 0;
                    }

                    obj.USU_id_centro_atencion = Convert.ToInt32(txt_codigocentro.Value.ToString());
                    wsgest.UPD_Usuario(obj);
                    Response.Redirect("frm_Grid_Usuario.aspx");
                }

                if (FormAccion == "CambioPassword")
                {
                    if (txt_contrasena.Value == txt_confirmacion.Value)
                    {
                        WSGestion.WSGestion wsgest = new WSGestion.WSGestion();
                        wsgest.Url = ConfigurationManager.AppSettings.Get("dirWs");
                        WSGestion.MOD_Usuario obj = new WSGestion.MOD_Usuario();
                        obj.USU_id_usuario = codigo_seleccionado;
                        obj.USU_nombre = txt_nombre.Value;
                        obj.USU_primapellido = txt_apellido1.Value;
                        obj.USU_segapellido = txt_apellido2.Value;
                        obj.USU_telefono = txt_telefono.Value;
                        obj.USU_contrasena = txt_contrasena.Value;
                        obj.USU_direccion = txt_Direccion.Value;
                        obj.USU_email = txt_email.Value;
                        obj.USU_id_puesto = Convert.ToInt32(dlPuesto.SelectedValue.ToString());
                        obj.USU_id_perfil = Convert.ToInt32(dl_perfil.SelectedValue.ToString());
                        if (chk_activo.Checked)
                        {
                            obj.USU_id_estado_usuario = 1;
                        }
                        else
                        {
                            obj.USU_id_estado_usuario = 0;
                        }

                        obj.USU_id_centro_atencion = Convert.ToInt32(txt_codigocentro.Value.ToString());
                        wsgest.UPD_Usuario(obj);
                        Response.Redirect("frm_Grid_Usuario.aspx");
                    }
                }
            }

            catch (Exception exc)
            {
                Alert_Mensaje.Attributes["class"] = "alert alert-danger";
                mensaje_alerta = exc.ToString();
                titulo_mensaje_alerta = "Error: ";
                Alert_Mensaje.Visible = true;
            }
        }