我要做的是从数据库中检索患者的详细信息,然后根据在文本框中输入的值,它将更新患者的详细信息,但如果文本框为空,我将现有详细信息分配给我认为的文本框相当愚蠢。
你会建议我做些什么来改进下面的代码以使其更高效或更少重复?
代码:
client = new ServiceReference1.Service1Client();
pat = client.GetPatientbyID(txtUpdatePatientID.Text);
grdView.DataSource = pat;
grdView.DataBind();
if (txtUpdateForename.Text == "")
txtUpdateForename.Text = pat[0].Forename;
if (txtUpdateSurname.Text == "")
txtUpdateSurname.Text = pat[0].Surname;
if (txtUpdateStreet.Text == "")
txtUpdateStreet.Text = pat[0].Street;
if (txtUpdateTown.Text == "")
txtUpdateTown.Text = pat[0].Town;
if (txtUpdateCity.Text == "")
txtUpdateCity.Text = pat[0].City;
if (txtUpdateDOB.Text == "")
txtUpdateDOB.Text = pat[0].DOB.ToString();
if (txtUpdateHouseNumber.Text == "")
txtUpdateHouseNumber.Text = pat[0].House_number;
if (txtUpdateMobile.Text == "")
txtUpdateMobile.Text = pat[0].Mobile;
client.UpdateAllDetails(txtUpdatePatientID.Text, txtUpdateForename.Text,
txtUpdateSurname.Text, txtUpdateStreet.Text, txtUpdateTown.Text,
txtUpdateCity.Text, Convert.ToDateTime(txtUpdateDOB.Text),
txtUpdateHouseNumber.Text, txtUpdateMobile.Text);
client.Close();
GetPatients(txtUpdatePatientID);