char<-->ASCII C#
using System.Text;
private string GenerateAgnUIDNum(string AgnId = "")
{
string comHead = "LXH";
string agnNum = "";
AgnId = AgnId.Trim();
if (string.IsNullOrEmpty(AgnId))
throw new Exception("传入的人员所在区域编号为空");
string sql = "select Rit_UID from Right_User with(nolock) where Rit_Uid like @Rit_UID and right(Rit_Uid,4)>='0001' and right(Rit_Uid,4)<='9999'";
var oRetVal = SqlHelper.GetSingle(sql, new SqlParameter[] { new SqlParameter("@Rit_UID", string.Format("{0}{1}____", comHead, AgnId)) });
if (oRetVal == null || string.IsNullOrEmpty(Convert.ToString(oRetVal)))
agnNum = "10001";
else
{
string sql2 = "select Max(Rit_UID) as Rit_UID from Right_User with(nolock) where Rit_Uid like @Rit_UID and right(Rit_Uid,4)>='0001' and right(Rit_Uid,4)<='9999'";
oRetVal = SqlHelper.GetSingle(sql2, new SqlParameter[] { new SqlParameter("@Rit_UID", string.Format("{0}{1}____", comHead, AgnId)) });
var strRetVal = (oRetVal != null && !string.IsNullOrEmpty(Convert.ToString(oRetVal))) ? Convert.ToString(oRetVal).Trim() : string.Empty;
if (!string.IsNullOrEmpty(strRetVal))
{
strRetVal = strRetVal.Substring((strRetVal.Length - 4));
agnNum = string.Format("{0}", 10000 + (Convert.ToInt32(strRetVal) + 1));
}
else
agnNum = "10001";
}
return string.Format(@"{0}{1}{2}", comHead, AgnId, agnNum.Substring((agnNum.Length - 4)));
}
private static int Asc(string character)
{
if (string.IsNullOrEmpty(character))
throw new Exception("传入的字符为空");
else
{
if (character.Length == 1)
{
ASCIIEncoding ascii = new ASCIIEncoding();
int intAsciiCode = (int)ascii.GetBytes(character)[0];
return (intAsciiCode);
}
else
throw new Exception("传入的字符无效");
}
}
private static string Chr(int asciiCode)
{
if (asciiCode >= 0 && asciiCode <= 255)
{
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] byteArray = new byte[] { (byte)asciiCode };
string strCharacter = ascii.GetString(byteArray);
return strCharacter;
}
else
{
throw new Exception("传入的ASCIICode无效");
}
}
private string GenerateMaxFileId()
{
string T_File_ID;
string sql_getMaxID = "select max(File_NO) as MaxID from cms2007..DocMng_File with(nolock) where len(File_NO)=6";
var oRetVal = SqlHelper.GetSingle(sql_getMaxID);
var strRetVal = (oRetVal != null && !string.IsNullOrEmpty(Convert.ToString(oRetVal))) ? Convert.ToString(oRetVal).Trim() : string.Empty;
if (string.IsNullOrEmpty(strRetVal))
T_File_ID = "000000";
else
{
if (strRetVal == "999999")
T_File_ID = "aaaaaa";
else
{
#region ASCIICode<-->Char
string id = strRetVal.Trim();
if (Asc(id.Substring(0, 1)) > 57)
{
object[] myArray = new object[6];
for (int i = 1; i <= 6; i++)
{
myArray[i - 1] = id.Substring((i - 1), 1);
}
for (int i = 0; i <= 5; i++)
{
var tempid = id.Substring((5 - i), 1);
var asctemp = Asc(tempid);
if (asctemp < 122)
{
var newtascempid = asctemp + 1;
var newcharid = Chr(newtascempid);
myArray[6 - i - 1] = newcharid;
break;
}
else
{
var newcharid = Chr(97);
myArray[6 - i - 1] = newcharid;
}
}
T_File_ID = string.Join("", myArray);
}
else
{
T_File_ID = string.Format("1{0}", id);
T_File_ID = string.Format("{0}", (Convert.ToInt32(T_File_ID) + 1));
T_File_ID = T_File_ID.Substring(1);
}
#endregion
}
}
return T_File_ID;
}

浙公网安备 33010602011771号