单号自增

 

开发工具与关键技术:  vs       单号自增

作者:      周乐献       

撰写时间:   2019      年        6月   27    日

$(function () {

            $.getJSON("ReturnNumber", function (data) {

                $("#PartsStockNumber").val(data);

                FoundTime();//调用制单日期

            })

        })

        function FoundTime() {

            var date = new Date();

            var seperator1 = "-";

            var month = date.getMonth() + 1;

            var strDate = date.getDate();

            if (month >= 1 && month <= 9) {

                month = "0" + month;

            }

            if (strDate >= 0 && strDate <= 9) {

                strDate = "0" + strDate;

            }

            var FoundTimee = date.getFullYear() + seperator1 + month + seperator1 + strDate

                    + " ";

            $("#FoundTime").val(FoundTimee);

        };

 

  public ActionResult ReturnNumber()

        {

            var num = AndyNumber.GetRandom();

            return Json(num, JsonRequestBehavior.AllowGet);

        }

        public class AndyNumber

        {

            public static object locker = new object();

            public static int count = 1;

            public static string GetRandom()

            {

                lock (locker)

                {

                    if (count >= 10000)

                    {

                        count = 1;

                    }

                    var Newnumber = "J" + DateTime.Now.ToString("yyyyMMdd") + count.ToString("0000");//ToString("0000"); 将对象格式化,比如第一次就是0001

                    count++;

                    return Newnumber;

                }

            }

        }

没有调用ReturnNumber方法时

 

调用ReturnNumber方法后

通过 条件语句来作用页面没刷新一次,订单号自增 1;

if (count >= 10000)

                    {

                        count = 1;

                    }

                    var Newnumber = "J" + DateTime.Now.ToString("yyyyMMdd") + count.ToString("0000");//ToString("0000"); 将对象格式化,比如第一次就是0001

                    count++;

                    return Newnumber;

 

你可能感兴趣的:(单号自增)