启动 加载语言配置文件
This commit is contained in:
@@ -6,6 +6,7 @@ using NX_LogUtility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
@@ -19,6 +20,7 @@ namespace CleanMachineHMI.Utils
|
||||
/// </summary>
|
||||
public static class frmUtil
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 给一个字符串进行MD5加密
|
||||
/// </summary>
|
||||
@@ -116,22 +118,44 @@ namespace CleanMachineHMI.Utils
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// object 选择返回值
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetObjToString(this object obj)
|
||||
private static void WriteFile(string strDir, string filePath, string txt)
|
||||
{
|
||||
if (obj == null)
|
||||
FileStream fs = null;
|
||||
StreamWriter sw = null;
|
||||
try
|
||||
{
|
||||
return string.Empty;
|
||||
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
|
||||
{
|
||||
Directory.CreateDirectory(strDir);
|
||||
}
|
||||
|
||||
if (File.Exists(filePath))//日志文件存放路径存在,向日志文件追加记录。
|
||||
{
|
||||
fs = new FileStream(filePath, FileMode.Append);
|
||||
}
|
||||
else//日志文件存放路径不存在,创建日志文件。
|
||||
{
|
||||
fs = new FileStream(filePath, FileMode.Create);
|
||||
}
|
||||
sw = new StreamWriter(fs);
|
||||
//开始写入
|
||||
sw.Write(txt);
|
||||
//清空缓冲区
|
||||
sw.Flush();
|
||||
//关闭流
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
if (obj.ToString() == "")
|
||||
catch (Exception)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return obj.ToString();
|
||||
finally
|
||||
{
|
||||
if (sw != null)
|
||||
sw.Close();
|
||||
if (fs != null)
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,46 +163,45 @@ namespace CleanMachineHMI.Utils
|
||||
/// </summary>
|
||||
/// <param name="form">窗体对象</param>
|
||||
/// <param name="languageCode">语言编码</param>
|
||||
public static void SetFormControlText(this Form form,string languageCode)
|
||||
public static void SetFormControlText(this ContainerControl form)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT * FROM SYS_LANGUAGE_CONTROL
|
||||
WHERE USED_FLAG = 1 AND DEL_FLAG = 0
|
||||
AND FORM_CODE='{form.Name}' AND LANGUAGE_CODE='{languageCode}' AND CONTROL_TYPE !='DataSource'";
|
||||
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
|
||||
ErgodicControlsText(form, dt);
|
||||
foreach (Control item in form.Controls)
|
||||
{
|
||||
var key = form.Name + "|" + item.Name;
|
||||
if (!GlobalHelper.ThemeLanguage.ContainsKey(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (item is KryptonGroupBox)
|
||||
{
|
||||
//Console.Write("模块名称"+ ((KryptonGroupBox)tmpC[0]).Values.Heading);
|
||||
//Console.Write("\r\n");
|
||||
|
||||
((KryptonGroupBox)item).Values.Heading = GlobalHelper.ThemeLanguage[key];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//Console.Write("控件名称:"+ tmpC[0].Name+ ":控件中文名:" + tmpC[0].Text);
|
||||
//Console.Write("\r\n");
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.Message, LogTypeEum.Err);
|
||||
}
|
||||
}
|
||||
public static void SetFormControlText(this UserControl form, string languageCode)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT * FROM SYS_LANGUAGE_CONTROL
|
||||
WHERE USED_FLAG = 1 AND DEL_FLAG = 0
|
||||
AND FORM_CODE='{form.Name}' AND LANGUAGE_CODE='{languageCode}' AND CONTROL_TYPE !='DataSource'";
|
||||
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
|
||||
ErgodicControlsText(form, dt);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.Message, LogTypeEum.Err);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设定数据视图列文本
|
||||
/// </summary>
|
||||
/// <param name="dataGrid"></param>
|
||||
/// <param name="formName"></param>
|
||||
/// <param name="languageCode"></param>
|
||||
public static void SetDataViewColumnText(this DataGridView dataGrid ,string formName, string languageCode)
|
||||
public static void SetDataViewColumnText(this DataGridView dataGrid, string formName, string languageCode)
|
||||
{
|
||||
|
||||
try
|
||||
@@ -202,12 +225,10 @@ namespace CleanMachineHMI.Utils
|
||||
/// <param name="dataGrid"></param>
|
||||
/// <param name="formName"></param>
|
||||
/// <param name="languageCode"></param>
|
||||
public static DataTable GetInfoLanguageText(this Form form, string languageCode, string controlType = "Info")
|
||||
public static DataTable GetInfoLanguageText(this ContainerControl form, string languageCode, string controlType = "Info")
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var sql = $@"SELECT * FROM SYS_LANGUAGE_CONTROL
|
||||
WHERE USED_FLAG = 1 AND DEL_FLAG = 0
|
||||
AND (FORM_CODE='{form.Name}' OR IFNULL(FORM_CODE,'')='') AND LANGUAGE_CODE='{languageCode}' AND CONTROL_TYPE = '{controlType}' ORDER BY LANGUAGE_CONTROL_ID";
|
||||
@@ -219,55 +240,7 @@ namespace CleanMachineHMI.Utils
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static DataTable GetInfoLanguageText(this UserControl form, string languageCode, string controlType = "Info")
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var sql = $@"SELECT * FROM SYS_LANGUAGE_CONTROL
|
||||
WHERE USED_FLAG = 1 AND DEL_FLAG = 0
|
||||
AND (FORM_CODE='{form.Name}' OR IFNULL(FORM_CODE,'')='') AND LANGUAGE_CODE='{languageCode}' AND CONTROL_TYPE = '{controlType}' ORDER BY LANGUAGE_CONTROL_ID";
|
||||
return LeadDbHelperSQLite.Query(sql).Tables[0];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.Message, LogTypeEum.Err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static DataTable GetInfoLanguageText_1(this Form form, string languageCode, string controlType = "Info")
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT * FROM SYS_LANGUAGE_CONTROL
|
||||
WHERE USED_FLAG = 1 AND DEL_FLAG = 0
|
||||
AND (FORM_CODE='{form.Name}' OR IFNULL(FORM_CODE,'')='') AND LANGUAGE_CODE='{languageCode}' AND CONTROL_TYPE like '{controlType}' ORDER BY LANGUAGE_CONTROL_ID";
|
||||
return LeadDbHelperSQLite.Query(sql).Tables[0];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.Message, LogTypeEum.Err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static DataTable GetInfoLanguageText_1(this UserControl form, string languageCode, string controlType = "Info")
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var sql = $@"SELECT * FROM SYS_LANGUAGE_CONTROL
|
||||
WHERE USED_FLAG = 1 AND DEL_FLAG = 0
|
||||
AND (FORM_CODE='{form.Name}' OR IFNULL(FORM_CODE,'')='') AND LANGUAGE_CODE='{languageCode}' AND CONTROL_TYPE like '{controlType}' ORDER BY LANGUAGE_CONTROL_ID";
|
||||
return LeadDbHelperSQLite.Query(sql).Tables[0];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.Message, LogTypeEum.Err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取等于查询行
|
||||
/// </summary>
|
||||
@@ -275,7 +248,7 @@ namespace CleanMachineHMI.Utils
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static DataRow[] GetEqualSelectRow(this DataTable dataTable,string key,string value)
|
||||
public static DataRow[] GetEqualSelectRow(this DataTable dataTable, string key, string value)
|
||||
{
|
||||
|
||||
try
|
||||
@@ -322,20 +295,18 @@ namespace CleanMachineHMI.Utils
|
||||
/// <param name="dataTable"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetInfoText(this DataTable dataTable,string defaultValue,string key)
|
||||
public static string GetInfoText(this Control form, string defaultValue, string infoCode, string controlType = "Info")
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var likeSql = $"`CONTROL_CODE` = '{key}' and `CONTROL_TYPE` = 'Info'";
|
||||
DataRow[] dataRow = dataTable.Select(likeSql);
|
||||
if (dataRow == null || !dataRow.Any())
|
||||
var key = form.Name + "|" + infoCode;
|
||||
if (!GlobalHelper.ThemeLanguage.ContainsKey(key))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return dataRow[0]["CONTROL_NAME"].ToString();
|
||||
return GlobalHelper.ThemeLanguage[key];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -344,28 +315,7 @@ namespace CleanMachineHMI.Utils
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static string GetInfoText_1(this DataTable dataTable, string defaultValue, string key, string controlType)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var likeSql = $"`CONTROL_CODE` = '{key}' and `CONTROL_TYPE` = '{controlType}'";
|
||||
DataRow[] dataRow = dataTable.Select(likeSql);
|
||||
if (dataRow == null || !dataRow.Any())
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return dataRow[0]["CONTROL_NAME"].ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.Message, LogTypeEum.Err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static DataRow[] GetComBoboxItemArr(this DataTable dataTable, string key, string controlType)
|
||||
{
|
||||
|
||||
@@ -387,26 +337,27 @@ namespace CleanMachineHMI.Utils
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="dataTable"></param>
|
||||
private static void ErgodicControlsText(Control container,DataTable dataTable)
|
||||
private static void ErgodicControlsText(Control container, DataTable dataTable)
|
||||
{
|
||||
|
||||
for (int i = 0; i < dataTable.Rows.Count; i++)
|
||||
{
|
||||
Control[] tmpC = container.Controls.Find(dataTable.Rows[i]["CONTROL_CODE"].ToString(), true);
|
||||
if (tmpC.Length>0)
|
||||
if (tmpC.Length > 0)
|
||||
{
|
||||
if (tmpC[0] is KryptonGroupBox)
|
||||
{
|
||||
//Console.Write("模块名称"+ ((KryptonGroupBox)tmpC[0]).Values.Heading);
|
||||
//Console.Write("\r\n");
|
||||
((KryptonGroupBox)tmpC[0]).Values.Heading = dataTable.Rows[i]["CONTROL_NAME"].ToString();
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//Console.Write("控件名称:"+ tmpC[0].Name+ ":控件中文名:" + tmpC[0].Text);
|
||||
//Console.Write("\r\n");
|
||||
tmpC[0].Text = dataTable.Rows[i]["CONTROL_NAME"].ToString();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,7 +369,7 @@ namespace CleanMachineHMI.Utils
|
||||
/// <param name="dataTable"></param>
|
||||
private static void ErgodicColumnsText(DataGridView dataGrid, DataTable dataTable)
|
||||
{
|
||||
for(int k = 0; k < dataGrid.Columns.Count; k++)
|
||||
for (int k = 0; k < dataGrid.Columns.Count; k++)
|
||||
{
|
||||
for (int i = 0; i < dataTable.Rows.Count; i++)
|
||||
{
|
||||
@@ -428,7 +379,25 @@ namespace CleanMachineHMI.Utils
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ThemeLanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// 窗体编码
|
||||
/// </summary>
|
||||
public string formCode { get; set; }
|
||||
/// <summary>
|
||||
/// 控件编码
|
||||
/// </summary>
|
||||
public string controlCode { get; set; }
|
||||
/// <summary>
|
||||
/// 控件名称
|
||||
/// </summary>
|
||||
public string controlName { get; set; }
|
||||
|
||||
public List<string> options { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user