コード例 #1
0
ファイル: TriggerService.cs プロジェクト: 2steuer/alarmsystem
        protected PersonInfo[] GetSlotPersons(TriggerSlotInfo slot)
        {
            List<PersonInfo> _persons = new List<PersonInfo>();

            MySqlCommand cmd = DatabaseService.TryCreateCommand();
            cmd.CommandText =
                "SELECT DISTINCT persons.id as p_id, persons.name as p_name, persons.number as p_number, persons.flash as p_flash " +
                "FROM persons, group_triggerslot, group_person WHERE " +
                "persons.id = group_person.person_id AND group_person.group_id = group_triggerslot.group_id AND " +
                "group_triggerslot.triggerslot_id = @SlotId "+
                "ORDER BY group_triggerslot.order ASC, group_person.order ASC";

            cmd.Parameters.AddWithValue("SlotId", slot.SlotId);

            using (IDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    _persons.Add(new PersonInfo()
                    {
                        PersonId = reader.GetInt32(0),
                        Name = reader.GetString(1),
                        Number = reader.GetString(2),
                        Flash = reader.GetBoolean(3)
                    });
                }
            }

            return _persons.ToArray();
        }
コード例 #2
0
ファイル: TriggerService.cs プロジェクト: 2steuer/alarmsystem
        protected TriggerSlotInfo GetCurrentTriggerSlot(TriggerInfo trigger, DateTime time)
        {
            bool specialSlotFound = false;
            TriggerSlotInfo specialSlot;
            TriggerSlotInfo generalSlot = new TriggerSlotInfo() {SlotId = -1};

            TimeField currentTime = TimeField.FromDateTime(time);

            int dayInt = (time.DayOfWeek == DayOfWeek.Sunday) ? 7 : (int) time.DayOfWeek;

            string sql =
                "SELECT id, text, weekday, start, end FROM triggerslots WHERE trigger_id = @TriggerId AND (weekday = @CurrentWeekday OR weekday = @GeneralWeekDay)";
            MySqlCommand cmd = DatabaseService.TryCreateCommand();
            cmd.CommandText = sql;
            cmd.Parameters.AddWithValue("TriggerId", trigger.Id);
            cmd.Parameters.AddWithValue("CurrentWeekDay", dayInt);
            cmd.Parameters.AddWithValue("GeneralWeekDay", 8);
            
            using (IDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    TriggerSlotInfo slot = new TriggerSlotInfo()
                    {
                        SlotId = reader.GetInt32(0),
                        Text = reader.GetString(1),
                        DayOfWeek = reader.GetInt32(2),
                        StartTime = TimeField.Parse(reader.GetString(3)),
                        EndTime = TimeField.Parse(reader.GetString(4))
                    };

                    if (slot.DayOfWeek == 8)
                    {
                        generalSlot = slot;
                    }
                    else
                    {
                        if (currentTime.IsBetween(slot.StartTime, slot.EndTime))
                        {
                            return slot;
                        }
                    }
                }
                

                return generalSlot;
            }
        }