public class SerialNum
{
public SerialNum()
{
m_NumByteArr = new byte[4] { 48, 48, 48, 48 };
//m_NumByteArr = new byte[4] { 90, 90, 90, 90 };
ExcludeChar = new List<byte>
{
(byte) 'A',
(byte) 'E',
(byte) 'I',
(byte) 'O',
(byte) 'U'
};
}
public List<byte> ExcludeChar { get; }
/**0~9 十进制ASCII码[48, 57] **/
/**A~Z 十进制ASCII码[65, 90]**/
public string Number
{
get
{
return Encoding.Default.GetString(m_NumByteArr);
}
}
protected byte[] m_NumByteArr;
public bool AddOne()
{
m_NumByteArr[3] = AddChar(m_NumByteArr[3]);
if (m_NumByteArr[3] > (byte)'Z')
{
m_NumByteArr[2] = AddChar(m_NumByteArr[2]);
m_NumByteArr[3] = (byte)'0';
}
if (m_NumByteArr[2] > (byte)'Z')
{
m_NumByteArr[1] = AddChar(m_NumByteArr[1]);
m_NumByteArr[2] = (byte)'0';
}
if (m_NumByteArr[1] > (byte)'Z')
{
m_NumByteArr[0] = AddChar(m_NumByteArr[0]);
m_NumByteArr[1] = (byte)'0';
}
return m_NumByteArr[0] <= (byte)'Z';
}
public bool SubOne()
{
m_NumByteArr[3] = SubChar(m_NumByteArr[3]);
if (m_NumByteArr[3] < (byte)'0')
{
m_NumByteArr[2] = SubChar(m_NumByteArr[2]);
m_NumByteArr[3] = (byte)'Z';
}
if (m_NumByteArr[2] < (byte)'0')
{
m_NumByteArr[1] = SubChar(m_NumByteArr[1]);
m_NumByteArr[2] = (byte)'Z';
}
if (m_NumByteArr[1] < (byte)'0')
{
m_NumByteArr[0] = SubChar(m_NumByteArr[0]);
m_NumByteArr[1] = (byte)'Z';
}
return m_NumByteArr[0] >= (byte)'0';
}
private byte AddChar(byte ch)
{
while (true)
{
ch++;
if (!ExcludeChar.Contains(ch))
{
break;
}
}
if (ch == ((byte)'9' + 1))
{
ch = (byte)'B';
}
return ch;
}
private byte SubChar(byte ch)
{
while (true)
{
ch--;
if (!ExcludeChar.Contains(ch))
{
break;
}
}
if (ch == ((byte)'A' - 1))
{
ch = (byte)'9';
}
return ch;
}
}
标签:NumByteArr,ch,48,C#,AddChar,流水号,90,序列号,byte
From: https://www.cnblogs.com/huvjie/p/16945272.html