/// <summary> /// 計算するボタン押下時イベントハンドラ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCalculate_Click(object sender, EventArgs e) { int excludingTaxPrice; Result result = DovalidationExcludingTaxPrice(out excludingTaxPrice); if (!result.IsSuccess) { MessageBox.Show(result.ErrorMessage); return; } int IncludingTaxPrice = this.CalculateIncludingTaxPrice(excludingTaxPrice); int numberOfPeople; result = DovalidationNumberOfPeople(out numberOfPeople); if (!result.IsSuccess) { MessageBox.Show(result.ErrorMessage); return; } SplitCost splitCost = this.CalculatePricePerPerson(IncludingTaxPrice, numberOfPeople); this.SetView(splitCost); }
/// <summary> /// 一人あたりの金額を算出します /// </summary> /// <param name="includingTaxPrice">消費税込み金額</param> /// <param name="numberOfPeople">人数</param> /// <returns>割り勘</returns> private SplitCost CalculatePricePerPerson(int includingTaxPrice, int numberOfPeople) { SplitCost splitCost = new SplitCost(); splitCost.PricePerPeson = includingTaxPrice / numberOfPeople; splitCost.Remainder = includingTaxPrice % numberOfPeople; return(splitCost); }
private void SetView(SplitCost splitCost) { this.lblPerPeoplePrice.Text = splitCost.PricePerPeson.ToString() + "円"; this.lblRemainderPrice.Text = splitCost.Remainder.ToString(); }