string No = ""; //生成编号
            DateTime now = DateTime.Now;
            string Year = now.Year.ToString();
            string Month = now.Month<10?"0"+now.Month:now.Month.ToString();
            string Day = now.Day < 10 ? "0" + now.Day : now.Day.ToString();
            string Hour = now.Hour < 10 ? "0" + now.Hour : now.Hour.ToString();
            string Minute = now.Minute < 10 ? "0" + now.Minute : now.Minute.ToString();
            string Second = now.Second < 10 ? "0" + now.Second : now.Second.ToString();
            string Millisecond = now.Millisecond < 10 ? "0" + now.Millisecond : now.Millisecond.ToString();
            Random rd = new Random();
            int a = rd.Next(0, 9);
            int b = rd.Next(0, 9);
            int c = rd.Next(0, 9);
            No = Year + Month + Day + Hour + Minute + Second + Millisecond + a + b + c;


本文转载:CSDN博客