public Prenotazione GetByID(int ID)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = String.Format(@"SELECT * 
                                              FROM prenotazioni WHERE id_pren={0}", ID);
            Prenotazione P = null;

            dt = db.eseguiQuery(cmd);
            if (dt.Rows.Count > 0)
            {
                P           = new Prenotazione();
                P.ID        = (int)dt.Rows[0]["id_pren"];
                P.Biglietti = (int)dt.Rows[0]["qta"];
                P.Data      = (Int64)dt.Rows[0]["data"];
                P.IDUtente  = (int)dt.Rows[0]["fk_utente"];
                P.IDReplica = (int)dt.Rows[0]["fk_replica"];
            }

            P.Replica = new daoReplica().GetByID(P.IDReplica);
            return(P);
        }
        public List <Prenotazione> GetByReplica(int RID)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = String.Format(@"SELECT * 
                                              FROM prenotazioni WHERE fk_replica={0}", RID);
            List <Prenotazione> prenotazioni = null;

            dt = db.eseguiQuery(cmd);
            if (dt.Rows.Count > 0)
            {
                prenotazioni = new List <Prenotazione>();
                foreach (DataRow dr in dt.Rows)
                {
                    Prenotazione P = new Prenotazione();
                    P.ID        = (int)dr["id_pren"];
                    P.Biglietti = (int)dr["qta"];
                    P.Data      = (Int64)dr["data"];
                    P.IDUtente  = (int)dr["fk_utente"];
                    P.IDReplica = (int)dr["fk_replica"];
                    P.Replica   = new daoReplica().GetByID(P.IDReplica);

                    prenotazioni.Add(P);
                }
            }

            return(prenotazioni);
        }
Exemple #3
0
        public Utente Login(Utente U)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = String.Format(@"SELECT * FROM utenti WHERE email='{0}' AND password='******'", U.Email, U.Password);

            dt = db.eseguiQuery(cmd);
            if (dt.Rows.Count == 1)
            {
                U.ID       = (int)dt.Rows[0]["id_utente"];
                U.Cognome  = (string)dt.Rows[0]["cognome"];
                U.Nome     = (string)dt.Rows[0]["nome"];
                U.Telefono = (string)dt.Rows[0]["telefono"];
                U.Email    = (string)dt.Rows[0]["email"];
                U.Password = (string)dt.Rows[0]["password"];
            }
            else
            {
                return(null);
            }

            //U.Prenotazioni = new daoPrenotazioni().GetByUtente(U.ID);
            return(U);
        }
Exemple #4
0
        public Utente Register(Utente U)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = String.Format(@"INSERT INTO utenti (nome,cognome,telefono,email,password)
                                                            VALUES('{0}','{1}','{2}','{3}')",
                                            U.Nome, U.Cognome, U.Telefono, U.Email, U.Password);

            int id = db.eseguiInsertIDreturn(cmd);

            U.ID = id;

            return(U);
        }
Exemple #5
0
        public int GetPostiOccupati(int ID)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = String.Format(@"SELECT SUM(qta) AS postioccupati
                                              FROM prenotazioni WHERE fk_replica={0}", ID);
            int postiOccupati = 0;

            dt = db.eseguiQuery(cmd);
            if (dt.Rows.Count > 0)
            {
                postiOccupati = dt.Rows[0].IsNull("postioccupati") ? 0 : (int)dt.Rows[0]["postioccupati"];
            }

            return(postiOccupati);
        }
        public Prenotazione AddPrenotazione(Prenotazione P)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            Int64 now = Convert.ToInt64(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);

            cmd.CommandText = String.Format(@"INSERT INTO prenotazioni (qta, data, fk_utente, fk_replica)
                                                         VALUES({0},{1},{2},{3});SELECT SCOPE_IDENTITY()", P.Biglietti, now, P.IDUtente, P.IDReplica);

            int id = db.eseguiInsertIDreturn(cmd);

            P.ID      = id;
            P.Replica = new daoReplica().GetByID(P.IDReplica);

            return(P);
        }
        public Locale GetByID(int ID)
        {
            DataTable dt = new DataTable();
            DBEntity  db = new DBEntity();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = String.Format(@"SELECT * 
                                              FROM locali WHERE id_locale={0}", ID);
            Locale L = null;

            dt = db.eseguiQuery(cmd);
            if (dt.Rows.Count > 0)
            {
                L       = new Locale();
                L.ID    = (int)dt.Rows[0]["id_locale"];
                L.Nome  = (string)dt.Rows[0]["nome"];
                L.Luogo = (string)dt.Rows[0]["luogo"];
                L.Posti = (int)dt.Rows[0]["posti"];
            }

            return(L);
        }