我构建了一个 WinForm 应用程序,可以很好地与在线存储的 SQL 数据库配合使用。我现在正试图转移到 asp.net 应用程序。在学习了构建 WinForm 应用程序所需的一切之后,我对新的学习曲线感到沮丧!
这是一个基本的应用程序,它有一个包含数据库中所有人的列表框。列表框将 NameLast + ', ' + NameFirst 组合显示为 NameFull,显示类似“Smith, John”的内容。当用户选择一个人时,文本框应显示相关信息。一旦我开始它应该很容易......我如何构建一个 OnSelectedChanged 类型的命令来填充文本框。在此示例中,我将有四 (4) 个文本框:NameFirstTxt、NameMiddleTxt、NameLastTxt 和 RecordIDTxt。
我附上了所选索引更改事件期间使用的 WinForm 应用程序的代码。任何建议和评论(好的或坏的)都会有所帮助。先感谢您。
private void peopleDetailsDirectoryLbx_SelectedIndexChanged(object sender, EventArgs e)
{
peopleDirectoryGbx.Text = "People Records : " + peopleDetailsDirectoryLbx.Items.Count.ToString();
DataRowView PeopleRow = peopleDetailsDirectoryLbx.SelectedItem as DataRowView;
if (PeopleRow != null && PeopleRow.Row != null && PeopleRow.Row.ItemArray != null)
{
DataRow row = PeopleRow.Row;
if (row.ItemArray.Count() > 0)
try
{
peopleDetailsIDTxt.Text = Convert.ToString(row["ID"]).ToString();
try
{
peopleDetailsPhotoImg.Load(@"http://www.officertech.com/PeoplePhotoBase/" + peopleDetailsIDTxt.Text + ".jpg");
}
catch
{
peopleDetailsPhotoImg.Load(@"http://www.officertech.com/PeoplePhotoBase/NoPhoto.jpg");
}
if (Convert.ToString(row["Active"].ToString()) == "True")
{
peopleDetailsActiveChk.Checked = true;
}
else
{
peopleDetailsActiveChk.Checked = false;
}
peopleDetailsNameFirstTxt.Text = (row["NameFirst"]).ToString();
peopleDetailsNameMiddleTxt.Text = (row["NameMiddle"]).ToString();
peopleDetailsNameLastTxt.Text = (row["NameLast"]).ToString();
peopleDetailsNameAka1Txt.Text = (row["NameAKA1"]).ToString();
peopleDetailsNameAka2Txt.Text = (row["NameAKA2"]).ToString();
peopleDetailsDobTxt.Text = Convert.ToDateTime(row["DOB"]).ToShortDateString();
peopleDetailsRaceCbx.Text = (row["Race"]).ToString();
peopleDetailsGenderCbx.Text = (row["Gender"]).ToString();
peopleDetailsAddStreetNumTxt.Text = (row["AddStreetNum"]).ToString();
peopleDetailsStreetNameCbx.Text = (row["AddStreetName"]).ToString();
peopleDetailsAddCityTxt.Text = (row["AddCity"]).ToString();
peopleDetailsAddStateTxt.Text = (row["AddState"]).ToString();
peopleDetailsAddZipTxt.Text = (row["AddZip"]).ToString();
peopleDetailsAddCountyTxt.Text = (row["AddCounty"]).ToString();
peopleDetailsDriverLicenseTxt.Text = (row["DriverLicense"]).ToString();
peopleDetailsDriverLicenseStateTxt.Text = (row["DriverLicenseState"]).ToString();
peopleDetailsSSNTxt.Text = (row["SSN"]).ToString();
peopleDetailsTrackingLab.ForeColor = Color.Black;
if (row["Tracking"].ToString() == "True")
{
peopleDetailsTrackingYesRad.Checked = true;
peopleDetailsTrackingLab.ForeColor = Color.Red;
}
else
{
peopleDetailsTrackingNoRad.Checked = true;
peopleDetailsTrackingLab.ForeColor = Color.Black;
}
peopleDetailsPhysIDColorHairCbx.Text = (row["PhysIDColorHair"].ToString());
peopleDetailsPhysIDColorEyesCbx.Text = (row["PhysIDColorEyes"].ToString());
peopleDetailsPhysIDWeightTxt.Text = (row["PhysIDWeight"].ToString());
peopleDetailsPhysIDHeightTxt.Text = (row["PhysIDHeight"].ToString());
peopleDetailsPhysIDScarTattTxt.Text = (row["PhysIDScarTatt"].ToString());
//////
if (Convert.ToString(row["School"].ToString()) == "True")
{
peopleDetailsSchoolRad.Checked = true;
}
else
{
peopleDetailsSchoolRad.Checked = false;
}
//////
if (Convert.ToString(row["Work"].ToString()) == "True")
{
peopleDetailsWorkRad.Checked = true;
}
else
{
peopleDetailsWorkRad.Checked = false;
}
//////
if (Convert.ToString(row["ciAssault"].ToString()) == "True")
{
peopleCIAssaultChk.Checked = true;
peopleCIAssaultChk.ForeColor = Color.Red;
}
else
{
peopleCIAssaultChk.Checked = false;
peopleCIAssaultChk.ForeColor = Color.Black;
}
//////
peopleDetailsSchoolWorkNameTxt.Text = (row["SchoolWorkName"]).ToString();
//////
if (Convert.ToString(row["ciBattery"].ToString()) == "True")
{
peopleCIBatteryChk.Checked = true;
peopleCIBatteryChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryChk.Checked = false;
peopleCIBatteryChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBatteryAgg"].ToString()) == "True")
{
peopleCIBatteryAggChk.Checked = true;
peopleCIBatteryAggChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryAggChk.Checked = false;
peopleCIBatteryAggChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBatteryDVR"].ToString()) == "True")
{
peopleCIBatteryDVRChk.Checked = true;
peopleCIBatteryDVRChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryDVRChk.Checked = false;
peopleCIBatteryDVRChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBatteryLEO"].ToString()) == "True")
{
peopleCIBatteryLEOChk.Checked = true;
peopleCIBatteryLEOChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryLEOChk.Checked = false;
peopleCIBatteryLEOChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBurglary"].ToString()) == "True")
{
peopleCIBurglaryChk.Checked = true;
peopleCIBurglaryChk.ForeColor = Color.Red;
}
else
{
peopleCIBurglaryChk.Checked = false;
peopleCIBurglaryChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciChildCrimes"].ToString()) == "True")
{
peopleCIChildCrimeChk.Checked = true;
peopleCIChildCrimeChk.ForeColor = Color.Red;
}
else
{
peopleCIChildCrimeChk.Checked = false;
peopleCIChildCrimeChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciCrimMisch"].ToString()) == "True")
{
peopleCICrimMischChk.Checked = true;
peopleCICrimMischChk.ForeColor = Color.Red;
}
else
{
peopleCICrimMischChk.Checked = false;
peopleCICrimMischChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDealStolen"].ToString()) == "True")
{
peopleCIDealStolenChk.Checked = true;
peopleCIDealStolenChk.ForeColor = Color.Red;
}
else
{
peopleCIDealStolenChk.Checked = false;
peopleCIDealStolenChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDisorderly"].ToString()) == "True")
{
peopleCIDisorderlyChk.Checked = true;
peopleCIDisorderlyChk.ForeColor = Color.Red;
}
else
{
peopleCIDisorderlyChk.Checked = false;
peopleCIDisorderlyChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDrugs"].ToString()) == "True")
{
peopleCIDrugsChk.Checked = true;
peopleCIDrugsChk.ForeColor = Color.Red;
}
else
{
peopleCIDrugsChk.Checked = false;
peopleCIDrugsChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDUI"].ToString()) == "True")
{
peopleCIDUIChk.Checked = true;
peopleCIDUIChk.ForeColor = Color.Red;
}
else
{
peopleCIDUIChk.Checked = false;
peopleCIDUIChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDWLSR"].ToString()) == "True")
{
peopleCIDWLSRChk.Checked = true;
peopleCIDWLSRChk.ForeColor = Color.Red;
}
else
{
peopleCIDWLSRChk.Checked = false;
peopleCIDWLSRChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciFraud"].ToString()) == "True")
{
peopleCIFraudChk.Checked = true;
peopleCIFraudChk.ForeColor = Color.Red;
}
else
{
peopleCIFraudChk.Checked = false;
peopleCIFraudChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciHomicide"].ToString()) == "True")
{
peopleCIHomicideChk.Checked = true;
peopleCIHomicideChk.ForeColor = Color.Red;
}
else
{
peopleCIHomicideChk.Checked = false;
peopleCIHomicideChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciLewdLasciv"].ToString()) == "True")
{
peopleCILewdLascivChk.Checked = true;
peopleCILewdLascivChk.ForeColor = Color.Red;
}
else
{
peopleCILewdLascivChk.Checked = false;
peopleCILewdLascivChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciMental"].ToString()) == "True")
{
peopleCIMentalChk.Checked = true;
peopleCIMentalChk.ForeColor = Color.Red;
}
else
{
peopleCIMentalChk.Checked = false;
peopleCIMentalChk.ForeColor = Color.Black;
}
//////
peopleCIProbationLab.ForeColor = Color.Black;
if (row["ciProbation"].ToString() == "True")
{
peopleCIProbationYesRad.Checked = true;
peopleCIProbationLab.ForeColor = Color.Red;
}
else
{
peopleCIProbationNoRad.Checked = true;
peopleCIProbationLab.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciResisting"].ToString()) == "True")
{
peopleCIResistingChk.Checked = true;
peopleCIResistingChk.ForeColor = Color.Red;
}
else
{
peopleCIResistingChk.Checked = false;
peopleCIResistingChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciRobbery"].ToString()) == "True")
{
peopleCIRobberyChk.Checked = true;
peopleCIRobberyChk.ForeColor = Color.Red;
}
else
{
peopleCIRobberyChk.Checked = false;
peopleCIRobberyChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciSexCrime"].ToString()) == "True")
{
peopleCISexCrimeChk.Checked = true;
peopleCISexCrimeChk.ForeColor = Color.Red;
}
else
{
peopleCISexCrimeChk.Checked = false;
peopleCISexCrimeChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciShoplift"].ToString()) == "True")
{
peopleCIShopLiftChk.Checked = true;
peopleCIShopLiftChk.ForeColor = Color.Red;
}
else
{
peopleCIShopLiftChk.Checked = false;
peopleCIShopLiftChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciTheft"].ToString()) == "True")
{
peopleCITheftChk.Checked = true;
peopleCITheftChk.ForeColor = Color.Red;
}
else
{
peopleCITheftChk.Checked = false;
peopleCITheftChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciTraffic"].ToString()) == "True")
{
peopleCITrafficChk.Checked = true;
peopleCITrafficChk.ForeColor = Color.Red;
}
else
{
peopleCITrafficChk.Checked = false;
peopleCITrafficChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciTrespass"].ToString()) == "True")
{
peopleCITrespassChk.Checked = true;
peopleCITrespassChk.ForeColor = Color.Red;
}
else
{
peopleCITrespassChk.Checked = false;
peopleCITrespassChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciWarrants"].ToString()) == "True")
{
peopleCIWarrantsChk.Checked = true;
peopleCIWarrantsChk.ForeColor = Color.Red;
}
else
{
peopleCIWarrantsChk.Checked = false;
peopleCIWarrantsChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciWeapons"].ToString()) == "True")
{
peopleCIWeaponsChk.Checked = true;
peopleCIWeaponsChk.ForeColor = Color.Red;
}
else
{
peopleCIWeaponsChk.Checked = false;
peopleCIWeaponsChk.ForeColor = Color.Black;
}
//////
CalcAge_People();
//arrestFieldsFill();
}
catch (Exception ex)
{
MessageBox.Show("Problem Locating Person Information" + ex, "CARDS 2012 | Message Center", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}