//添加一条课程信息 protected void Save_Click(object sender, EventArgs e) { CourseModel Course_Model = new CourseModel(); Bap_Course Bap_Course = new Bap_Course(); Bap_Course.Course_Name = Course_Name_Edit.Text; Bap_Course.Staff_num = Staff_num_Edit.Text; Bap_Course.Teacher_Name = Teacher_Name_Edit.Text; Bap_Course.Department = Department_Edit.Text; Bap_Course.Hours = Hours_Edit.Text; Bap_Course.Class_Time = Class_Time_Edit.SelectedValue; Bap_Course.Class_Week = Class_Week_Edit.SelectedValue; Bap_Course.Total_Week = Total_Week_Edit1.Text + "-" + Total_Week_Edit2.Text + "周"; Bap_Course.Is_Week = Is_Week_Edit.SelectedValue; ; Bap_Course.Class_Addr = Class_Addr_Edit.Text; Bap_Course.Classes = Classes_Edit.Text; bool is_Success = Course_Model.Add(Bap_Course); if (is_Success) { Response.Redirect("List.aspx"); } else { SaveInfo.Text = "修改失败..."; } }
//添加一条课程信息 public bool Add(Bap_Course Bap_Course) { DatabaseAccess database = new DatabaseAccess(); String sql = String.Format(@"insert into Bap_Course(Course_Name,Staff_num,Teacher_Name,Department,Hours,Class_Time,Class_Week,Total_Week,Is_Week,Class_Addr,Classes) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')", Bap_Course.Course_Name, Bap_Course.Staff_num, Bap_Course.Teacher_Name, Bap_Course.Department, Bap_Course.Hours, Bap_Course.Class_Time, Bap_Course.Class_Week, Bap_Course.Total_Week, Bap_Course.Is_Week, Bap_Course.Class_Addr, Bap_Course.Classes); return database.executeUpdate(sql); }
//获得个人课表 public List<Bap_Course> getCourse(String name, String value) { List<Bap_Course> list = new List<Bap_Course>(); DatabaseAccess database = new DatabaseAccess(); string sql = "select * from Bap_Course where " + name + " = '" + value + "'"; try { SqlDataReader result = database.executeQuery(sql); while (result.Read()) { Bap_Course course = new Bap_Course(); course.Id = result["Id"].ToString(); course.Course_Name = result.GetString(1); course.Staff_num = result.GetString(2); course.Teacher_Name = result.GetString(3); course.Department = result.GetString(4); course.Hours = result["Hours"].ToString(); course.Class_Time = result.GetString(6); course.Class_Week = result.GetString(7); course.Total_Week = result.GetString(8); course.Is_Week = result.GetString(9); course.Class_Addr = result.GetString(10); course.Classes = result.GetString(11); list.Add(course); } } catch (Exception e) { throw new Exception(e.Message); } finally { database.close(); } return list; }
protected void queding_Click(object sender, EventArgs e) { int iii = 0; string filename = Session["filename"].ToString(); //获取Execle文件名 DateTime日期函数 // Label2.Text = filename; //Server.MapPath 获得虚拟服务器相对路径 string savePath = Server.MapPath(("~\\DaoRu\\files\\") + filename); //SaveAs 将上传的文件内容保存在服务器上 //调用自定义方法 DataSet ds = new ExcelDateSet().ExcelDs(savePath); //定义一个DataRow数组 DataRow[] dr = ds.Tables[0].Select(); int rowsnum = ds.Tables[0].Rows.Count; // Response.Write("<table width='1380px;' style=' border : yellow 2px solid;'>"); //存放拆分之后的所有课表 LinkedList<LinkedList<String>> lastlist = new LinkedList<LinkedList<String>>(); //LinkedList<Object> lastlist = new LinkedList<Object>(); //读取execl表中的每一行,放在一个list中 for (int i = 0; i < dr.Length; i++) { LinkedList<String> List = new LinkedList<String>(); List.AddFirst(dr[i][0].ToString()); List.AddLast(dr[i][1].ToString()); List.AddLast(dr[i][2].ToString()); List.AddLast(dr[i][3].ToString()); List.AddLast(dr[i][4].ToString()); List.AddLast(dr[i][5].ToString()); List.AddLast(dr[i][6].ToString()); List.AddLast(dr[i][7].ToString()); //调用自己写方法,将execl表中的数据划分好。返回的数据是一个list中包含的list成员的链表 LinkedList<LinkedList<String>> templist = new ExcelDateSet().ListCutter(List); //将返回的list放在最后的集合中 foreach (LinkedList<String> obj in templist) { lastlist.AddLast(obj); } foreach (LinkedList<String> linklist in lastlist) { int j = 0; String[] tempstr = new String[20]; foreach (String str in linklist) { tempstr[j++] = str; } Bap_Course classbean = new Bap_Course(); classbean.Course_Name = tempstr[0]; classbean.Staff_num = tempstr[1]; classbean.Teacher_Name = tempstr[2]; classbean.Department = tempstr[3]; classbean.Hours = tempstr[4]; classbean.Class_Addr = tempstr[5]; classbean.Classes = tempstr[6]; // classbean.Class_Time = tempstr[7]; classbean.Class_Time = tempstr[8]; classbean.Class_Week = tempstr[9]; // classbean.Startweek = tempstr[10]; classbean.Total_Week = tempstr[11]; classbean.Is_Week = tempstr[12]; //try中的操作是将课程安排写到数据库中,暂时没有完成。 try { // DataBase db = new DataBase(); String insertstr = @"insert into Bap_Course(Course_Name ,Staff_num,Teacher_Name,Department,Hours,Class_Addr,Classes,Class_Time,Class_Week,Total_Week,Is_Week) values ('" + classbean.Course_Name + "','" + classbean.Staff_num + "','" + classbean.Teacher_Name + "','" + classbean.Department + "','" + classbean.Hours + "','" + classbean.Class_Addr + "','" + classbean.Classes + "','" + classbean.Class_Time + "','" + classbean.Class_Week + "','" + classbean.Total_Week + "','" + classbean.Is_Week + "' ) "; //Boolean b = db.DateExecuteSQL(insertstr); if (DbHelperSQL.ExecuteSql(insertstr)>0) { iii++; } } catch (Exception ex) //捕捉异常 { Response.Write("<script>alert('导入内容:" + ex.Message + "')</script>"); } } Response.Write("<script>alert('" + iii + "条数据导入成功!');</script>"); trselet.Visible = true; queding.Visible = false; fanhui.Visible = false; Session["filename"] = ""; //Response.Redirect("~/DaoRu/Default.aspx"); Response.Write("<script>document.location=document.location;</script>"); //数据的拆分,写入数据库工作完成。 } }
//获取查询结果 public List<Bap_Course> Search(String name, String value, int page, int size) { List<Bap_Course> list = new List<Bap_Course>(); DatabaseAccess database = new DatabaseAccess(); // String sql = "select * from Bap_Course where 1=1"; String sql = "select top(" + size + ") * from Bap_Course where id not in(select top(" + (page - 1) * size + ") id from Bap_Course where 1=1)"; if(name!="") { sql +=" and Teacher_Name like '%"+name +"%'"; } if (value != "") { sql += " and Staff_num like '%" + value + "%'"; } // String sql = "select * from Bap_Course where " + name + " like '" + value + "%'"; try { SqlDataReader result = database.executeQuery(sql); while (result.Read()) { Bap_Course course = new Bap_Course(); course.Id = result["Id"].ToString(); course.Course_Name = result.GetString(1); course.Staff_num = result.GetString(2); course.Teacher_Name = result.GetString(3); course.Department = result.GetString(4); course.Hours = result["Hours"].ToString(); course.Class_Time = result.GetString(6); course.Class_Week = result.GetString(7); course.Total_Week = result.GetString(8); course.Is_Week = result.GetString(9); course.Class_Addr = result.GetString(10); course.Classes = result.GetString(11); list.Add(course); } } catch (Exception e) { throw new Exception(e.Message); } finally { database.close(); } return list; }
//根据ID保存修改后的课程信息 public bool SaveById(Bap_Course Bap_Course) { DatabaseAccess database = new DatabaseAccess(); String sql = String.Format(@"update Bap_Course set Course_Name='{0}', Staff_num='{1}', Teacher_Name='{2}', Department='{3}', Hours='{4}', Class_Time='{5}', Class_Week='{6}', Total_Week='{7}', Is_Week='{8}', Class_Addr='{9}', Classes='{10}' where id='" + Convert.ToInt32(Bap_Course.Id) + "'", Bap_Course.Course_Name, Bap_Course.Staff_num, Bap_Course.Teacher_Name, Bap_Course.Department, Bap_Course.Hours, Bap_Course.Class_Time, Bap_Course.Class_Week, Bap_Course.Total_Week, Bap_Course.Is_Week, Bap_Course.Class_Addr, Bap_Course.Classes); return database.executeUpdate(sql); }
//根据ID获得某一条信息 public Bap_Course getOne(string id) { Bap_Course Bap_Course = new Bap_Course(); DatabaseAccess database = new DatabaseAccess(); string sql = "select * from Bap_Course where id = " + Int32.Parse(id); try { SqlDataReader result = database.executeQuery(sql); while (result.Read()) { // Bap_Course.Id = result["Id"].ToString(); Bap_Course.Course_Name = result["Course_Name"].ToString(); Bap_Course.Staff_num = result["Staff_num"].ToString(); Bap_Course.Teacher_Name = result["Teacher_Name"].ToString(); Bap_Course.Department = result["Department"].ToString(); Bap_Course.Hours = result["Hours"].ToString(); Bap_Course.Class_Time = result["Class_Time"].ToString(); Bap_Course.Class_Week = result["Class_Week"].ToString(); Bap_Course.Total_Week = result["Total_Week"].ToString(); Bap_Course.Is_Week = result["Is_Week"].ToString(); Bap_Course.Class_Addr = result["Class_Addr"].ToString(); Bap_Course.Classes = result["Classes"].ToString(); } } catch (Exception e) { throw new Exception(e.Message); } finally { database.close(); } return Bap_Course; }