Example #1
0
File: BD.cs Project: apachecot/DAW
    public static string AltaHotel(int id_ciudad, string nombre, string cif, int categoria, string direccion, int telefono, string tipo)
    {
        string mensaje = "";

        hoteles h = new hoteles();

        h.id_ciudad = id_ciudad;
        h.nombre    = nombre;
        h.cif       = cif;
        h.categoria = categoria;
        h.direccion = direccion;
        h.telefono  = telefono;
        h.tipo      = tipo;

        contexto.hoteles.Add(h);
        try
        {
            contexto.SaveChanges();
        }
        catch (DbUpdateException ex)
        {
            SqlException sqlEx = (SqlException)ex.InnerException.InnerException;
            mensaje = BDErrores.MensajeError(sqlEx);

            contexto.hoteles.Remove(h);
        }

        return(mensaje);
    }
Example #2
0
 protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e)
 {
     if (e.Exception != null)
     {
         SqlException sqlEx = (SqlException)e.Exception.InnerException;
         LabelMensaje.Text  = BDErrores.Mensaje(sqlEx);
         e.ExceptionHandled = true;
     }
 }
Example #3
0
File: BD.cs Project: apachecot/DAW
    public static string ModificarModulProfesional(int id, int id_cicle, int id_curs, string codi, string nom, int hores, int hores_lliures, int id_professor)
    {
        string mensaje = "";

        var moduls = (from c in contexto.moduls_prof

                      where c.id == id

                      select c).ToList();

        moduls_prof modul = moduls.First();

        modul.id_curs       = id_curs;
        modul.codi          = codi;
        modul.nom           = nom;
        modul.hores         = hores;
        modul.hores_lliures = hores_lliures;
        modul.id_professor  = id_professor;
        var comprobar = (from c in contexto.moduls_prof

                         where c.id != id && c.id_curs == id_curs && (c.nom == nom || c.codi == codi)

                         select c).ToList();

        if (comprobar.Count() == 0)
        {
            try
            {
                contexto.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                SqlException sqlEx = (SqlException)ex.InnerException.InnerException;
                mensaje = BDErrores.MensajeError(sqlEx);
            }
        }
        else
        {
            mensaje = "Ja existeix un registre amb el mateix nom o codi";
        }
        return(mensaje);
    }
Example #4
0
File: BD.cs Project: apachecot/DAW
    public static string ModificarNota(int id_uf, int id_alumne, int id_avaluacio, int nota)
    {
        string mensaje = "";

        var notas = (from c in contexto.avaluar

                     where c.id_uf == id_uf &&
                     c.id_alumne == id_alumne &&
                     c.id_avaluacio == id_avaluacio
                     select c).ToList();

        if (notas.Count != 0)
        {
            avaluar aval = notas.First();

            aval.id_uf        = id_uf;
            aval.id_alumne    = id_alumne;
            aval.id_avaluacio = id_avaluacio;
            aval.nota         = nota;
        }
        else
        {
            avaluar aval = new avaluar();

            aval.id_uf        = id_uf;
            aval.id_alumne    = id_alumne;
            aval.id_avaluacio = id_avaluacio;
            aval.nota         = nota;
            contexto.avaluar.Add(aval);
        }

        try
        {
            contexto.SaveChanges();
        }
        catch (DbUpdateException ex)
        {
            SqlException sqlEx = (SqlException)ex.InnerException.InnerException;
            mensaje = BDErrores.MensajeError(sqlEx);
        }
        return(mensaje);
    }
Example #5
0
File: BD.cs Project: apachecot/DAW
    public static string AltaModulProfesional(int id_cicle, int id_curs, string codi, string nom, int hores, int hores_lliures, int id_professor)
    {
        string mensaje = "";

        moduls_prof h = new moduls_prof();

        h.id_curs       = id_curs;
        h.codi          = codi;
        h.nom           = nom;
        h.hores         = hores;
        h.hores_lliures = hores_lliures;
        h.id_professor  = id_professor;

        var comprobar = (from c in contexto.moduls_prof

                         where c.id_curs == id_curs && (c.nom == nom || c.codi == codi)

                         select c).ToList();

        if (comprobar.Count() == 0)
        {
            contexto.moduls_prof.Add(h);
            try
            {
                contexto.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                SqlException sqlEx = (SqlException)ex.InnerException.InnerException;
                mensaje = BDErrores.MensajeError(sqlEx);

                contexto.moduls_prof.Remove(h);
            }
        }
        else
        {
            mensaje = "Ja existeix un registre amb el mateix nom o codi";
        }

        return(mensaje);
    }
Example #6
0
File: BD.cs Project: apachecot/DAW
    public static string ModificarUF(int id, int id_modul, string nom)
    {
        string mensaje = "";

        var ufs = (from c in contexto.ufs

                   where c.id == id

                   select c).ToList();

        ufs uf = ufs.First();

        uf.id_modul_prof = id_modul;
        uf.nom           = nom;
        var comprobar = (from c in contexto.ufs

                         where c.id_modul_prof == id_modul && c.nom == nom

                         select c).ToList();

        if (comprobar.Count() == 0)
        {
            try
            {
                contexto.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                SqlException sqlEx = (SqlException)ex.InnerException.InnerException;
                mensaje = BDErrores.MensajeError(sqlEx);
            }
        }
        else
        {
            mensaje = "Ja existeix un registre amb el mateix nom";
        }
        return(mensaje);
    }
Example #7
0
File: BD.cs Project: apachecot/DAW
    public static string AltaUF(int id_modul, string nom)
    {
        string mensaje = "";

        ufs h = new ufs();

        h.id_modul_prof = id_modul;
        h.nom           = nom;

        var comprobar = (from c in contexto.ufs

                         where c.id_modul_prof == id_modul && c.nom == nom

                         select c).ToList();

        if (comprobar.Count() == 0)
        {
            contexto.ufs.Add(h);
            try
            {
                contexto.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                SqlException sqlEx = (SqlException)ex.InnerException.InnerException;
                mensaje = BDErrores.MensajeError(sqlEx);

                contexto.ufs.Remove(h);
            }
        }
        else
        {
            mensaje = "Ja existeix un registre amb el mateix nom";
        }

        return(mensaje);
    }
Example #8
0
    public static string AltaCurso(int id, string codi, string descripcion, int id_cicle)
    {
        string mensaje = "";
        cursos cur     = new cursos();

        cur.id         = id;
        cur.codi       = codi;
        cur.descripcio = descripcion;
        cur.id_cicle   = id_cicle;

        contexto.cursos.Add(cur);
        try
        {
            contexto.SaveChanges();
        }
        catch (DbUpdateException ex)
        {
            SqlException sqlEx = (SqlException)ex.InnerException.InnerException;

            mensaje = BDErrores.Mensaje(sqlEx);
        }

        return(mensaje);
    }
Example #9
0
File: BD.cs Project: apachecot/DAW
    public static string EsborrarHotel(Exception ex)
    {
        SqlException sqlEx = (SqlException)ex.InnerException;

        return(BDErrores.MensajeError(sqlEx));
    }