public static int Update(Dovolena dovolena, MyDatabase pDb = null)
        {
            MyDatabase db;

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

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

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

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

            return(ret);
        }
 private static void PrepareCommand(SqlCommand command, Dovolena dovolena)
 {
     command.Parameters.AddWithValue("@ID_dovolene", dovolena.ID_dovolene);
     command.Parameters.AddWithValue("@ID_zamestnance", dovolena.ID_zamestnance);
     command.Parameters.AddWithValue("@ID_duvodu", dovolena.ID_duvodu);
     command.Parameters.AddWithValue("@Od", Convert.ToDateTime(dovolena.Od).ToString("yyyy-MM-dd"));
     command.Parameters.AddWithValue("@Do", Convert.ToDateTime(dovolena.Do).ToString("yyyy-MM-dd"));
 }
        private static Collection <Dovolena> Read(SqlDataReader reader)
        {
            Collection <Dovolena> dovolene = new Collection <Dovolena>();

            while (reader.Read())
            {
                int      i        = -1;
                Dovolena dovolena = new Dovolena();
                dovolena.ID_dovolene    = reader.GetInt32(++i);
                dovolena.ID_zamestnance = reader.GetInt32(++i);
                dovolena.ID_duvodu      = reader.GetInt32(++i);
                dovolena.Od             = reader.GetDateTime(++i);
                dovolena.Do             = reader.GetDateTime(++i);


                dovolene.Add(dovolena);
            }
            return(dovolene);
        }
        public static Dovolena Select(int id, MyDatabase pDb = null)
        {
            MyDatabase db;

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

            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue("@ID_dovolene", id);
            SqlDataReader reader = db.Select(command);

            Collection <Dovolena> dovolene = Read(reader);
            Dovolena dovolena = null;

            if (dovolene.Count == 1)
            {
                dovolena = dovolene[0];
            }
            reader.Close();

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

            if (dovolena == null)
            {
                Console.WriteLine("Dovolena neexistuje");
            }

            return(dovolena);
        }