|
@@ -4,10 +4,14 @@ using SqlSugar;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
+using System.Globalization;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
+using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
using TeamAAS_VP.Core;
|
|
using TeamAAS_VP.Core;
|
|
|
|
|
+using TeamAAS_VP.Data; // for ISystemDatabaseService (if used)
|
|
|
|
|
+using TeamAAS_VP.Enums;
|
|
|
using TeamAAS_VP.Interfaces;
|
|
using TeamAAS_VP.Interfaces;
|
|
|
using TeamAAS_VP.Models;
|
|
using TeamAAS_VP.Models;
|
|
|
using TeamAAS_VP.Models.Calibration;
|
|
using TeamAAS_VP.Models.Calibration;
|
|
@@ -15,8 +19,8 @@ using TeamAAS_VP.Models.Feeder;
|
|
|
using TeamAAS_VP.Models.Lights;
|
|
using TeamAAS_VP.Models.Lights;
|
|
|
using TeamAAS_VP.Models.PLC;
|
|
using TeamAAS_VP.Models.PLC;
|
|
|
using TeamAAS_VP.Models.ScrewDriver;
|
|
using TeamAAS_VP.Models.ScrewDriver;
|
|
|
-using TeamAAS_VP.Data; // for ISystemDatabaseService (if used)
|
|
|
|
|
-using System.Threading;
|
|
|
|
|
|
|
+using TeamAAS_VP.Resources.Languages;
|
|
|
|
|
+using WPFLocalizeExtension.Engine;
|
|
|
|
|
|
|
|
namespace TeamAAS_VP.Services
|
|
namespace TeamAAS_VP.Services
|
|
|
{
|
|
{
|
|
@@ -46,6 +50,8 @@ namespace TeamAAS_VP.Services
|
|
|
public static readonly string ScrewDriverConfigurationPath = "..//Config//ScrewDriverConfiguration.cfg";
|
|
public static readonly string ScrewDriverConfigurationPath = "..//Config//ScrewDriverConfiguration.cfg";
|
|
|
// 螺丝供料器(物料)配置路径
|
|
// 螺丝供料器(物料)配置路径
|
|
|
public static readonly string ScrewFeedersConfigurationPath = "..//Config//ScrewFeedersConfiguration.cfg";
|
|
public static readonly string ScrewFeedersConfigurationPath = "..//Config//ScrewFeedersConfiguration.cfg";
|
|
|
|
|
+ // 刷卡器配置路径
|
|
|
|
|
+ public static readonly string CardReaderConfigurationPath = "..//Config//CardReaderConfiguration.cfg";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private readonly object _sync = new object();
|
|
private readonly object _sync = new object();
|
|
@@ -62,13 +68,15 @@ namespace TeamAAS_VP.Services
|
|
|
private ObservableCollection<LightControllerConfig> LightControllers { get; set; }
|
|
private ObservableCollection<LightControllerConfig> LightControllers { get; set; }
|
|
|
// Device info
|
|
// Device info
|
|
|
private DeviceInfo _deviceInfo;
|
|
private DeviceInfo _deviceInfo;
|
|
|
|
|
+
|
|
|
private PlcAddressConfig PlcAddressConfig { get; set; }
|
|
private PlcAddressConfig PlcAddressConfig { get; set; }
|
|
|
// 单个电批配置
|
|
// 单个电批配置
|
|
|
private TeamAAS_VP.Models.ScrewDriver.ScrewDriverConfig _screwDriverConfig;
|
|
private TeamAAS_VP.Models.ScrewDriver.ScrewDriverConfig _screwDriverConfig;
|
|
|
public TeamAAS_VP.Models.ScrewDriver.ScrewDriverConfig ScrewDriverConfig { get { lock(_sync) { return _screwDriverConfig; } } }
|
|
public TeamAAS_VP.Models.ScrewDriver.ScrewDriverConfig ScrewDriverConfig { get { lock(_sync) { return _screwDriverConfig; } } }
|
|
|
|
|
|
|
|
private ISystemDatabaseService _systemDatabaseService;
|
|
private ISystemDatabaseService _systemDatabaseService;
|
|
|
-
|
|
|
|
|
|
|
+ // 刷卡器配置
|
|
|
|
|
+ private SerialPortConfig _cardReaderConfig;
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 注入系统数据库服务(可选),用于记录螺丝批次变更等记录。
|
|
/// 注入系统数据库服务(可选),用于记录螺丝批次变更等记录。
|
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -220,6 +228,15 @@ namespace TeamAAS_VP.Services
|
|
|
_deviceInfo = new DeviceInfo();
|
|
_deviceInfo = new DeviceInfo();
|
|
|
FileHelper.WriteJsonFile(_deviceInfo, ConfigPaths.DeviceInfoConfigurationPath);
|
|
FileHelper.WriteJsonFile(_deviceInfo, ConfigPaths.DeviceInfoConfigurationPath);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // load card reader configuration
|
|
|
|
|
+ if (File.Exists(ConfigPaths.CardReaderConfigurationPath))
|
|
|
|
|
+ _cardReaderConfig = FileHelper.ReadJsonFile<SerialPortConfig>(ConfigPaths.CardReaderConfigurationPath);
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ _cardReaderConfig = new SerialPortConfig();
|
|
|
|
|
+ FileHelper.WriteJsonFile(_cardReaderConfig, ConfigPaths.CardReaderConfigurationPath);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -258,6 +275,9 @@ namespace TeamAAS_VP.Services
|
|
|
// save device info
|
|
// save device info
|
|
|
if (_deviceInfo != null)
|
|
if (_deviceInfo != null)
|
|
|
FileHelper.WriteJsonFile(_deviceInfo, ConfigPaths.DeviceInfoConfigurationPath);
|
|
FileHelper.WriteJsonFile(_deviceInfo, ConfigPaths.DeviceInfoConfigurationPath);
|
|
|
|
|
+ // save card reader config
|
|
|
|
|
+ if (_cardReaderConfig != null)
|
|
|
|
|
+ FileHelper.WriteJsonFile(_cardReaderConfig, ConfigPaths.CardReaderConfigurationPath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -760,6 +780,69 @@ namespace TeamAAS_VP.Services
|
|
|
FileHelper.WriteJsonFile(systemConfiguration, ConfigPaths.SystemConfigurationPath);
|
|
FileHelper.WriteJsonFile(systemConfiguration, ConfigPaths.SystemConfigurationPath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 获取当前语言
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public Language GetCurrentLanguage()
|
|
|
|
|
+ {
|
|
|
|
|
+ lock (_sync)
|
|
|
|
|
+ {
|
|
|
|
|
+ var config = GetSystemConfiguration();
|
|
|
|
|
+ return config.CurrentLanguage;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 设置当前语言
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="language"></param>
|
|
|
|
|
+ public void SetCurrentLanguage(Language language)
|
|
|
|
|
+ {
|
|
|
|
|
+ lock (_sync)
|
|
|
|
|
+ {
|
|
|
|
|
+ var config = GetSystemConfiguration();
|
|
|
|
|
+ config.CurrentLanguage = language;
|
|
|
|
|
+ if (language == Enums.Language.ChineseSimplified)
|
|
|
|
|
+ {
|
|
|
|
|
+ var culture = new CultureInfo("zh-CN");
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentCulture = culture;
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentUICulture = culture;
|
|
|
|
|
+ LocalizeDictionary.Instance.Culture = culture;
|
|
|
|
|
+ Lang.Culture = culture;
|
|
|
|
|
+ System.Windows.Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (language == Enums.Language.ChineseTraditional)
|
|
|
|
|
+ {
|
|
|
|
|
+ var culture = new CultureInfo("zh-TW");
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentCulture = culture;
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentUICulture = culture;
|
|
|
|
|
+ LocalizeDictionary.Instance.Culture = culture;
|
|
|
|
|
+ Lang.Culture = culture;
|
|
|
|
|
+ System.Windows.Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Microsoft YaHei");
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (language == Enums.Language.English)
|
|
|
|
|
+ {
|
|
|
|
|
+ var culture = new CultureInfo("en");
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentCulture = culture;
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentUICulture = culture;
|
|
|
|
|
+ LocalizeDictionary.Instance.Culture = culture;
|
|
|
|
|
+ Lang.Culture = culture;
|
|
|
|
|
+ System.Windows.Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (language == Enums.Language.Japanese)
|
|
|
|
|
+ {
|
|
|
|
|
+ var culture = new CultureInfo("ja-JP");
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentCulture = culture;
|
|
|
|
|
+ App.Current.Dispatcher.Thread.CurrentUICulture = culture;
|
|
|
|
|
+ LocalizeDictionary.Instance.Culture = culture;
|
|
|
|
|
+ Lang.Culture = culture;
|
|
|
|
|
+ System.Windows.Application.Current.Resources["DefaultFont"] = new System.Windows.Media.FontFamily("Segoe UI");
|
|
|
|
|
+ }
|
|
|
|
|
+ SaveSystemConfiguration(config);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region Feeder清料任务
|
|
#region Feeder清料任务
|
|
@@ -1289,6 +1372,63 @@ namespace TeamAAS_VP.Services
|
|
|
}
|
|
}
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
+ #region 用户登录刷卡器
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 获取刷卡器配置
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public SerialPortConfig GetCardReaderConfig()
|
|
|
|
|
+ {
|
|
|
|
|
+ lock (_sync)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (_cardReaderConfig != null)
|
|
|
|
|
+ return _cardReaderConfig;
|
|
|
|
|
+
|
|
|
|
|
+ if (File.Exists(ConfigPaths.CardReaderConfigurationPath))
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ _cardReaderConfig = FileHelper.ReadJsonFile<SerialPortConfig>(ConfigPaths.CardReaderConfigurationPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch
|
|
|
|
|
+ {
|
|
|
|
|
+ // 若读取失败,创建默认配置并覆盖文件(与项目中其他配置策略一致)
|
|
|
|
|
+ _cardReaderConfig = new SerialPortConfig();
|
|
|
|
|
+ try { FileHelper.WriteJsonFile(_cardReaderConfig, ConfigPaths.CardReaderConfigurationPath); } catch { }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ _cardReaderConfig = new SerialPortConfig();
|
|
|
|
|
+ try { FileHelper.WriteJsonFile(_cardReaderConfig, ConfigPaths.CardReaderConfigurationPath); } catch { }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return _cardReaderConfig;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 保存刷卡器配置
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="config"></param>
|
|
|
|
|
+ public void SaveCardReaderConfig(SerialPortConfig config)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (config == null) return;
|
|
|
|
|
+ lock (_sync)
|
|
|
|
|
+ {
|
|
|
|
|
+ _cardReaderConfig = config;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ FileHelper.WriteJsonFile(_cardReaderConfig, ConfigPaths.CardReaderConfigurationPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch
|
|
|
|
|
+ {
|
|
|
|
|
+ // 忽略持久化错误(与项目中其它保存方法一致),可在需要时添加日志记录
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 释放资源并保存当前内存中的所有配置到文件。
|
|
/// 释放资源并保存当前内存中的所有配置到文件。
|
|
|
/// </summary>
|
|
/// </summary>
|