Beispiel #1
0
    //protected void CompressAttachments() {
    //	MagickImage image = new MagickImage(Web.MapPath("~/attachments/bigfoimage.png"));
    //	image.CompressionMethod = ImageMagick.CompressionMethod.ZipS;
    //	image.Resize(50);
    //	FileSystem.Delete(Web.MapPath("~/attachments/newbigfoimage.png"));
    //	image.Write(Web.MapPath("~/attachments/newbigfoimage.png"));
    //}

    protected void CompressMultiplePng()
    {
        var files = Directory.GetFiles(Web.MapPath(Web.Attachments), "*.*", SearchOption.AllDirectories);

        Web.Flush("Compressing Images into folder attachments/compressed/ <br>");
        foreach (var oldFile in files)
        {
            var attachmentName = oldFile.RightFrom(Web.MapPath(Web.Attachments)).ToLower();
            var ext            = FileSystem.GetExtension(attachmentName);
            if (ext == ".png" || ext == ".jpeg" || ext == ".jpg")
            {
                if (!attachmentName.Contains("compressed\\"))
                {
                    if (oldFile.Contains("nature_wallpaper"))
                    {
                        var originalFileSize = FileSystem.GetFileSize(oldFile);
                        Web.Flush("Filename " + attachmentName + "... Orig File Size: " + originalFileSize + "kb");
                        //FileSystem.CopyFile(file, Web.MapPath("~/attachments/originals/" + attachmentName));
                        var newFile = Web.MapPath("~/attachments/compressed/" + attachmentName);
                        ImageProcessing.CompressImage(oldFile, newFile);
                        var fileSize = FileSystem.GetFileSize(newFile);
                        Web.Flush(" New File Size: " + fileSize + "kb (" + Fmt.Number(Numbers.SafeDivide(fileSize, originalFileSize) * 100, 0) + "%) <br>");
                    }
                }
            }
        }
    }
Beispiel #2
0
        /// <summary>
        /// Return a display version of the value.
        /// String = as is
        /// Bool = yes/no
        /// Date = formatted
        /// Foreign key = lookup field and get name using GetName()
        /// </summary>
        /// <returns></returns>
        public string ToStringNice()
        {
            string displayText = "";

            if (IsForeignKey)
            {
                var lookup = GetForeignRecord();
                if (lookup != null)
                {
                    displayText = lookup.GetName();
                }
            }
            else if (IsBooleanField)
            {
                displayText = Fmt.YesNo(ValueObject.ToBool());
            }
            else if (IsNumericField)
            {
                displayText = Fmt.Number(ValueObject, DecimalPlaces ?? -1, true);
            }
            else
            {
                displayText = ToString();
            }
            return(displayText);
        }
Beispiel #3
0
        /// <summary>
        /// You can supply any of the parameters you like. You must supply either 'percentage' (as a whole number out of 100) or 'amount' and 'outOfTotal' parameters.
        /// </summary>
        /// <example>
        ///     <%=Beweb.Html.BarGraph(percentage:project.PercentOfBudget.ToInt(0), amount:actualHours, showAmount:true, decimalPlaces:1) %>
        ///     <%=Beweb.Html.BarGraph(amount:totalHoursUsed, outOfTotal:totalHoursPurchased, showPercentage:true) %>
        /// </example>
        public static string BarGraph(decimal?amount = null, decimal?outOfTotal = null, bool showPercentage = false, bool showAmount = false, bool showOutOf = false, decimal?percentage = null, string label = null, int decimalPlaces = 0)
        {
            /* You need to add the following CSS to your stylesheet.
             * .svyBarGraph { width: 150px; }
             * .svyBarGraphLabel { position: absolute;color:white;margin-left: 5px; }
             * .svyBarGraphOuter { width:50px;background:#333;float:left;margin-right:10px;height:18px;border-radius: 5px; }
             * .svyBarGraphInner { background:green;height:14px;margin-top:2px;margin-left:2px;border-radius: 4px; }
             */
            if (percentage == null && amount != null && outOfTotal != null)
            {
                percentage = Numbers.Floor(Numbers.SafeDivide(amount.Value, outOfTotal.Value) * 100);
            }
            else if (percentage == null)
            {
                percentage = 0;
            }
            if (showAmount && amount == null)
            {
                throw new BewebException("Html.BarGraph: You need to supply 'amount' parameter if you set 'showAmount' to true.");
            }
            if (showOutOf && outOfTotal == null)
            {
                throw new BewebException("Html.BarGraph: You need to supply 'outOfTotal' parameter if you set 'showOutOf' to true.");
            }

            if (label.IsBlank())
            {
                if (showAmount)
                {
                    label = Fmt.Number(amount, decimalPlaces);
                    if (showOutOf)
                    {
                        label += " of " + Fmt.Number(outOfTotal, decimalPlaces);
                    }
                    if (showPercentage)
                    {
                        label += " (" + Fmt.Percent(percentage, decimalPlaces) + ")";
                    }
                }
                else if (showPercentage)
                {
                    label = Fmt.Percent(percentage, decimalPlaces);
                }
            }

            var html      = new HtmlTag("div").Add("class", "svyBarGraph");
            var labelSpan = new HtmlTag("span").Add("class", "svyBarGraphLabel").SetInnerText(label);
            var barOuter  = new HtmlTag("div").Add("class", "svyBarGraphOuter");
            var barInner  = new HtmlTag("div").Add("class", "svyBarGraphInner").Add("style", "width:" + Fmt.Number(percentage, 0, false) + "%");

            barOuter.AddTag(barInner);
            html.AddTag(labelSpan);
            html.AddTag(barOuter);

            return(html.ToString());
        }
Beispiel #4
0
        public string OriginalValueToStringNice()
        {
            string displayText = "";

            if (IsForeignKey)
            {
                displayText = null;
            }
            else if (IsBooleanField)
            {
                displayText = Fmt.YesNo(OriginalValueObject.ToBool());
            }
            else if (IsNumericField)
            {
                displayText = Fmt.Number(OriginalValueObject, DecimalPlaces ?? -1, true);
            }
            else
            {
                displayText = OriginalValueToString();
            }
            return(displayText);
        }