以下是引用片段:
其关键代码实现如下: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable tmprs = new DataTable(); //显示当前学生的教材推荐
if (Request.QueryString["ID"] != null) { tmprs = DataControl.GetData("select * from 教材推荐 where 教材代码=" + Request.QueryString["ID"] + ""); if (tmprs.Rows.Count > 0) { Button2.Visible = false; TextBox1.Text = tmprs.Rows[0]["教材名称"].ToString(); TextBox3.Text = tmprs.Rows[0]["主要内容"].ToString(); Textbox2.Text = tmprs.Rows[0]["教材介绍"].ToString(); Textbox5.Text = tmprs.Rows[0]["教材价格"].ToString(); strPic = @"Other\" + tmprs.Rows[0]["教材图片"].ToString();
} } } } protected void Button2_Click(object sender, EventArgs e) { //将相关的图片上传到@"..\Other\"路径下 string FileName = ""; string FileName1; string DPath; if (Server.MapPath("").Substring(Server.MapPath("").Length - 1, 1) == @"\") { DPath = Server.MapPath(""); } else { DPath = Server.MapPath("") + @"\"; } string delPath = DPath; DPath = DPath + @"Other\"; //上传图片文件 if (this.File1.PostedFile.FileName != "") { string[] temp = this.File1.PostedFile.FileName.Split('.'); string strHzm = "." + temp[temp.Length - 1];
Guid tmp = Guid.NewGuid(); FileName = tmp.ToString() + strHzm; FileName1 = DPath + tmp.ToString() + strHzm; this.File1.PostedFile.SaveAs(FileName1); if (File.Exists(delPath + this.Hidden1.Value)) { File.Delete(delPath + this.Hidden1.Value); } } //添加新的教材推荐信息 DataControl.Execute("insert into 教材推荐(教材名称,教材价格,主要内容,教材介绍,教师帐号,教材图片,推荐时间) " + " values('" + TextBox1.Text + "'," + Textbox5.Text + ",'" + TextBox3.Text + "', " + " '" + Textbox2.Text + "','"+ Session["Acount"].ToString() +"','" + FileName + "','"+ DateTime.Now.ToString()+"')"); Response. }
|