Problem to change en-US culture to fa-IR culture in windows form application in window 10 64 bit - cultureinfo

The culture of windows form application doesn't change, despite using the correct code (I think of course).
In the Program.cs file in the win form application I try to change the current culture from en-US to fa-IR and I use these codes:
CultureInfo culture = CultureInfo.CreateSpecificCulture("Fa-IR");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
But after running the program, nothing happened. The current culture is still en-US!. Let me also say this, I don't change the culture program anywhere else.

I thought that after changing the culture of the system, the language of the system should change as well. While I was wrong. By adding the following code I was able to change the Windows language to Farsi.
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(culture);

public static void InitializePersianCulture() {
var culture = new CultureInfo("fa-ir");
var info = culture.DateTimeFormat;
var calendar = new PersianCalendar();
info.Calendar = calendar;
var field = typeof(CultureInfo).GetField("Calendar", System.Reflection.BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
field.SetValue(culture, "fa-ir");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.CurrentCulture.DateTimeFormat = info;
CultureInfo.CurrentUICulture.DateTimeFormat = info;
}

Related

AEM: getting current locale from $PATH

I am reading values for dropdown using selector + request parameters.
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
the $PATH gives me currentPath.path. I can I get the current locale using the path.
for example:
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=en-us
How can I return only the locale from the $PATH and pass it to locale. That will resolve the issue.
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
Page targetPage = resource.adaptTo(Page.class);
if (targetPage != null) {
Locale pageLocale = targetPage.getLanguage(true);
String countryLocale = pageLocale.getCountry();
}
}
To retrieve locale using $PATH
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
String compNodePath = (String) request.getParameter("locale");
String pagePath = StringUtils.substringBefore(compNodePath, "jcr:content");
PageManager pageMgr = request.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(pagePath);
Locale pageLocale = page.getLanguage(false);
For this to work, Language field in page properties should be set to a suitable value.

Decimal conversion not happening for tr-TR culture

I have very simple code
Decimal Value=34.23m;
Decimal spent;
spent = Math.Round((Convert.ToDecimal(Value)), 2);
Spent = 34.23
It works fine for en-GB culture
If my culture is defined as 'tr-TR' then it fails to convert as the above
it displays as 3423.
Not sure why this is causing such a difference.
Code:
protected override void InitializeCulture()
{
string culture = ConfigurationManager.AppSettings["CultureDefaultloc"];
// string culture = "zh-CN";
if (!string.IsNullOrEmpty(culture))
{
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
base.InitializeCulture();
}
}
<add key="CultureDefaultloc" value="tr-TR"/>

rendering reportviewer as PDf affects the display

After performing "serverreport.render" in order to print the report in PDF format, the Interactive sort does not work on the WebPage.
Below is my code.
private void Print()
{
HttpContext cont = HttpContext.Current;
HttpResponse myRes = cont.Response;
System.Web.SessionState.HttpSessionState mySess = cont.Session;
string enCoding = null;
string strNull = null;
string strPDF = "PDF";
enCoding = Request.Headers["Accept-Encoding"];
string mimeType = "application/pdf";
string extension = ".pdf";
string[] streamids = null;
Warning[] warnings = null;
byte[] mybytes = null;
mybytes = ReportViewer1.ServerReport.Render(strPDF, strNull, out mimeType,
out enCoding, out extension, out streamids, out warnings);
myRes.Buffer = true;
myRes.Clear();
myRes.ContentType = "application/pdf";
myRes.AddHeader("Content-disposition", "filename=output.pdf");
myRes.BinaryWrite(mybytes);
myRes.Flush();
myRes.End();
}
Apparently the rendering of the report as PDF messes up things.
All suggestions are welcome.
Thanks
David
If you require interactive sorting to be available on the web interface, you'll need to display the report via the Report Viewer or HTML (but not MHTML).
Once a report has been rendered to anything other than Report Viewer or HTML, Interactive Sorting is not available.
Comparing Interactive Functionality for Different Report Rendering Extensions

How to pass default keyword for table valued function call in ADO.NET

