-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck_Datetime.aspx.cs
81 lines (78 loc) · 2.65 KB
/
Check_Datetime.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using System.Xml.Linq;
public partial class Check_Datetime : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//检查时间是否正确
//传入参数:d1 日期1 |d2 日期2(可选) |t1 时间1| t2 时间2|flag 多时段
//如果d2 传参存在,则为多时段判断
//-1:日期错
//-2:日期先后
//-3:时间错
//-4:时间先后
if (!IsPostBack)
{
var d1 = Request.QueryString["d1"];
var d2 = Request.QueryString["d2"];
var t1 = Request.QueryString["t1"];
var t2 = Request.QueryString["t2"];
var flag = Request.QueryString["flag"];
DateTime result1 = DateTime.Now;
DateTime result2 = DateTime.Now;
DateTime result3 = DateTime.Now;
DateTime result4 = DateTime.Now;
DateTime.TryParse(d1, out result1);
DateTime.TryParse(d2, out result2);
DateTime.TryParse(t1, out result3);
DateTime.TryParse(t2, out result4);
int SpanCompare = TimeSpan.Compare(result3.TimeOfDay, result4.TimeOfDay);
int success;
int DateCompare = DateTime.Compare(result1.Date, result2.Date);
if (SpanCompare < 0)
{
success = 0;
}
else
{
success = -4;
}
if (flag != "0")
{
if (DateCompare >= 0)
{
success = -2;
}
}
if (result1 == DateTime.MinValue || result2 == DateTime.MinValue&&flag!="0") success = -1;
if (result3 == DateTime.MinValue || result4 == DateTime.MinValue) success = -3;
if (flag == "3")
{
if (result1 != DateTime.MinValue && result2 != DateTime.MinValue && result3 != DateTime.MinValue && result4 != DateTime.MinValue)
{
result1 = result1 + result3.TimeOfDay;
result2 = result2 + result4.TimeOfDay;
if (result1 > result2)
{
success = -4;
}
else
{
success = 0;
}
}
else
{
success=-3;
}
}
Response.Write(success);
}
}
}