예제 #1
0
        public ActionResult Index(string cultureCode)
        {
            if (string.IsNullOrWhiteSpace(cultureCode))
            {
                cultureCode = CultureManager.GetCurrentUiCulture().Name;
            }

            var    culture   = new CultureInfo(cultureCode);
            var    resources = ResourceManager.GeResourceBy(culture);
            string json      = JsonConvert.SerializeObject(resources, Formatting.Indented);

            string script = "var i18n = " + json;

            return(this.Content(script, "text/javascript", Encoding.UTF8));
        }
예제 #2
0
        internal static string Localize(string text, bool hasUnderscores)
        {
            string key          = text;
            var    allResources = ResourceManager.GeResourceBy(CultureManager.GetCurrentUiCulture());

            if (hasUnderscores)
            {
                key = key.ToPascalCase();
            }

            var item = allResources.FirstOrDefault(x => x.Key == key);

            if (item.Value != null)
            {
                return(item.Value);
            }

            return(text.ToTitleCaseSentence());
        }
예제 #3
0
        public static string GetFormattedValue(object value)
        {
            string cellValue = value.ToString();

            if (value is DateTime)
            {
                var date = value.To <DateTime>();

                if (date.Date == date)
                {
                    return(date.ToString("d"));
                }

                cellValue = date.ToLocalTime().ToString("g");
            }

            if (value is DateTimeOffset)
            {
                var date = value.To <DateTimeOffset>();

                if (date.Date == date)
                {
                    return(date.ToString("d"));
                }

                cellValue = date.ToLocalTime().ToString("g");
            }

            if (value is decimal || value is double || value is float)
            {
                decimal amount = value.To <decimal>();

                cellValue = amount.ToString("C", CultureManager.GetCurrentUiCulture()).Replace(CultureManager.GetCurrentUiCulture().NumberFormat.CurrencySymbol, "");
            }

            return(HttpUtility.HtmlEncode(cellValue));
        }
