之前的写的自动编码单据流水码是写在存储过程或者函数中的,今天用程序写一个发现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;
        }
04-12 00:35