internal class Data
{
public static int row = 0;
public static int maxrow = 5;
public static Person[] plist = new Person[21];
}private void cbxSub_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cbxSub.SelectedIndex)
{
case 0:
{
Data.maxrow = 5;
break;
}
case 1:
{
Data.maxrow = 10;
break;
}
case 2:
{
Data.maxrow = 20;
break;
}
}
}bool IsValid()
{
if (txtName.Text != "" && txtLastname.Text != "" && numAge.Value > 0 && Data.row != Data.maxrow)
{
return true;
}
else
{
if (txtName.Text == "")
{
MessageBox.Show("Name is required", "Error", MessageBoxButtons.OK);
}
else if (txtLastname.Text == "")
{
MessageBox.Show("Lastname is required", "Error", MessageBoxButtons.OK);
}
else if (numAge.Value == 0)
{
MessageBox.Show("Age is required", "Error", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("The maximum amount of people has been reached", "Error", MessageBoxButtons.OK);
}
return false;
}
}private void btnSubmit_Click(object sender, EventArgs e)
{
if (IsValid())
{
if (txtphnnumber.Text == "")
{
txtphnnumber.Text = "None";
}
Person p1 = new();
p1.Pname = txtName.Text;
p1.Plastname = txtLastname.Text;
p1.Pnumber = txtphnnumber.Text;
p1.Page = int.Parse(numAge.Value.ToString());
switch (_role)
{
case -1:
{
p1.Prole = "Student";
break;
}
case 0:
{
p1.Prole = "Teacher";
break;
}
case 1:
{
p1.Prole = "Employee";
break;
}
}
Data.plist[Data.row] = p1;
Data.row++;
this.Close();
}
}اینطوری دیگه نیازی به ایجاد لیست جدید نیست و اطلاعات لیست قبلی نمیپره
بسیار عالی بود