예제 #1
0
        public Usuario TraerUsuario(string codigo)
        {
            Usuario u = new Usuario();
            AdoConn ado = new AdoConn();
            ArrayList parametros = new ArrayList();
            DataSet ds = new DataSet();

            ds = ListadoDeUsuarios(codigo);
            if (ds.Tables[0].Rows.Count > 0)
            {
                u.Usu_id = ds.Tables[0].Rows[0]["USU_ID"].ToString();
                u.Usu_desc = ds.Tables[0].Rows[0]["USU_DESC"].ToString();
                u.Legajo = ds.Tables[0].Rows[0]["LEGAJO"].ToString();
                u.Mail = ds.Tables[0].Rows[0]["MAIL"].ToString();
                u.Pass = ds.Tables[0].Rows[0]["PASS"].ToString();
                u.Activo = Convert.ToBoolean(ds.Tables[0].Rows[0]["ACTIVO"]);

            }
            u.Grupos = new List<MDGrupos>();
            parametros.Add(codigo);
            ds = new DataSet();
            ds = ado.ExecuteStoredProcedureDS("SP_SELECT_GRUPOS_USUARIO", parametros);
            if (ds.Tables[0].Rows.Count > 0)
            {
                MDGrupos mdg;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    mdg = new MDGrupos();
                    mdg.Grupo_id = Convert.ToInt32(ds.Tables[0].Rows[i]["GRUPO_ID"]);
                    mdg.Grupo_desc = ds.Tables[0].Rows[i]["GRUPO_DESC"].ToString();
                    u.Grupos.Add(mdg);
                }

            }

            return u;
        }
 protected void btnAceptar_Click(object sender, EventArgs e)
 {
     ddlUsuarios.Enabled = false;
     if (modo.Value == "ALTA")
     {
         if (conUsuario.ValidarUsuarioIDExistente(txtUsuarioID.Text))
         {
             lblMensaje.Text = "Ya existe un usuario con el mismo ID";
             ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
         }
         else if (conUsuario.ValidarUsuarioLegajoExistente(txtLegajo.Text))
         {
             lblMensaje.Text = "Ya existe un usuario con el mismo legajo";
             ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
         }
         else if (conUsuario.ValidarUsuarioMailExistente(txtMailUser.Text))
         {
             lblMensaje.Text = "Ya existe un usuario con el mismo mail";
             ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
         }
         else
         {
             Usuario u = new Usuario();
             u.Usu_id = txtUsuarioID.Text;
             u.Usu_desc = txtDescripcion.Text;
             u.Legajo = txtLegajo.Text;
             u.Mail = txtMailUser.Text;
             u.Pass = txtPassUser.Text;
             u.Activo = chkActivo.Checked ? true : false;
             u.Grupos = new List<MDGrupos>();
             MDGrupos mdg;
             for (int i = 0; i < chkListGrupos.Items.Count; i++)
             {
                 if (chkListGrupos.Items[i].Selected)
                 {
                     mdg = new MDGrupos();
                     mdg.Grupo_id = Convert.ToInt32(chkListGrupos.Items[i].Value);
                     mdg.Grupo_desc = chkListGrupos.Items[i].Text;
                     u.Grupos.Add(mdg);
                 }
             }
             conUsuario.InsertarUsuario(u);
             lblMensaje.Text = "Usuario creado con exito!!";
             ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
         }
     }
     else if (modo.Value == "EDITAR")
     {
         bool flag = true;
         if (hdCodigoUsuario.Value != txtUsuarioID.Text)
         {
             if (conUsuario.ValidarUsuarioIDExistente(txtUsuarioID.Text))
             {
                 flag = false;
                 lblMensaje.Text = "Ya existe un usuario con el mismo ID";
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
             }
         }
         if (hdLegajo.Value != txtLegajo.Text)
         {
             if (conUsuario.ValidarUsuarioLegajoExistente(txtLegajo.Text))
             {
                 flag = false;
                 lblMensaje.Text = "Ya existe un usuario con el mismo legajo";
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
             }
         }
         if (hdMail.Value != txtMailUser.Text)
         {
             if (conUsuario.ValidarUsuarioMailExistente(txtMailUser.Text))
             {
                 flag = false;
                 lblMensaje.Text = "Ya existe un usuario con el mismo mail";
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
             }
         }
        if(flag)
         {
             Usuario u = new Usuario();
             u.Usu_id = txtUsuarioID.Text;
             u.Usu_desc = txtDescripcion.Text;
             u.Legajo = txtLegajo.Text;
             u.Mail = txtMailUser.Text;
             u.Pass = txtPassUser.Text;
             u.Activo = chkActivo.Checked ? true : false;
             u.Grupos = new List<MDGrupos>();
             MDGrupos mdg;
             for (int i = 0; i < chkListGrupos.Items.Count; i++)
             {
                 if (chkListGrupos.Items[i].Selected)
                 {
                     mdg = new MDGrupos();
                     mdg.Grupo_id = Convert.ToInt32(chkListGrupos.Items[i].Value);
                     mdg.Grupo_desc = chkListGrupos.Items[i].Text;
                     u.Grupos.Add(mdg);
                 }
             }
             conUsuario.ModificarUsuario(u,hdCodigoUsuario.Value);
             lblMensaje.Text = "Usuario modificado con exito!!";
             ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensaje();", true);
         }
     }
 }