遇到这样的问题首先要学会分割字符,前面的字母都是不变的,但是后面的数字是自增的,我们不需要对前面的字母进行操作,只需要对后面的数字+1就可以了
// DAL中得到表中最大的custcode
public static string getLastCopacode()
{
string sql = "select top(1) copacode from tb_copartner order by copacode desc";
DataTable dt = DBHelper.GetDataSet(sql);
if (dt.Rows.Count > 0)
{
return dt.Rows[0][0].ToString();
}
else
{
return "";
}
}
private string getCopacode()
{
string copacode = Tb_copartnerManager.getLastCopacode();
if (copacode != "")
{
string num = copacode.Substring(copacode.Length - 4);//得到字母后面的数字
int order = int.Parse(num) + 1;//数字+1
return "GYS" + order.ToString().PadLeft(4, '0');//把字符拼接起来 字符+数字
}
else
{
return "GYS0001";
}
}
tb_factory.Factcode = getFactcode();//最后得到增长的数字
浙公网安备 33010602011771号