예제 #4
0
        public static string ParseExpression(string tenant, string expression, List <DataSource> dataSources, ParameterInfo info)
        {
            if (string.IsNullOrWhiteSpace(expression))
            {
                return(string.Empty);
            }


            string logo = GetLogo();

            if (!string.IsNullOrWhiteSpace(logo))
            {
                //Or else logo will not be exported into excel.
                expression = expression.Replace("{LogoPath}", GetCurrentDomainName() + VirtualPathUtility.ToAbsolute(logo));
            }

            expression = expression.Replace("{PrintDate}", DateTime.Now.ToString(CultureManager.GetCurrentUiCulture()));

            foreach (var match in Regex.Matches(expression, "{.*?}"))
            {
                string word = match.ToString();

                if (word.StartsWith("{Meta.", StringComparison.OrdinalIgnoreCase))
                {
                    string sessionKey = RemoveBraces(word);
                    sessionKey = sessionKey.Replace("Meta.", "");
                    sessionKey = sessionKey.Trim();

                    string value = GetDictionaryValue(tenant, sessionKey);

                    expression = expression.Replace(word, value);
                }
                else if (word.StartsWith("{Query.", StringComparison.OrdinalIgnoreCase))
                {
                    string res      = RemoveBraces(word);
                    var    resource = res.Split('.');

                    string key = resource[1];

                    var parameter = info.Parameters.FirstOrDefault(x => x.Name.ToLower().Equals(key.ToLower()));

                    if (parameter != null)
                    {
                        string value = FormattingHelper.GetFormattedValue(parameter.Value);

                        var datasourceParameter = info.DataSourceParameters.FirstOrDefault(x => x.Name.Replace("@", "").ToLower().Equals(parameter.Name.ToLower()));

                        if (datasourceParameter != null)
                        {
                            string type = datasourceParameter.Type;
                            value = DataSourceParameterHelper.CastValue(value, type).ToString();
                        }

                        expression = expression.Replace(word, value);
                    }
                }
                else if (word.StartsWith("{Resources.", StringComparison.OrdinalIgnoreCase))
                {
                    string res      = RemoveBraces(word);
                    var    resource = res.Split('.');

                    string key = resource[2];

                    expression = expression.Replace(word, ResourceManager.GetString(tenant, resource[1], key));
                }
                else if (word.StartsWith("{DataSource", StringComparison.OrdinalIgnoreCase) &&
                         word.ToLower(CultureInfo.InvariantCulture).Contains("runningtotalfieldvalue"))
                {
                    string res      = RemoveBraces(word);
                    var    resource = res.Split('.');

                    int dataSourceIndex =
                        resource[0].ToLower(CultureInfo.InvariantCulture)
                        .Replace("datasource", "")
                        .Replace("[", "")
                        .Replace("]", "").To <int>();
                    int index =
                        resource[1].ToLower(CultureInfo.InvariantCulture)
                        .Replace("runningtotalfieldvalue", "")
                        .Replace("[", "")
                        .Replace("]", "").To <int>();

                    if (dataSourceIndex >= 0 && index >= 0)
                    {
                        var dataSource = dataSources.FirstOrDefault(x => x.Index.Equals(dataSourceIndex));

                        if (dataSource?.Data != null)
                        {
                            expression = expression.Replace(word,
                                                            GetSum(dataSource.Data, index)
                                                            .ToString(CultureInfo.InvariantCulture));
                        }
                    }
                }
                //else if (word.StartsWith("{Barcode", StringComparison.OrdinalIgnoreCase))
                //{
                //string res = RemoveBraces(word).Replace("Barcode(", "").Replace(")", "");
                //string barCodeValue = res;

                //    if (res.StartsWith("DataSource"))
                //    {
                //        barCodeValue = ParseDataSource("{" + res + "}", dataTableCollection);
                //    }

                //    string barCodeFormat = ConfigurationHelper.GetReportParameter("BarCodeFormat");
                //    string barCodeDisplayValue = ConfigurationHelper.GetReportParameter("BarCodeDisplayValue");
                //    string barCodeFontSize = ConfigurationHelper.GetReportParameter("BarCodeFontSize");
                //    string barCodeWidth = ConfigurationHelper.GetReportParameter("BarCodeWidth");
                //    string barCodeHeight = ConfigurationHelper.GetReportParameter("BarCodeHeight");
                //    string barCodeQuite = ConfigurationHelper.GetReportParameter("BarCodeQuite");
                //    string barCodeFont = ConfigurationHelper.GetReportParameter("BarCodeFont");
                //    string barCodeTextAlign = ConfigurationHelper.GetReportParameter("BarCodeTextAlign");
                //    string barCodeBackgroundColor = ConfigurationHelper.GetReportParameter("BarCodeBackgroundColor");
                //    string barCodeLineColor = ConfigurationHelper.GetReportParameter("BarCodeLineColor");

                //    string imageSource =
                //        "<img class='reportEngineBarCode' data-barcodevalue='{0}' alt='{0}' value='{0}' data-barcodeformat='{1}' data-barcodedisplayvalue='{2}' data-barcodefontsize='{3}' data-barcodewidth='{4}' data-barcodeheight='{5}' data-barcodefont='{6}' data-barcodetextalign='{7}' data-barcodebackgroundcolor='{8}' data-barcodelinecolor='{9}' data-barcodequite={10} />";
                //    imageSource = string.Format(CultureInfo.InvariantCulture, imageSource, barCodeValue,
                //        barCodeFormat, barCodeDisplayValue, barCodeFontSize, barCodeWidth, barCodeHeight,
                //        barCodeFont, barCodeTextAlign, barCodeBackgroundColor, barCodeLineColor, barCodeQuite);
                //    expression = expression.Replace(word, imageSource).ToString(CultureInfo.InvariantCulture);
                //}
                //else if (word.StartsWith("{QRCode", StringComparison.OrdinalIgnoreCase))
                //{
                //    string res = RemoveBraces(word).Replace("QRCode(", "").Replace(")", "");
                //    string qrCodeValue = res;

                //    if (res.StartsWith("DataSource"))
                //    {
                //        qrCodeValue = ParseDataSource("{" + res + "}", dataTableCollection);
                //    }

                //    string qrCodeRender = ConfigurationHelper.GetReportParameter("QRCodeRender");
                //    string qrCodeBackgroundColor = ConfigurationHelper.GetReportParameter("QRCodeBackgroundColor");
                //    string qrCodeForegroundColor = ConfigurationHelper.GetReportParameter("QRCodeForegroundColor");
                //    string qrCodeWidth = ConfigurationHelper.GetReportParameter("QRCodeWidth");
                //    string qrCodeHeight = ConfigurationHelper.GetReportParameter("QRCodeHeight");
                //    string qrCodeTypeNumber = ConfigurationHelper.GetReportParameter("QRCodeTypeNumber");

                //    string qrCodeDiv =
                //        "<div class='reportEngineQRCode' data-qrcodevalue={0} data-qrcoderender='{1}' data-qrcodebackgroundcolor='{2}' data-qrcodeforegroundcolor='{3}' data-qrcodewidth='{4}' data-qrcodeheight='{5}' data-qrcodetypenumber='{6}'></div>";
                //    qrCodeDiv = string.Format(CultureInfo.InvariantCulture, qrCodeDiv, qrCodeValue, qrCodeRender,
                //        qrCodeBackgroundColor, qrCodeForegroundColor, qrCodeWidth, qrCodeHeight, qrCodeTypeNumber);
                //    expression = expression.Replace(word, qrCodeDiv).ToString(CultureInfo.InvariantCulture);
                //
                //}
            }
            return(expression);
        }