|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using HandyControl.Controls; |
|
|
|
|
using log4net; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SparkClient.Model.Entity.Base; |
|
|
|
|
using SparkClient.Model.Helper; |
|
|
|
@ -17,6 +18,7 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages |
|
|
|
|
{ |
|
|
|
|
public class SettingsVM : BaseViewModel |
|
|
|
|
{ |
|
|
|
|
private static readonly ILog Logger = LogManager.GetLogger(typeof(ModelColorSetPageVM)); |
|
|
|
|
public ICommand SelectFileCommand { get; } |
|
|
|
|
|
|
|
|
|
public string _languageId; |
|
|
|
@ -47,119 +49,154 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages |
|
|
|
|
public DataTable Rules { get { return _rules; } set { _rules = value; OnPropertyChanged(nameof(Rules)); } } |
|
|
|
|
public SettingsVM() |
|
|
|
|
{ |
|
|
|
|
SelectFileCommand = new RelayCommand(SelectFile); |
|
|
|
|
InitSetting(); |
|
|
|
|
try { |
|
|
|
|
SelectFileCommand = new RelayCommand(SelectFile); |
|
|
|
|
InitSetting(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Logger.Error($"全局异常捕获:{ex.Message}", ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void InitSetting() |
|
|
|
|
{ |
|
|
|
|
Languages = new DataTable(); |
|
|
|
|
Languages.Columns.Add("Key"); |
|
|
|
|
Languages.Columns.Add("Value"); |
|
|
|
|
Languages.Rows.Add("中文", "zh-cn"); |
|
|
|
|
Languages.Rows.Add("English", "en"); |
|
|
|
|
LanguageId = Settings.SelectValueByName("LanguageId"); |
|
|
|
|
if (LanguageId.Length == 0) |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
Languages = new DataTable(); |
|
|
|
|
Languages.Columns.Add("Key"); |
|
|
|
|
Languages.Columns.Add("Value"); |
|
|
|
|
Languages.Rows.Add("中文", "zh-cn"); |
|
|
|
|
Languages.Rows.Add("English", "en"); |
|
|
|
|
LanguageId = Settings.SelectValueById("LanguageId"); |
|
|
|
|
if (LanguageId.Length == 0) |
|
|
|
|
{ |
|
|
|
|
LanguageId = "zh-cn"; |
|
|
|
|
} |
|
|
|
|
bool.TryParse( Settings.SelectValueById("TxtFileChecked"), out bool TxtFileChecked); |
|
|
|
|
this.TxtFileChecked = TxtFileChecked; |
|
|
|
|
bool.TryParse(Settings.SelectValueById("StlFileChecked"), out bool StlFileChecked); |
|
|
|
|
this.StlFileChecked = StlFileChecked; |
|
|
|
|
bool.TryParse(Settings.SelectValueById("ExcelFileChecked"), out bool ExcelFileChecked); |
|
|
|
|
this.ExcelFileChecked = ExcelFileChecked; |
|
|
|
|
bool.TryParse(Settings.SelectValueById("DatFileChecked"), out bool DatFileChecked); |
|
|
|
|
this.DatFileChecked = DatFileChecked; |
|
|
|
|
FilePath = Settings.SelectValueById("FilePath"); |
|
|
|
|
RuleId = Settings.SelectValueById("RuleId"); |
|
|
|
|
selectRules(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
LanguageId = "zh-cn"; |
|
|
|
|
Logger.Error($"全局异常捕获:{ex.Message}", ex); |
|
|
|
|
} |
|
|
|
|
bool.TryParse( Settings.SelectValueByName("TxtFileChecked"), out bool TxtFileChecked); |
|
|
|
|
this.TxtFileChecked = TxtFileChecked; |
|
|
|
|
bool.TryParse(Settings.SelectValueByName("StlFileChecked"), out bool StlFileChecked); |
|
|
|
|
this.StlFileChecked = StlFileChecked; |
|
|
|
|
bool.TryParse(Settings.SelectValueByName("ExcelFileChecked"), out bool ExcelFileChecked); |
|
|
|
|
this.ExcelFileChecked = ExcelFileChecked; |
|
|
|
|
bool.TryParse(Settings.SelectValueByName("DatFileChecked"), out bool DatFileChecked); |
|
|
|
|
this.DatFileChecked = DatFileChecked; |
|
|
|
|
FilePath = Settings.SelectValueByName("FilePath"); |
|
|
|
|
RuleId = Settings.SelectValueByName("RuleId"); |
|
|
|
|
selectRules(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void selectRules() |
|
|
|
|
{ |
|
|
|
|
Rules = new DataTable(); |
|
|
|
|
Rules.Columns.Add("Key"); |
|
|
|
|
Rules.Columns.Add("Value"); |
|
|
|
|
string sql = $"SELECT * FROM RULE WHERE RULE_ID NOT LIKE '%_TA_%';"; |
|
|
|
|
DataTable db = DataBaseHelper.ExecuteQuery(sql); |
|
|
|
|
foreach (DataRow row in db.Rows) |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
Rules.Rows.Add(row[MultilingualHelper.getString("RULE_NAME")].ToString(), row["RULE_ID"].ToString()); |
|
|
|
|
Rules = new DataTable(); |
|
|
|
|
Rules.Columns.Add("Key"); |
|
|
|
|
Rules.Columns.Add("Value"); |
|
|
|
|
string sql = $"SELECT * FROM RULE WHERE RULE_ID NOT LIKE '%_TA_%';"; |
|
|
|
|
DataTable db = DataBaseHelper.ExecuteQuery(sql); |
|
|
|
|
foreach (DataRow row in db.Rows) |
|
|
|
|
{ |
|
|
|
|
Rules.Rows.Add(row[MultilingualHelper.getString("RULE_NAME")].ToString(), row["RULE_ID"].ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Logger.Error($"全局异常捕获:{ex.Message}", ex); |
|
|
|
|
} |
|
|
|
|
//Rules.Rows.Add("IGI 2023", "IGI2023"); |
|
|
|
|
} |
|
|
|
|
public bool SaveUpdate(object param) |
|
|
|
|
{ |
|
|
|
|
if (!Directory.Exists(FilePath)) |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
Growl.Error(MultilingualHelper.getString("SavePathIsnotExists")); |
|
|
|
|
if (!Directory.Exists(FilePath)) |
|
|
|
|
{ |
|
|
|
|
Growl.Error(MultilingualHelper.getString("SavePathIsnotExists")); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
MultilingualHelper.setLanguage(_languageId); |
|
|
|
|
|
|
|
|
|
updateDataBase(); |
|
|
|
|
Growl.InfoGlobal(MultilingualHelper.getString("Save_successful_message")); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Logger.Error($"全局异常捕获:{ex.Message}", ex); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
MultilingualHelper.setLanguage(_languageId); |
|
|
|
|
|
|
|
|
|
updateDataBase(); |
|
|
|
|
Growl.InfoGlobal(MultilingualHelper.getString("Save_successful_message")); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
private void updateDataBase() |
|
|
|
|
{ |
|
|
|
|
// 语言设置登录 |
|
|
|
|
Settings LanguageData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "LanguageId", |
|
|
|
|
ItemName = "语言设置", |
|
|
|
|
Value = LanguageId, |
|
|
|
|
}; |
|
|
|
|
LanguageData.insert(); |
|
|
|
|
// 上传文件登录 |
|
|
|
|
Settings TxtFileCheckedData = new Settings() |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
Key = "TxtFileChecked", |
|
|
|
|
ItemName = "上传文件 TXT文件", |
|
|
|
|
Value = TxtFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
TxtFileCheckedData.insert(); |
|
|
|
|
// 语言设置登录 |
|
|
|
|
Settings LanguageData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "LanguageId", |
|
|
|
|
ItemName = "语言设置", |
|
|
|
|
Value = LanguageId, |
|
|
|
|
}; |
|
|
|
|
LanguageData.insert(); |
|
|
|
|
// 上传文件登录 |
|
|
|
|
Settings TxtFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "TxtFileChecked", |
|
|
|
|
ItemName = "上传文件 TXT文件", |
|
|
|
|
Value = TxtFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
TxtFileCheckedData.insert(); |
|
|
|
|
|
|
|
|
|
Settings StlFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "StlFileChecked", |
|
|
|
|
ItemName = "上传文件 STL文件", |
|
|
|
|
Value = StlFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
StlFileCheckedData.insert(); |
|
|
|
|
Settings StlFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "StlFileChecked", |
|
|
|
|
ItemName = "上传文件 STL文件", |
|
|
|
|
Value = StlFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
StlFileCheckedData.insert(); |
|
|
|
|
|
|
|
|
|
Settings ExcelFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "ExcelFileChecked", |
|
|
|
|
ItemName = "上传文件 Excel文件", |
|
|
|
|
Value = ExcelFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
ExcelFileCheckedData.insert(); |
|
|
|
|
Settings ExcelFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "ExcelFileChecked", |
|
|
|
|
ItemName = "上传文件 Excel文件", |
|
|
|
|
Value = ExcelFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
ExcelFileCheckedData.insert(); |
|
|
|
|
|
|
|
|
|
Settings DatFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "DatFileChecked", |
|
|
|
|
ItemName = "上传文件 Dat文件", |
|
|
|
|
Value = DatFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
DatFileCheckedData.insert(); |
|
|
|
|
// 保存路径登录 |
|
|
|
|
Settings FilePathData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "FilePath", |
|
|
|
|
ItemName = "保存路径", |
|
|
|
|
Value = FilePath, |
|
|
|
|
}; |
|
|
|
|
FilePathData.insert(); |
|
|
|
|
// 定级标准登录 |
|
|
|
|
Settings RuleData = new Settings() |
|
|
|
|
Settings DatFileCheckedData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "DatFileChecked", |
|
|
|
|
ItemName = "上传文件 Dat文件", |
|
|
|
|
Value = DatFileChecked.ToString(), |
|
|
|
|
}; |
|
|
|
|
DatFileCheckedData.insert(); |
|
|
|
|
// 保存路径登录 |
|
|
|
|
Settings FilePathData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "FilePath", |
|
|
|
|
ItemName = "保存路径", |
|
|
|
|
Value = FilePath, |
|
|
|
|
}; |
|
|
|
|
FilePathData.insert(); |
|
|
|
|
// 定级标准登录 |
|
|
|
|
Settings RuleData = new Settings() |
|
|
|
|
{ |
|
|
|
|
Key = "RuleId", |
|
|
|
|
ItemName = "定级标准", |
|
|
|
|
Value = RuleId, |
|
|
|
|
}; |
|
|
|
|
RuleData.insert(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
Key = "RuleId", |
|
|
|
|
ItemName = "定级标准", |
|
|
|
|
Value = RuleId, |
|
|
|
|
}; |
|
|
|
|
RuleData.insert(); |
|
|
|
|
Logger.Error($"全局异常捕获:{ex.Message}", ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void SelectFile(object param) |
|
|
|
|
{ |
|
|
|
@ -182,6 +219,9 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// <summary> |
|
|
|
|
/// 设定表实体 |
|
|
|
|
/// </summary> |
|
|
|
|
public class Settings |
|
|
|
|
{ |
|
|
|
|
private static string TABLE_NAME = "SETTING"; |
|
|
|
@ -203,7 +243,10 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages |
|
|
|
|
/// </summary> |
|
|
|
|
[DbField("SETTING_P")] |
|
|
|
|
public required string Value { get; set; } |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 设定表DB登录 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <returns>更新数量</returns> |
|
|
|
|
public int insert() |
|
|
|
|
{ |
|
|
|
|
string sql = $"SELECT * FROM {TABLE_NAME} WHERE SETTING_ID = '{Key}';"; |
|
|
|
@ -219,8 +262,12 @@ namespace SparkClient.ViewModel.Configuration.SettingsPages |
|
|
|
|
return DataBaseHelper.ExecuteNonQuery(insertSql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static string SelectValueByName(string Id) |
|
|
|
|
/// <summary> |
|
|
|
|
/// 设定表值检索 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="Id"></param> |
|
|
|
|
/// <returns>value</returns> |
|
|
|
|
public static string SelectValueById(string Id) |
|
|
|
|
{ |
|
|
|
|
string sql = $"SELECT * FROM {TABLE_NAME} WHERE SETTING_ID = '{Id}';"; |
|
|
|
|
DataTable db = DataBaseHelper.ExecuteQuery(sql); |
|
|
|
|