我試圖組織標籤和文本框在C#我有兩個功能:如何管理在C#標籤
private void BtnKaydet_Click(object sender, EventArgs e)
{
_service = new Client.BioAuthenticationService.BioAuthenticationService();
int warningcase = 0;
if ((string.IsNullOrEmpty(TbTcNo.Text) || string.IsNullOrWhiteSpace(TbTcNo.Text)))
{
warningcase = 1;
TextLabelManagement(warningcase);
}
else if ((string.IsNullOrEmpty(TbId.Text) || string.IsNullOrWhiteSpace(TbId.Text)))
{
warningcase = 2;
TextLabelManagement(warningcase);
}
else if ((string.IsNullOrEmpty(TbName.Text) || string.IsNullOrWhiteSpace(TbName.Text)))
{
warningcase = 3;
TextLabelManagement(warningcase);
}
else if ((string.IsNullOrEmpty(TbSurname.Text) || string.IsNullOrWhiteSpace(TbSurname.Text)))
{
warningcase = 4;
TextLabelManagement(warningcase);
}
else if ((string.IsNullOrEmpty(TbDepartment.Text) || string.IsNullOrWhiteSpace(TbDepartment.Text)))
{
warningcase = 5;
TextLabelManagement(warningcase);
}
else
{
if (_imageIndex == 3)
{
bool enrollResult = _service.CheckAndEnrollUser(image1, image2, image3, 300, 6);
}
else
{
warningcase = 6;
TextLabelManagement(warningcase);
}
}
}
在這裏,我寫的情況下,如果文本框爲空,我會給錯誤信息,以填補他們。這是我的情況:
private void TextLabelManagement(int cases)
{
switch (cases)
{
case 1:
LblWarning.Visible = true;
LblWarning.Text = "* Lütfen Bu Alanları Doldurunuz..";
LblTcNo.Text = "* TC No";
LblTcNo.ForeColor = System.Drawing.Color.Red;
LblWarning.ForeColor = System.Drawing.Color.Red;
break;
case 2:
LblWarning.Visible = true;
LblWarning.Text = "* Lütfen Bu Alanları Doldurunuz..";
LblId.Text = "* ID";
LblId.ForeColor = System.Drawing.Color.Red;
LblWarning.ForeColor = System.Drawing.Color.Red;
break;
case 3:
LblWarning.Visible = true;
LblWarning.Text = "* Lütfen Bu Alanları Doldurunuz..";
LblName.Text = "* Ad";
LblName.ForeColor = System.Drawing.Color.Red;
LblWarning.ForeColor = System.Drawing.Color.Red;
break;
case 4:
LblWarning.Visible = true;
LblWarning.Text = "* Lütfen Bu Alanları Doldurunuz..";
LblSurname.Text = "* Soyad";
LblSurname.ForeColor = System.Drawing.Color.Red;
LblWarning.ForeColor = System.Drawing.Color.Red;
break;
case 5:
LblWarning.Visible = true;
LblWarning.Text = "* Lütfen Bu Alanları Doldurunuz..";
LblDepartment.Text = "* Soyad";
LblDepartment.ForeColor = System.Drawing.Color.Red;
LblWarning.ForeColor = System.Drawing.Color.Red;
break;
case 6:
LblFingerWarning.Visible = true;
LblFingerWarning.Text = "Lütfen Parmak İzinizi Üç Kez Veriniz.";
LblFingerWarning.ForeColor = System.Drawing.Color.Red;
break;
default:
break;
}
}
但是,當用戶點擊保存按鈕,它將進入第一個IF條件。然後,否則,如果..但這是我的問題。我如何組織這些項目。例如,如果用戶沒有填寫所有的框,我想給他所有的警告信息不是一步一步的。
非常感謝。 – goGud