doubt why SQL Server ??? !!! good xd I leave you the code generator that you perform according to the mockup you sample.
First you have to create a form like the following:
From left to right:
Create a groupBox with 3 radiobuttons (the name of the groupbox for this exercise does not matter):
To the radiobuttons name them as:
rbCI and text ponle CI
rbAT and text ponle AT
rbEI and text put EI
Now create another groupBox and place the two remaining radiobuttons:
To radiobutons name them as:
rbD and text ponle D
rbN and text ponle N
Now create a button with name btnGenerar and a label with name lblCodigo
Now if the code:
The first thing you need to know is that according to what you say you need to form a chain where the first value of the first group of radiobuttons is placed at the beginning of the label "lblCodigo" and the value of the second group of radiobuttons is place after this, when the user press generate a number of sequences with 000 format is added.
The code of your form would be of the following form I put it to you complete so that you give you an idea:
public partial class Form1 : Form
{
string firstCode = string.Empty;
string secondCode = string.Empty;
int secuenceNumber = 0;
public Form1()
{
InitializeComponent();
rbCI.CheckedChanged += new EventHandler(rbFirstCode_CheckedChanged);
rbAT.CheckedChanged += new EventHandler(rbFirstCode_CheckedChanged);
rbEI.CheckedChanged += new EventHandler(rbFirstCode_CheckedChanged);
rbD.CheckedChanged += new EventHandler(rbSecondCode_CheckedChanged);
rbN.CheckedChanged += new EventHandler(rbSecondCode_CheckedChanged);
}
private void rbFirstCode_CheckedChanged(object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
firstCode = radioButton.Text;
ShowbuildCode();
}
private void rbSecondCode_CheckedChanged(object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
secondCode = radioButton.Text;
ShowbuildCode();
}
private void ShowbuildCode()
{
lblCodigo.Text = string.Format("{0}{1}{2}", firstCode, secondCode, (secuenceNumber.Equals(0) ? string.Empty : secuenceNumber.ToString("000")));
}
private void btnGenerar_Click(object sender, EventArgs e)
{
secuenceNumber++;
ShowbuildCode();
}
}
Variables
string firstCode = string.Empty;
string secondCode = string.Empty;
int secuenceNumber = 0;
serve to store the current value of the radiobuttons and the current value of the sequence
The following code fragment tells the group of radiobuttons 1 that the rbFirstCode_CheckedChanged event will be assigned to their CheckedChanged event and the same thing is done but this time with the group of radiobuttons 2 and assigning them in the ChechedChaged event rbSecondCode_CheckedChanged
rbCI.CheckedChanged += new EventHandler(rbFirstCode_CheckedChanged);
rbAT.CheckedChanged += new EventHandler(rbFirstCode_CheckedChanged);
rbEI.CheckedChanged += new EventHandler(rbFirstCode_CheckedChanged);
rbD.CheckedChanged += new EventHandler(rbSecondCode_CheckedChanged);
rbN.CheckedChanged += new EventHandler(rbSecondCode_CheckedChanged);
Both events have the same function except that in the first one, the value of the radiobutton of the first group is assigned to the variable firstCode and in the second, the value of the radiobutton of the second group is assigned to the variable secondCode.
finally the method that updates the label to show the generated code is invoked:
private void ShowbuildCode()
{
lblCodigo.Text = string.Format("{0}{1}{2}", firstCode, secondCode, (secuenceNumber.Equals(0) ? string.Empty : secuenceNumber.ToString("000")));
}
if you notice in the string.Format a sequence is indicated that must follow the string where {0} is any value of group 1 of radiobuttons and {1} is the value of group 2 of radiobuttons and finally {2} it would be the current value of the sequence.
The event that has the btnGenerar button attached increases the value of the sequence and calls the method that updates the label value:
private void btnGenerar_Click(object sender, EventArgs e)
{
secuenceNumber++;
ShowbuildCode();
}
Remember to assign this method btnGenerar_Click to the button in the event form:
Here are some exits from the program: