├── BNR.v11.suo
├── BNR
├── BNR.csproj.user
├── IParameterHandler.cs
├── ParameterTypeAttribute.cs
├── ConstantParameterHandler.cs
├── DateParameterHandler.cs
├── Properties
│ └── AssemblyInfo.cs
├── RuleAnalysis.cs
├── BNRFactory.cs
├── BNR.csproj
├── SequenceParameter.cs
└── ChineseSpellCode.cs
├── BNR.TestConsole
├── BNR.TestConsole.csproj.user
├── Properties
│ └── AssemblyInfo.cs
├── Program.cs
└── BNR.TestConsole.csproj
├── README.md
└── BNR.sln
/BNR.v11.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beetlex-io/BNR/HEAD/BNR.v11.suo
--------------------------------------------------------------------------------
/BNR/BNR.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 |
6 |
--------------------------------------------------------------------------------
/BNR.TestConsole/BNR.TestConsole.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BNR
2 | 业务流水号规则生成器
3 |
4 | {S:OD}{CN:广州}{D:yyyyMM}{N:{S:ORDER}{CN:广州}{D:yyyyMM}/00000000}{N:{S:ORDER_SUB}{CN:广州}{D:yyyyMM}/00000000}
5 |
6 | ODGZ2016090029297200292972
7 |
8 | {CN:广州}{D:yyyyMMdd}{N:{D:yyyyMMdd}/0000}{S:RJ}
9 |
10 | GZ20160913292971RJ
11 |
--------------------------------------------------------------------------------
/BNR/IParameterHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace BNR
7 | {
8 | public interface IParameterHandler
9 | {
10 | void Execute(StringBuilder sb, string value);
11 |
12 | BNRFactory Factory
13 | {
14 | get;
15 | set;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/BNR/ParameterTypeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace BNR
7 | {
8 | [AttributeUsage(AttributeTargets.Class)]
9 | public class ParameterTypeAttribute:Attribute
10 | {
11 | public ParameterTypeAttribute(string name)
12 | {
13 | Name = name;
14 | }
15 | public string Name { get; set; }
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/BNR/ConstantParameterHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace BNR
7 | {
8 | [ParameterType("S")]
9 | public class ConstantParameterHandler : IParameterHandler
10 | {
11 | public void Execute(StringBuilder sb, string value)
12 | {
13 | sb.Append(value);
14 | }
15 | public BNRFactory Factory
16 | {
17 | get;
18 | set;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/BNR/DateParameterHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace BNR
7 | {
8 | ///
9 | /// {D:yyyyMMdd}
10 | ///
11 | [ParameterType("D")]
12 | public class DateParameterHandler : IParameterHandler
13 | {
14 |
15 | public void Execute(StringBuilder sb, string value)
16 | {
17 | sb.Append(DateTime.Now.ToString(value));
18 | }
19 |
20 | public BNRFactory Factory
21 | {
22 | get;
23 | set;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/BNR/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("BNR")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("www.ikende.com")]
12 | [assembly: AssemblyProduct("BNR")]
13 | [assembly: AssemblyCopyright("Copyright © www.ikende.com 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("86ad0262-75c0-49ab-bf69-7b2632cf6eed")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/BNR.TestConsole/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("BNR.TestConsole")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BNR.TestConsole")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("5743dc7b-d0c2-4746-b083-bf09fcacb6f5")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/BNR.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BNR", "BNR\BNR.csproj", "{9F9EFA21-1321-45EC-B25C-E5ED590E1DB5}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BNR.TestConsole", "BNR.TestConsole\BNR.TestConsole.csproj", "{F003DB75-C158-433C-89EF-7B874F4339D8}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {9F9EFA21-1321-45EC-B25C-E5ED590E1DB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {9F9EFA21-1321-45EC-B25C-E5ED590E1DB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {9F9EFA21-1321-45EC-B25C-E5ED590E1DB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {9F9EFA21-1321-45EC-B25C-E5ED590E1DB5}.Release|Any CPU.Build.0 = Release|Any CPU
18 | {F003DB75-C158-433C-89EF-7B874F4339D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {F003DB75-C158-433C-89EF-7B874F4339D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {F003DB75-C158-433C-89EF-7B874F4339D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {F003DB75-C158-433C-89EF-7B874F4339D8}.Release|Any CPU.Build.0 = Release|Any CPU
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/BNR/RuleAnalysis.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace BNR
7 | {
8 | public class RuleAnalysis
9 | {
10 | [ThreadStatic]
11 | private static Stack stack;
12 |
13 | public static string[] Execute(string rule)
14 | {
15 | List items = new List();
16 | StringBuilder sb = new StringBuilder();
17 | if (stack == null)
18 | stack = new Stack();
19 | stack.Clear();
20 | foreach (char c in rule)
21 | {
22 | if (c == '{')
23 | {
24 | if (stack.Count > 0)
25 | sb.Append(c);
26 | stack.Push(c);
27 |
28 | }
29 | else if (c == '}')
30 | {
31 | stack.Pop();
32 | if (stack.Count == 0)
33 | {
34 | items.Add(sb.ToString());
35 | sb.Clear();
36 | }
37 | else
38 | sb.Append(c);
39 | }
40 | else
41 | {
42 | sb.Append(c);
43 | }
44 | }
45 | return items.ToArray();
46 | }
47 |
48 | public static string[] GetProperties(string value)
49 | {
50 | int index = value.IndexOf(':');
51 | return new string[] { value.Substring(0,index),value.Substring(index+1,value.Length -index-1)};
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/BNR.TestConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace BNR.TestConsole
7 | {
8 | class Program
9 | {
10 |
11 | static long mCount;
12 |
13 | static void Main(string[] args)
14 | {
15 | //{N:ORDER2016/0000}
16 | //string[] rule = new string[]{
17 | // "{S:OD}{CN:广州}{D:yyyyMM}{N:{S:ORDER}{CN:广州}{D:yyyyMM}/00000000}{N:{S:ORDER_SUB}{CN:广州}{D:yyyyMM}/00000000}",
18 | // "{S:OD}{CN:深圳}{D:yyyyMM}{N:{S:ORDER}{CN:深圳}{D:yyyyMM}/00000000}",
19 | // "{S:SQ}{D:yyyy}{N:{S:SQ}{D:yyyy}/00000000}"
20 | //};
21 | string[] rule = new string[]{
22 |
23 | "{S:OD}{CN:广州}{D:yyyyMM}{N:{S:ORDER}{CN:广州}{D:yyyyMM}/00000000}{N:{S:ORDER_SUB}{CN:广州}{D:yyyyMM}/00000000}",
24 | "{CN:广州}{D:yyyyMMdd}{N:{D:yyyyMMdd}/0000}{S:RJ}"
25 | };
26 | foreach (string item in rule)
27 | {
28 | string value = BNRFactory.Default.Create(item);
29 | Console.WriteLine(item);
30 | Console.WriteLine(value);
31 | }
32 | System.Threading.ThreadPool.QueueUserWorkItem(o =>
33 | {
34 | while (true)
35 | {
36 | foreach (string item in rule)
37 | {
38 | string value = BNRFactory.Default.Create(item);
39 | // Console.WriteLine("{0}={1}", item, value);
40 | System.Threading.Interlocked.Increment(ref mCount);
41 | }
42 | }
43 | });
44 | while (true)
45 | {
46 | Console.WriteLine(mCount);
47 | System.Threading.Thread.Sleep(1000);
48 | }
49 | Console.Read();
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/BNR/BNRFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 |
7 | namespace BNR
8 | {
9 | public class BNRFactory
10 | {
11 | private Dictionary mHandlers = new Dictionary();
12 |
13 |
14 | public IDictionary Handlers
15 | {
16 |
17 | get
18 | {
19 | return mHandlers;
20 | }
21 | }
22 |
23 | public void Initialize()
24 | {
25 | Register(typeof(BNRFactory).Assembly);
26 | }
27 |
28 | public void Register(System.Reflection.Assembly assembly)
29 | {
30 | foreach (Type type in assembly.GetTypes())
31 | {
32 | Register(type);
33 | }
34 | }
35 |
36 | private static BNRFactory mDefault = null;
37 |
38 | public static BNRFactory Default
39 | {
40 | get
41 | {
42 | if (mDefault == null)
43 | {
44 | mDefault = new BNRFactory();
45 | mDefault.Initialize();
46 | }
47 | return mDefault;
48 | }
49 | }
50 |
51 | public void Register(Type type)
52 | {
53 | ParameterTypeAttribute[] result = (ParameterTypeAttribute[])type.GetCustomAttributes(typeof(ParameterTypeAttribute), false);
54 | if (result != null && result.Length > 0)
55 | {
56 | mHandlers[result[0].Name] =(IParameterHandler) Activator.CreateInstance(type);
57 | mHandlers[result[0].Name].Factory = this;
58 | }
59 | }
60 | public void Register() where T:SequenceParameter
61 | {
62 | Register(typeof(T));
63 | }
64 |
65 | public string Create(string rule)
66 | {
67 | string[] items = RuleAnalysis.Execute(rule);
68 | StringBuilder sb = new StringBuilder();
69 | foreach (string item in items)
70 | {
71 | string[] properties = RuleAnalysis.GetProperties(item);
72 | IParameterHandler handler = null;
73 | if(mHandlers.TryGetValue(properties[0],out handler))
74 | {
75 | handler.Execute(sb, properties[1]);
76 | }
77 | }
78 | return sb.ToString();
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/BNR.TestConsole/BNR.TestConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F003DB75-C158-433C-89EF-7B874F4339D8}
8 | Exe
9 | Properties
10 | BNR.TestConsole
11 | BNR.TestConsole
12 | v4.0
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | {9f9efa21-1321-45ec-b25c-e5ed590e1db5}
50 | BNR
51 |
52 |
53 |
54 |
61 |
--------------------------------------------------------------------------------
/BNR/BNR.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {9F9EFA21-1321-45EC-B25C-E5ED590E1DB5}
8 | Library
9 | Properties
10 | BNR
11 | BNR
12 | v4.0
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 |
--------------------------------------------------------------------------------
/BNR/SequenceParameter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.IO.MemoryMappedFiles;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace BNR
9 | {
10 | ///
11 | /// {N:ORDER/00000}
12 | ///
13 | [ParameterType("N")]
14 | public class SequenceParameter : IParameterHandler
15 | {
16 | private static MemoryMappedFile mSequenceFile;
17 |
18 | private static MemoryMappedViewAccessor mAccessor;
19 |
20 | private static byte[] mBuffer = new byte[64];
21 |
22 | private static Dictionary mSequenceItems;
23 |
24 | private static System.IO.FileStream mFileStream;
25 |
26 | private static int mRecordSize = 64;
27 |
28 | private static int mRecordCount = 1024 * 100;
29 |
30 | static SequenceParameter()
31 | {
32 | string filename = AppDomain.CurrentDomain.BaseDirectory + "sequence.data";
33 | if (!System.IO.File.Exists(filename))
34 | {
35 | mFileStream = System.IO.File.Open(filename, System.IO.FileMode.OpenOrCreate);
36 | byte[] data = new byte[mRecordSize * mRecordCount];
37 | mFileStream.Write(data, 0, mRecordSize * mRecordCount);
38 | mFileStream.Flush();
39 | mFileStream.Close();
40 | }
41 | mSequenceFile = MemoryMappedFile.CreateFromFile(filename);
42 | mAccessor = mSequenceFile.CreateViewAccessor(mRecordSize, 0, MemoryMappedFileAccess.ReadWrite);
43 | mSequenceItems = new Dictionary();
44 | Load();
45 | }
46 |
47 | public SequenceParameter()
48 | {
49 |
50 | }
51 |
52 |
53 | private SequenceItem GetSequenceItem(string key)
54 | {
55 | lock (mSequenceItems)
56 | {
57 | SequenceItem result;
58 | if (!mSequenceItems.TryGetValue(key, out result))
59 | {
60 | result = new SequenceItem();
61 | result.Index = mSequenceItems.Count;
62 | result.Name = key;
63 | mSequenceItems[key] = result;
64 |
65 | }
66 | return result;
67 | }
68 |
69 | }
70 |
71 | private static void Save(SequenceItem item)
72 | {
73 | lock (mAccessor)
74 | {
75 | string value = item.Name + "=" + item.Value.ToString();
76 | Int16 length = (Int16)Encoding.UTF8.GetBytes(value, 0, value.Length, mBuffer, 2);
77 | BitConverter.GetBytes(length).CopyTo(mBuffer, 0);
78 | mAccessor.WriteArray(item.Index * mRecordSize, mBuffer, 0, mBuffer.Length);
79 | }
80 |
81 | }
82 |
83 | private static void Load()
84 | {
85 | for (int i = 0; i < 1024; i++)
86 | {
87 | mAccessor.ReadArray(i * mRecordSize, mBuffer, 0, mBuffer.Length);
88 | int length = BitConverter.ToInt16(mBuffer, 0);
89 | if (length > 0)
90 | {
91 | string value = Encoding.UTF8.GetString(mBuffer, 2, length);
92 | string[] properties = value.Split('=');
93 | SequenceItem item = new SequenceItem();
94 | item.Index = i;
95 | item.Name = properties[0];
96 | item.Value = long.Parse(properties[1]);
97 | mSequenceItems[item.Name] = item;
98 | }
99 | else
100 | break;
101 |
102 | }
103 | }
104 |
105 | public void Execute(StringBuilder sb, string value)
106 | {
107 | string[] properties = value.Split('/');
108 | StringBuilder key = new StringBuilder();
109 | string[] items = RuleAnalysis.Execute(properties[0]);
110 | foreach (string p in items)
111 | {
112 |
113 | string[] sps = RuleAnalysis.GetProperties(p);
114 | IParameterHandler handler = null;
115 | if (Factory.Handlers.TryGetValue(sps[0], out handler))
116 | {
117 | handler.Execute(key, sps[1]);
118 | }
119 | }
120 |
121 | SequenceItem item = GetSequenceItem(key.ToString());
122 | lock (item)
123 | {
124 | item.Value++;
125 | sb.Append(item.Value.ToString(properties[1]));
126 | }
127 | Save(item);
128 |
129 | }
130 |
131 | public class SequenceItem
132 | {
133 |
134 |
135 |
136 |
137 | public int Index { get; set; }
138 |
139 | public string Name { get; set; }
140 |
141 | public long Value { get; set; }
142 |
143 |
144 | }
145 |
146 |
147 |
148 |
149 | public BNRFactory Factory
150 | {
151 | get;
152 | set;
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/BNR/ChineseSpellCode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 |
7 | namespace BNR
8 | {
9 | ///
10 | /// {CN:广州}
11 | ///
12 | [ParameterType("CN")]
13 | public class ChineseSpellCodeParameter : IParameterHandler
14 | {
15 | public void Execute(StringBuilder sb, string value)
16 | {
17 |
18 | foreach (char item in value)
19 | {
20 | sb.Append(Hz2Py.Convert(item.ToString()).Substring(0, 1));
21 | }
22 |
23 | }
24 |
25 | ///
26 | /// 汉字转拼音类
27 | ///
28 | public class Hz2Py
29 | {
30 | private static int[] pyValue = new int[]
31 | {
32 | -20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,
33 | -20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,
34 | -19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,
35 | -19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,
36 | -19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,
37 | -19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,
38 | -18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,
39 | -18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,
40 | -17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,
41 | -17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,
42 | -17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,
43 | -16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,
44 | -16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,
45 | -16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,
46 | -15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,
47 | -15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,
48 | -15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,
49 | -15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-15117,-15110,-15109,
50 | -14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-14914,-14908,-14902,
51 | -14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-14668,-14663,-14654,
52 | -14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-14355,-14353,-14345,
53 | -14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-14123,-14122,-14112,
54 | -14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-13914,-13910,-13907,
55 | -13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-13658,-13611,-13601,
56 | -13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-13359,-13356,-13343,
57 | -13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076,
58 | -13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-12849,-12838,-12831,
59 | -12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-12346,-12320,-12300,
60 | -12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-11847,-11831,-11798,
61 | -11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-11097,-11077,-11067,
62 | -11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-11014,-10838,-10832,
63 | -10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,
64 | -10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-10260,-10256,-10254
65 | };
66 |
67 | private static string[] pyName = new string[]
68 | {
69 | "A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben",
70 | "Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can",
71 | "Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng",
72 | "Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong",
73 | "Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De",
74 | "Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui",
75 | "Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo",
76 | "Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong",
77 | "Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han",
78 | "Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan",
79 | "Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing",
80 | "Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke",
81 | "Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo",
82 | "La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang",
83 | "Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun",
84 | "Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian",
85 | "Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang",
86 | "Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning",
87 | "Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan",
88 | "Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po",
89 | "Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu",
90 | "Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou",
91 | "Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen",
92 | "Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu",
93 | "Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan",
94 | "Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian",
95 | "Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai",
96 | "Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao",
97 | "Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang",
98 | "Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun",
99 | "Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan",
100 | "Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan",
101 | "Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"
102 | };
103 |
104 | ///
105 | /// 把汉字转换成拼音(全拼)
106 | ///
107 | /// 汉字字符串
108 | /// 转换后的拼音(全拼)字符串
109 | public static string Convert(string hzString)
110 | {
111 | // 匹配中文字符
112 | Regex regex = new Regex("^[\u4e00-\u9fa5]$");
113 | byte[] array = new byte[2];
114 | string pyString = "";
115 | int chrAsc = 0;
116 | int i1 = 0;
117 | int i2 = 0;
118 | char[] noWChar = hzString.ToCharArray();
119 |
120 | for (int j = 0; j < noWChar.Length; j++)
121 | {
122 | // 中文字符
123 | if (regex.IsMatch(noWChar[j].ToString()))
124 | {
125 | array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());
126 | i1 = (short)(array[0]);
127 | i2 = (short)(array[1]);
128 | chrAsc = i1 * 256 + i2 - 65536;
129 | if (chrAsc > 0 && chrAsc < 160)
130 | {
131 | pyString += noWChar[j];
132 | }
133 | else
134 | {
135 | // 修正部分文字
136 | if (chrAsc == -9254) // 修正“圳”字
137 | pyString += "Z";
138 | else
139 | {
140 | for (int i = (pyValue.Length - 1); i >= 0; i--)
141 | {
142 | if (pyValue[i] <= chrAsc)
143 | {
144 | pyString += pyName[i].Substring(0, 1);
145 | break;
146 | }
147 | }
148 | }
149 | }
150 | }
151 | // 非中文字符
152 | else
153 | {
154 | pyString += noWChar[j].ToString();
155 | }
156 | }
157 | return pyString;
158 | }
159 | }
160 |
161 | public BNRFactory Factory
162 | {
163 | get;
164 | set;
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------