Exemple #1
0
        public static int Update(Tym tym, 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, tym);
            int ret = db.ExecuteNonQuery(command);

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

            return(ret);
        }
Exemple #2
0
 public static void PrepareCommand(SqlCommand command, Tym tymy)
 {
     command.Parameters.AddWithValue("@tId", tymy.Tid);
     command.Parameters.AddWithValue("@lId", tymy.Lid);
     command.Parameters.AddWithValue("@dtId", tymy.Tid);
     command.Parameters.AddWithValue("@Nazev_tymu", tymy.Nazev_tymu);
 }
Exemple #3
0
        public static Tym Select(int tym_id)
        {
            var db = new Db();

            db.Connect();

            OracleCommand command = db.CreateCommand(SQL_SELECT);

            command.Parameters.Add(new OracleParameter(":tym_id", OracleDbType.Int32));
            command.Parameters[":tym_id"].Value = tym_id;
            OracleDataReader reader = db.Select(command);

            Collection <Tym> tymy = Read(reader);

            Tym tym = null;

            if (tymy.Count == 1)
            {
                tym = tymy[0];
            }

            reader.Close();
            db.Close();
            return(tym);
        }
Exemple #4
0
        //3.1
        public static int Insert(Hrac hrac, Tym tym, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = pDb;
            }
            using (db)
                using (SqlCommand command = db.CreateCommand("pridejHrace"))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@p_hrac", hrac.Jmeno);
                    command.Parameters.AddWithValue("@p_tym", tym.Jmeno);
                    command.Parameters.AddWithValue("@p_datum", hrac.Datum_narozeni);

                    int status = db.ExecuteNonQuery(command);

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

                    return(status);
                }
        }
 private void listTymu_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (listTymu.SelectedItem != null)
     {
         tym = tymy.FirstOrDefault(t => t.tym_nazev == (string)(listTymu.SelectedItem as ListBoxItem)?.Content);
     }
 }
Exemple #6
0
        private void buttPridejHrace_Click(object sender, EventArgs e)
        {
            string jmeno    = textPridejHraceJmeno.Text;
            string prijmeni = textPridejHracePrijmeni.Text;
            int    rok      = Int32.Parse(textPridejHraceRok.Text);
            int    cislo    = Int32.Parse(textPridejHraceCislo.Text);
            string pozice   = textPridejHracePozice.Text;
            int    tym      = Int32.Parse(textPridejHraceTym.Text);

            Tym t = new Tym()
            {
                TymId = tym
            };

            Hrac h = new Hrac()
            {
                Jmeno       = jmeno,
                Prijmeni    = prijmeni,
                CisloDresu  = cislo,
                RokNarozeni = rok,
                Pozice      = pozice,
                Tym         = t
            };

            z.PridejHrace(h);

            textPridejHraceJmeno.Text    = "";
            textPridejHracePrijmeni.Text = "";
            textPridejHraceRok.Text      = "";
            textPridejHraceCislo.Text    = "";
            textPridejHracePozice.Text   = "";
            textPridejHraceTym.Text      = "";
        }
        //5.2
        public static int Update(Tym tym, Database pDb = null)
        {
            Database db;

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

            using (db)
                using (SqlCommand command = db.CreateCommand(SQL_UPDATE))
                {
                    command.Parameters.AddWithValue("@idTym", tym.IdTym);
                    PrepareCommand(command, tym);

                    int status = db.ExecuteNonQuery(command);
                    if (pDb == null)
                    {
                        db.Close();
                    }

                    return(status);
                }
        }
        //5.1
        public static int Insert(Tym tym, Database pDb = null)
        {
            Database db;

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

            using (db)
                using (SqlCommand command = db.CreateCommand(SQL_INSERT))
                {
                    PrepareCommand(command, tym);
                    int status = db.ExecuteNonQuery(command);

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

                    return(status);
                }
        }
Exemple #9
0
        public static int Insert(Tym tym, MyDatabase pDB = null)
        {
            MyDatabase db;

            if (pDB == null)
            {
                db = new MyDatabase();
                db.Connect();
            }
            else
            {
                db = (MyDatabase)pDB;
            }
            SqlCommand command = db.CreateCommand(SQL_INSERT);

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

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

            return(ret);
        }
Exemple #10
0
 public PrihlaseniDoTurnaje()
 {
     InitializeComponent();
     lb_turnaje.DataSource = Turnaj.Find();
     l_uzivatel.Text       = Trener.Find(Global.IdTrener).ToString();
     l_tym.Text            = Tym.FindByCoach(Global.IdTrener).nazev;
 }
