Exemplo n.º 1
0
        public bool Update(Tickets ticket)
        {
            //Tickets ticDB = TicketsDao.GetSingleTicket(ticket.TicketType, ticket.Beginning, ticket.Destination);
            Type    t     = SimpleTicketFactory.CreateTicketType(ticket.TicketType);
            Tickets ticDB = (Tickets)typeof(TicketsDao).GetMethod("GetSingleTicketGeneric").MakeGenericMethod(t)
                            .Invoke(null, new object[] { ticket.TicketType, ticket.Beginning, ticket.Destination });

            ticket.Remainder = ticDB.Remainder + ticket.Remainder;

            return(TicketsDao.Update(ticket) > 0);
        }
Exemplo n.º 2
0
 public bool Add(Tickets ticket)
 {
     if (CheckExist(ticket.Beginning, ticket.Destination))
     {
         return(Update(ticket));
     }
     else
     {
         return(TicketsDao.Add(ticket) > 0);
     }
 }
Exemplo n.º 3
0
        public List <string> BuyTicket(Tickets ticket, int count)
        {
            Type t = SimpleTicketFactory.CreateTicketType(ticket.TicketType);

            //反射调用泛型方法,由于具体泛型只能在运行时确定
            object  res   = typeof(TicketsDao).GetMethod("GetSingleTicketByIDGeneric").MakeGenericMethod(t).Invoke(null, new object[] { ticket.ID });
            Tickets ticDb = (Tickets)res;

            if (ticDb.Remainder < count)
            {
                return(null);
            }
            ticket.Remainder = ticDb.Remainder - count;
            TicketsDao.Update(ticket);
            NotifyObserver(ticket, count);
            return(ticDb.GetSeats(count));
        }
Exemplo n.º 4
0
 /// <summary>
 /// 反射调用
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="ticketType"></param>
 /// <returns></returns>
 public List <T> GetTicketsGeneric <T>(string ticketType) where T : Tickets, new()
 {
     return(TicketsDao.GetTickets <T>(ticketType));
 }
Exemplo n.º 5
0
 public bool CheckExist(string begin, string destination)
 {
     return(TicketsDao.CheckExist(begin, destination) > 0);
 }