-
Notifications
You must be signed in to change notification settings - Fork 3
/
Form2.cs
193 lines (166 loc) · 6.84 KB
/
Form2.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
namespace kw_enrolment_practice
{
public partial class Form2 : Form
{
int sec = 50;
int getNum = 0;
int numOfSub = 6;
bool isStarted = false;
int selected = -1;
List<bool> isFull = new List<bool>();
List<bool> isDone = new List<bool>();
List<int> subType = new List<int>();
public Form2(int subNum)
{
InitializeComponent();
numOfSub = subNum;
}
void clearRef()
{
codeRef.Text =
subRef.Text =
pointRef.Text =
profRef.Text =
dayRef.Text =
timeRef.Text =
profRef.Text =
roomRef.Text =
cntRef.Text =
typeRef.Text =
"";
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0 || e.ColumnIndex !=
favList.Columns["add"].Index) return;
if (!isStarted)
{
MessageBox.Show("수강신청이 시작된 이후에만 조회가 가능합니다.", "수강신청 연습", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
Random rand = new Random();
String[] typeList = new String[6] { "기필", "기선", "교필", "교선", "전필", "전선"};
Thread.Sleep(rand.Next(300,500));
selected = e.RowIndex;
codeRef.Text = favList.Rows[e.RowIndex].Cells["code"].Value as String;
subRef.Text = favList.Rows[e.RowIndex].Cells["sub"].Value as String;
pointRef.Text = favList.Rows[e.RowIndex].Cells["point"].Value as String;
profRef.Text = favList.Rows[e.RowIndex].Cells["prof"].Value as String;
String day = favList.Rows[e.RowIndex].Cells["time"].Value as String; day = day.Substring(0, 1);
String time = favList.Rows[e.RowIndex].Cells["time"].Value as String; time = time.Substring(2, 1);
dayRef.Text = day;
timeRef.Text = time;
typeRef.Text = typeList[subType[e.RowIndex]];
cntRef.Text = isFull[e.RowIndex] ? "만석" : "여석";
roomRef.Text = "새404";
}
private void Form2_Load(object sender, EventArgs e)
{
String[] dayList = new String[7]{ "월","화","수","목","금","토","일"};
Random rand = new Random();
for(int i = 1; i <= numOfSub; i++)
{
String no = i.ToString();
String code = rand.Next(1000, 10000).ToString() + "-" + rand.Next(0, 10).ToString() + "-" + rand.Next(1000, 10000).ToString() + "-" + rand.Next(10, 100).ToString();
String sub = "과목" + no;
String point = rand.Next(1, 4).ToString();
String prof = "교수님" + no;
String time = dayList[rand.Next(0, 7)] + "(" + rand.Next(1, 9).ToString() + ")";
favList.Rows.Add("조회", no, code, sub, point, prof, time);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("수강신청 연습 프로그램을 종료하시겠습니까?", "수강신청 연습", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
Application.Exit();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
startBtn.Visible = false;
MessageBox.Show("10초 후 수강신청이 시작됩니다.\n서버 시간을 주목해주세요!", "수강신청 시작", MessageBoxButtons.OK, MessageBoxIcon.Information);
timer1.Enabled = true;
}
void practiceStart()
{
Random rand = new Random();
isStarted = true;
enrolBtn.Enabled = true;
enrolBtn.BackColor = Color.Yellow;
for (int i = 0; i < numOfSub; i++)
{
isFull.Add(rand.Next(0, 10) < 2);
isDone.Add(false);
subType.Add(rand.Next(0, 6));
}
}
private void timer1_Tick(object sender, EventArgs e)
{
sec++;
if (sec == 55) curTime.ForeColor = Color.Red;
else if (sec == 60)
{
timer1.Enabled = false;
curTime.Text = "10:00:00";
practiceStart();
MessageBox.Show("수강신청이 시작되었습니다.", "수강신청 시작", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
curTime.Text = "09:59:"+sec.ToString();
}
private void enrolBtn_Click(object sender, EventArgs e)
{
if (selected==-1)
{
MessageBox.Show("수강신청하려는 과목을 먼저 조회해주세요!", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else if (isDone[selected])
{
MessageBox.Show("이미 수강신청이 완료된 과목입니다!", "수강신청 연습", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else if (isFull[selected])
{
MessageBox.Show("해당 과목은 만석입니다.", "여석 없음", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Thread.Sleep(new Random().Next(1000, 1500));
getList.Rows.Add((++getNum).ToString(), codeRef.Text, typeRef.Text, subRef.Text, pointRef.Text, profRef.Text, dayRef.Text, timeRef.Text+"교시", roomRef.Text, "", "", "");
getList.CurrentCell = null;
clearRef();
isDone[selected] = true;
this.Text = "수강신청 성공 과목 수 [" + getNum.ToString() + "/" + numOfSub.ToString() + "]";
selected = -1;
}
private void label16_Click(object sender, EventArgs e)
{
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
}
private void label20_Click(object sender, EventArgs e)
{
}
private void label22_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/yjyoon-dev/kw-enrolment-practice");
}
}
}