using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.IO; public partial class SysAdmin_ClassInfo : System.Web.UI.Page { static bool Load; public static string Requeststr; public static DataTable ClassInfo; private static DataTable ClassType; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindTypeDDl(); if (Request.QueryString["ClassInfo"] != null) { Requeststr = Request.QueryString["ClassInfo"]; Load = true; string SelectClassInfoByClassId = "select * from Class where ClassTypeId = " + Requeststr; { ClassInfo = new common().ExcuteReader(SelectClassInfoByClassId).Tables[0]; this.txtClassName.Text = ClassInfo.Rows[0]["ClassName"].ToString(); this.txtPingFen.Text = ClassInfo.Rows[0]["PingFen"].ToString(); this.txtListenCount.Text = ClassInfo.Rows[0]["ListenCount"].ToString(); this.TextBox4.Text = ClassInfo.Rows[0]["Description"].ToString(); this.DDLFromCLass.SelectedIndex = DDLFromCLass.Items.IndexOf(DDLFromCLass.Items.FindByValue(ClassInfo.Rows[0]["ClassTypeId"].ToString())); } } else { Requeststr = null; Load = false; } } } private void BindTypeDDl() { string sqlstr = "select * from ClassType"; this.DDLFromCLass.DataSource = new common().ExcuteReader(sqlstr).Tables[0]; this.DDLFromCLass.DataValueField = "ClassId"; this.DDLFromCLass.DataTextField = "ClassName"; this.DDLFromCLass.DataBind(); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string FilePath = FileUpload1.PostedFile.FileName; string FileName = Path.GetFileName(FilePath);//文件名 if (Load)////修改 { string UpdateClassLessonInfo = " update Class set ClassTypeId =" + this.DDLFromCLass.SelectedItem.Value + ", ClassName ='" + this.txtClassName.Text.Trim() + "',PingFen =" + this.txtPingFen.Text.Trim() + " ,ListenCount= " + txtListenCount.Text.Trim() + ",Description = '" + this.TextBox4.Text.Trim().ToString().Replace("'", " ") + "',_MP3 ='UpLoadResource/Mp3/" + FileName + "',_VIDEO ='UpLoadResource/Video/" + this.FileUpload2.FileName +"' ,EditTime=" + DateTime.Now.ToString()+" where ClassId ="+ClassInfo.Rows[0][0].ToString(); bool result = new common().ExcuteNoneQuery(UpdateClassLessonInfo, null); if (result) { Methods1.Methods1.Alert(this, "修改课时成功!"); } } else///新建 { string InsertClassLessonInfo = " insert into Class(ClassTypeId,ClassName,PingFen,ListenCount,Description,_MP3,_VIDEO,EditTime) values(" + this.DDLFromCLass.SelectedItem.Value + ", '" + this.txtClassName.Text.Trim() + "'," + this.txtPingFen.Text.Trim() + "," + txtListenCount.Text.Trim() + ", '" + this.TextBox4.Text.Trim().ToString().Replace("'", " ") + "','UpLoadResource/Mp3/" + FileName + "','UpLoadResource/Video/" + this.FileUpload2.FileName +"'," + DateTime.Now.ToString("yyyy-MM-dd") + ")"; bool result = new common().ExcuteNoneQuery(InsertClassLessonInfo, null); if (result) { Methods1.Methods1.Alert(this, "添加课时成功!"); } } } protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { Response.Redirect(Request.Url.ToString()); } }