WB tips generate random numbers for serial numbers

Source: Internet
Author: User

Foreground HTML code:

<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%><! DOCTYPE html>

Background C # code:

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class _default:system.web.ui.page{protected void Page_Load (object sender, E Ventargs e) {} protected void Button3_Click (object sender, EventArgs e) {//Fetch value string name = Te        Xtbox1.text;        Decimal Price = Convert.todecimal (TextBox2.Text);        Testdatacontext context = new Testdatacontext ();        String code = ""; The format of the serial number takes the current date time to take out his month//check the commodity table there is no code if (context.        Shangpin.count () = = 0) {code = DateTime.Now.ToString ("yyyyMMdd") + "001"; } else {//finds the Database Code column with the largest data interception after three bits +1 string max = context.            Shangpin.max (P=>p.code); Intercepts string max1 = max.            Substring (8,3); Intercept string, RQ = max.            Substring (8); if (RQ = = DateTime.Now.ToString ("YyyyMMdd"))If you want to wait the same day {//turn int max2 = Convert.ToInt32 (MAX1);//If it is executed the same day                MAX2 = max2 + 1;                if (Max2 <) {code = DateTime.Now.ToString ("yyyyMMdd") + "XX" + max2; } else if (Max2 <) {code = DateTime.Now.ToString ("YyyyMMdd")                + "0" + max2;                } else {code = DateTime.Now.ToString ("yyyyMMdd") + max2; }}//execute to this else//not the same day restart {code = DateTime.Now.ToStrin            G ("YyyyMMdd") + "001";        }}//Add data first create a Shangpin object shangpin data = new Shangpin (); Assigns the value data.        Code = code; Data.        name = name; Data.                Price = Price; Context.        Shangpin.insertonsubmit (data); Context.    SubmitChanges (); } protected void Button4_Click (objECT sender, EventArgs e) {testdatacontext context = new Testdatacontext ();        String name = TextBox1.Text;        Decimal Price = Convert.todecimal (TextBox2.Text);        A random number is defined by the randomness rd = new random (); Generates a random number of string code = DateTime.Now.ToString ("Yyyymmddhhmmss") +rd within 1000.        Next (1000);        Add data first create a Shangpin object shangpin data = new Shangpin (); Assigns the value data.        Code = code; Data.        name = name; Data.        Price = Price; Context.        Shangpin.insertonsubmit (data); Context.    SubmitChanges (); }}

SQL display:

WB tips generate random numbers for serial numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.