public static int Update(PoziceZamestnance pz, 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, pz);
            int ret = db.ExecuteNonQuery(command);

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

            return(ret);
        }
        private static Collection <PoziceZamestnance> Read(SqlDataReader reader)
        {
            Collection <PoziceZamestnance> pzC = new Collection <PoziceZamestnance>();

            while (reader.Read())
            {
                int i = -1;
                PoziceZamestnance pz = new PoziceZamestnance();
                pz.ID_poziceZamestnance = reader.GetInt32(++i);
                pz.ID_zamestnance       = reader.GetInt32(++i);
                pz.ID_pozice            = reader.GetInt32(++i);
                pzC.Add(pz);
            }
            return(pzC);
        }
        public static PoziceZamestnance 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_poziceZamestnance", id);
            SqlDataReader reader = db.Select(command);

            Collection <PoziceZamestnance> pzC = Read(reader);
            PoziceZamestnance pz = null;

            if (pzC.Count == 1)
            {
                pz = pzC[0];
            }
            reader.Close();

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

            if (pz == null)
            {
                Console.WriteLine("Pozice zamestnance neexistuje");
            }

            return(pz);
        }
 private static void PrepareCommand(SqlCommand command, PoziceZamestnance pz)
 {
     command.Parameters.AddWithValue("@ID_poziceZamestnance", pz.ID_poziceZamestnance);
     command.Parameters.AddWithValue("@ID_zamestnance", pz.ID_zamestnance);
     command.Parameters.AddWithValue("@ID_pozice", pz.ID_pozice);
 }