Exemple #11
0
        public void AktualizujGolyTymu(Zapas zapas)
        {
            TymyTable  tymyTable = new TymyTable();
            List <Tym> tymy      = tymyTable.Select();
            Tym        domaci    = new Tym();
            Tym        hoste     = new Tym();

            if (zapas.GolyDomaci > zapas.GolyHoste)
            {
                for (int i = 0; i < tymy.Count; i++)
                {
                    if (tymy[i].TymId == zapas.Domaci.TymId)
                    {
                        tymy[i].PocetVyher += 1;
                        domaci              = tymy[i];
                    }
                    else if (tymy[i].TymId == zapas.Hoste.TymId)
                    {
                        tymy[i].PocetProher += 1;
                        hoste = tymy[i];
                    }
                }
            }
            else if (zapas.GolyDomaci == zapas.GolyHoste)
            {
                for (int i = 0; i < tymy.Count; i++)
                {
                    if (tymy[i].TymId == zapas.Domaci.TymId)
                    {
                        tymy[i].PocetRemiz += 1;
                        domaci              = tymy[i];
                    }
                    else if (tymy[i].TymId == zapas.Hoste.TymId)
                    {
                        tymy[i].PocetRemiz += 1;
                        hoste = tymy[i];
                    }
                }
            }
            else
            {
                for (int i = 0; i < tymy.Count; i++)
                {
                    if (tymy[i].TymId == zapas.Domaci.TymId)
                    {
                        tymy[i].PocetProher += 1;
                        domaci = tymy[i];
                    }
                    else if (tymy[i].TymId == zapas.Hoste.TymId)
                    {
                        tymy[i].PocetVyher += 1;
                        hoste = tymy[i];
                    }
                }
            }

            tymyTable.Update(domaci);
            tymyTable.Update(hoste);
        }
Exemple #12
0
 private static void PrepareCommand(SqlCommand command, Tym tym)
 {
     command.Parameters.AddWithValue("@ID_tym", tym.ID_tym);
     command.Parameters.AddWithValue("@ID_pracoviste", tym.ID_pracoviste);
     command.Parameters.AddWithValue("@Nazev", tym.Nazev);
     command.Parameters.AddWithValue("@Min_zamestnancu", tym.Min_zamestnancu);
     command.Parameters.AddWithValue("@Datum", Convert.ToDateTime(tym.Datum).ToString("yyyy-MM-dd"));
 }
 public Bodovani(Tym tym1, Tym tym2, int goly1, int goly2)
 {
     InitializeComponent();
     this.tym1  = tym1;
     this.tym2  = tym2;
     this.goly1 = goly1;
     this.goly2 = goly2;
     listing();
 }
Exemple #14
0
 public Form1()
 {
     InitializeComponent();
     dataGridView1.DataSource = Administrator.Find();
     dataGridView2.DataSource = Hrac.Find();
     dataGridView3.DataSource = Organizator.Find();
     dataGridView4.DataSource = Trener.Find();
     dataGridView5.DataSource = Turnaj.Find();
     dataGridView6.DataSource = Tym.Find();
     dataGridView7.DataSource = TymVturnaji.Find();
     dataGridView8.DataSource = Zapas.Find();
 }
Exemple #15
0
        private static void PrepareCommand(OracleCommand command, Tym tym)
        {
            command.BindByName = true;
            //command.Parameters.AddWithValue(":klub_id", klub.klub_id);
            command.Parameters.AddWithValue(":tym_nazev", tym.tym_nazev);
            command.Parameters.AddWithValue(":klub_id", tym.klub_id);
            command.Parameters.AddWithValue(":smazano", tym.smazano ? "1" : "0");

            foreach (OracleParameter p in command.Parameters)
            {
                Debug.WriteLine($"{p.ParameterName} = {p.Value}");
            }
        }
Exemple #16
0
        private static Collection <Tym> Read(SqlDataReader reader)
        {
            Collection <Tym> tymy = new Collection <Tym>();

            while (reader.Read())
            {
                int i   = -1;
                Tym tym = new Tym();
                tym.kod   = reader.GetString(++i);
                tym.nazev = reader.GetString(++i);
                tymy.Add(tym);
            }
            return(tymy);
        }
Exemple #17
0
 public int Update(Tym t)
 {
     using (db.GetConnection())
     {
         db.Connect();
         OracleCommand command = db.CreateCommand(update);
         command.Parameters.AddWithValue(":ID", t.TymId);
         command.Parameters.AddWithValue(":Vyhry", t.PocetVyher);
         command.Parameters.AddWithValue(":Remizy", t.PocetRemiz);
         command.Parameters.AddWithValue(":Prohry", t.PocetProher);
         int ret = db.ExecuteNonQuery(command);
         return(ret);
     }
 }
Exemple #18
0
        /*Read pro seznam týmů*/
        private static Collection <Tym> Read(SqlDataReader reader)
        {
            Collection <Tym> teams = new Collection <Tym>();

            while (reader.Read())
            {
                Tym team = new Tym();
                int i    = -1;
                team.Nazev_tymu = reader.GetString(++i);

                teams.Add(team);
            }
            return(teams);
        }
Exemple #19
0
        public static int Update(Tym tym)
        {
            var db = new Db();

            db.Connect();

            OracleCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, tym);
            command.Parameters.AddWithValue(":tym_id", tym.tym_id);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
Exemple #20
0
        public static int Update(Tym tym)
        {
            Database db;

            db = new Database();
            db.Connect();

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

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

            db.Close();

            return(ret);
        }
