Ejemplo n.º 1
0
        public void FormatText()
        {
            if (NumberFormatString.IsNullOrWhiteSpace())
            {
                return;
            }

            IsPercent = NumberFormatString.Contains("p") || NumberFormatString.Contains("%");

            // Remove the % sign as it screws up our parse
            if (IsPercent)
            {
                Text = Text.Replace("%", string.Empty);
            }

            decimal value;

            decimal.TryParse(Text, NumberStyles.Any, null, out value);

            // Turn the percentage into a ratio before formatting, as it will multiply by 100
            if (IsPercent)
            {
                value = value / 100;
            }

            Text = value.ToString(NumberFormatString);
        }
Ejemplo n.º 2
0
        private static bool IsDateFormatString(string formatString)
        {
            var format = new NumberFormatString(formatString);

            return(format.IsDateTimeFormat);
        }
Ejemplo n.º 3
0
        private static void TestValid(string format)
        {
            var to = new NumberFormatString(format);

            Assert.IsTrue(to.IsValid, "Invalid format: {0}", format);
        }
        protected override void Execute(CodeActivityContext eContext)
        {
            // Read Variables
            int precision = DecimalPrecision.Get(eContext);

            // Setup
            var             context        = eContext.GetExtension <IWorkflowContext>();
            var             serviceFactory = eContext.GetExtension <IOrganizationServiceFactory>();
            var             service        = serviceFactory.CreateOrganizationService(null);
            ITracingService tracer         = eContext.GetExtension <ITracingService>();


            tracer.Trace("Retrieving User Settings");
            // Read Settings
            var settings = UserSettings.GetUserSettings(service, context.UserId);

            tracer.Trace("User Settings Retrieved");


            tracer.Trace("Retrieving User Setting Attributes");
            var uilang                     = GetEntityValue <int>(tracer, settings, "uilanguageid");
            var currencyPrecision          = GetEntityValue <int>(tracer, settings, "currencydecimalprecision");
            var currencyFormatCode         = GetEntityValue <int>(tracer, settings, "currencyformatcode");
            var currencySymbol             = GetEntityValue <string>(tracer, settings, "currencysymbol");
            var numberGroupFormat          = GetEntityValue <string>(tracer, settings, "numbergroupformat");
            var negativeCurrencyFormatCode = GetEntityValue <int>(tracer, settings, "negativecurrencyformatcode");
            var negativeFormatCode         = GetEntityValue <int>(tracer, settings, "negativeformatcode");
            var decimalSymbol              = GetEntityValue <string>(tracer, settings, "decimalsymbol");
            var numberSeparator            = GetEntityValue <string>(tracer, settings, "numberseparator");
            var businessUnitId             = GetEntityValue <Guid>(tracer, settings, "businessunitid");
            var timeFormatString           = GetEntityValue <string>(tracer, settings, "timeformatstring");
            var dateFormatString           = GetEntityValue <string>(tracer, settings, "dateformatstring");
            var timeZoneCode               = GetEntityValue <int>(tracer, settings, "timezonecode");
            var localeid                   = GetEntityValue <int>(tracer, settings, "localeid");

            // Calculate Fields
            tracer.Trace("Calculating Fields");
            var uiCulture = new CultureInfo(uilang);

            var currencyFormat = NumberFormat.GetFormatString(decimalSymbol, numberSeparator,
                                                              currencyPrecision, numberGroupFormat,
                                                              negativeCurrencyFormatCode, true,
                                                              currencySymbol,
                                                              currencyFormatCode);

            var numberFormat = NumberFormat.GetFormatString(decimalSymbol, numberSeparator,
                                                            precision, numberGroupFormat,
                                                            negativeFormatCode);

            var businessUnit = new EntityReference("businessunit", businessUnitId);

            // Store Results
            tracer.Trace("Storing Results");
            Locale.Set(eContext, localeid);
            BusinessUnit.Set(eContext, businessUnit);
            CurrencySymbol.Set(eContext, currencySymbol);
            CurrencyFormatString.Set(eContext, currencyFormat);
            NumberFormatString.Set(eContext, numberFormat);
            DateFormatString.Set(eContext, dateFormatString);
            TimeFormatString.Set(eContext, timeFormatString);
            TimeZoneCode.Set(eContext, timeZoneCode);
            UILanguageCode.Set(eContext, uilang);
            UILanguageName.Set(eContext, uiCulture.DisplayName);
            UILanguageEnglishName.Set(eContext, uiCulture.EnglishName);
        }
Ejemplo n.º 5
0
        bool IsDateFormatString(string formatString)
        {
            var format = new NumberFormatString(formatString);

            return(format?.IsDateTimeFormat ?? false);
        }
Ejemplo n.º 6
0
 public XlsxNumFmt(int id, string formatCode)
 {
     Id         = id;
     FormatCode = new NumberFormatString(formatCode);
 }