自动生成16位的单据编号
2007-07-27 09:38
387 查看
/// 自动生成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;
}
/// </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;
}
相关文章推荐
- Microsoft Dynamics CRM4.0 创建单据的时候,自动生成单据编号的通用方法
- sql server 按照日期自动生成单据编号的函数
- sql server 按照日期自动生成单据编号的函数
- 自动生成单据编号
- T-SQL利用触发器自动生成单据编号
- delphi中自动生成单据和记录编号
- access如何用代码在“默认值”里实现自动编号?单据流水号生成问题。
- 利用触发器自动生成单据编号
- 自动生成单据编号
- 自动生成剩余编号字符串
- 在PHP中实现按照预定规则自动生成编号的方法
- 单据号的自动生成问题
- 分享一个自动生成单据的存储过程
- 编写程序,统计某旅馆住宿客人的总数,要求输入客人姓名,输出客人编号(按先后顺序自动生成),姓名以及总人数。
- sql自动生成{00N}编号
- 在数据库中自动生成编号的实现!
- 如何在代码中对由框架自动生成的单据分录三个小按钮设置状态?
- 框架-数据库自动生成编号
- Word2010 自动生成二级编号
- 自动生成单据号