Exemple #21
0
        private static Collection <Tym> Read(SqlDataReader reader)
        {
            Collection <Tym> tymy = new Collection <Tym>();

            while (reader.Read())
            {
                int i = -1;

                Tym tym = new Tym()
                {
                    IdTym = reader.GetInt32(++i),
                    Jmeno = reader.GetString(++i),
                };
                tymy.Add(tym);
            }
            return(tymy);
        }
Exemple #22
0
        private static Collection <Tym> Read(SqlDataReader reader)
        {
            Collection <Tym> tymy = new Collection <Tym>();

            while (reader.Read())
            {
                int i   = -1;
                Tym tym = new Tym();
                tym.ID_tym          = reader.GetInt32(++i);
                tym.ID_pracoviste   = reader.GetInt32(++i);
                tym.Nazev           = reader.GetString(++i);
                tym.Min_zamestnancu = reader.GetInt32(++i);
                tym.Datum           = reader.GetDateTime(++i);

                tymy.Add(tym);
            }
            return(tymy);
        }
Exemple #23
0
        public static int Vlozeni(Tym tym)
        {
            Database db;

            db = new Database();
            db.Connect();

            SqlCommand command = db.CreateCommand("VlozeniTymu");

            command.CommandType = CommandType.StoredProcedure;
            PrepareCommand(command, tym);

            int ret = db.ExecuteNonQuery(command);

            db.Close();

            return(ret);
        }
Exemple #24
0
        private static Collection <Tym> Read(OracleDataReader reader)
        {
            Collection <Tym> tymy = new Collection <Tym>();

            while (reader.Read())
            {
                Tym Tym = new Tym();
                int i   = -1;
                Tym.tym_id    = reader.GetInt32(++i);
                Tym.tym_nazev = reader.GetString(++i);
                Tym.klub_id   = reader.GetInt32(++i);
                Tym.smazano   = reader.GetString(++i) == "1";


                tymy.Add(Tym);
            }
            return(tymy);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (nazev == null)
            {
                MessageBox.Show("Vyplňte název týmu");
                return;
            }
            Tym t = new Tym();

            t.tym_nazev = nazev.Text;
            t.klub_id   = tym.klub_id;
            t.smazano   = false;

            TymTable.Update(t);
            MessageBox.Show("Tým vložen");
            var w = new MainWindow();

            w.Show();
            this.Close();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (listKlubu.SelectedItem == null)
            {
                MessageBox.Show("Zvolte klub");
                return;
            }
            if (nazev == null)
            {
                MessageBox.Show("Vyplňte název týmu");
                return;
            }
            Tym t = new Tym();

            t.tym_nazev = nazev.Text;
            t.klub_id   = klub.klub_id;
            t.smazano   = false;

            TymTable.Insert(t);
            MessageBox.Show("Tým vložen");
        }
Exemple #27
0
        public static Tym 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_tym", id);
            SqlDataReader reader = db.Select(command);

            Collection <Tym> tymy = Read(reader);
            Tym tym = null;

            if (tymy.Count == 1)
            {
                tym = tymy[0];
            }
            reader.Close();

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

            if (tym == null)
            {
                Console.WriteLine("Tym neexistuje");
            }

            return(tym);
        }
Exemple #28
0
        public static int Insert(Tym tym)
        {
            var db = new Db();

            db.Connect();

            OracleCommand command = db.CreateCommand(SQL_INSERT);

            command.Parameters.Add(":tym_id", OracleDbType.Int32);
            command.Parameters[":tym_id"].Direction = ParameterDirection.ReturnValue;
            PrepareCommand(command, tym);
            db.ExecuteNonQuery(command);

            Console.WriteLine(command.Parameters[":tym_id"].Value.ToString());

            string idString = command.Parameters[":tym_id"].Value.ToString();

            int id = Convert.ToInt32(idString);

            db.Close();
            return(id);
        }
Exemple #29
0
        public static Collection <Tym> SelectAll()
        {
            var db = new Db();

            db.Connect();

            OracleCommand command = db.CreateCommand(SQL_SELECT_ALL);

            OracleDataReader reader = db.Select(command);

            Collection <Tym> tymy = Read(reader);

            Tym tym = null;

            if (tymy.Count == 1)
            {
                tym = tymy[0];
            }

            reader.Close();
            db.Close();
            return(tymy);
        }
Exemple #30
0
        public static Collection <Tym> Read(OracleDataReader reader)
        {
            var data = new Collection <Tym>();

            while (reader.Read())
            {
                int i   = -1;
                var tym = new Tym
                {
                    TymId       = reader.GetInt32(++i),
                    Nazev       = reader.GetString(++i),
                    PocetVyher  = reader.GetInt32(++i),
                    PocetRemiz  = reader.GetInt32(++i),
                    PocetProher = reader.GetInt32(++i),
                    Trener      = new Trener
                    {
                        TrenerId = reader.GetInt32(++i)
                    }
                };
                data.Add(tym);
            }
            return(data);
        }