オンラインで保存された SQL データベースで正常に動作する WinForm アプリを作成しました。現在、asp.net アプリに移行しようとしています。WinForm アプリを構築するために必要なことをすべて学んだ後、新しい学習曲線に不満を感じています!
これは、データベース内のすべての人を含むリストボックスを持つ基本的なアプリです。リストボックスには、結合された NameLast + ', ' + NameFirst が NameFull として表示され、「Smith, John」のように表示されます。ユーザーが人物を選択すると、テキストボックスに関連情報が表示されます。しかし、一度始めたら簡単なはずです...テキストボックスを埋めるための OnSelectedChanged タイプのコマンドを作成するにはどうすればよいですか。この例では、NameFirstTxt、NameMiddleTxt、NameLastTxt、および RecordIDTxt の 4 つのテキスト ボックスがあります。
選択したインデックス変更イベント中に使用される 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);
}
}
}