別のフォームのユーザー入力からの値を保持することを目的としたフォームにいくつかのラベルがあるため、プロパティウィンドウではなく、プログラムでラベルテキストを設定する必要があります。私はこれを行いましたが、問題はデータが他の形式に渡されていないように見えることです。デバッグを実行しようとしましたが、ソリューションがロックされ、タスクマネージャーからシャットダウンする必要があります。2番目のフォームを開くメソッドにブレークポイントを設定しました。私の考えでは、プログラムがメソッドをステップスルーするときに、プロパティが正しい情報で埋められているかどうかを確認できました。残念ながら、メソッドをステップスルーする代わりに、フォームを開いてロックするだけです
誰かが私のコードを見て、どこが間違っているのか教えてくれることを願っています。
ユーザーがすべてのデータを入力した後、ユーザーはボタンをクリックしてデータをデータベースに保存し、ユーザーに別のボタンをクリックして別のフォームに移動するように求めるメッセージを表示します。この部分は正常に機能します。そのアクションのイベントハンドラーコードは次のとおりです。
private void btnEnterNutritionInfo_Click(object sender, EventArgs e)
{
//call methods from NutritionBOL class to input calculated
//data into textboxes
this.txtRMR.Text = Convert.ToString(busObject.GetRMRdata(
busObject.BodyWeight));
this.txtDailyActivityBurn.Text = Convert.ToString(
busObject.GetDailyActivityBurnData(
busObject.RestingMetabolicRate));
this.txtEnergyAmount.Text = Convert.ToString(
busObject.GetEnergyAmount(
busObject.RestingMetabolicRate, busObject.DailyActivityBurn));
this.txtYourNutritionLevel.Text = busObject.GetNutritionLevel(
busObject.DailyEnergyAmount);
//convert text box data and assign to variables
busObject.BodyFatStart = double.Parse(this.txtBodyFatStart.Text);
busObject.BodyFatEndOfPhase1 = double.Parse(this.txtBodyFatEndOfPhase1.Text);
busObject.BodyFatEndOfPhase2 = double.Parse(this.txtbodyFatEndOfPhase2.Text);
busObject.BodyFatEndOfPhase3 = double.Parse(this.txtbodyFatEndOfPhase3.Text);
busObject.BodyWeight = double.Parse(this.txtBodyWeight.Text);
busObject.RestingMetabolicRate = double.Parse(this.txtRMR.Text);
busObject.DailyActivityBurn = double.Parse(this.txtDailyActivityBurn.Text);
busObject.DailyEnergyAmount = double.Parse(this.txtEnergyAmount.Text);
busObject.BodyFatStartNotes = this.txtStartNotes.Text;
busObject.BodyFatEndOfPhase1Notes = this.txtBodyFatEndOfPhase1Notes.Text;
busObject.BodyFatEndOfPhase2Notes = this.txtBodyFatEndOfPhase2Notes.Text;
busObject.BodyFatEndOfPhase3Notes = this.txtBodyFatEndOfPhase3Notes.Text;
busObject.NutritionLevel = this.txtYourNutritionLevel.Text;
//call method to save input data
busObject.SaveData();
//set visibility to true
txtRMR.Visible = true;
txtDailyActivityBurn.Visible = true;
txtEnergyAmount.Visible = true;
txtYourNutritionLevel.Visible = true;
lblYourNutritionLevel.Visible = true;
}
それが終了したら、ユーザーはボタンをクリックして他のフォームに移動します。この時点で、ラベルデータは他のフォームに渡されることになっています。もう1つのフォームが開きますが、ラベルデータが入力されていません。ボタンクリックのイベントハンドラーは次のとおりです。
private void btnMeasurementData_Click(object sender, EventArgs e)
{
//assign text boxes to properties
this.BodyFatB4 = this.txtBodyFatStart.Text;
this.BodyWeightB4 = this.txtBodyWeight.Text;
this.BodyFatAfter = this.txtBodyFatEndOfPhase1.Text;
this.BodyWeightAfter = this.txtBodyWeight.Text;
//instantiate an object from the MeasurementsBOL to pass data
MeasurementsForm measurementsForm = new MeasurementsForm();
measurementsForm.BodyFatB4 = this.BodyFatB4;
measurementsForm.BodyWeightB4 = this.BodyWeightB4;
measurementsForm.BodyFatAfter = this.BodyFatAfter;
measurementsForm.BodyWeightAfter = this.BodyWeightAfter;
//StartDate data is just being passed through to the
//MeasurementsForm from the FitnessTest form
measurementsForm.StartDate = this.StartDate;
this.Hide();
//method call to open MeasurementsForm
busObject.GoToMeasurementsForm(this.StartDate, this.BodyFatB4,
this.BodyWeightB4, this.BodyFatAfter, this.BodyWeightAfter);
}
MeasurementsFormを開くためのメソッド呼び出しのコードは次のとおりです。
public void GoToMeasurementsForm(string startDate, string bodyFatB4,
string bodyWeightB4, string bodyFatAfter, string bodyWeightAfter)
{
MeasurementsForm f2;
//logic to decide what to do if an instance is not already instanitated
if (Application.OpenForms["MeasurementsForm"] == null)
{
f2 = new MeasurementsForm();
f2.StartDate = startDate;
f2.BodyFatB4 = bodyFatB4;
f2.BodyWeightB4 = bodyWeightB4;
f2.BodyFatAfter = bodyFatAfter;
f2.BodyWeightAfter = bodyWeightAfter;
f2.Name = "MeasurementsForm";
}
//logic to decide what to do if an instance is not already instantiated
else
{
f2 = Application.OpenForms["MeasurementsForm"] as MeasurementsForm;
f2.StartDate = startDate;
f2.BodyFatB4 = bodyFatB4;
f2.BodyWeightB4 = bodyWeightB4;
f2.BodyFatAfter = bodyFatAfter;
f2.BodyWeightAfter = bodyWeightAfter;
}
f2.Show();
}
これは、ボタンがクリックされたときに開くフォームのコードです。
public partial class MeasurementsForm : Form
{
//declare variables
string bodyFatB4 = "",
bodyWeightB4 = "",
bodyFatAfter = "",
bodyWeightAfter = "",
startDate = "";
//instantiate object from MeasurementsBOL class
MeasurementsBOL busObject = new MeasurementsBOL();
//default constructor
public MeasurementsForm()
{
InitializeComponent();
busObject.InitializeConnection();
}
//properties for variables
public string BodyFatB4
{
get { return bodyFatB4; }
set { bodyFatB4 = value; }
}
public string BodyWeightB4
{
get { return bodyWeightB4; }
set { bodyWeightB4 = value; }
}
public string BodyFatAfter
{
get { return bodyFatAfter; }
set { bodyFatAfter = value; }
}
public string BodyWeightAfter
{
get { return bodyWeightAfter; }
set { bodyWeightAfter = value; }
}
public string StartDate
{
get { return startDate; }
set { startDate = value; }
}
private void Form1_Load(object sender, System.EventArgs e)
{
//pass text data from nutrition form to labels
this.lblBodyFatB4FromNutrition.Text = this.BodyFatB4;
this.lblWeightB4FromNutrition.Text = this.BodyWeightB4;
this.lblBodyFatAfterFromNutrition.Text = this.BodyFatAfter;
this.lblWeightAfterFromNutrition.Text = this.BodyWeightAfter;
}
//event handler for B4 input data
private void btnEnterMeasurementsB4_Click(object sender, EventArgs e)
{
//convert input data and assign to variables
busObject.BodyFatB4 = double.Parse(lblBodyFatB4FromNutrition.Text);
busObject.BodyWeightB4 = double.Parse(lblWeightB4FromNutrition.Text);
busObject.ChestMeasurementB4 = double.Parse(txtChestB4.Text);
busObject.WaistMeasurementB4 = double.Parse(txtWaistB4.Text);
busObject.HipsMeasurementB4 = double.Parse(txtHipsB4.Text);
busObject.RightThighB4 = double.Parse(txtRightThighB4.Text);
busObject.LeftThighB4 = double.Parse(txtLeftThighB4.Text);
busObject.RightArmB4 = double.Parse(txtRightArmB4.Text);
busObject.LeftArmB4 = double.Parse(txtLeftArmB4.Text);
//call method to save input data
busObject.SaveB4Data();
//clear text boxes of data
this.txtChestB4.Clear();
this.txtWaistB4.Clear();
this.txtHipsB4.Clear();
this.txtRightThighB4.Clear();
this.txtLeftThighB4.Clear();
this.txtRightArmB4.Clear();
this.txtLeftArmB4.Clear();
//close form
this.Close();
}
//event handler for after input data
private void btnEnterMeasurementsAfter_Click(object sender, EventArgs e)
{
//convert input data and assign to variables
busObject.BodyFatAfter = double.Parse(lblBodyFatAfterFromNutrition.Text);
busObject.BodyWeightAfter = double.Parse(lblWeightAfterFromNutrition.Text);
busObject.ChestMeasurementAfter = double.Parse(txtChestAfter.Text);
busObject.WaistMeasurementAfter = double.Parse(txtWaistAfter.Text);
busObject.HipMeasurementAfter = double.Parse(txtHipsAfter.Text);
busObject.RightThighAfter = double.Parse(txtRightThighAfter.Text);
busObject.LeftThighAfter = double.Parse(txtLeftThighAfter.Text);
busObject.RightArmAfter = double.Parse(txtRightArmAfter.Text);
busObject.LeftArmAfter = double.Parse(txtLeftArmAfter.Text);
//call method to save input data
busObject.SaveAfterData();
//clear text boxes of data
this.txtChestAfter.Clear();
this.txtWaistAfter.Clear();
this.txtHipsAfter.Clear();
this.txtRightThighAfter.Clear();
this.txtLeftThighAfter.Clear();
this.txtRightArmAfter.Clear();
this.txtLeftArmAfter.Clear();
//close form
this.Close();
}
//event handler to open schedule form and hide this form
private void btnClickForSchedule_Click(object sender, EventArgs e)
{
this.Hide();
busObject.BackToMainSchedule(this.StartDate);
}
}