我希望客户能够选择租赁开始和结束日期。然后计算然后在文本框中输入#天数,然后使用在另一个计算中在文本框中输入的数字。
我有dtpStartDate,dtpReturnDate& txtDays 这将是我的btnCalc_Click事件处理程序下的代码的一部分。 我是否需要声明StartDate& ReturnDate首先作为变量? 我有一个可变的日子,我已经在另一个计算中使用。
/* This method calculates vehicle cost, add ons, discount and rental total cost
*/
private void btnCalculate_Click(object sender, EventArgs e) {
decimal addItemsCost = 0.0m; //Cost of the selected additional items
decimal rentalTotal; //Total cost of the rental
int days; //Number of rental days
decimal discountTotal = 0.0m; //Total discount if promotion criteria met
//Transfer inputs to variables
days = int.Parse(vTools.unformat(txtDays.Text));
//Vehicle cost determined by rdoVehicle Check Changed
//Calculate additional item cost
if (chkDvd.Checked) addItemsCost += DVDCOST;
if (chkAir.Checked) addItemsCost += AIRCOST;
if (chkCarSeat.Checked) addItemsCost += CARSEATCOST;
if (chkInsurance.Checked) addItemsCost += INSURANCECOST;
//Calculate the total cost of add on's and total rental cost
if (days >= PROMODAYS && rdoLuxury.Checked) {
rentalTotal = ((vehicleCost * days) + addItemsCost - discountTotal );
discountTotal = rentalTotal * PDISCOUNT;
} else {
rentalTotal = (vehicleCost * days) + addItemsCost;
}//end if else
rentalTotal = (vehicleCost * days) + addItemsCost - discountTotal;
答案 0 :(得分:0)
将文本框中的两个日期解析为DateTime
个对象EndDate
和StartDate
,然后计算间隔:
var startDate = DateTime.Parse(myStartDateTextBox.Text);
var endDate = DateTime.Parse(myEndDateTextBox.Text);
myIntervalTextBox.Text = (endDate - startDate).TotalDays.ToString();