You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
6.6 KiB
224 lines
6.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.Windows.Forms;
|
|
using System.Configuration;
|
|
using DBFactory;//20130510
|
|
namespace CommonClassLib
|
|
{
|
|
public class LocalisationHelper
|
|
{
|
|
|
|
public LocalisationHelper()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public string Parse(string input)
|
|
{
|
|
string resultstr = string.Empty; ;
|
|
try
|
|
{
|
|
if (input == null || input.Trim() == "")
|
|
return String.Empty;
|
|
input = input.Replace("${", "");
|
|
input = input.Replace("}", "");
|
|
if (DBFactory.DBOperator.MultiLanguageRes.TryGetValue(input, out resultstr) == false)
|
|
{
|
|
resultstr = input;
|
|
}
|
|
|
|
return resultstr;
|
|
}
|
|
catch
|
|
{
|
|
return input;
|
|
}
|
|
}
|
|
|
|
#region ApplyResource
|
|
|
|
public void ApplyResource(UserControl userControl)
|
|
{
|
|
userControl.Text = Parse(userControl.Text);
|
|
|
|
foreach (Control control in userControl.Controls)
|
|
{
|
|
ApplyResource(control);
|
|
}
|
|
}
|
|
|
|
public void ApplyResource(Form form)
|
|
{
|
|
form.Text = Parse(form.Text);
|
|
|
|
foreach (Control control in form.Controls)
|
|
{
|
|
ApplyResource(control);
|
|
}
|
|
|
|
}
|
|
|
|
public void ApplyResource(Control control)
|
|
{
|
|
control.Text = Parse(control.Text);
|
|
|
|
if (control.Controls != null)
|
|
{
|
|
foreach (Control ctrl in control.Controls)
|
|
{
|
|
ApplyResource(ctrl);
|
|
}
|
|
}
|
|
|
|
if (control.ContextMenuStrip != null)
|
|
{
|
|
ContextMenuStrip contextMenuStrip = control.ContextMenuStrip as ContextMenuStrip;
|
|
ApplyResource(contextMenuStrip);
|
|
}
|
|
|
|
if (control is DataGridView)
|
|
{
|
|
DataGridView dataGridView = control as DataGridView;
|
|
ApplyResource(dataGridView);
|
|
}
|
|
|
|
if (control is ToolStrip)
|
|
{
|
|
ToolStrip toolStrip = control as ToolStrip;
|
|
ApplyResource(toolStrip);
|
|
}
|
|
if (control is ComboBox)
|
|
{
|
|
ComboBox cbb = control as ComboBox;
|
|
ApplyResource(cbb);
|
|
}
|
|
}
|
|
|
|
public void ApplyResource(DataGridView dataGridView)
|
|
{
|
|
foreach (DataGridViewColumn column in dataGridView.Columns)
|
|
{
|
|
column.HeaderText = Parse(column.HeaderText);
|
|
}
|
|
}
|
|
|
|
public void ApplyResource(ToolStrip toolStrip)
|
|
{
|
|
foreach (System.Windows.Forms.ToolStripItem item in toolStrip.Items)
|
|
{
|
|
item.Text = Parse(item.Text);
|
|
if (item is ToolStripDropDownItem)
|
|
{
|
|
ToolStripDropDownItem toolStripDropDownItem = item as ToolStripDropDownItem;
|
|
ApplyResource(toolStripDropDownItem.DropDownItems);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ApplyResource(ContextMenuStrip contextMenuStrip)
|
|
{
|
|
ApplyResource(contextMenuStrip.Items);
|
|
}
|
|
|
|
public void ApplyResource(ToolStripItemCollection items)
|
|
{
|
|
foreach (System.Windows.Forms.ToolStripItem item in items)
|
|
{
|
|
item.Text = Parse(item.Text);
|
|
if (item is ToolStripMenuItem)
|
|
{
|
|
ToolStripMenuItem toolStripMenuItem = item as ToolStripMenuItem;
|
|
ApplyResource(toolStripMenuItem.DropDownItems);
|
|
}
|
|
}
|
|
}
|
|
public void ApplyResource(ComboBox cbb)
|
|
{
|
|
for (int i = 0; i < cbb.Items.Count; i++)
|
|
{
|
|
cbb.Items[i] = Parse(cbb.Items[i].ToString());
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
/// <summary>
|
|
/// Creator:Richard.liu
|
|
/// </summary>
|
|
public static class AppSettings
|
|
{
|
|
public static DBOperator dbo = new DBOperator();//20130510
|
|
public static DBOperator dbo1 = new DBOperator();//20130510
|
|
public static DBOperator dboM = new DBOperator("ManConnString", "ManDBFactory");//20130510
|
|
//add for CATL YB5
|
|
public static DBOperator dboM1 = new DBOperator("ManConnString", "ManDBFactory");//20130510
|
|
public static string GetConfig(string str)
|
|
{
|
|
string sResult = str;
|
|
|
|
sResult = new AppSettingsReader().GetValue(str, typeof(string)).ToString().Trim();
|
|
|
|
return sResult;
|
|
}
|
|
public static string AppConfig()
|
|
{
|
|
return (Application.ExecutablePath.Substring(0,(Application.ExecutablePath.Length)) +".config");
|
|
}
|
|
|
|
public static string GetValue(string appKey)
|
|
{
|
|
XmlDocument xDoc = new XmlDocument();
|
|
try
|
|
{
|
|
xDoc.Load(AppSettings.AppConfig());
|
|
XmlNode xNode;
|
|
XmlElement xElem;
|
|
xNode = xDoc.SelectSingleNode("//appSettings");
|
|
xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
|
|
if (xElem != null)
|
|
return xElem.GetAttribute("value");
|
|
else
|
|
return "";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static void SetValue(string AppKey, string AppValue)
|
|
{
|
|
try
|
|
{
|
|
XmlDocument xDoc = new XmlDocument();
|
|
xDoc.Load(AppSettings.AppConfig());
|
|
XmlNode xNode;
|
|
XmlElement xElem1;
|
|
XmlElement xElem2;
|
|
xNode = xDoc.SelectSingleNode("//appSettings");
|
|
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
|
|
if (xElem1 != null)
|
|
{
|
|
xElem1.SetAttribute("value", AppValue);
|
|
}
|
|
else
|
|
{
|
|
xElem2 = xDoc.CreateElement("add");
|
|
xElem2.SetAttribute("key", AppKey);
|
|
xElem2.SetAttribute("value", AppValue);
|
|
xNode.AppendChild(xElem2);
|
|
}
|
|
xDoc.Save(AppSettings.AppConfig());
|
|
xDoc = null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|