/// 自动生成16位的单据编号
/// </summary>
/// <param name="?"></param>
/// <param name="?"></param>
/// <param name="?"></param>
/// <returns></returns>
public string CreateSixteenID(string s_danju, string s_table, string s_field)
{
string sDate = GetServerSysDate("yyyyMMdd");
string Str="select max("+ s_field +") id from "+ s_table;
string constr=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();
SqlConnection myconnection=new SqlConnection(constr);
SqlCommand mycommand = new SqlCommand(Str, myconnection);
myconnection.Open();
string maxID=mycommand.ExecuteScalar().ToString();
myconnection.Close();
string Result="";
if (maxID=="")
{
Result = s_danju + sDate + "000001";//"CG20060323000001"
}
else
{
string sFirstEight = maxID.Substring(2,8);
string sLastSix = maxID.Substring(10,6);
if (sDate==sFirstEight)
{
string sNewLastSix = (Convert.ToInt32(sLastSix)+1).ToString("000000");//"000006"
Result = s_danju + sDate + sNewLastSix;
}
else
{
Result = s_danju + sDate + "000001";
}
}
return Result;
}