protected void Page_Load(object sender, EventArgs e)
 {
     Tools.authentication(this, "2");
     stuNameStr = getStuName(Session["UserId"].ToString().Trim());
     markUnder60();
     examrecordBLL ExamRecordBLL=new examrecordBLL();
     sumCreditStr=ExamRecordBLL.SumCredit(Session["UserId"].ToString().Trim());
     stuGXWCreditStr = ExamRecordBLL.SumGXWCredit(Session["UserId"].ToString().Trim());
     stuGXWAverageCreditStr = ExamRecordBLL.SumGXWAverageCredit(Session["UserId"].ToString().Trim());
 }
 protected void InitializeFeiXueWeike()
 {
     int i = 0;
     StringBuilder sb = new StringBuilder();
     examrecordBLL ExamrecordBLL = new examrecordBLL();
     DataSet ds = ExamrecordBLL.getFeiXueWeiKe(stuId);
     if (ds.Tables[0].Rows.Count > 0)
     {
         sb.Append("<tr>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\" rowspan=\"15\">非学位课程</td>");
         sb.Append("<td colspan=\"4\" style=\"width: 273px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[0].ToString()).Append("</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[3].ToString()).Append("</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[2].ToString()).Append("</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[1].ToString()).Append("</td>");
         sb.Append("<td colspan=\"2\" style=\"width: 145px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[4].ToString()).Append("</td>");
         sb.Append("</tr>");
         i++;
     }
     else
     {
         sb.Append("<tr>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\" rowspan=\"15\">学位课程</td>");
         sb.Append("<td colspan=\"4\" style=\"width: 273px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td colspan=\"2\" style=\"width: 145px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("</tr>");
         i++;
     }
     for (; i < ds.Tables[0].Rows.Count; i++)
     {
         sb.Append("<tr>");
         sb.Append("<td colspan=\"4\" style=\"width: 273px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[0].ToString()).Append("</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[3].ToString()).Append("</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[2].ToString()).Append("</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[1].ToString()).Append("</td>");
         sb.Append("<td colspan=\"2\" style=\"width: 145px;border: solid #000 1px;\">").Append(ds.Tables[0].Rows[i].ItemArray[4].ToString()).Append("</td>");
         sb.Append("</tr>");
     }
     for (; i < 15; i++)
     {
         sb.Append("<tr>");
         sb.Append("<td colspan=\"4\" style=\"width: 273px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td style=\"width: 72px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("<td colspan=\"2\" style=\"width: 145px;border: solid #000 1px;\">&nbsp;</td>");
         sb.Append("</tr>");
     }
     feiXueWeiKeStr = sb.ToString();
 }
 protected void addBtn_Click(object sender, EventArgs e)
 {
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     examrecord ExamRecord = new examrecord();
     string stuIdStr = Tools.safeUserInput(stuIdTB.Text.ToString().Trim());
     if (stuIdStr.Length < 1)
     {
         MessageBox.Show(this, "学生学号不能为空!");
         return;
     }
     else
     {
         ExamRecord.student = stuIdStr;
     }
     string scoreStr = Tools.safeUserInput(scoreTB.Text.ToString().Trim());
     if (scoreStr.Length < 1)
     {
         MessageBox.Show(this, "学生成绩不能为空!");
         return;
     }
     else
     {
         int scoreInt = -1;
         try
         {
             scoreInt = Convert.ToInt32(scoreStr);
         }
         catch
         {
             MessageBox.Show(this, "学生成绩只能为数字!");
             return;
         }
         if (scoreInt != -1)
             ExamRecord.score = scoreInt.ToString();
         else MessageBox.Show(this, "学生成绩只能为数字!");
     }
     string remarkStr = Tools.safeUserInput(remarkTB.Text.ToString().Trim());
     ExamRecord.remark = remarkStr;
     ExamRecord.classId = id.ToString();
     if (ExamRecordBLL.Add(ExamRecord) != 0)
     {
         MessageBox.Show(this, "添加成功!");
         GV2DataBind();
     }
     else MessageBox.Show(this, "添加失败!");
 }
    protected void Button2_Click(object sender, EventArgs e)
    {
        studentBLL StudentBLL = new studentBLL();
        examrecordBLL ExamRecordBLL = new examrecordBLL();
        studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL();

        try
        {
            ExamRecordBLL.Delete(Session["StuId"].ToString().Trim());
            StudentLoginLogBLL.Delete(Session["StuId"].ToString().Trim());
            StudentBLL.Delete(id);
        }
        catch
        {

            MessageBox.Show(this, "删除失败!");
        }
        MessageBox.ShowAndRedirect(this, "删除成功!", "student.aspx");
    }
 protected void Button3_Click(object sender, EventArgs e)
 {
     int classId = 0;
     int score = 0;
     string remark = "";
     try
     {
         classId = Convert.ToInt32(TextBox1.Text.Trim());
         score = Convert.ToInt32(TextBox2.Text.Trim());
         remark = Tools.safeUserInput(TextBox3.Text.Trim());
     }
     catch
     {
         MessageBox.Show(this, "输入格式不对,请重新输入!");
     }
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     if (!ClassDetailBLL.Exists(classId))
     {
         MessageBox.Show(this, "课程不存在!");
         return;
     }
     examrecord ExamRecord = new examrecord();
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     ExamRecord.classId = classId.ToString();
     ExamRecord.score = score.ToString();
     ExamRecord.student = Session["StuId"].ToString().Trim();
     ExamRecord.remark = remark;
     try
     {
         ExamRecordBLL.Add(ExamRecord);
     }
     catch
     {
         MessageBox.Show(this, "添加成绩失败!");
     }
     MessageBox.Show(this, "添加" + ClassDetailBLL.GetModel(classId).teacher.Trim() + "的" + ClassDetailBLL.GetModel(classId).name + ",分数:"+score+"。");
     GridView1.DataBind();
 }
 protected void InitializePage()
 {
     studentBLL StudentBAll = new studentBLL();
     student Student = StudentBAll.GetModel(stuId);
     stuIdStr = Student.stuId;
     nameStr = Student.name;
     sexStr = Student.sex;
     colleageStr = Student.colleage;
     majorStr = Student.majorName;
     if (Student.admissionDate!=null&&Student.admissionDate.ToString().Length == 6)
         schoolTimeStr = Student.admissionDate.Insert(4, "年").Insert(7, "年");
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     zongXueFenStr = ExamRecordBLL.SumCredit(stuId);
     xueWeiKeZongXueFenStr = ExamRecordBLL.SumGXWCredit(stuId);
     xueWeikeJiaQuanPingJunStr = ExamRecordBLL.SumGXWAverageCredit(stuId);
 }
    protected void Button1_Click(object sender, EventArgs e)
    {
        examrecordBLL ExamRecordBLL = new examrecordBLL();
        classdetailBLL ClassDetailBLL = new classdetailBLL();
        try
        {
            ExamRecordBLL.Delete(Convert.ToInt32(Request.QueryString["id"].ToString().Trim()), "1");
            ClassDetailBLL.Delete(Convert.ToInt32(Request.QueryString["id"].ToString().Trim()));
        }

        catch
        {
            MessageBox.Show(this, "删除失败!");
        }
        MessageBox.ShowAndRedirect(this, "删除成功!", "class.aspx");
    }
 protected void uploadBtn_Click(object sender, EventArgs e)
 {
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     int result = ExamRecordBLL.Add(this, excelFU,id);
     if (result == 0) MessageBox.Show(this, "上传失败!");
     else
     {
         MessageBox.Show(this, "成功导入" + result + "条成绩信息");
         GV2DataBind();
     }
 }
 protected void GV2DataBind()
 {
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     DataSet dSet = ExamRecordBLL.Select(id);
     GridView2.DataSource = dSet;
     GridView2.DataBind();
 }
 protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     examrecord ExamRecord = new examrecord();
     ExamRecord.id = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value);
     ExamRecord.student = ExamRecordBLL.GetModel(ExamRecord.id).student;
     try
     {
         ExamRecord.score = (Convert.ToInt32(((TextBox)(GridView2.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim())).ToString();
         ExamRecord.remark = ((TextBox)(GridView2.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
     }
     catch
     {
         MessageBox.Show(this, "成绩只能为数字!更新失败!");
         return;
     }
     if (ExamRecordBLL.Update(ExamRecord)) MessageBox.Show(this, "更新成功!");
     else MessageBox.Show(this, "更新失败!");
     GridView2.EditIndex = -1;
     GV2DataBind();
 }
 protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     MessageBox.Show(this, "确定删除!");
     try
     {
         if (ExamRecordBLL.Delete(Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value))) MessageBox.Show(this, "删除成功!");
         else MessageBox.Show(this, "删除失败!");
     }
     catch
     {
         MessageBox.Show(this, "删除失败!");
     }
     GV2DataBind();
 }
 /// <summary>
 /// 批量导入信息
 /// </summary>
 public int Add(Page page, FileUpload fu)
 {
     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/studentInput/");
         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)
         {
             MessageBox.Show(page, "Excel表为空表,无数据!");//当Excel表为空时,对用户进行提示
             return 0;
         }
         else
         {
             for (i = 0; i < dr.Length; i++)
             {
                 student Student = new student();
                 string stuId = dr[i]["学生学号"].ToString();
                 if (stuId.Length < 1)
                 {
                     MessageBox.Show(page, "第" + (i + 1).ToString() + "学生学号不能为空,请检查数据");
                     return i;
                 }
                 else Student.stuId = stuId;
                 string name = dr[i]["学生姓名"].ToString();
                 if (name.Length < 1)
                 {
                     MessageBox.Show(page, "第" + (i + 1).ToString() + "学生姓名不能为空,请检查数据");
                     return i;
                 }
                 else Student.name = name;
                 Student.nation = Tools.safeUserInput(dr[i]["学生民族"].ToString());
                 Student.birthday = Tools.safeUserInput(dr[i]["出生日期"].ToString());
                 Student.certificateType = Tools.safeUserInput(dr[i]["证件类型"].ToString());
                 Student.certificateId = Tools.safeUserInput(dr[i]["证件号码"].ToString());
                 Student.majorId = Tools.safeUserInput(dr[i]["专业代码"].ToString());
                 Student.majorName = Tools.safeUserInput(dr[i]["专业名称"].ToString());
                 Student.colleage = Tools.safeUserInput(dr[i]["所在学院"].ToString());
                 Student.classType = Tools.safeUserInput(dr[i]["集中办学"].ToString());
                 Student.degree = Tools.safeUserInput(dr[i]["毕业学位"].ToString());
                 Student.placeOfWork =Tools.safeUserInput( dr[i]["工作单位"].ToString());
                 Student.type = Tools.safeUserInput(dr[i]["单位类型"].ToString());
                 Student.workPhone = Tools.safeUserInput(dr[i]["办公电话"].ToString());
                 Student.phone = Tools.safeUserInput(dr[i]["移动电话"].ToString());
                 Student.email = Tools.safeUserInput(dr[i]["电子邮箱"].ToString());
                 Student.address = Tools.safeUserInput(dr[i]["工作地址"].ToString());
                 Student.zipCode = Tools.safeUserInput(dr[i]["邮政编码"].ToString());
                 Student.passWord = Tools.encrypt(Student.certificateId);
                 Student.sex = Tools.safeUserInput(dr[i]["学生性别"].ToString());
                 Student.admissionDate = Tools.safeUserInput(dr[i]["入学年份"].ToString());
                 Add(Student);
                 string oldStuId = Tools.safeUserInput(dr[i]["进修学号"].ToString().Trim());
                 if (oldStuId.Length > 1)
                 {
                     examrecordBLL ExamRecordBLL = new examrecordBLL();
                     studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL();
                     ExamRecordBLL.repalaceStuId(oldStuId, Student.stuId);
                     StudentLoginLogBLL.repalaceStuId(oldStuId, Student.stuId);
                     Delete(GetModel(oldStuId).id);
                 }
             }
             return i+1;
         }
     }
     catch { return 0; }
     finally { }
 }
 protected void initial(int Id)
 {
     studentBLL StudentBLL = new studentBLL();
     student Student = StudentBLL.GetModel(Id);
     try
     {
         stuIdTB.Text = Student.stuId;
         nameTB.Text = Student.name;
         sexDDL.SelectedValue = Student.sex;
         nationTB.Text = Student.nation;
         birthdayTB.Text = Student.birthday;
         certificateTypeTB.Text = Student.certificateType;
         certificateIdTB.Text = Student.certificateId;
         majorIdTB.Text = Student.majorId;
         majorNameTB.Text = Student.majorName;
         colleageTB.Text = Student.colleage;
         degreeTB.Text = Student.degree;
         classTypeTB.Text = Student.classType;
         typeTB.Text = Student.type;
         placeOfWorkTB.Text = Student.placeOfWork;
         workPhoneTB.Text = Student.workPhone;
         phoneTB.Text = Student.phone;
         emailTB.Text = Student.email;
         addressTB.Text = Student.address;
         zipCodeTB.Text = Student.zipCode;
         schoolYearTB.Text = Student.admissionDate;
     }
     catch
     {
         MessageBox.Show(this, "该学生不存在!");
         Response.Write("<script language=javascript>history.go(-2);</script>");
     }
     finally { };
     examrecordBLL ExamRecordBLL = new examrecordBLL();
     sumCreditStr = ExamRecordBLL.SumCredit(Session["StuId"].ToString().Trim());
     stuGXWCreditStr = ExamRecordBLL.SumGXWCredit(Session["StuId"].ToString().Trim());
     stuGXWAverageCreditStr = ExamRecordBLL.SumGXWAverageCredit(Session["StuId"].ToString().Trim());
 }
    protected void updateStudentBtn_Click(object sender, EventArgs e)
    {
        student Student = new student();
        if (isTextBoxEmpty(stuIdTB, "学生学号")) Student.stuId = getText(stuIdTB);
        else return;
        if (isTextBoxEmpty(nameTB, "学生姓名")) Student.name = getText(nameTB);
        else return;
        Student.sex = sexDDL.SelectedItem.Value;
        if (isTextBoxEmpty(nationTB, "民族")) Student.nation = getText(nationTB);
        else return;
        if (isTextBoxEmpty(birthdayTB, "出生日期"))
        {
            string birthday = getText(birthdayTB);
            if (birthday.Length != 8)
            {
                MessageBox.Show(this, "出生日期格式不正确!");
                return;
            }
            Student.birthday = birthday;
        }
        else return;
        if (isTextBoxEmpty(certificateTypeTB, "证件类型")) Student.certificateType = getText(certificateTypeTB);
        else return;
        if (isTextBoxEmpty(certificateIdTB, "证件号码")) Student.certificateId = getText(certificateIdTB);
        else return;
        if (isTextBoxEmpty(schoolYearTB, "入学时间")) Student.admissionDate = getText(schoolYearTB);
        else return;
        if (isTextBoxEmpty(majorIdTB, "专业代码")) Student.majorId = getText(majorIdTB);
        else return;
        if (isTextBoxEmpty(majorNameTB, "专业名称")) Student.majorName = getText(majorNameTB);
        else return;
        if (isTextBoxEmpty(colleageTB, "所在学院")) Student.colleage = getText(colleageTB);
        else return;
        Student.classType = getText(classTypeTB);
        Student.degree = getText(degreeTB);
        Student.type = getText(typeTB);
        Student.placeOfWork = getText(placeOfWorkTB);
        Student.workPhone = getText(workPhoneTB);
        if (isTextBoxEmpty(phoneTB, "移动电话")) Student.phone = getText(phoneTB);
        else return;
        Student.email = getText(emailTB);
        Student.address = getText(addressTB);
        Student.zipCode = getText(zipCodeTB);
        string passWord = Tools.safeUserInput(passWordTB.Text.Trim().ToString());
        studentBLL StudentBLL = new studentBLL();
        if (passWord.Length < 1) Student.passWord = StudentBLL.GetModel(id).passWord;
        else Student.passWord = Tools.encrypt(passWord);

        if (StudentBLL.GetModel(id).stuId != Student.stuId)
        {
            examrecordBLL ExamRecordBLL = new examrecordBLL();
            studentloginlogBLL StudentLoginLogBLL = new studentloginlogBLL();
            try
            {
                StudentBLL.Add(Student);
                ExamRecordBLL.repalaceStuId(StudentBLL.GetModel(id).stuId, Student.stuId);
                StudentLoginLogBLL.repalaceStuId(StudentBLL.GetModel(id).stuId, Student.stuId);
                StudentBLL.Delete(id);

            }
            catch
            {
                MessageBox.Show(this, "更新失败!");
            }
        }
        if (Session["StuId"].ToString().Trim().Equals(getText(stuIdTB)))
        {
            Student.id = id;
            try
            {
                StudentBLL.Update(Student);
            }
            catch
            {
                MessageBox.Show(this, "更新失败!");
            }
        }
        MessageBox.ShowAndRedirect(this, "更新成功!", "student.aspx");
    }