Repository navigation
Expand file tree
/
Copy pathWebForm__AARegistration.aspx.cs
More file actions
169 lines (160 loc) · 7.18 KB
/
Copy pathWebForm__AARegistration.aspx.cs
File metadata and controls
169 lines (160 loc) · 7.18 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BreakfastCards1
{
public partial class WebForm__AARegistration : System.Web.UI.Page
{
string ThisYear = DateTime.Now.ToString("yyyy");
string ThisMonth = DateTime.Now.ToString("MMMM", CultureInfo.GetCultureInfo("en-US"));
string LastMonth = DateTime.Now.AddMonths(-1).ToString("MMMM", CultureInfo.GetCultureInfo("en-US"));
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindYear();
BindMonth();
BindGroupName();
BindGridView();
}
}
protected void Button_Add_Comfirm_Click(object sender, EventArgs e)
{
Table_FourName a = new Table_FourName();
a.Date = DropDownList_Add_Year.Text + "-" + DropDownList_Add_Month.Text;
a.GroupName = DropDownList_Add_GroupName.Text;
a.Quantity = Convert.ToInt16(TextBox_Add_Quantity.Text);
//在Table_FourName里,ID的规则,顺序分别:4位是年份,2位是月份,2位是团队代号。
a.ID = DropDownList_Add_Year.Text + Month_EngToDigit(DropDownList_Add_Month.Text) + GroupName_Num(DropDownList_Add_GroupName.Text);
Dictionary<string, string> GroupName_Manager = new Dictionary<string, string>();
GroupName_Manager.Add("Intune", "John Huang");
GroupName_Manager.Add("Office", "Amanda Luo");
GroupName_Manager.Add("SCCM", "Eric Zhang");
GroupName_Manager.Add("Teams", "Peter Gao");
GroupName_Manager.Add("POD1", "Haiwei Xu");
GroupName_Manager.Add("POD2", "Liu Bai");
GroupName_Manager.Add("S500_1", "Dongli Li");
GroupName_Manager.Add("S500_2", "Dorothy Deng");
GroupName_Manager.Add("SharePoint", "Cindy Ge");
a.Manager = GroupName_Manager[DropDownList_Add_GroupName.Text];
BreakfastCardsEntities db = new BreakfastCardsEntities();
db.Table_FourName.Add(a);
db.SaveChanges();
Response.Redirect(Request.Url.ToString());
}
protected string Month_EngToDigit(string month)
{
Dictionary<string, string> Month_EngToDigit = new Dictionary<string, string>();
Month_EngToDigit.Add("January", "01");
Month_EngToDigit.Add("February", "02");
Month_EngToDigit.Add("March", "03");
Month_EngToDigit.Add("April", "04");
Month_EngToDigit.Add("May", "05");
Month_EngToDigit.Add("June", "06");
Month_EngToDigit.Add("July", "07");
Month_EngToDigit.Add("August", "08");
Month_EngToDigit.Add("September", "09");
Month_EngToDigit.Add("October", "10");
Month_EngToDigit.Add("November", "11");
Month_EngToDigit.Add("December", "12");
return Month_EngToDigit[month]; //System.Collections.Generic.KeyNotFoundException:“给定关键字不在字典中。”
}
protected string GroupName_Num(string groupname)
{
Dictionary<string, string> GroupName_Num = new Dictionary<string, string>();
GroupName_Num.Add("Intune", "01");
GroupName_Num.Add("Office", "02");
GroupName_Num.Add("SCCM", "03");
GroupName_Num.Add("Teams", "04");
GroupName_Num.Add("POD1", "05");
GroupName_Num.Add("POD2", "06");
GroupName_Num.Add("S500_1", "07");
GroupName_Num.Add("S500_2", "08");
GroupName_Num.Add("SharePoint", "09");
return GroupName_Num[groupname];
}
protected void BindYear()
{
DropDownList_Add_Year.Items.Clear();
//年份Year
int ThisYearInt = Convert.ToInt16(ThisYear);
for (int i = ThisYearInt; i >= 1997; i--)
{
DropDownList_Add_Year.Items.Add(i.ToString());
if (i == ThisYearInt && ThisMonth == "December")
DropDownList_Add_Year.Items.Add((i + 1).ToString());
}
}
protected void BindMonth()
{
DropDownList_Add_Month.Items.Clear();
//Month月份
Dictionary<int, string> Month_DigitToEng = new Dictionary<int, string>();
Month_DigitToEng.Add(1, "January");
Month_DigitToEng.Add(2, "February");
Month_DigitToEng.Add(3, "March");
Month_DigitToEng.Add(4, "April");
Month_DigitToEng.Add(5, "May");
Month_DigitToEng.Add(6, "June");
Month_DigitToEng.Add(7, "July");
Month_DigitToEng.Add(8, "August");
Month_DigitToEng.Add(9, "September");
Month_DigitToEng.Add(10, "October");
Month_DigitToEng.Add(11, "November");
Month_DigitToEng.Add(12, "December");
string ThisMonth = DateTime.Now.ToString("MMMM");
for (int i = Convert.ToInt16(ThisMonth) - 1; i <= 12; i++)
{
DropDownList_Add_Month.Items.Add(Month_DigitToEng[i]); //System.Collections.Generic.KeyNotFoundException:“The given key was not present in the dictionary.”
}
for (int i = 1; i < Convert.ToInt16(ThisMonth) - 1; i++)
{
DropDownList_Add_Month.Items.Add(Month_DigitToEng[i]);
}
}
protected void BindGroupName()
{
DropDownList_Add_GroupName.Items.Clear();
//GroupName
Dictionary<int, string> GroupName_Dic = new Dictionary<int, string>();
GroupName_Dic.Add(1, "Intune");
GroupName_Dic.Add(2, "Office");
GroupName_Dic.Add(3, "SCCM");
GroupName_Dic.Add(4, "Teams");
GroupName_Dic.Add(5, "POD1");
GroupName_Dic.Add(6, "POD2");
GroupName_Dic.Add(7, "S500_1");
GroupName_Dic.Add(8, "S500_2");
GroupName_Dic.Add(9, "SharePoint");
Dictionary<int, string>.ValueCollection GroupNameCol = GroupName_Dic.Values;
foreach (string value in GroupNameCol)
{
DropDownList_Add_GroupName.Items.Add(value.ToString());
}
}
protected void BindGridView()
{
BreakfastCardsEntities db = new BreakfastCardsEntities();
string date = ThisYear + "-" + ThisMonth;
string datelastmonth = ThisYear + "-" + LastMonth;
string datenextmonth;
if(ThisMonth=="December")
{
datenextmonth = DateTime.Now.AddYears(+1).ToString("yyyy") +"-"+ "January";
}
else
{
datenextmonth = DateTime.Now.ToString("yyyy") + "-" + DateTime.Now.AddMonths(+1).ToString();
}
var clients = from c in db.Table_FourName
where c.Date == date || c.Date == datelastmonth || c.Date==datenextmonth
select c;
GridView1.DataSource = clients.ToList();
GridView1.DataBind();
}
}
}