日期:2014-05-16  浏览次数:20592 次

根据数据库现有数据生成单号
/// <summary>
        /// 根据数据库现有数据生成单号
        /// </summary>
        /// <param name="pDBtran"></param>
        /// <returns></returns>
        public static string GetNewBillNo(DbTransaction pDBtran)
        {
            //取得数据
            DataSet vds = null;
            string vNewBillNo = null;
            string SelectBillNo = "select NVL(LPAD(MAX(SUBSTR(BILL_NO,LENGTH(BILL_NO)-3,4))+1,4,'0'),'0001') as Max_NO ";

            //构建SQL语句
            StringBuilder vsql = new StringBuilder();
            vsql.Append(SelectBillNo + "from  MOULDING_TESTMOULD where substr(bill_no,3,8)=to_char(sysdate,'yyyyMMdd')");
            try
            {
                DataBaseHelper.ExecuteQuery(true, vsql.ToString(), out vds, null);
                vNewBillNo = vds.Tables[0].Rows[0]["Max_NO"].ToString();
            }
            catch (System.Data.Odbc.OdbcException exp)
            {
                throw new Exception("New Bill No DataSet 获取 Error ", exp);
            }
            return vNewBillNo;
        }