📄 发布作业.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 teacher : 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() != "t")
{
Response.Redirect("Login.aspx");
}
GridViewBind();
}
protected void UploadButton_Click(object sender, EventArgs e)
{
String savePath = @"C:\Inetpub\wwwroot\hwork\homework\";
if (FileUpload1.HasFile)
{
String fileName = FileUpload1.FileName;
savePath += fileName;
FileUpload1.SaveAs(savePath);
UploadStatusLabel.Text = "你的文件已经保存为 " + fileName;
try
{
SqlConnection Connection = new SqlConnection();
String strSQL = "insert into homework (作业名称,提交期限,资料名称) values('" + txtWorkName.Text + "','"+txtDate.Text+"','" + fileName + "')";
Connection.ConnectionString = strConnection;
SqlCommand command = new SqlCommand(strSQL, Connection);
Connection.Open();
command.ExecuteNonQuery();
Connection.Close();
System.IO.Directory.CreateDirectory(@"C:\Inetpub\wwwroot\hwork\homework\" + txtWorkName.Text);
GridViewBind();
}
catch (Exception)
{
UploadStatusLabel.Text = "同名作业!如要上传该作业,请更改作业名称!";
}
}
else
{
UploadStatusLabel.Text = "你还没有选择要上传的文件!";
}
}
private void GridViewBind()
{
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 Button1_Click(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -