C#生成编号

//自动生成账单编号   
   public string GetNewPoID(string Prefix)
        {
            string NewPoID = Prefix + DateTime.Now.Year.ToString().Substring(2);
            CommandText = "SELECT count(*) FROM OverSystems_PoInfo where PoNo like '" + NewPoID + "%'";
            if (Convert.ToInt32(sqlAccess.ExecuteScalar(CommandText)) > 0)
            {
                string LastPoID;
                CommandText = "SELECT PoNo FROM OverSystems_PoInfo where PoNo like '" + NewPoID + "%' order by PoNo desc";
                LastPoID = Convert.ToString(sqlAccess.ExecuteScalar(CommandText)).Substring(4);
                if (LastPoID.IndexOf("-") >= 0)
                    LastPoID = LastPoID.Substring(0, LastPoID.IndexOf("-"));
                NewPoID += (Convert.ToInt32(LastPoID) + 1).ToString("000");
            }
            else
            {
                NewPoID += "001";
            }
            return NewPoID;
        }

  

posted @ 2021-09-05 20:46  刘贵庆  阅读(391)  评论(0编辑  收藏  举报