Exemple #1
0
        public void Save(Participant participant)
        {
            utils.OpenConnection();
            int             resultId     = 0;
            string          queryIdCurse = "SELECT id FROM curse WHERE cap = " + participant.Cap;
            MySqlCommand    cmd          = new MySqlCommand(queryIdCurse, utils.Connection);
            MySqlDataReader reader       = cmd.ExecuteReader();

            while (reader.Read())
            {
                resultId = reader.GetInt32(0);
            }
            utils.CloseConnection();

            utils.OpenConnection();
            string       query  = "INSERT INTO participanti VALUES(" + participant.Id + ",'" + participant.Nume + "','" + participant.Echipa + "'," + participant.Cap + "," + resultId + ")";
            MySqlCommand cmd1   = new MySqlCommand(query, utils.Connection);
            var          result = cmd1.ExecuteNonQuery();

            utils.CloseConnection();
        }
Exemple #2
0
        public Cursa FindOne(int id)
        {
            utils.OpenConnection();
            string          query  = "SELECT * FROM curse WHERE id = " + id;
            MySqlCommand    cmd    = new MySqlCommand(query, utils.Connection);
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                int   idc   = reader.GetInt32(0);
                int   capc  = reader.GetInt32(1);
                Cursa cursa = new Cursa(idc, capc);
                if (cursa != null)
                {
                    utils.CloseConnection();
                    return(cursa);
                }
            }
            utils.CloseConnection();
            return(null);
        }
        public List <Operator> FindAll()
        {
            string          query     = "SELECT * FROM operatori";
            List <Operator> operatori = new List <Operator>();

            utils.OpenConnection();
            MySqlCommand    cmd    = new MySqlCommand(query, utils.Connection);
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                int      id        = reader.GetInt32(0);
                string   name      = reader.GetString(1);
                string   pass      = reader.GetString(2);
                Operator operatorN = new Operator(id, name, pass);
                operatori.Add(operatorN);
            }
            utils.CloseConnection();
            return(operatori);
        }