void generateCode() { //Initialize variable x as an empty string and a rand varaiable as Random String x = ""; // The z string variable holds the current year string z = Convert.ToString(DateTime.Now.Year); // This loop creates 2 random numbers at first and concatenates the STI word after the 2 random numbers // And also it only generates a number from 0-9 for (int y = 1; y <= 2; y++) { x += Convert.ToString(rand.Next(0, 9)); if (y == 2) { x += "STI-"; } } // This loop creates 3 random numbers from 0-9 for (int y = 1; y <= 3; y++) { x += Convert.ToString(rand.Next(0, 9)); } //display the generated code in the textbox txtIDno.Text = z + "-" + x; }
private void btnGenerate_Click(object sender, EventArgs e) { if (txtIDno.Text == "") { generateCode(); } }