-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.aspx.cs
More file actions
641 lines (577 loc) · 22.7 KB
/
Copy pathindex.aspx.cs
File metadata and controls
641 lines (577 loc) · 22.7 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class index : System.Web.UI.Page
{
protected string SiteTitle { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
SiteTitle = LearnSite.Common.XmlHelp.SiteTitle();
if (string.IsNullOrEmpty(SiteTitle))
{
SiteTitle = "信息科技学习网站";
}
LitSiteTitle.Text = SiteTitle;
if (LearnSite.Common.CookieHelp.IsStudentLogin())
{
LearnSite.Model.Cook cook = new LearnSite.Model.Cook();
OpenJump(cook.Sgrade, cook.Sclass);//跳转选择
}
else
{
if (!verChecking())
return;
if (!IsPostBack)
{
if (Session["LoginMessage"] != null)
{
Labelmsg.Text = Session["LoginMessage"].ToString();
Session.Remove("LoginMessage");
}
else
{
Labelmsg.Text = "";
}
ShowFoot();
Btnlogin.Attributes["onClick"] = "return doubleCheck()";
this.Page.Title = LearnSite.Common.CookieHelp.SetMainPageTitle();
Request.Cookies.Clear();
}
}
}
private void ShowFoot()
{
DateTime dt3 = DateTime.Now;
string pp = LearnSite.Common.Computer.MyIp();// Page.Request.UserHostAddress;
DateTime dt4 = DateTime.Now;
if (Request.QueryString["mysnum"] != null)
{
string myname = "";
string mysnum=Request.QueryString["mysnum"].ToString();
TextBoxuser.Text = mysnum;
TextBoxpwd.Focus();
if (Request.QueryString["myname"] != null)
{
myname = Request.QueryString["myname"].ToString();
}
LearnSite.BLL.Signin gbll = new LearnSite.BLL.Signin();
if (!gbll.IsSameIp(mysnum, pp))
{
// IsSameIp从Students表查座位号,再从Computers表查IP进行对比
// IP不匹配时,显示学生的固定座位信息
LearnSite.BLL.Students sbll = new LearnSite.BLL.Students();
LearnSite.Model.Students student = sbll.SnumGetModel(mysnum);
string seatInfo = (student != null && !string.IsNullOrEmpty(student.Sseat)) ? student.Sseat : "未设置";
Labelmsg.Text = myname + ",这不是你的座位,你的固定座位是: " + seatInfo;
Labelmsg.ForeColor = System.Drawing.Color.Red;
}
else {
Labelmsg.Text = "欢迎 "+ myname + " 同学";
Labelmsg.ForeColor = System.Drawing.Color.Black;
}
}
Labelterm.Text = LearnSite.Common.XmlHelp.GetTerm();
int loginm = LearnSite.Common.XmlHelp.LoginMode();//获取登录方式 0表示个人密码方式登录 1表示班级密码方式登录
DateTime dt5 = DateTime.Now;
Labelhostname.Text = GetHostNameMy(pp);
DateTime dt6 = DateTime.Now;
Labelip.Text = pp;
Labelloadtime.Text = "IP:" + LearnSite.Common.Computer.DatagoneMilliseconds(dt3, dt4) + "毫秒 " + " 主机名:" + LearnSite.Common.Computer.DatagoneMilliseconds(dt5, dt6) + "毫秒 ";
if (loginm == 1)
{
Labelversion.Text = "『班级模式』";
}
else
{
Labelversion.Text = "『个人模式』";
}
/*
LearnSite.BLL.Computers cbll = new LearnSite.BLL.Computers();
string autosnum = cbll.getIpSnum(pp);//获取自动分配的学号,填充到登录页面,方便培训
if (autosnum != "")
{
TextBoxuser.Text = autosnum;
TextBoxuser.ReadOnly = true;//不可修改
}
else
{
TextBoxuser.ReadOnly = false;//可修改
}
*/
}
/// <summary>
/// 获取IP对应机器名,返回主机名
/// 支持多网段自动识别机房
/// </summary>
/// <param name="Pip"></param>
/// <returns></returns>
private string GetHostNameMy(string aPip)
{
string msg = "否";//表示不自动获取主机名
if (!string.IsNullOrEmpty(aPip))
{
LearnSite.BLL.Computers cbll = new LearnSite.BLL.Computers();
LearnSite.Model.Computers cmodel = new LearnSite.Model.Computers();
cmodel = cbll.GetModelByIp(aPip);
bool autohostname = LearnSite.Common.XmlHelp.GetAutoHostName();//自动取主机名开关
if (cmodel != null)//如果存在
{
msg = cmodel.Pmachine;//获取主机名
if (!cmodel.Plock && autohostname)//如果未锁定,更新主机名并锁定
{
string newMachine = LearnSite.Common.Computer.GetGuestHost(aPip);
cbll.UpdateByPid(cmodel.Pid, newMachine);
msg = newMachine;//返回新主机名
}
}
else
{
string inum = TryGetInumByNetSegment(aPip);
if (!string.IsNullOrEmpty(inum))
{
msg = inum;
}
else if (autohostname)
{
LearnSite.Model.Computers newmodel = new LearnSite.Model.Computers();
newmodel.Pip = aPip;
newmodel.Plock = true;
string addMachine = LearnSite.Common.Computer.GetGuestHost(aPip);
newmodel.Pmachine = addMachine;
newmodel.Pdate = DateTime.Now;
cbll.Add(newmodel);
msg = addMachine;
}
}
}
else
{
msg = "空";//表示获取不到IP,反回主机名为空
}
return msg;
}
/// <summary>
/// 通过网段识别机房,获取机号
/// 用于多机房不同网段的情况
/// </summary>
/// <param name="ip">客户端IP地址</param>
/// <returns>机号,如果未找到返回空字符串</returns>
private string TryGetInumByNetSegment(string ip)
{
try
{
int? hid = LearnSite.Common.Computer.GetHidByIp(ip);
if (hid.HasValue)
{
LearnSite.BLL.Ip ipBll = new LearnSite.BLL.Ip();
string inum = ipBll.GetInumByIpAndHid(ip, hid.Value);
return inum;
}
}
catch
{
}
return string.Empty;
}
protected void Btnlogin_Click(object sender, EventArgs e)
{
bool issamenet = LearnSite.Common.XmlHelp.GetLogin();
bool checkresult = LearnSite.Common.Computer.IsSameNet();
if (issamenet)
{
if (checkresult)
LoginCode();//如果受限制,且在同网段内,则允许访问
else
{
Labelmsg.Text = "『许可访问→内网√』";
TextBoxuser.Text = "";
TextBoxpwd.Text = "";
}
}
else
{
LoginCode();
}
}
private void LoginCode()
{
string Snum = TextBoxuser.Text.Trim();
string Spwd = TextBoxpwd.Text.Trim();
string lbip = Labelip.Text;
string msg = "";
if (string.IsNullOrEmpty(Snum) || string.IsNullOrEmpty(Spwd))
{
msg = "请输入学号和密码!";
RedirectWithMessage(msg);
return;
}
if (!LearnSite.Common.WordProcess.IsNum(Snum))
{
msg = "学号必须为数字!";
RedirectWithMessage(msg);
return;
}
if (!LearnSite.Common.WordProcess.IsEnNum(Spwd))
{
msg = "密码只能包含字母和数字!";
RedirectWithMessage(msg);
return;
}
LearnSite.Model.Students model = AuthenticateStudent(Snum, Spwd);
if (model == null)
{
int loginm = LearnSite.Common.XmlHelp.LoginMode();
string msgstr = loginm == 1 ? "『当前为班级密码模式』" : "『当前为个人密码模式』";
// Debugging
if (loginm == 1) {
LearnSite.BLL.Students bll = new LearnSite.BLL.Students();
LearnSite.Model.Students stu = bll.SnumGetModel(Snum);
if (stu != null) {
string sgrade = stu.Sgrade.ToString();
string sclass = stu.Sclass.ToString();
LearnSite.BLL.Room rbll = new LearnSite.BLL.Room();
LearnSite.Model.Room rmodel = rbll.GetModel(stu.Sgrade.Value, stu.Sclass.Value);
if (rmodel != null) {
msgstr += " Debug: 期待的班级密码为(" + rmodel.Rpwd + ") 输入的是(" + Spwd + ") 数据库Rset=" + rmodel.Rset;
} else {
msgstr += " Debug: 找不到该班级的Room记录 (Sgrade=" + sgrade + ", Sclass=" + sclass + ")";
}
} else {
msgstr += " Debug: 找不到该学生 (" + Snum + ")";
}
}
msg = "用户名或密码错误!" + msgstr;
RedirectWithMessage(msg);
return;
}
ProcessLoginSuccess(model, Snum, lbip);
}
private LearnSite.Model.Students AuthenticateStudent(string Snum, string Spwd)
{
LearnSite.BLL.Students bll = new LearnSite.BLL.Students();
int loginm = LearnSite.Common.XmlHelp.LoginMode();
if (loginm == 1)
{
if (bll.ExistsLogin(Snum, Spwd))
{
return bll.SnumGetModel(Snum);
}
if (bll.isRlogin(Snum))
{
return bll.GetStudentModel(Snum, Spwd);
}
return null;
}
return bll.GetStudentModel(Snum, Spwd);
}
private void ProcessLoginSuccess(LearnSite.Model.Students model, string Snum, string lbip)
{
int Qgrade = model.Sgrade.Value;
int Qclass = model.Sclass.Value;
int Qsid = model.Sid;
string Qname = model.Sname;
int Qsyear = model.Syear.Value;
int Qterm = Int32.Parse(LearnSite.Common.XmlHelp.GetTerm());
string Qsession = LearnSite.Common.TimeSlotHelper.GetCurrentTimeSlot();
int Sgrade = Qgrade;
int Sclass = Qclass;
LearnSite.BLL.Room rm = new LearnSite.BLL.Room();
string Qtitle = GetCourseTitleFromRoom(Sgrade, Sclass);
if (string.IsNullOrEmpty(Qtitle))
{
string teacherName;
Qtitle = GetCourseTitleFromSchedule(Sgrade, Sclass, out teacherName);
}
if (string.IsNullOrEmpty(Qtitle))
{
Qtitle = "信息科技";
}
if (LearnSite.Common.XmlHelp.GetSingleLogin())
{
string existingIp = LearnSite.Common.App.GetUserIp(Snum);
if (!string.IsNullOrEmpty(existingIp))
{
LearnSite.Common.App.AppUserRemove(Snum);
LearnSite.Common.App.AppKickUserRemove(Snum);
}
}
if (!LearnSite.Common.CookieHelp.SetStudentCookies(model, lbip))
{
RedirectWithMessage("请不要换机,否则无法登录!");
return;
}
DateTime LoginTime = DateTime.Now;
LearnSite.BLL.Signin gbll = new LearnSite.BLL.Signin();
gbll.SigninToday(Snum, LoginTime, lbip, Qgrade, Qterm, Qsid, Qname, Qclass, Qsyear, Qtitle, Qsession);
if (rm.IsLoginLock(Qgrade, Qclass) && string.IsNullOrEmpty(model.Sseat))
{
LearnSite.BLL.Students sbll = new LearnSite.BLL.Students();
string seatInfo = GetHostNameMy(lbip);
sbll.UpdateFixedSeat(Snum, seatInfo);
}
LearnSite.Common.App.AppKickUserRemove(Snum);
LearnSite.Common.App.AppUserAddWithIp(Snum, lbip);
System.Threading.Thread.Sleep(200);
OpenJump(Qgrade, Qclass);
}
private void RedirectWithMessage(string message)
{
Session["LoginMessage"] = message;
Response.Redirect("index.aspx", false);
Context.ApplicationInstance.CompleteRequest();
}
private void OpenJump(int Sgrade, int Sclass)
{
// 检查是否启用课前检查
bool enablePreClassCheck = false;
string preClassCheckSetting = LearnSite.Common.XmlHelp.GetTypeName("EnablePreClassCheck");
if (!string.IsNullOrEmpty(preClassCheckSetting))
{
bool.TryParse(preClassCheckSetting, out enablePreClassCheck);
}
if (enablePreClassCheck)
{
// 课前检查模式:无论是否有课程,都跳转到sub.aspx进行课前检查
Response.Redirect("sub.aspx", false);
}
else
{
// 正常模式:无论是否有课程,都不跳转到课前检查页面
LearnSite.BLL.Room rm = new LearnSite.BLL.Room();
// 检查是否开启快速模式
bool isOpenMode = rm.IsRopen(Sgrade, Sclass);
string Cid = rm.IsRopenRcid(Sgrade, Sclass);
if (isOpenMode)
{
// 快速模式开启时,直接跳转到课程页面,不管是否有课程
if (!string.IsNullOrEmpty(Cid))
{
// 有课程时直接跳转到课程页面
string myurl = "student/showcourse.aspx?Cid=" + Cid;
Response.Redirect(myurl, true);
}
else
{
// 没有课程时跳转到我的课程页面
Response.Redirect("student/mycourse.aspx", true);
}
}
else
{
// 非快速模式时,按照原有逻辑处理
if (string.IsNullOrEmpty(Cid))
{
// 没有课程时跳转到学生信息页面
Response.Redirect("student/myinfo.aspx", false);
}
else
{
// 有课程时直接跳转到课程页面
string myurl = "student/showcourse.aspx?Cid=" + Cid;
Response.Redirect(myurl, true);
}
}
}
}
private bool verChecking()
{
if (!LearnSite.DBUtility.SqlHelper.DatabaseExist())
{
Response.Redirect("~/upgrade.aspx", false);
Context.ApplicationInstance.CompleteRequest();
return false;
}
if (!LearnSite.DBUtility.UpdateGrade.TableCheck())
{
string ch = "您的数据库未创建、连接失败或版本需要更新,现在将跳到更新程序UpGrade.aspx,请执行检查或修改配置,不影响原有数据!";
LearnSite.Common.WordProcess.Alert(ch, this.Page);
Response.Redirect("~/upgrade.aspx", false);
Context.ApplicationInstance.CompleteRequest();
return false;
}
return true;
}
/// <summary>
/// 获取星期几的数字表示(1-7)
/// </summary>
private int GetDayOfWeekNumber(DayOfWeek dayOfWeek)
{
switch (dayOfWeek)
{
case DayOfWeek.Monday: return 1;
case DayOfWeek.Tuesday: return 2;
case DayOfWeek.Wednesday: return 3;
case DayOfWeek.Thursday: return 4;
case DayOfWeek.Friday: return 5;
case DayOfWeek.Saturday: return 6;
case DayOfWeek.Sunday: return 7;
default: return 0;
}
}
/// <summary>
/// 从课程表获取当前课程的标题和教师信息
/// 优先从CourseSchedule表获取,找不到则返回空
/// </summary>
/// <param name="grade">年级</param>
/// <param name="classNum">班级号</param>
/// <returns>课程标题,找不到则返回空字符串</returns>
private string GetCourseTitleFromSchedule(int grade, int classNum, out string teacherName)
{
teacherName = string.Empty;
try
{
int currentYear = DateTime.Now.Year;
int currentMonth = DateTime.Now.Month;
int currentDay = DateTime.Now.Day;
// 计算当前学年
int schoolYear;
if (currentMonth >= 9)
{
schoolYear = currentYear;
}
else if (currentMonth == 1 || (currentMonth == 2 && currentDay <= 10))
{
schoolYear = currentYear - 1;
}
else if (currentMonth == 2 && currentDay > 10)
{
schoolYear = currentYear;
}
else if (currentMonth >= 3 && currentMonth <= 8)
{
schoolYear = currentYear;
}
else
{
schoolYear = currentYear;
}
// 计算学期
int term = (currentMonth >= 2 && currentMonth <= 7) ? 2 : 1;
// 获取当前星期几
int weekDay = GetDayOfWeekNumber(DateTime.Now.DayOfWeek);
// 获取当前节次(使用统一的节次判断方法)
string timeSlot = LearnSite.Common.TimeSlotHelper.GetCurrentTimeSlot();
int slotNumber = 0;
if (!string.IsNullOrEmpty(timeSlot) && timeSlot != "其他")
{
// 尝试从节次名称中提取数字(如"第1节" → 1)
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(timeSlot, @"\d+");
if (match.Success)
{
int.TryParse(match.Value, out slotNumber);
}
}
if (slotNumber == 0)
{
return string.Empty; // 无法获取节次,直接返回
}
// 构建班级名称(格式:年级-班级,如"1-1")
string className = grade + "-" + classNum;
// 从CourseSchedule表查询课程信息
string sql = @"
SELECT DISTINCT
cs.Subject AS Subject
FROM CourseSchedule cs
WHERE cs.SchoolYear = @SchoolYear
AND cs.Term = @Term
AND cs.WeekDay = @WeekDay
AND cs.TimeSlot = @TimeSlot
AND cs.ClassName = @ClassName";
System.Collections.Generic.List<System.Data.SqlClient.SqlParameter> parameters =
new System.Collections.Generic.List<System.Data.SqlClient.SqlParameter>();
parameters.Add(new System.Data.SqlClient.SqlParameter("@SchoolYear", schoolYear));
parameters.Add(new System.Data.SqlClient.SqlParameter("@Term", term));
parameters.Add(new System.Data.SqlClient.SqlParameter("@WeekDay", weekDay));
parameters.Add(new System.Data.SqlClient.SqlParameter("@TimeSlot", slotNumber));
parameters.Add(new System.Data.SqlClient.SqlParameter("@ClassName", className));
object result = LearnSite.DBUtility.DbHelperSQL.GetSingle(sql, parameters.ToArray());
if (result != null && result != DBNull.Value)
{
teacherName = "课程表";
return result.ToString();
}
return string.Empty;
}
catch (Exception ex)
{
// 出错时返回空,使用备用方法
return string.Empty;
}
}
/// <summary>
/// 从Room表获取当前课程的标题(备用方法)
/// 用于兴趣小组或其他临时课程
/// </summary>
/// <param name="grade">年级</param>
/// <param name="classNum">班级号</param>
/// <returns>课程标题,找不到则返回空字符串</returns>
private string GetCourseTitleFromRoom(int grade, int classNum)
{
try
{
LearnSite.BLL.Room rm = new LearnSite.BLL.Room();
string Cid = rm.IsRopenRcid(grade, classNum);
// 获取课程标题
if (!string.IsNullOrEmpty(Cid))
{
int courseId;
if (int.TryParse(Cid, out courseId))
{
LearnSite.BLL.Courses cs = new LearnSite.BLL.Courses();
LearnSite.Model.Courses courseModel = cs.GetModel(courseId);
if (courseModel != null)
{
return courseModel.Ctitle;
}
}
}
return string.Empty;
}
catch (Exception ex)
{
// 出错时返回空
return string.Empty;
}
}
protected void BtnStartClass_Click(object sender, EventArgs e)
{
// 移除当前时间段的会话缓存
Session.Remove("CurrentTimeSlot");
DateTime now = DateTime.Now;
TimeSpan currentTime = now.TimeOfDay;
int dayOfWeek = GetDayOfWeekNumber(now.DayOfWeek);
// 只在工作日查询课程表
if (dayOfWeek < 1 || dayOfWeek > 5)
{
Session["CurrentTimeSlot"] = "其他";
return;
}
// 从kechengbiao表获取当前时间段的节次信息
string sql = @"
SELECT TOP 1 CAST(SlotNumber AS VARCHAR(10)) as SlotName
FROM kechengbiao
WHERE Year = @Year
AND Term = @Term
AND SlotNumber IS NOT NULL
AND StartTime IS NOT NULL
AND EndTime IS NOT NULL
AND StartTime <= @CurrentTime
AND EndTime >= @CurrentTime
ORDER BY SlotNumber";
System.Data.SqlClient.SqlParameter[] parameters = new System.Data.SqlClient.SqlParameter[]
{
new System.Data.SqlClient.SqlParameter("@Year", System.Data.SqlDbType.Int),
new System.Data.SqlClient.SqlParameter("@Term", System.Data.SqlDbType.Int),
new System.Data.SqlClient.SqlParameter("@CurrentTime", System.Data.SqlDbType.Time)
};
parameters[0].Value = now.Year;
parameters[1].Value = LearnSite.Common.XmlHelp.GetIntTerm();
parameters[2].Value = currentTime;
object result = LearnSite.DBUtility.DbHelperSQL.GetSingle(sql, parameters);
string slot = result != null ? result.ToString() : "其他";
// 将时间段存入会话
Session["CurrentTimeSlot"] = slot;
}
}