Beispiel #1
0
        protected void btnOpen_Click( object sender, EventArgs e )
        {
            ceLabel.Label = "Label Contents";
            btnSave.Visible = false;

            int? fileId = ddlLabel.SelectedValueAsInt();
            if ( fileId.HasValue )
            {
                hfBinaryFileId.Value = fileId.Value.ToString();
                using ( var rockContext = new RockContext() )
                {
                    var file = new BinaryFileService( rockContext ).Get( fileId.Value );
                    if ( file != null )
                    {
                        ceLabel.Text = file.ContentsToString();
                        SetLabelSize( ceLabel.Text );
                        ceLabel.Label = string.Format( file.FileName );
                        btnSave.Text = "Save " + file.FileName;
                        btnSave.Visible = true;
                    }
                }
            }
        }
        /// <summary>
        /// Reads the specified label by guid.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        /// <returns></returns>
        public static KioskLabel Read( Guid guid )
        {
            string cacheKey = KioskLabel.CacheKey( guid );

            RockMemoryCache cache = RockMemoryCache.Default;
            KioskLabel label = cache[cacheKey] as KioskLabel;

            if ( label != null )
            {
                return label;
            }
            else
            {
                using ( var rockContext = new RockContext() )
                {
                    var file = new BinaryFileService( rockContext ).Get( guid );
                    if ( file != null )
                    {
                        label = new KioskLabel();

                        label.Guid = file.Guid;
                        label.Url = string.Format( "{0}GetFile.ashx?id={1}", System.Web.VirtualPathUtility.ToAbsolute( "~" ), file.Id );
                        label.MergeFields = new Dictionary<string, string>();
                        label.FileContent = file.ContentsToString();

                        file.LoadAttributes( rockContext );
                        string attributeValue = file.GetAttributeValue( "MergeCodes" );
                        if ( !string.IsNullOrWhiteSpace( attributeValue ) )
                        {
                            string[] nameValues = attributeValue.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
                            foreach ( string nameValue in nameValues )
                            {
                                string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );
                                if ( nameAndValue.Length == 2 && !label.MergeFields.ContainsKey( nameAndValue[0] ) )
                                {
                                    label.MergeFields.Add( nameAndValue[0], nameAndValue[1] );

                                    int definedValueId = int.MinValue;
                                    if ( int.TryParse( nameAndValue[1], out definedValueId ) )
                                    {
                                        var definedValue = DefinedValueCache.Read( definedValueId );
                                        if ( definedValue != null )
                                        {
                                            string mergeField = definedValue.GetAttributeValue( "MergeField" );
                                            if ( mergeField != null )
                                            {
                                                label.MergeFields[nameAndValue[0]] = mergeField;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        var cachePolicy = new CacheItemPolicy();
                        cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds( 60 );
                        cache.Set( cacheKey, label, cachePolicy );

                        return label;
                    }
                }
            }

            return null;
        }
Beispiel #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad( EventArgs e )
        {
            base.OnLoad( e );

            if ( !Page.IsPostBack )
            {
                using ( var rockContext = new RockContext() )
                {
                    int? binaryFileId = PageParameter( "BinaryFileId" ).AsIntegerOrNull();
                    if ( binaryFileId.HasValue )
                    {
                        hfBinaryFileId.Value = binaryFileId.Value.ToString();
                        pnlOpenFile.Visible = false;
                        btnSave.Visible = true;
                        btnCancel.Visible = true;

                        var binaryFile = new BinaryFileService( rockContext ).Get( binaryFileId.Value );
                        if ( binaryFile != null )
                        {
                            lTitle.Text = binaryFile.FileName;
                            ceLabel.Text = binaryFile.ContentsToString();
                            SetLabelSize( ceLabel.Text );
                        }
                    }
                    else
                    {
                        pnlOpenFile.Visible = true;

                        ddlLabel.Items.Clear();
                        Guid labelTypeGuid = Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL.AsGuid();
                        foreach ( var labelFile in new BinaryFileService( rockContext )
                            .Queryable().AsNoTracking()
                            .Where( f => f.BinaryFileType.Guid == labelTypeGuid )
                            .OrderBy( f => f.FileName ) )
                        {
                            ddlLabel.Items.Add( new ListItem( labelFile.FileName, labelFile.Id.ToString() ) );
                        }
                        ddlLabel.SelectedIndex = 0;
                    }

                    ddlDevice.Items.Clear();
                    var printerDeviceType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.DEVICE_TYPE_PRINTER.AsGuid() );
                    if ( printerDeviceType != null )
                    {
                        foreach ( var device in new DeviceService( rockContext )
                            .Queryable().AsNoTracking()
                            .Where( d =>
                                d.DeviceTypeValueId == printerDeviceType.Id &&
                                d.IPAddress != "" ) )
                        {
                            ddlDevice.Items.Add( new ListItem( device.Name, device.Id.ToString() ) );
                        }

                        if ( ddlDevice.Items.Count > 0 )
                        {
                            ddlDevice.SelectedIndex = 0;
                        }
                    }
                }

                SetLabelImage();

            }
        }