Пример #1
0
        public static int Update(Person p, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();
            db.BeginTransaction();
            Person prv = SelectOne(p.Id);

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


            OracleCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, p);

            int ret = db.ExecuteNonQuery2(command);

            db.EndTransaction();
            db.Close();
            return(ret);
        }
Пример #2
0
        private static Collection <Person> Read(OracleDataReader reader)
        {
            Collection <Person> People = new Collection <Person>();

            while (reader.Read())
            {
                int    i = -1;
                Person m = new Person();
                m.Id         = reader.GetInt32(++i);
                m.First_Name = reader.GetString(++i);
                m.Last_Name  = reader.GetString(++i);
                if (!reader.IsDBNull(++i))
                {
                    m.Birth_Date = reader.GetInt32(i);
                }
                if (!reader.IsDBNull(++i))
                {
                    m.Role = reader.GetString(i);
                }
                Game g = new Game();
                g.Id      = reader.GetInt32(++i);
                g         = GameTable.SelectOne(g.Id);
                m.Game_Id = g;

                Team t = new Team();
                t.Id      = reader.GetInt32(++i);
                t         = TeamTable.SelectOne(t.Id);
                m.Team_Id = t;

                People.Add(m);
            }
            return(People);
        }
Пример #3
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);
        }
Пример #4
0
        public static int Prestup(int pID, int tID, DatabaseT pDb = null)
        {
            DatabaseT db = new DatabaseT();

            db.Connect();
            Person p = null;
            Team   t = null;

            db.BeginTransaction();
            try
            {
                p = SelectOne(pID);
                t = TeamTable.SelectOne(tID);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(-1);
            }
            if (p.Game_Id.Id != t.Game_Id.Id)
            {
                p.Game_Id.Id = t.Game_Id.Id;
                try
                {
                    Update(p, db);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    db.Rollback();
                    return(-1);
                }
            }
            if (p.Role == "Coach")
            {
                try
                {
                    Team ot = TeamTable.SelectOne(p.Team_Id.Id);
                    ot.Person_Id = null;
                    TeamTable.Update(ot);

                    ot           = TeamTable.SelectOne(tID);
                    ot.Person_Id = p;
                    TeamTable.Update(ot);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    db.Rollback();
                    return(-1);
                }
            }

            OracleCommand command = db.CreateCommand(SQL_UPDATE_PRESTUP);

            command.Parameters.AddWithValue(":team_id", tID);
            command.Parameters.AddWithValue(":id", pID);
            int ret = db.ExecuteNonQuery2(command);

            command.Dispose();
            db.EndTransaction();
            if (pDb == null)
            {
                db.Close();
            }
            return(ret);
        }