Commit 02196bad 张东亮

tmp

1 个父辈 9e753723
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Script.Serialization;
namespace Model
{
/// <summary>
/// 关键字自动生成信息
/// </summary>
public class AutoGenRule
{
/// <summary>
/// 关键字
/// </summary>
public string Keyword { get; set; } = "";
/// <summary>
/// 生成规则
/// </summary>
public string GenRule { get; set; } = "";
/// <summary>
/// 前缀
/// </summary>
public string Prefix { get; set; } = "";
/// <summary>
/// 后缀
/// </summary>
public string Postfix { get; set; } = "";
/// <summary>
/// 数字的长度
/// </summary>
public int NumLength { get; set; } = 1;
/// <summary>
/// 当数字位数不够时,是否填充0
/// </summary>
public bool IsFillZero { get; set; } = false;
/// <summary>
/// 序号每日重置
/// </summary>
public bool NumAutoResetByDate { get; set; } = true;
/// <summary>
/// 是否启用后缀数字
/// </summary>
public bool AutoGenID { get; set; } = false;
public static List<AutoGenRule> LoadFile()
{
List<AutoGenRule> rules = new List<AutoGenRule>();
try
{
if (!File.Exists(Model.FilePath.CONFIG_AUTOGENRULES))
return rules;
string rtxt = File.ReadAllText(Model.FilePath.CONFIG_AUTOGENRULES);
JavaScriptSerializer serializer = new();
rules = (List<AutoGenRule>)serializer.DeserializeObject(rtxt);
return rules;
}
catch (Exception ex)
{
LogNet.log.Error("Load AutoGenRule File", ex);
}
return rules;
}
public static void Save(List<AutoGenRule> rules)
{
try
{
// if (!File.Exists(Model.FilePath.CONFIG_AUTOGENRULES))
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(rules);
File.WriteAllText(Model.FilePath.CONFIG_AUTOGENRULES, json);
}
catch (Exception ex)
{
LogNet.log.Error("LoadFile", ex);
}
}
}
}
...@@ -24,5 +24,6 @@ namespace Model ...@@ -24,5 +24,6 @@ namespace Model
public static readonly string CONFIG_EXTENSION = Environment.CurrentDirectory + "\\Config\\Extension.json"; public static readonly string CONFIG_EXTENSION = Environment.CurrentDirectory + "\\Config\\Extension.json";
public static readonly string CONFIG_REELID = Environment.CurrentDirectory + "\\Config\\ReelID"; public static readonly string CONFIG_REELID = Environment.CurrentDirectory + "\\Config\\ReelID";
public static readonly string CONFIG_DATABASE = Environment.CurrentDirectory + "\\Config\\Database.db3"; public static readonly string CONFIG_DATABASE = Environment.CurrentDirectory + "\\Config\\Database.db3";
public static readonly string CONFIG_AUTOGENRULES = Environment.CurrentDirectory + "\\Config\\AutoGenRules.json";
} }
} }
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
<Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" /> <Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
...@@ -77,6 +78,7 @@ ...@@ -77,6 +78,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AutoGenRule.cs" />
<Compile Include="ExtensionControl.cs" /> <Compile Include="ExtensionControl.cs" />
<Compile Include="ExtensionFunction.cs" /> <Compile Include="ExtensionFunction.cs" />
<Compile Include="FilePath.cs" /> <Compile Include="FilePath.cs" />
......
using System; using Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
...@@ -24,6 +25,7 @@ namespace SmartScan ...@@ -24,6 +25,7 @@ namespace SmartScan
public static int mateMaxCodeID; public static int mateMaxCodeID;
public static readonly string[] CODE_SPLIT = new string[] { ",", ";", ":", "@", "#", "$", "%", "&", "-", "_", "+", "|", "!", "^", "*", "?", "/", "\\", "[Space]", "[Tab]" }; public static readonly string[] CODE_SPLIT = new string[] { ",", ";", ":", "@", "#", "$", "%", "&", "-", "_", "+", "|", "!", "^", "*", "?", "/", "\\", "[Space]", "[Tab]" };
public static List<AutoGenRule> AutoGenRules;
} }
} }
...@@ -260,7 +260,7 @@ namespace SmartScan ...@@ -260,7 +260,7 @@ namespace SmartScan
//语言 //语言
CboLanguage.Items.AddRange(Language.Name); CboLanguage.Items.AddRange(Language.Name);
CboLanguage.SelectedText = Common.config.Language; CboLanguage.SelectedText = Common.config.Language;
Common.AutoGenRules = AutoGenRule.LoadFile();
if (Common.config.OpenMaximize) Maximize(); if (Common.config.OpenMaximize) Maximize();
......
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DocumentFormat.OpenXml.Wordprocessing;
using Model;
namespace SmartScan
{
public partial class UsrMacro : UserControl, ISetMenu
{
private readonly List<string> keyCopy;
private readonly List<AutoGenRule> autoGenRulesCopy;
AutoGenRule genRule;
public UsrMacro()
{
InitializeComponent();
keyCopy = new(Common.macroKey);
autoGenRulesCopy = new(Common.AutoGenRules);
LstKey.Items.AddRange(keyCopy.ToArray());
setRIkey();
if (autoGenRulesCopy.Count > 0)
{
genRule = autoGenRulesCopy[0];
}
else
{
genRule = new AutoGenRule();
}
TxtReelIDMatch.Text = genRule.GenRule;
TxtPrefix.Text = genRule.Prefix;
TxtPostfix.Text = genRule.Postfix;
NumReelIDPlaces.Value = genRule.NumLength;
ChkReelIDFillZero.Checked = genRule.IsFillZero;
ChkResetidbydate.Checked = genRule.NumAutoResetByDate;
Asa.FaceControl.Language.SetLanguage(this);
}
public Asa.FaceControl.FacePanel GetPanel()
{
return facePanel1;
}
public void Save()
{
Common.macroKey.Clear();
Common.macroKey.AddRange(keyCopy);
System.IO.File.WriteAllLines(FilePath.CONFIG_MACRO_KEY, Common.macroKey.ToArray());
Common.config.ReelIDMatch = TxtReelIDMatch.Text;
Common.config.ReelIDPrefix = TxtPrefix.Text;
Common.config.ReelIDPostfix = TxtPostfix.Text;
Common.config.ReelIDPlaces = (int)NumReelIDPlaces.Value;
Common.config.ReelIDFillZero = ChkReelIDFillZero.Checked;
Common.config.ReelIDAutoResetByDate = ChkResetidbydate.Checked;
Common.AutoGenRules.Clear();
Common.AutoGenRules.AddRange(autoGenRulesCopy);
AutoGenRule.Save(Common.AutoGenRules);
}
void setRIkey()
{
LstKey.Items.Clear();
LstKey.Items.AddRange(keyCopy.ToArray());
for (int i = 0; i < LstKey.Items.Count; i++)
{
var rule = autoGenRulesCopy.Find(s => s.Keyword.Equals(LstKey.Items[i]));
if (rule != null)
{
LstKey.Items[i] = "[Auto]" + rule.Keyword;
}
}
}
private void LstKey_SelectedIndexChanged(object sender, EventArgs e)
{
if (LstKey.SelectedIndex >= 0)
{
TxtKey.Text = keyCopy[LstKey.SelectedIndex];
genRule = autoGenRulesCopy.Find(s=>s.Keyword.Equals(TxtKey.Text));
}
}
private void BtnAddKey_Click(object sender, EventArgs e)
{
string text = TxtKey.Text;
int index = keyCopy.FindIndex(match => match == text);
if (index == -1)
{
keyCopy.Add(text);
LstKey.Items.Add(text);
autoGenRulesCopy.Add(new AutoGenRule() { Keyword= text);
}
else
{
string hint = Asa.FaceControl.Language.Dialog("KeyExists");
hint = hint.Replace("[name]", text);
new Asa.FaceControl.FaceMessageBox("", hint, MessageBoxButtons.OK).ShowDialog();
}
}
private void BtnDelKey_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
keyCopy.RemoveAt(LstKey.SelectedIndex);
LstKey.Items.RemoveAt(LstKey.SelectedIndex);
var rule = autoGenRulesCopy.Find(s => s.Keyword.Equals(keyCopy[LstKey.SelectedIndex]));
if (rule != null) { }
autoGenRulesCopy.Remove(rule);
}
private void BtnUpdateKey_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
string text = TxtKey.Text;
int index = keyCopy.FindIndex(match => match == text);
if (index == -1)
{
keyCopy[LstKey.SelectedIndex] = text;
LstKey.Items[LstKey.SelectedIndex] = text;
setRIkey();
}
else
{
string hint = Asa.FaceControl.Language.Dialog("KeyExists");
hint = hint.Replace("[name]", text);
new Asa.FaceControl.FaceMessageBox("", hint, MessageBoxButtons.OK).ShowDialog();
}
}
private void BtnAppendKey_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
string key = "[" + LstKey.Text + "]";
TxtReelIDMatch.AppendText(key);
}
private void btn_up_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1 || LstKey.SelectedIndex == 0) return;
keyCopy.Insert(LstKey.SelectedIndex - 1, keyCopy[LstKey.SelectedIndex]);
keyCopy.RemoveAt(LstKey.SelectedIndex + 1);
LstKey.Items.Clear();
LstKey.Items.AddRange(keyCopy.ToArray());
LstKey.SelectedIndex = LstKey.SelectedIndex - 1;
}
private void btn_down_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1 || LstKey.SelectedIndex == keyCopy.Count - 1) return;
keyCopy.Insert(LstKey.SelectedIndex + 2, keyCopy[LstKey.SelectedIndex]);
keyCopy.RemoveAt(LstKey.SelectedIndex);
LstKey.Items.Clear();
LstKey.Items.AddRange(keyCopy.ToArray());
LstKey.SelectedIndex = LstKey.SelectedIndex + 1;
}
private void btn_setriid_Click(object sender, EventArgs e)
{
if (LstKey.SelectedIndex == -1) return;
if (keyCopy[LstKey.SelectedIndex] == Common.config.ReelIDKeyWord)
Common.config.ReelIDKeyWord = "";
else
Common.config.ReelIDKeyWord = keyCopy[LstKey.SelectedIndex];
setRIkey();
}
private void btn_adddatetime_Click(object sender, EventArgs e)
{
string key = "[datetime:yyyyMMddHHmmss]";
TxtReelIDMatch.AppendText(key);
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!