So here's the deal. In our database, we wrap most of our reads (i.e. select statements) in table valued functions for purposes of security and modularity. So I've got a TVF which defines one or more optional parameters.
I believe having a TVF with defaulted parameters mandates the use of the keyword default when calling the TVF like so:
select * from fn_SampleTVF(123, DEFAULT, DEFAULT)
That's fine, everything works in the query analyzer, but when it comes time to actually make this request from ADO.NET, I'm not sure how to create a sql parameter that actually puts the word default into the rendered sql.
I have something roughly like this now:
String qry = "select * from fn_SampleTVF(#requiredParam, #optionalParam)";
DbCommand command = this.CreateStoreCommand(qry, CommandType.Text);
SqlParameter someRequiredParam = new SqlParameter("#requiredParam", SqlDbType.Int);
someRequiredParam.Value = 123;
command.Parameters.Add(someRequiredParam);
SqlParameter optionalParam = new SqlParameter("#optionalParam", SqlDbType.Int);
optionalParam.Value = >>>> WTF? <<<<
command.Parameters.Add(optionalParam);
So, anybody got any ideas how to pass default to the TVF?
SqlParameter optionalParam = new SqlParameter("#optionalParam", SqlDbType.Int);
optionalParam.Value = >>>> WTF? <<<<
command.Parameters.Add(optionalParam);
You don't have to add above code (The optional parameter) for default. SQL Server will use the default as defined in your UDF. However if you would like to pass different value then you can pass:
SqlParameter optionalParam = new SqlParameter("#optionalParam", SqlDbType.Int);
optionalParam.Value = newValue;
command.Parameters.Add(optionalParam);
I would have done so:
public void YourMethod(int rparam, int? oparam = null)
{
String qry = string.Format("select * from fn_SampleTVF(#requiredParam, {0})"
, !oparam.HasValue ? "default" : "#optionalParam");
SqlParameter someRequiredParam = new SqlParameter("#requiredParam", SqlDbType.Int);
someRequiredParam.Value = rparam;
command.Parameters.Add(someRequiredParam);
if (oparam.HasValue)
{
SqlParameter optionalParam = new SqlParameter("#optionalParam", SqlDbType.Int);
optionalParam.Value = oparam.Value;
command.Parameters.Add(optionalParam);
}
}
You can pass Null as the parameter value.
This article shows examples: http://support.microsoft.com/kb/321902

SSRS2008: LocalReport export to HTML / fragment

I need local RDL report to be exported to HTML, preferably HTML fragment. In 2005 it wasn't officially supported but there was a trick. In SSRS2008 they seem to drop this support (there's no HTML extension in the supported extensions when enumerating using reflection) and use RPL instead which is a binary format that I doubt someone will be happy to parse. Actually it's doesn't seem to be about HTML at all.
Now, is there a way to render HTML using SSRS2008 local report?
Notice that I use VS2008 but with reporting assemblies installed from VS2010 Beta 2 reportviewer.
I found a way, but it's not very good.
Export report to mhtml (it's supported by SSRS2008)
Then use System.Windows.Forms.WebBrowser for render mhtml.
In wb.DocumentText property will be full html page.
It's not very good, because you need a file (as url for WebBrowser).
And also, if I use WebBrowser in ASP.NET application, I need to process it in another thread, with STA ApartmentState.
Looking for the same thing. I suppose I suppose we could try to grab the rendered output of the ReportViewer somehow with reflection?
I might play around with it in a little bit to see what I can come up with.
If you can get the mht, you can extract it's content with MIMER.
There is a nu-get package here (MIMER will require .NET Framework 3.5):
https://www.nuget.org/packages/MIMER/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using MIMER;
namespace MimerTest
{
// https://github.com/smithimage/MIMER/blob/master/MIMERTests/MHT/MhtTests.cs
// https://github.com/smithimage/MIMER/
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
if (false)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
System.IO.Stream m_Stream;
string path = #"d:\USERNAME\documents\visual studio 2013\Projects\MimerTest\MimerTest\whatismht.mht";
System.IO.FileInfo finf = new System.IO.FileInfo(path);
m_Stream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
var reader = new MIMER.RFC2045.MailReader();
MIMER.IEndCriteriaStrategy endofmessage = new MIMER.RFC2045.BasicEndOfMessageStrategy();
var message = reader.ReadMimeMessage(ref m_Stream, endofmessage);
System.Collections.Generic.IDictionary<string,string> allContents = message.Body;
string strFile = allContents["text/html"];
foreach (System.Collections.Generic.KeyValuePair<string,string> kvp in allContents)
{
System.Console.WriteLine(kvp.Key);
System.Console.WriteLine(kvp.Value);
}
System.Console.WriteLine(" --- Press any key to continue --- ");
System.Console.ReadKey();
}
}
}
In the 2005 ReportViewer, you can enable HTML via reflection:
private static void EnableFormat(ReportViewer viewer, string formatName)
{
const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
FieldInfo m_previewService = viewer.LocalReport.GetType().GetField
(
"m_previewService",
Flags
);
MethodInfo ListRenderingExtensions = m_previewService.FieldType.GetMethod
(
"ListRenderingExtensions",
Flags
);
object previewServiceInstance = m_previewService.GetValue(viewer.LocalReport);
IList extensions = ListRenderingExtensions.Invoke(previewServiceInstance, null) as IList;
PropertyInfo name = extensions[0].GetType().GetProperty("Name", Flags);
foreach (object extension in extensions)
{
if (string.Compare(name.GetValue(extension, null).ToString(), formatName, true) == 0)
{
FieldInfo m_isVisible = extension.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo m_isExposedExternally = extension.GetType().GetField("m_isExposedExternally", BindingFlags.NonPublic | BindingFlags.Instance);
m_isVisible.SetValue(extension, true);
m_isExposedExternally.SetValue(extension, true);
break;
}
}
}
Usage:
var Viewer = new Microsoft.Reporting.WebForms.ReportViewer();
EnableFormat(Viewer, "HTML4.0");
You might also find this interesting:
http://www.codeproject.com/Articles/23966/Report-Viewer-generate-reports-MS-Word-formats