您的位置:首页 > 编程语言 > C#

[C#]ToString("##")格式化用法案例一:自动编码单据流水码

2013-11-12 08:01 363 查看
之前的写的自动编码单据流水码是写在存储过程或者函数中的,今天用程序写一个发现TOSTRING可以格式化方便。

/// <summary>
/// 年月日+两位流水码
/// </summary>
/// <returns></returns>
public static string AutoCode()
{
string yearmonthday =System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString("00") + System.DateTime.Now.Day.ToString("00");

string flowcode = string.Empty;//流水码
StringBuilder sb = new StringBuilder();
sb.Append(" select  报价单号  from   [dbo].[UF_Quotation]");
sb.Append(" where Left(报价单号,8)='" + yearmonthday  + "'");
using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.conn, CommandType.Text, sb.ToString()))
{
if (dr.Read())
{
int tempcode=int.Parse(dr[0].ToString().Substring (8,2))+1;
flowcode = tempcode.ToString("00"); ;
}
else
{
flowcode = "01";
}
}
return yearmonthday + flowcode;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: