//serial number consists of: p+ month Day + number
//step:
//1, query the serial number, judging the current date there is no water
//2, the current date has a serial number
///3, find the maximum, intercept +1 and generate a new serial number
//4, no serial number, direct generation
string demo = "P" + DateTime.Now.ToString ("YyyyMMdd");
int num = 0;
var query = This._context.info.where (r = R.code.contains (demo));//query current date with no serial number
if (query. Count () >0)//Some cases
{
//Query results in descending order of maximum
string maxcode = query. OrderByDescending (r = r.code). First (). Code;
//intercept number last three digits, self-increment one
num = Convert.ToInt32 (maxcode.substring (maxcode.length-3)) + 1;
//Get new serial number
demo + = num. ToString ("the");
}
else//Current date no running water
{
demo + = (num + 1). ToString ("000");//serial number starting from 1
}
TextBox1.Text = demo;//assigns the serial number to the text box, preferably readonly=true the text box property;
Automatic serial number generation