Exemple #1
0
        /// <summary>
        /// Handles the ItemCommand event of the rLocations control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void rLocations_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            int?locationId = (e.CommandArgument as string).AsIntegerOrNull();

            if (locationId.HasValue)
            {
                var rockContext = new RockContext();
                var location    = new LocationService(rockContext).Get(locationId.Value);
                if (location != null)
                {
                    if (e.CommandName == "Open" && !location.IsActive)
                    {
                        location.IsActive = true;
                        rockContext.SaveChanges();
                    }
                    else if (e.CommandName == "Close" && location.IsActive)
                    {
                        location.IsActive = false;
                        rockContext.SaveChanges();
                    }

                    // flush the current kiosk ( the kiosk only caches groups, etc for active locations, so we need to flush anytime a location is opened/closed )
                    if (this.CurrentKioskId.HasValue)
                    {
                        KioskDevice.Flush(this.CurrentKioskId.Value);
                    }
                }

                BindManagerLocationsGrid();
            }
        }
        /// <summary>
        /// Attempts to match a known kiosk based on the IP address of the client.
        /// </summary>
        private void GetKioskType(Kiosk kiosk, RockContext rockContext)
        {
            if (kiosk.KioskType != null)
            {
                DeviceService deviceService = new DeviceService(rockContext);
                //Load matching device and update or create information
                var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault();

                //create new device to match our kiosk
                if (device == null)
                {
                    device = new Device();
                    device.DeviceTypeValueId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                    deviceService.Add(device);
                }

                device.Name      = kiosk.Name;
                device.IPAddress = kiosk.IPAddress;
                device.Locations.Clear();
                foreach (var loc in kiosk.KioskType.Locations.ToList())
                {
                    device.Locations.Add(loc);
                }
                device.PrintFrom       = kiosk.PrintFrom;
                device.PrintToOverride = kiosk.PrintToOverride;
                device.PrinterDeviceId = kiosk.PrinterDeviceId;
                rockContext.SaveChanges();
                CurrentKioskId      = device.Id;
                CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();

                CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

                CurrentCheckInState     = null;
                CurrentWorkflow         = null;
                Session["KioskTypeId"]  = kiosk.KioskType.Id;
                Session["KioskMessage"] = kiosk.KioskType.Message;
                KioskDevice.Flush(device.Id);
                SaveState();
                NavigateToNextPage();
            }
            else
            {
                ltDNS.Text      = kiosk.Name;
                pnlMain.Visible = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                GroupLocationService groupLocationService = new GroupLocationService(rockContext);
                ScheduleService      scheduleService      = new ScheduleService(rockContext);
                bool schedulesChanged = false;

                var gridViewRows = gGroupLocationSchedule.Rows;
                foreach (GridViewRow row in gridViewRows.OfType <GridViewRow>())
                {
                    int           groupLocationId = int.Parse(gGroupLocationSchedule.DataKeys[row.RowIndex].Value as string);
                    GroupLocation groupLocation   = groupLocationService.Get(groupLocationId);
                    if (groupLocation != null)
                    {
                        foreach (var fieldCell in row.Cells.OfType <DataControlFieldCell>())
                        {
                            var checkBoxTemplateField = fieldCell.ContainingField as CheckBoxEditableField;
                            if (checkBoxTemplateField != null)
                            {
                                CheckBox checkBox   = fieldCell.Controls[0] as CheckBox;
                                string   dataField  = (fieldCell.ContainingField as CheckBoxEditableField).DataField;
                                int      scheduleId = int.Parse(dataField.Replace("scheduleField_", string.Empty));

                                // update GroupLocationSchedule depending on if the Schedule is Checked or not
                                if (checkBox.Checked)
                                {
                                    // This schedule is selected, so if GroupLocationSchedule doesn't already have this schedule, add it
                                    if (!groupLocation.Schedules.Any(a => a.Id == scheduleId))
                                    {
                                        var schedule = scheduleService.Get(scheduleId);
                                        groupLocation.Schedules.Add(schedule);
                                        schedulesChanged = true;
                                    }
                                }
                                else
                                {
                                    // This schedule is not selected, so if GroupLocationSchedule has this schedule, delete it
                                    if (groupLocation.Schedules.Any(a => a.Id == scheduleId))
                                    {
                                        groupLocation.Schedules.Remove(groupLocation.Schedules.FirstOrDefault(a => a.Id == scheduleId));
                                        schedulesChanged = true;
                                    }
                                }
                            }
                        }
                    }
                }

                if (schedulesChanged)
                {
                    rockContext.SaveChanges();
                    if (this.CurrentKioskId.HasValue)
                    {
                        KioskDevice.Flush(this.CurrentKioskId.Value);
                    }
                }
            }

            NavigateToHomePage();
        }