AutoGenRule.cs
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
}
}
}
}