Beispiel #1
0
        /// <summary>
        /// Insert the record.
        /// </summary>
        public static int Prihlas(Dvojice dvojice, Soutez soutez, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_PRIHLAS);

            command.Parameters.AddWithValue("@did", dvojice.did);
            command.Parameters.AddWithValue("@cid", soutez.cid);


            int ret = db.ExecuteNonQuery(command);

            //int dvojice = DvojiceTable.Select(kun.cislo_licence, jezdec.cislo_licence, db);

            if (pDb == null)
            {
                db.Close();
            }

            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Update the record.
        /// </summary>
        public static int Update(Dvojice dvojice, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, dvojice);
            int ret = db.ExecuteNonQuery(command);

            if (pDb == null)
            {
                db.Close();
            }

            return(ret);
        }
Beispiel #3
0
        private static Collection <Dvojice> Read(SqlDataReader reader)
        {
            Collection <Dvojice> dvojice = new Collection <Dvojice>();

            while (reader.Read())
            {
                int     i    = -1;
                Dvojice dvoj = new Dvojice();
                dvoj.did    = reader.GetInt32(++i);
                dvoj.jezdec = reader.GetString(++i);
                dvoj.kun    = reader.GetString(++i);

                dvojice.Add(dvoj);
            }
            return(dvojice);
        }
Beispiel #4
0
        public void PrihlasDvojici(int zid, int cid, string kun, string cislo_licence)
        {
            int did = DvojiceTable.Select(kun, cislo_licence);

            if (did == -1)
            {
                did = DvojiceTable.Insert(new Dvojice {
                    kun = kun, jezdec = cislo_licence
                });
            }

            Dvojice dvojice = DvojiceTable.Select(did);

            VysledekTable.Prihlas(dvojice, SoutezTable.Select(cid));
            vysledky = VysledekJezdce.GetVysledkyJezdce(jezdec.cislo_licence);
        }
Beispiel #5
0
        /// <summary>
        /// Select the record.
        /// </summary>
        /// <param name="id">dvojice id</param>
        public static int Select(string kun, string jezdec, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_SELECT_ONE);

            command.Parameters.AddWithValue("@kun", kun);
            command.Parameters.AddWithValue("@jezdec", jezdec);

            SqlDataReader reader = db.Select(command);

            Collection <Dvojice> dvojice = Read(reader);
            Dvojice dvoj = new Dvojice();

            if (dvojice.Count == 1)
            {
                dvoj = dvojice[0];
            }
            reader.Close();
            if (dvojice.Count == 0)
            {
                dvoj.did = -1;
            }

            if (pDb == null)
            {
                db.Close();
            }

            return(dvoj.did);
        }
Beispiel #6
0
        public static Dvojice Select(int did, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue("@id", did);

            SqlDataReader reader = db.Select(command);

            Collection <Dvojice> dvojice = Read(reader);
            Dvojice dvoj = null;

            if (dvojice.Count == 1)
            {
                dvoj = dvojice[0];
            }
            reader.Close();

            if (pDb == null)
            {
                db.Close();
            }

            return(dvoj);
        }
Beispiel #7
0
 /// <summary>
 ///  Prepare a command.
 /// </summary>
 private static void PrepareCommand(SqlCommand command, Dvojice dvojice)
 {
     command.Parameters.AddWithValue("@did", dvojice.did);
     command.Parameters.AddWithValue("@jezdec", dvojice.jezdec);
     command.Parameters.AddWithValue("@kun", dvojice.kun);
 }