【发布时间】:2017-10-17 17:27:17
【问题描述】:
我目前正在用 Visual C# 创建一个 Web 表单,该应用程序是一个财务计算器。
下面的大部分代码都是无关的,只是为了显示整个页面,如标题中所述,我希望能够从网络表单上的日历中选择一个日期,然后从那里获取日期第一个星期一并将其显示在标签中。我目前可以选择一个日期并显示它。
namespace FinanceCalc
{
public partial class About : Page
{
decimal NumPmt = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Price_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(Price.Text))
{
Response.Write("Please enter the Vehicle Price");
}
}
protected void DepositCalc_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(Price.Text))
{
Response.Write("Please enter the Vehicle Price");
}
else
{
decimal price = Convert.ToDecimal(Price.Text);
decimal depositamount = (price / 100 * 15);
Deposit.Text = depositamount.ToString();
}
}
protected void FinanceCalc_Click(object sender, EventArgs e)
{
// This works out if all required boxes have been populated and displays a warning message if they have not been.
if (String.IsNullOrEmpty(Price.Text))
{
Response.Write("Please enter the Vehicle Price.");
}
if (String.IsNullOrEmpty(Deposit.Text))
{
Response.Write("Please calculate the deposit.");
}
if (String.IsNullOrEmpty(Length.Text))
{
Response.Write("Please enter the finance length.");
}
if (Convert.ToInt32(Length.Text) < 1)
{
Response.Write("Please choose between 1, 2 and 3 years.");
}
if (Convert.ToInt32(Length.Text) > 3)
{
Response.Write("Please choose between 1, 2 and 3 years.");
}
else
{
// This works out payment amounts
NumPmt = 12 * int.Parse(Length.Text);
decimal price = Convert.ToDecimal(Price.Text);
decimal deposit = Convert.ToDecimal(Deposit.Text);
decimal MonthlyPayments = (price - deposit) / NumPmt;
// This populates the Finance Info text box with the information
Results.Text = "Deposit Amount - £" + Deposit.Text + Environment.NewLine + "Arrangement Fee - £88" + Environment.NewLine + "Completion Fee - £20" + Environment.NewLine + "Number of Payments: " + NumPmt
+ Environment.NewLine + "Delivery Date: " + DeliveryDate.SelectedDate + Environment.NewLine + "First Payment Date: " + Environment.NewLine + "First Payment Amount: £" + MonthlyPayments + " plus your £88 Arrangement Fee."
+ Environment.NewLine + "Monthly Payments: £" + MonthlyPayments + " for " + (12 * int.Parse(Length.Text) - 2) + " months." + Environment.NewLine + "Final Payment Amount: £" + MonthlyPayments + " plus your £20 Completion Fee";
}
}
protected void Reset_Click(object sender, EventArgs e)
{
//This resets all of the information boxes, allowing the user to start again
Price.Text = "";
Deposit.Text = "";
Results.Text = "";
}
protected void Length_TextChanged(object sender, EventArgs e)
{
// This works out how many monthly payments will be made.
NumPmt = 12 * int.Parse(Length.Text);
}
}
}
【问题讨论】:
-
如果用户选择一个月的第一个星期一会发生什么?你是显示那个还是下个月的?
-
查看此帖子并获取该月的第一天..然后从那里您可以检查一周中的某一天是否是星期一..星期日...等stackoverflow.com/questions/25233520/…这实际上不是和你想象的一样难.. 你可以在 .C# 中使用很多日期和月份函数,stackoverflow.com/questions/25233520/…