diff --git a/SuperCom/Config/ConfigManager.cs b/SuperCom/Config/ConfigManager.cs
index 57cc253..b96bb53 100644
--- a/SuperCom/Config/ConfigManager.cs
+++ b/SuperCom/Config/ConfigManager.cs
@@ -6,12 +6,20 @@ namespace SuperCom.Config
{
public static class ConfigManager
{
- public static Main Main = Main.CreateInstance();
+ public const string SQLITE_DATA_PATH = "user_data.sqlite";
+
+ public static Main Main { get; set; }
+
+
+ static ConfigManager()
+ {
+ Main = Main.CreateInstance();
+ }
public static void InitConfig()
{
- System.Reflection.FieldInfo[] fieldInfos = typeof(ConfigManager).GetFields();
- foreach (var item in fieldInfos)
+ System.Reflection.PropertyInfo[] propertyInfos = typeof(ConfigManager).GetProperties();
+ foreach (var item in propertyInfos)
{
AbstractConfig config = item.GetValue(null) as AbstractConfig;
if (config == null)
diff --git a/SuperCom/Config/WindowConfig/Main.cs b/SuperCom/Config/WindowConfig/Main.cs
index 18a5aa5..36b83dc 100644
--- a/SuperCom/Config/WindowConfig/Main.cs
+++ b/SuperCom/Config/WindowConfig/Main.cs
@@ -5,7 +5,7 @@ namespace SuperCom.Config.WindowConfig
{
public class Main : AbstractConfig
{
- private Main() : base("user_data.sqlite", $"WindowConfig.Main")
+ private Main() : base(ConfigManager.SQLITE_DATA_PATH, $"WindowConfig.Main")
{
Width = SystemParameters.WorkArea.Width * 0.8;
Height = SystemParameters.WorkArea.Height * 0.8;
@@ -32,6 +32,7 @@ public static Main CreateInstance()
public bool FirstRun { get; set; }
public string SendHistory { get; set; }
+ public string OpeningPorts { get; set; }
}
}
diff --git a/SuperCom/CustomWindows/About.xaml b/SuperCom/CustomWindows/About.xaml
index 78a9b71..1d525d2 100644
--- a/SuperCom/CustomWindows/About.xaml
+++ b/SuperCom/CustomWindows/About.xaml
@@ -44,13 +44,13 @@
FontSize="14"
Foreground="{DynamicResource Window.Foreground}"
Style="{StaticResource ReadOnlyTextBox}"
- Text="版本:1.1" />
+ Text="版本:1.2" />
+ Text="发行日期:2022-09-13" />
diff --git a/SuperCom/Entity/ComSettings.cs b/SuperCom/Entity/ComSettings.cs
new file mode 100644
index 0000000..4ad942e
--- /dev/null
+++ b/SuperCom/Entity/ComSettings.cs
@@ -0,0 +1,59 @@
+using SuperUtils.Framework.ORM.Attributes;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SuperCom.Entity
+{
+
+ [Table(tableName: "com_settings")]
+ public class ComSettings
+ {
+ [TableId(IdType.AUTO)]
+ public int Id { get; set; }
+ public string PortName { get; set; }
+ public bool Connected { get; set; }
+ public bool AddTimeStamp { get; set; }
+ public bool AddNewLineWhenWrite { get; set; }
+ public string PortSetting { get; set; } // json 格式
+ public string WriteData { get; set; }
+
+ public string CreateDate { get; set; }
+ public string UpdateDate { get; set; }
+
+
+ // 必须要有无参构造器
+ public ComSettings()
+ {
+
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is ComSettings com)
+ {
+ if (PortName == null && com.PortName == null) return true;
+ else if (PortName != null)
+ return PortName.Equals(com.PortName);
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return this.PortName.GetHashCode();
+ }
+
+ // SQLite 中建表语句
+ public static class SqliteTable
+ {
+ public static Dictionary Table = new Dictionary()
+ {
+ {"com_settings","create table if not exists com_settings( Id INTEGER PRIMARY KEY autoincrement, PortName VARCHAR(50), Connected INT DEFAULT 0, AddTimeStamp INT DEFAULT 0, AddNewLineWhenWrite INT DEFAULT 0, PortSetting VARCHAR(1000), WriteData VARCHAR(5000), CreateDate VARCHAR(30) DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW', 'localtime')), UpdateDate VARCHAR(30) DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW', 'localtime')), unique(PortName) );" }
+ };
+
+ }
+ }
+}
diff --git a/SuperCom/Entity/CustomSerialPort.cs b/SuperCom/Entity/CustomSerialPort.cs
index fc1d09c..232c21d 100644
--- a/SuperCom/Entity/CustomSerialPort.cs
+++ b/SuperCom/Entity/CustomSerialPort.cs
@@ -1,6 +1,8 @@
using DynamicData.Annotations;
using SuperControls.Style;
+using SuperUtils.Common;
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.IO.Ports;
using System.Runtime.CompilerServices;
@@ -38,6 +40,9 @@ public void RefreshSetting()
this.Encoding = GetEncoding();
this.StopBits = GetStopBits();
this.Parity = GetParity();
+
+ // 保存
+ SettingJson = PortSettingToJson();
}
catch (Exception ex)
{
@@ -45,6 +50,38 @@ public void RefreshSetting()
}
}
+ public string SettingJson { get; set; }
+
+ private string PortSettingToJson()
+ {
+ Dictionary dic = new Dictionary();
+ dic.Add("BaudRate", this.BaudRate);
+ dic.Add("DataBits", this.DataBits);
+ dic.Add("Encoding", this.Encoding.HeaderName);
+ dic.Add("StopBits", this.StopBitsString);
+ dic.Add("Parity", this.ParityString);
+ return JsonUtils.TrySerializeObject(dic);
+ }
+
+ public void SetPortSettingByJson(string json)
+ {
+ Dictionary dict = JsonUtils.TryDeserializeObject>(json);
+ if (dict != null)
+ {
+ int baudRate = PortSetting.DEFAULT_BAUDRATE;
+ int.TryParse(dict["BaudRate"].ToString(), out baudRate);
+ this.BaudRate = baudRate;
+
+ int dataBits = PortSetting.DEFAULT_DATABITS;
+ int.TryParse(dict["DataBits"].ToString(), out dataBits);
+ this.DataBits = dataBits;
+
+ this.PortEncoding = dict["Encoding"].ToString();
+ this.ParityString = dict["Parity"].ToString();
+ this.StopBitsString = dict["StopBits"].ToString();
+ }
+ }
+
public Encoding GetEncoding()
{
try
diff --git a/SuperCom/Entity/PortTabItem.cs b/SuperCom/Entity/PortTabItem.cs
index ee60ed4..0395ed1 100644
--- a/SuperCom/Entity/PortTabItem.cs
+++ b/SuperCom/Entity/PortTabItem.cs
@@ -78,7 +78,12 @@ public string WriteData
private StringBuilder Builder { get; set; }
public TextBox TextBox { get; set; }
- public bool AddTimeStamp { get; set; }
+ private bool _AddTimeStamp = true;
+ public bool AddTimeStamp
+ {
+ get { return _AddTimeStamp; }
+ set { _AddTimeStamp = value; OnPropertyChanged(); }
+ }
@@ -148,7 +153,7 @@ public PortTabItem(string name, bool connected)
Connected = connected;
Setting = new PortSetting();
Builder = new StringBuilder();
- AddTimeStamp = true;
+ //AddTimeStamp = true;
}
public event PropertyChangedEventHandler PropertyChanged;
diff --git a/SuperCom/MainWindow.xaml b/SuperCom/MainWindow.xaml
index 2bc68c9..2d02281 100644
--- a/SuperCom/MainWindow.xaml
+++ b/SuperCom/MainWindow.xaml
@@ -1300,12 +1300,12 @@
+
@@ -1351,7 +1351,7 @@
Width="100"
SelectedIndex="0"
Style="{StaticResource BorderComboBox}"
- Text="{Binding SerialPort.ParityString, Mode=TwoWay}">
+ Text="{Binding SerialPort.ParityString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
None
Odd
Even
@@ -1400,7 +1400,6 @@
@@ -1427,7 +1426,14 @@
-
+
+