我已经完成了一个我已经工作了三个多月的项目。这是我制作的第一个程序,所以它可能不是最干净的代码,但大部分都是有效的。我现在唯一的问题是让时间在特定时间之间排队(在这个例子中是早上8点和下午3点)。我在这些时间之外的时间而不是在里面。我目前的代码是
if (DateTime.Now.AddMinutes(timetoadd).Hour < 8)
{
MessageBox.Show("Too early_Button Pressed");
var now = DateTime.Now;
var today8am = now.AddDays(0).Date.AddHours(8);
double totalHours = (today8am - now).TotalHours;
MessageBox.Show("totalHours=" + totalHours);
double hourstoadd = 0;// = timetoadd / 60;
MessageBox.Show("TTA = " + timetoadd.ToString());
do
{
hourstoadd++;
if (DateTime.Now.AddHours(hourstoadd).Hour == 15)
{
hourstoadd = hourstoadd + 17;
}
timetoadd = timetoadd - 60;
System.Diagnostics.Debug.WriteLine(hourstoadd.ToString());
}
while (timetoadd >= 60);
MessageBox.Show("TTA2 = " + timetoadd.ToString());
do
{
hourstoadd = hourstoadd - 8;
daystoadd++;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
}
while (hourstoadd > 8);
if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
EstimatedCompleteDate = DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).ToString();
MessageBox.Show("ETA = " + EstimatedCompleteDate);
}
else if (DateTime.Now.AddMinutes(timetoadd).Hour > 15)
{
MessageBox.Show("Too Late_Button Pressed");
var now = DateTime.Now;
var tomorrow8am = now.AddDays(1).Date.AddHours(8);
double totalHours = (tomorrow8am - now).TotalHours;
MessageBox.Show("totalHours=" + totalHours);
double hourstoadd = 0;// = timetoadd / 60;
MessageBox.Show("TTA = " + timetoadd.ToString());
do
{
hourstoadd++;
if (DateTime.Now.AddHours(hourstoadd).Hour == 15)
{
hourstoadd = hourstoadd + 17;
}
timetoadd = timetoadd - 60;
System.Diagnostics.Debug.WriteLine(hourstoadd.ToString());
}
while (timetoadd >= 60);
MessageBox.Show("TTA2 = " + timetoadd.ToString());
do
{
hourstoadd = hourstoadd - 8;
daystoadd++;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
}
while (hourstoadd > 8);
if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
EstimatedCompleteDate = DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).ToString();
MessageBox.Show("ETA = " + EstimatedCompleteDate);
}
else if (DateTime.Now.AddMinutes(timetoadd).Hour <= 15 && DateTime.Now.AddMinutes(timetoadd).Hour >= 8)
{
MessageBox.Show("Regular hours");
var now = DateTime.Now;
var tomorrow8am = now.AddDays(1).Date.AddHours(8);
double totalHours = 0;
MessageBox.Show("totalHours=" + totalHours);
double hourstoadd = 0 + now.Minute;// = timetoadd / 60;
MessageBox.Show("TTA = " + timetoadd.ToString());
do
{
hourstoadd++;
if (DateTime.Now.AddHours(hourstoadd).Hour == 15)
{
hourstoadd = hourstoadd + 17;
}
timetoadd = timetoadd - 60;
System.Diagnostics.Debug.WriteLine(hourstoadd.ToString());
}
while (timetoadd >= 60);
MessageBox.Show("TTA2 = " + timetoadd.ToString());
do
{
hourstoadd = hourstoadd - 8;
daystoadd++;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
}
while (hourstoadd > 8);
if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
EstimatedCompleteDate = DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).ToString();
MessageBox.Show("ETA = " + EstimatedCompleteDate);
}
timetoadd
= sum + current_ticket_time in minutes
。
sum
= all previous ticket times
。
我正在使用Messagebox为我提供一种即时反馈。
答案 0 :(得分:0)
另一个晚上,我能够得到一个适合所需内容的脚本。
var soonh = 0;
var now = DateTime.Now;
var soonm = 0;
double minutestoadd = timetoadd;
int hourstoadd = 0;
if (minutestoadd >= 60)
{
do
{
minutestoadd = minutestoadd - 60;
hourstoadd++;
}
while (minutestoadd > 60);
}
soonh = 6 - (Convert.ToInt32(now.Hour));
soonm = 60 - ((Convert.ToInt32(now.Minute)));
if (soonm < 0)
{
var temp = soonm;
soonm = 0;
soonh = soonh - 1;
soonm = 60 + temp;
Console.WriteLine("Sample");
}
double totalmin = soonm + now.Minute + minutestoadd;
if (totalmin >= 60)
{
do
{
if (totalmin >= 60)
{
totalmin = totalmin - 60;
hourstoadd = hourstoadd + 1;
}
}
while (totalmin >= 60);
if (soonh < 0)
{
soonh = 0;
}
int totalhour = soonh + now.Hour + hourstoadd;
int totalday = 0;
bool sample = false;
do
{
if (totalhour >= 8)
{
totalhour = totalhour - 7;
totalday = totalday + 1;
sample = true;
}
}
while (totalhour >= 8);
if (sample == true)
{
totalday = totalday - 1;
}
totalhour = totalhour + 7;
if (totalhour + DateTime.Today.Hour >= 15)
{
totalhour = totalhour - 7;
}
if (DateTime.Today.Date.AddDays(totalday) == DateTime.Today)
{
totalday++;
}
EstimatedCompleteDate = (DateTime.Today.Date.AddDays(totalday).AddHours(totalhour).AddMinutes(totalmin).ToString());
}