public RoutineTicket GetTicketByTickedId(int id)
    {
        operation.InitConnection(data_resource);

        string sql = "select routine.*, purchased_tickets.* from routine, purchased_tickets where purchased_tickets.routine_id = routine.routine_id and purchased_tickets.ticket_id = " + id;

        Lucky.LuckyUtils.Log(sql);
        RoutineTicket ticket = new RoutineTicket();

        try
        {
            SqliteDataReader reader = operation.ExecuteQuery(sql);

            if (reader.HasRows)
            {
                reader.Read();

                int begin_time = reader.GetInt32(reader.GetOrdinal("start_time"));
                int end_time   = reader.GetInt32(reader.GetOrdinal("end_time"));
                ticket.SetRoutineId(reader.GetInt32(reader.GetOrdinal("routine_id")));
                ticket.SetEndNode(reader.GetString(reader.GetOrdinal("end_node")));
                ticket.SetStartNode(reader.GetString(reader.GetOrdinal("start_node")));
                ticket.SetType(reader.GetInt32(reader.GetOrdinal("type")));
                ticket.SetBeginTime(GetTodayTime(reader.GetInt32(reader.GetOrdinal("start_time"))));
                ticket.SetEndTime(GetTodayTime(reader.GetInt32(reader.GetOrdinal("end_time"))));
                ticket.SetMoney((int)reader.GetFloat(reader.GetOrdinal("money")));
                SetTicketName(reader, ticket);
                ticket.SetTicketid(reader.GetInt32(reader.GetOrdinal("ticket_id")));

                int actual_begin_time = reader.GetInt32(reader.GetOrdinal("actual_start_time"));
                int actual_end_time   = reader.GetInt32(reader.GetOrdinal("actual_end_time"));

                if (actual_begin_time == 0)
                {
                    ticket.SetActualBeginTime(TicketsOperaton.GetTodayTime(begin_time));
                }
                else
                {
                    ticket.SetActualBeginTime(TicketsOperaton.GetTodayTime(actual_begin_time));
                }

                if (actual_end_time != 0)
                {
                    ticket.SetActualEndTime(TicketsOperaton.GetTodayTime(actual_end_time));
                }
                else
                {
                    ticket.SetActualEndTime(TicketsOperaton.GetTodayTime(end_time));
                }
            }
        } catch (Exception e)
        {
        }
        finally
        {
            operation.CloseConnection();
        }
        return(ticket);
    }
    public static List <Routine> GetRoutinInfo(SqliteDataReader reader)
    {
        List <Routine> res = new List <Routine>();

        while (reader.Read())
        {
            RoutineTicket ticket     = new RoutineTicket();
            int           begin_time = reader.GetInt32(reader.GetOrdinal("start_time"));
            int           end_time   = reader.GetInt32(reader.GetOrdinal("end_time"));

            ticket.SetRoutineId(reader.GetInt32(reader.GetOrdinal("routine_id")));
            ticket.SetEndNode(reader.GetString(reader.GetOrdinal("end_node")));
            ticket.SetStartNode(reader.GetString(reader.GetOrdinal("start_node")));
            ticket.SetType(reader.GetInt32(reader.GetOrdinal("type")));


            ticket.SetBeginTime(TicketsOperaton.GetTodayTime(begin_time));
            ticket.SetEndTime(TicketsOperaton.GetTodayTime(end_time));

            ticket.SetMoney((int)reader.GetFloat(reader.GetOrdinal("money")));

            int actual_begin_time = reader.GetInt32(reader.GetOrdinal("actual_start_time"));
            int actual_end_time   = reader.GetInt32(reader.GetOrdinal("actual_end_time"));

            if (actual_begin_time == 0)
            {
                ticket.SetActualBeginTime(TicketsOperaton.GetTodayTime(begin_time));
            }
            else
            {
                ticket.SetActualBeginTime(TicketsOperaton.GetTodayTime(actual_begin_time));
            }

            if (actual_end_time != 0)
            {
                ticket.SetActualEndTime(TicketsOperaton.GetTodayTime(actual_end_time));
            }
            else
            {
                ticket.SetActualEndTime(TicketsOperaton.GetTodayTime(end_time));
            }



            // Lucky.LuckyUtils.Log(ticket.GetRoutineId());

            TicketsOperaton.SetTicketName(reader, ticket);
            res.Add(ticket);
        }
        return(res);
    }
    public List <RoutineTicket> GetUserTickets(DateTime time)
    {
        UInt64 ts = RoutineOperation.GetSeconds(time);

        operation.InitConnection(data_resource);
        UInt64 seconds = RoutineOperation.GetSeconds(time);
        // string sql = "select routine.*, purchased_tickets.* from routine, purchased_tickets where purchased_tickets.routine_id = routine.routine_id ";
        string sql = "select routine.*, purchased_tickets.* from routine, purchased_tickets where purchased_tickets.routine_id = routine.routine_id and ((routine.start_time > "
                     + seconds + "  and routine.actual_start_time = 0) or (routine.actual_start_time > 0 and routine.actual_start_time > " + seconds + "))";

        Lucky.LuckyUtils.Log(sql);
        List <RoutineTicket> res = new List <RoutineTicket>();

        try
        {
            SqliteDataReader reader = operation.ExecuteQuery(sql);
            while (reader.Read())
            {
                RoutineTicket ticket     = new RoutineTicket();
                int           begin_time = reader.GetInt32(reader.GetOrdinal("start_time"));
                int           end_time   = reader.GetInt32(reader.GetOrdinal("end_time"));
                ticket.SetRoutineId(reader.GetInt32(reader.GetOrdinal("routine_id")));
                ticket.SetEndNode(reader.GetString(reader.GetOrdinal("end_node")));
                ticket.SetStartNode(reader.GetString(reader.GetOrdinal("start_node")));
                ticket.SetType(reader.GetInt32(reader.GetOrdinal("type")));
                ticket.SetBeginTime(GetTodayTime(reader.GetInt32(reader.GetOrdinal("start_time"))));
                ticket.SetEndTime(GetTodayTime(reader.GetInt32(reader.GetOrdinal("end_time"))));
                ticket.SetMoney((int)reader.GetFloat(reader.GetOrdinal("money")));
                SetTicketName(reader, ticket);
                int actual_begin_time = reader.GetInt32(reader.GetOrdinal("actual_start_time"));
                int actual_end_time   = reader.GetInt32(reader.GetOrdinal("actual_end_time"));

                if (actual_begin_time == 0)
                {
                    ticket.SetActualBeginTime(TicketsOperaton.GetTodayTime(begin_time));
                }
                else
                {
                    ticket.SetActualBeginTime(TicketsOperaton.GetTodayTime(actual_begin_time));
                }

                if (actual_end_time != 0)
                {
                    ticket.SetActualEndTime(TicketsOperaton.GetTodayTime(actual_end_time));
                }
                else
                {
                    ticket.SetActualEndTime(TicketsOperaton.GetTodayTime(end_time));
                }

                ticket.SetTicketid(reader.GetInt32(reader.GetOrdinal("ticket_id")));

                res.Add(ticket);
            }
        }
        catch (Exception e)
        {
            Lucky.LuckyUtils.Log(e.StackTrace);
        }
        finally
        {
            operation.CloseConnection();
            Lucky.LuckyUtils.Log(res.Count);
        }
        return(res);
    }