/// <summary> /// 添加EXCEL信息 /// </summary> public int Add(Page page, FileUpload fu, int classId) { examrecordDAL ExamRecordDAL = new examrecordDAL(); try { int i = 0; if (fu.HasFile == false) { MessageBox.Show(page, "请选择您要上传的Excel文件!"); return 0;//当无文件时,返回 } string IsXls = System.IO.Path.GetExtension(fu.FileName).ToString().ToLower(); if (IsXls != ".xls") { MessageBox.Show(page, "只可以上传Excel文件!"); return 0;//当选择的不是Excel文件时,返回 } string path = page.Server.MapPath("storage/scoreInput/"); string strpath = fu.PostedFile.FileName.ToString(); //获取Execle文件路径 string filename = "批量成绩信息" + System.DateTime.Now.ToString("yyyyMMddHHmmss").Trim() + ".xls"; //从时间获取文件路径 fu.PostedFile.SaveAs(path + filename); DataSet ds = Tools.ExecleDs(path + filename, filename); DataRow[] dr = ds.Tables[0].Select(); //定义一个DataRow数组 int rowsnum = ds.Tables[0].Rows.Count; if (rowsnum == 0) { //Response.Write("<script>alert('Excel表为空表,无数据!')</script>"); MessageBox.Show(page, "Excel表为空表,无数据!");//当Excel表为空时,对用户进行提示 return 0; } else { for (i = 0; i < dr.Length; i++) { if (isInClass(dr[i]["任课教师"].ToString(), dr[i]["课程名称"].ToString(), classId)) { examrecord ExamRecord = new examrecord(); string stuId = dr[i]["学生学号"].ToString(); if (stuId.Length < 1) { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生学号不能为空,请检查数据"); return i; } else { studentBLL StudentBLL = new studentBLL(); student Student = null; try { Student = StudentBLL.GetModelList("stuId='" + stuId + "'")[0]; } catch { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生学号不存在,请检查数据"); return i; } if (Student != null) { if (Student.name.Trim().Equals(dr[i]["学生姓名"].ToString().Trim())) { ExamRecord.student = stuId; } else { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生学号不存在,请检查数据"); return i; } } } int score = 0; try { score = Convert.ToInt32(dr[i]["成绩"].ToString()); } catch { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生成绩仅可以为数字且不能为空,请检查数据"); return i; } if (score != 0) { ExamRecord.score = score.ToString(); } else { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生成绩仅可以为数字且不能为空,请检查数据"); return i; } ExamRecord.classId = classId.ToString(); ExamRecordDAL.Add(ExamRecord); } else { MessageBox.Show(page, "导入第" + (i + 1).ToString() + "个成绩信息失败,学生课程名称不存在,请检查数据"); return i; } } return i; } } catch { return 0; } finally { } }
public string SumGXWCredit(string stuId) { examrecordDAL ExamRecordDAL=new examrecordDAL(); return ExamRecordDAL.SumGXWCredit(stuId); }
/// <summary> /// 重新绑定学号 /// </summary> public bool repalaceStuId(string oldStuId, string newStuId) { examrecordDAL ExamRecordDAL=new examrecordDAL(); return ExamRecordDAL.repalaceStuId(oldStuId, newStuId); }
/// <summary> /// 分页获取数据列表 /// </summary> //public DataSet GetList(int PageSize,int PageIndex,string strWhere) //{ //return dal.GetList(PageSize,PageIndex,strWhere); //} /// <summary> /// 获取成绩列表 /// </summary> public DataSet Select(int classId) { GS.DAL.examrecordDAL ExamRecordDAL = new GS.DAL.examrecordDAL(); return ExamRecordDAL.Select(classId); }
/// <summary> /// 获取学位课程 /// </summary> public DataSet getXueWeiKe(string StuId) { examrecordDAL ExamRecordDAL = new examrecordDAL(); return ExamRecordDAL.getXueWeiKe(StuId); }