Exemple #1
0
        public static int Delete(int id, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();
            OracleCommand command = db.CreateCommand(SQL_DELETE_ID);

            Person p = PersonTable.SelectOne(id);

            if (p.Role == "Coach")
            {
                Team ot = TeamTable.SelectOne(p.Team_Id.Id);
                ot.Person_Id = null;
                TeamTable.Update(ot);
            }

            command.Parameters.AddWithValue(":id", id);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
Exemple #2
0
        public static int UpdateManager(Organisation o, int pID, bool is_manager, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();

            db.BeginTransaction();
            if (SelectOne(o.Id) == null)
            {
                Console.WriteLine("Organizace nenalezena");
                db.Rollback();
                return(-1);
            }
            if (PersonTable.SelectOne(pID) == null)
            {
                Console.WriteLine("Osoba nenalezena");
                db.Rollback();
                return(-1);
            }

            if (o.Person_Id.Id == pID)
            {
                Console.WriteLine("Osoba j*z je kontaktni osobou organizace");
                db.Rollback();
                return(-1);
            }

            try
            {
                Person p = new Person();
                p = PersonTable.SelectOne(pID);

                if (is_manager)
                {
                    p.Role = "Manager";
                }
                else
                {
                    p.Role = null;
                }
                PersonTable.Update(p);

                o.Person_Id.Id = pID;
                Update(o);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Rollback();
                return(-1);
            }


            OracleCommand command = db.CreateCommand(SQL_UPDATE_MAN);

            PrepareCommand(command, o);
            int ret = db.ExecuteNonQuery2(command);

            db.EndTransaction();
            db.Close();
            return(ret);
        }
Exemple #3
0
        public static int ZmenitHru(Team t, int gID, DatabaseT pDb = null)
        {
            DatabaseT db;

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

            if (SelectOne(t.Id) == null)
            {
                db.Rollback();
                return(-1);
            }
            if (GameTable.SelectOne(gID) == null)
            {
                db.Rollback();
                return(-1);
            }

            try
            {
                PersonTable.UpdateGame(t.Id, gID);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Rollback();
                return(-1);
            }

            try
            {
                t.Game_Id = GameTable.SelectOne(gID);
                Update(t);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Rollback();
                return(-1);
            }


            OracleCommand command = db.CreateCommand(SQL_SELECT_COUNT);

            command.Parameters.AddWithValue(":gID", gID);
            OracleDataReader reader = db.Select(command);

            int res = ReadCount(reader);

            reader.Close();

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

            return(res);
        }