コード例 #1
0
        void LoadGroup(Group group)
        {
            lvGroups.Enabled   = false;
            btnCancel.Enabled  = true;
            btnSave.Enabled    = false;
            panelGroup.Enabled = true;
            btnSelect.Enabled  = false;

            currentGroup = group;

            lvGroupZones.Items.Clear();
            lvGroupSchedules.Items.Clear();

            if (currentGroup.ID != -1)
            {
                txtName.Text        = group.Name;
                txtDescription.Text = group.Description;

                var zones = GroupZones.GetZones(currentGroup.ID);

                zones.ForEach(zone =>
                {
                    ListViewItem item = new ListViewItem(zone.Location);
                    item.Tag          = zone;
                    lvGroupZones.Items.Add(item);
                });

                var schedules = GroupSchedules.GetSchedules(currentGroup.ID);

                schedules.ForEach(schedule =>
                {
                    ListViewItem item = new ListViewItem(new string[] { schedule.Name, schedule.ToString() });
                    item.Tag          = schedule;
                    lvGroupSchedules.Items.Add(item);
                });
            }

            HasGroupChanges     = false;
            HasZonesChanges     = false;
            HasSchedulesChanges = false;
        }
コード例 #2
0
        private void SaveCurrentGroup()
        {
            if (IsNew)
            {
                currentGroup.Name        = txtName.Text;
                currentGroup.Description = txtDescription.Text;

                Groups.InsertGroup(currentGroup);
                foreach (ListViewItem item in lvGroupZones.Items)
                {
                    GroupZone zone = item.Tag as GroupZone;
                    zone.GroupID = currentGroup.ID;

                    GroupZones.InsertZone(zone);
                }
                foreach (ListViewItem item in lvGroupSchedules.Items)
                {
                    GroupSchedule schedule = item.Tag as GroupSchedule;
                    schedule.GroupID = currentGroup.ID;

                    GroupSchedules.InsertSchedule(schedule);
                }

                var groups = Groups.GetAllGroups();

                lvGroups.BeginUpdate();

                lvGroups.Items.Clear();

                groups.ForEach(group =>
                {
                    ListViewItem item = new ListViewItem(new string[] { group.Name, group.Description });
                    item.Tag          = group;
                    lvGroups.Items.Add(item);

                    if (group.ID == currentGroup.ID)
                    {
                        item.Selected = true;
                    }
                });

                lvGroups.EndUpdate();
            }
            else
            {
                if (HasGroupChanges)
                {
                    currentGroup.Name        = txtName.Text;
                    currentGroup.Description = txtDescription.Text;

                    Groups.UpdateGroup(currentGroup);

                    lvGroups.SelectedItems[0].Text             = currentGroup.Name;
                    lvGroups.SelectedItems[0].SubItems[1].Text = currentGroup.Description;
                }
                if (HasZonesChanges)
                {
                    GroupZones.DeleteZones(currentGroup.ID);

                    foreach (ListViewItem item in lvGroupZones.Items)
                    {
                        GroupZone zone = item.Tag as GroupZone;
                        GroupZones.InsertZone(zone);
                    }
                }
                if (HasSchedulesChanges)
                {
                    GroupSchedules.DeleteSchedules(currentGroup.ID);

                    foreach (ListViewItem item in lvGroupSchedules.Items)
                    {
                        GroupSchedule schedule = item.Tag as GroupSchedule;
                        GroupSchedules.InsertSchedule(schedule);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Employees.cs プロジェクト: woakes070048/tigerfid
        public static bool CheckAccess(uint id, int zone, DateTime date)
        {
            var groups = GetEmployeeAccessGroup(id);

            foreach (var group in groups)
            {
                var valid = GroupZones.HasZone(group.ID, zone);
                if (!valid)
                {
                    return(false);
                }

                var denySchedules = GroupSchedules.GetDenySchedules(group.ID, date.DayOfWeek);
                foreach (var schedule in denySchedules)
                {
                    bool match_date = false;
                    if (schedule.DateFrom.HasValue && schedule.DateTo.HasValue)
                    {
                        if ((date.Date >= schedule.DateFrom.Value) &&
                            (date.Date >= schedule.DateTo.Value))
                        {
                            match_date = true;
                        }
                    }
                    else if (schedule.DateFrom.HasValue)
                    {
                        if (date.Date >= schedule.DateFrom.Value)
                        {
                            match_date = true;
                        }
                    }
                    else if (schedule.DateTo.HasValue)
                    {
                        if (date.Date <= schedule.DateTo.Value)
                        {
                            match_date = true;
                        }
                    }
                    else
                    {
                        match_date = true;
                    }

                    bool match_time = false;
                    if (schedule.TimeFrom.HasValue && schedule.TimeTo.HasValue)
                    {
                        if ((date.TimeOfDay >= schedule.TimeFrom.Value) &&
                            (date.TimeOfDay <= schedule.TimeTo.Value))
                        {
                            match_time = true;
                        }
                    }
                    else if (schedule.TimeFrom.HasValue)
                    {
                        if (date.TimeOfDay >= schedule.TimeFrom.Value)
                        {
                            match_time = true;
                        }
                    }
                    else if (schedule.TimeTo.HasValue)
                    {
                        if (date.TimeOfDay <= schedule.TimeTo.Value)
                        {
                            match_time = true;
                        }
                    }
                    else
                    {
                        match_time = true;
                    }

                    if (match_date && match_time)
                    {
                        return(false);
                    }
                }

                var grantSchedules = GroupSchedules.GetGrantSchedules(group.ID, date.DayOfWeek);
                foreach (var schedule in grantSchedules)
                {
                    bool match_date = false;
                    if (schedule.DateFrom.HasValue && schedule.DateTo.HasValue)
                    {
                        if ((date.Date >= schedule.DateFrom.Value) &&
                            (date.Date >= schedule.DateTo.Value))
                        {
                            match_date = true;
                        }
                    }
                    else if (schedule.DateFrom.HasValue)
                    {
                        if (date.Date >= schedule.DateFrom.Value)
                        {
                            match_date = true;
                        }
                    }
                    else if (schedule.DateTo.HasValue)
                    {
                        if (date.Date <= schedule.DateTo.Value)
                        {
                            match_date = true;
                        }
                    }
                    else
                    {
                        match_date = true;
                    }

                    bool match_time = false;
                    if (schedule.TimeFrom.HasValue && schedule.TimeTo.HasValue)
                    {
                        if ((date.TimeOfDay >= schedule.TimeFrom.Value) &&
                            (date.TimeOfDay <= schedule.TimeTo.Value))
                        {
                            match_time = true;
                        }
                    }
                    else if (schedule.TimeFrom.HasValue)
                    {
                        if (date.TimeOfDay >= schedule.TimeFrom.Value)
                        {
                            match_time = true;
                        }
                    }
                    else if (schedule.TimeTo.HasValue)
                    {
                        if (date.TimeOfDay <= schedule.TimeTo.Value)
                        {
                            match_time = true;
                        }
                    }
                    else
                    {
                        match_time = true;
                    }

                    if (match_date && match_time)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }