This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
forked from pigsquare/StuAct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStuHome.aspx.cs
63 lines (58 loc) · 2.52 KB
/
StuHome.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
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
public partial class StuHome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["role"] == null || Session["role"].ToString() != "stu")
{
Response.Redirect("Index.aspx");
Session["login"] = "未登录学生用户!";
}
else
{
if (Session["name"] != null)
TeaName.InnerText = "欢迎您," + Session["name"].ToString() + "!";
string sql = "SELECT * FROM [Detail] INNER JOIN Act ON Detail.act_id=Act.act_id WHERE [stu_id]='" + Session["id"].ToString() + "' ORDER BY Act.[act_id]";
string conf = ConfigurationManager.ConnectionStrings["ActManageConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(conf);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = cmd.ExecuteReader();
TableStu.InnerHtml = "<table class='table table-striped table-bordered table-hover'><tr><th>作业序号</th><th>作业类型</th><th>作业名称</th><th>分数</th><th>备注</th></tr>";
while (dr.Read())
{
TableStu.InnerHtml += "<tr><td>" + dr.GetInt32(1).ToString() + "</td><td>" + dr.GetString(6) + "</td><td>" + dr.GetString(7) + "</td><td>" + dr.GetInt32(3).ToString() + "</td><td>" + dr.GetString(4) + "</td></tr>";
}
TableStu.InnerHtml += "</table>";
}
}
protected void Logout(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("Index.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.ContentLength == 0)
{
Label1.Text = "请选择文件";
}
else
{
//获得扩展名
string extension = Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
string fileName = Session["id"].ToString() + Session["name"] + "-" + DropDownList1.SelectedValue;
string newFileName = fileName + extension;
string filePath = Server.MapPath("~/upload/") + newFileName;
if (File.Exists(filePath))
{
File.Delete(filePath);
}
FileUpload1.PostedFile.SaveAs(filePath);
Label1.Text = "文件上传成功!";
}
}
}