📄 查看提交作业.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Home : System.Web.UI.Page
{
string strConnection = "server=F45F1B20D9B348B;database=Student;uid=sa;pwd=1017;";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["权限"].ToString() != "s")
{
Response.Redirect("Login.aspx");
}
GridViewBind1();
}
protected void UploadButton_Click(object sender, EventArgs e)
{
while (txtWorkName.Text == "" || txtWorkName.Text == null)
{
UploadStatusLabel.Text = "请先选择作业!";
}
String savePath = @"C:\Inetpub\wwwroot\hwork\homework\" + txtWorkName.Text+"\\";
if (FileUpload1.HasFile)
{
String fileName = Session["用户名"].ToString() + ".rar";
savePath += fileName;
FileUpload1.SaveAs(savePath);
UploadStatusLabel.Text = "你的文件已经保存为 " + fileName;
}
else
{
UploadStatusLabel.Text = "你还没有选择要上传的文件!";
}
}
private void GridViewBind1()
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = strConnection;
string cmdString = "select * from homework";
SqlDataAdapter myAdapter = new SqlDataAdapter(cmdString, myConnection);
myConnection.Open();
DataSet mySet = new DataSet();
myAdapter.Fill(mySet);
myGridView.DataSource = mySet;
myGridView.DataBind();
myConnection.Close();
}
protected void myGridView_SelectedIndexChanged(object sender, EventArgs e)
{
txtWorkName.Text = myGridView.SelectedRow.Cells[0].Text;
string path="http://localhost/hwork/homework/"+myGridView.SelectedRow.Cells[1].Text;
LbtnDowmload.PostBackUrl = path;
}
protected void LbtnDowmload_Click(object sender, EventArgs e)
{
if (txtWorkName.Text == "" || txtWorkName.Text == null)
{
Downloadlbl.Text ="请先选择要下载的作业!";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -