/// <summary> /// Displays the text of the current filters /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void fDevice_DisplayFilterValue( object sender, GridFilter.DisplayFilterValueArgs e ) { switch ( e.Key ) { case "Printer": int deviceId = 0; if ( int.TryParse( e.Value, out deviceId ) ) { var service = new DeviceService( new RockContext() ); var device = service.Get( deviceId ); if ( device != null ) { e.Value = device.Name; } } break; case "Device Type": int definedValueId = 0; if ( int.TryParse( e.Value, out definedValueId ) ) { var definedValue = DefinedValueCache.Read( definedValueId ); if ( definedValue != null ) { e.Value = definedValue.Value; } } break; case "Print To": e.Value = ( (PrintTo)System.Enum.Parse( typeof( PrintTo ), e.Value ) ).ToString(); break; case "Print From": e.Value = ( (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), e.Value ) ).ToString(); break; } }
/// <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 ) { Device Device = null; var rockContext = new RockContext(); var deviceService = new DeviceService( rockContext ); var attributeService = new AttributeService( rockContext ); var locationService = new LocationService( rockContext ); int DeviceId = int.Parse( hfDeviceId.Value ); if ( DeviceId != 0 ) { Device = deviceService.Get( DeviceId ); } if ( Device == null ) { // Check for existing var existingDevice = deviceService.Queryable() .Where( d => d.Name == tbName.Text ) .FirstOrDefault(); if ( existingDevice != null ) { nbDuplicateDevice.Text = string.Format( "A device already exists with the name '{0}'. Please use a different device name.", existingDevice.Name ); nbDuplicateDevice.Visible = true; } else { Device = new Device(); deviceService.Add( Device ); } } if ( Device != null ) { Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse( typeof( PrintTo ), ddlPrintTo.SelectedValue ); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), ddlPrintFrom.SelectedValue ); if ( Device.Location == null ) { Device.Location = new Location(); } Device.Location.GeoPoint = geopPoint.SelectedValue; Device.Location.GeoFence = geopFence.SelectedValue; if ( !Device.IsValid || !Page.IsValid ) { // Controls will render the error messages return; } // Remove any deleted locations foreach ( var location in Device.Locations .Where( l => !Locations.Keys.Contains( l.Id ) ) .ToList() ) { Device.Locations.Remove( location ); } // Add any new locations var existingLocationIDs = Device.Locations.Select( l => l.Id ).ToList(); foreach ( var location in locationService.Queryable() .Where( l => Locations.Keys.Contains( l.Id ) && !existingLocationIDs.Contains( l.Id ) ) ) { Device.Locations.Add( location ); } rockContext.SaveChanges(); Rock.CheckIn.KioskDevice.Flush( Device.Id ); NavigateToParentPage(); } }
/// <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 ) { Device Device; var rockContext = new RockContext(); var deviceService = new DeviceService( rockContext ); var attributeService = new AttributeService( rockContext ); var locationService = new LocationService( rockContext ); int DeviceId = int.Parse( hfDeviceId.Value ); if ( DeviceId == 0 ) { Device = new Device(); deviceService.Add( Device ); } else { Device = deviceService.Get( DeviceId ); } Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse( typeof( PrintTo ), ddlPrintTo.SelectedValue ); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), ddlPrintFrom.SelectedValue ); if ( Device.Location == null ) { Device.Location = new Location(); } Device.Location.GeoPoint = geopPoint.SelectedValue; Device.Location.GeoFence = geopFence.SelectedValue; if ( !Device.IsValid || !Page.IsValid ) { // Controls will render the error messages return; } // Remove any deleted locations foreach ( var location in Device.Locations .Where( l => !Locations.Keys.Contains( l.Id ) ) .ToList() ) { Device.Locations.Remove( location ); } // Add any new locations var existingLocationIDs = Device.Locations.Select( l => l.Id ).ToList(); foreach ( var location in locationService.Queryable() .Where( l => Locations.Keys.Contains( l.Id ) && !existingLocationIDs.Contains( l.Id) ) ) { Device.Locations.Add(location); } rockContext.SaveChanges(); NavigateToParentPage(); }
/// <summary> /// Handles the Delete event of the gDevice control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gDevice_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); DeviceService DeviceService = new DeviceService( rockContext ); Device Device = DeviceService.Get( e.RowKeyId ); if ( Device != null ) { int deviceId = Device.Id; string errorMessage; if ( !DeviceService.CanDelete( Device, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } DeviceService.Delete( Device ); rockContext.SaveChanges(); Rock.CheckIn.KioskDevice.Flush( deviceId ); } BindGrid(); }
/// <summary> /// Prints a test label. /// </summary> protected void SendTestPrint() { if ( CurrentKioskId != null ) { // get the current kiosk print options Device device = null; if ( CurrentCheckInState != null ) { device = CurrentCheckInState.Kiosk.Device; } // get the current device and printer if ( device == null || device.PrinterDevice == null ) { using ( var rockContext = new RockContext() ) { var deviceService = new DeviceService( rockContext ); device = device ?? deviceService.Get( (int)CurrentKioskId ); device.PrinterDevice = device.PrinterDevice ?? deviceService.Get( (int)device.PrinterDeviceId ); } } var printerAddress = string.Empty; if ( device != null && device.PrinterDevice != null ) { printerAddress = device.PrinterDevice.IPAddress; } // set the label content var labelContent = GetAttributeValue( "TestLabelContent" ); labelContent = Regex.Replace( labelContent, string.Format( @"(?<=\^FD){0}(?=\^FS)", "DeviceName" ), device.Name ); labelContent = Regex.Replace( labelContent, string.Format( @"(?<=\^FD){0}(?=\^FS)", "PrinterIP" ), printerAddress ); // try printing the label if ( !string.IsNullOrWhiteSpace( labelContent ) && !string.IsNullOrWhiteSpace( printerAddress ) ) { var socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); var printerIpEndPoint = new IPEndPoint( IPAddress.Parse( printerAddress ), 9100 ); var result = socket.BeginConnect( printerIpEndPoint, null, null ); bool success = result.AsyncWaitHandle.WaitOne( 5000, true ); if ( socket.Connected ) { var ns = new NetworkStream( socket ); byte[] toSend = System.Text.Encoding.ASCII.GetBytes( labelContent.ToString() ); ns.Write( toSend, 0, toSend.Length ); } else { maAlert.Show( string.Format( "Can't connect to printer {0} from {1}", printerAddress, device.Name ), ModalAlertType.Alert ); pnlContent.Update(); } if ( socket != null && socket.Connected ) { socket.Shutdown( SocketShutdown.Both ); socket.Close(); } maAlert.Show( string.Format( "Sent a test print job to {0} from {1}", printerAddress, device.Name ), ModalAlertType.Information ); pnlContent.Update(); } else { maAlert.Show( "The test label or the device printer isn't configured with an IP address.", ModalAlertType.Alert ); pnlContent.Update(); } } else { maAlert.Show( "Current check-in state is not instantiated.", ModalAlertType.Alert ); pnlContent.Update(); } }
/// <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 ) { Device Device; DeviceService DeviceService = new DeviceService(); AttributeService attributeService = new AttributeService(); int DeviceId = int.Parse( hfDeviceId.Value ); if ( DeviceId == 0 ) { Device = new Device(); DeviceService.Add( Device, CurrentPersonId ); } else { Device = DeviceService.Get( DeviceId ); } Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse( typeof( PrintTo ), ddlPrintTo.SelectedValue ); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), ddlPrintFrom.SelectedValue ); if ( Device.Location == null ) { Device.Location = new Location(); } Device.Location.GeoPoint = gpGeoPoint.SelectedValue; Device.Location.GeoFence = gpGeoFence.SelectedValue; if ( !Device.IsValid ) { // Controls will render the error messages return; } DeviceService.Save( Device, CurrentPersonId ); NavigateToParentPage(); }
/// <summary> /// Handles the Delete event of the gDevice control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gDevice_Delete( object sender, RowEventArgs e ) { RockTransactionScope.WrapTransaction( () => { DeviceService DeviceService = new DeviceService(); Device Device = DeviceService.Get( (int)e.RowKeyValue ); if ( Device != null ) { string errorMessage; if ( !DeviceService.CanDelete( Device, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } DeviceService.Delete( Device, CurrentPersonId ); DeviceService.Save( Device, CurrentPersonId ); } } ); BindGrid(); }