分享

实现编码的自动增长

 昵称2525280 2010-08-26
      方法一: 
            DataSet ds = new DataSet;
            int p_int_newCode = 0;
            string P_string_newcode = "";
            ds = bc.ExecDS("select * from repair order by ID");
            if (ds.Tables[0].Rows.Count == 0)
            {
                labID.Text = DateTime.Now.ToString("yyyy-MM-dd") + "BX100001";
            }
            else
            {
                P_string_newcode = Convert.ToString(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ID"]);
                p_int_newCode = Convert.ToInt32(P_string_newcode.Substring(12, 6)) + 1;
                P_string_newcode = DateTime.Now.ToString("yyyy-MM-dd") + "BX" + p_int_newCode.ToString();
                labID.Text = P_string_newcode;
            }
 
在ASP.NET中写在Page_Load事件里
 
方法二:
#region   public void GetCustomerNO()编号自动增长
        //编号自动增长
        public void GetCustomerNO()//---------------------------------------------------------
        {
            int countone = 0;//计算零的个数
            string Zero = "C";//获取数值前面的字符串
            string myID = "";//获得字符串
            Logistics.DALayer.Customer myCustomer = new Logistics.DALayer.Customer();
            //自动增长邦定
            DataTable myDataTable = myCustomer.GetCustomerNO();
            //截取字符"C"
            if (myDataTable.Rows.Count == 0)
            {
                myID = "C000";
                myID = myID.Substring(1, myID.Length - 1);
            }
            else
            {
                myID = myDataTable.Rows[myDataTable.Rows.Count - 1]["CustomerNO"].ToString();
                myID = myID.Substring(1, myID.Length - 1);
            }
            //判断有多上个零
            for (int i = 0; i <= myID.Length - 1; i++)
            {
                if (myID.Substring(i, 1) == "9")
                {
                    countone--;
                }
                if (myID.Substring(i, 1) == "0")
                {
                    if (i != myID.Length - 1)
                    {
                        countone++;
                        if (myID.Substring(i + 1, 1) != "0")
                        {
                            continue;
                        }
                    }
                }
            }
            //组合字符串
            for (int m = 0; m < countone; m++)
            {
                Zero += "0";
            }
            this.txtCustomerNO.Text = Zero + Convert.ToString((Convert.ToInt32(myID) + 1));
        }
        #endregion

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多