protected void uploadBtn_Click(object sender, EventArgs e)
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     int result = ClassDetailBLL.Add(this, excelFU);
     if (result == 0) MessageBox.Show(this, "上传失败!");
     else MessageBox.ShowAndRedirect(this, "成功导入" + result + "门课程信息","class.aspx");
 }
 protected string getClassName()
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     classdetail ClassDetail = ClassDetailBLL.GetModel(id);
     string result;
     if (ClassDetail != null)
     {
         result = ClassDetail.name + " " + ClassDetail.teacher + " " + ClassDetail.startTime.ToShortDateString() + "~" + ClassDetail.endTime.ToShortDateString();
     }
     else
         result = "你选择的课程不存在!";
     return result;
 }
 protected void Button1_Click(object sender, EventArgs e)
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     ds = ClassDetailBLL.Select(Tools.safeUserInput(TextBox1.Text.ToString()), DropDownList1.SelectedItem.Value);
     if (ds == null) MessageBox.Show(this, "未找到符合条件的课程!");
     else
     {
         ViewState["source"] = ds;
         GridViewDataBind(GridView2, ds);
         GridView2.Visible = true;
         GridView1.Visible = false;
     }
 }
 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();
 }
 /// <summary>
 /// 增加excel数据库
 /// </summary>
 public int Add(Page page, FileUpload fu)
 {
     classtypeBLL ClassTypeBLL=new classtypeBLL();
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     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/classInput/");
         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++)
             {
                 classdetail ClassDetail = new classdetail();
                 string name = dr[i]["课程名称"].ToString();
                 if (name.Length < 1)
                 {
                     MessageBox.Show(page, "导入第" + (i + 1).ToString() + "门课程信息失败,课程名称不能为空,请检查数据");
                     return i;
                 }
                 else ClassDetail.name = name;
                 int classType=0;
                 try
                 {
                     classType = Convert.ToInt32(dr[i]["课程类别"]);
                 }
                 catch {
                     MessageBox.Show(page, "导入第" + (i + 1).ToString() + "门课程信息失败,课程类别必须为数字,请检查数据");
                     return i;
                 }
                 if (!(ClassTypeBLL.Exists(classType.ToString())))
                 {
                     MessageBox.Show(page, "导入第" + (i + 1).ToString() + "门课程信息失败,课程类别不存在,请检查数据");
                     return i;
                 }
                 else ClassDetail.type = classType;
                 ClassDetail.teacher = dr[i]["教师姓名"].ToString();
                 try
                 {
                     ClassDetail.startTime = Convert.ToDateTime(dr[i]["开始时间"]);
                 }
                 catch {
                     MessageBox.Show(page, "导入第" + (i + 1).ToString() + "门课程信息失败,开始时间格式不正确,请确保为“yyyy/mm/dd  hh:mm:ss”,请检查数据");
                     return i;
                 }
                 try
                 {
                     ClassDetail.endTime = Convert.ToDateTime(dr[i]["结束时间"]);
                 }
                 catch
                 {
                     MessageBox.Show(page, "导入第" + (i + 1).ToString() + "门课程信息失败,结束时间格式不正确,请确保为“yyyy/mm/dd  hh:mm:ss”,请检查数据");
                     return i;
                 }
                 ClassDetail.period = dr[i]["学时"].ToString();
                 ClassDetail.credit = dr[i]["学分"].ToString();
                 ClassDetail.location = dr[i]["开课地点"].ToString();
                 ClassDetail.remark = dr[i]["备注"].ToString();
                 ClassDetailBLL.Add(ClassDetail);
             }
             return i ;
         }
     }
     catch { return 0; }
     finally { }
 }
 protected bool isInClass(string teacher, string className, int classId)
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     classdetail ClassDetail = ClassDetailBLL.GetModel(classId);
     if (teacher.Trim().Equals(ClassDetail.teacher.Trim()) && className.Trim().Equals(ClassDetail.name.Trim())) return true;
     else return false;
 }
    protected void addStudentBtn_Click(object sender, EventArgs e)
    {
        classdetail ClassDetail = new classdetail();
        if (isTextBoxEmpty(nameTB, "课程名称")) ClassDetail.name = getText(nameTB);
        else return;
         ClassDetail.type = Convert.ToInt32(typeDDL.SelectedItem.Value);
        if (isTextBoxEmpty(teacherTB, "教师姓名")) ClassDetail.teacher= getText(teacherTB);
        else return;
        string startTimeStr = "";
        if (isTextBoxEmpty(startYearTB, "开始时间-年"))
        {
            string year = getText(startYearTB);
            if (year.Length != 4)
            {
                MessageBox.Show(this, "开始时间-年:格式不正确!");
                return;
            }
            startTimeStr += year+"-";
        }
        if (isTextBoxEmpty(startMonthTB, "开始时间-月"))
        {
            int month = Convert.ToInt32(getText(startMonthTB));
            if (month<1||month>12)
            {
                MessageBox.Show(this, "开始时间-月:格式不正确!");
                return;
            }
            if (month < 10)
                startTimeStr += "0" + month.ToString()+"-";
            else startTimeStr += month.ToString()+"-";
        }
        if (isTextBoxEmpty(startDayTB, "开始时间-日"))
        {
            int day = Convert.ToInt32(getText(startDayTB));
            if (day < 1 || day > 31)
            {
                MessageBox.Show(this, "开始时间-日:格式不正确!");
                return;
            }
            if(day<10)
            startTimeStr += "0"+day.ToString();
            else startTimeStr += day.ToString() ;
        }
            ClassDetail.startTime=Convert.ToDateTime(startTimeStr);
         string endTimeStr = "";
        if (isTextBoxEmpty(endYearTB, "结束时间-年"))
        {
            string year = getText(endYearTB);
            if (year.Length != 4)
            {
                MessageBox.Show(this, "结束时间-年:格式不正确!");
                return;
            }
            endTimeStr += year + "-";
        }
        if (isTextBoxEmpty(endMonthTB, "结束时间-月"))
        {
            int month = Convert.ToInt32(getText(endMonthTB));
            if (month<1||month>12)
            {
                MessageBox.Show(this, "结束时间-月:格式不正确!");
                return;
            }
            if (month < 10)
                endTimeStr += "0" + month.ToString() + "-";
            else endTimeStr += month.ToString() + "-";
        }
        if (isTextBoxEmpty(endDayTB, "结束时间-日"))
        {
            int day = Convert.ToInt32(getText(endDayTB));
            if (day < 1 || day > 31)
            {
                MessageBox.Show(this, "结束时间-日:格式不正确!");
                return;
            }
            if (day < 10)
                endTimeStr += "0" + day.ToString();
            else endTimeStr += day.ToString();
        }
            ClassDetail.endTime=Convert.ToDateTime(endTimeStr);

            if (isTextBoxEmpty(periodTB, "学时")) ClassDetail.period = getText(periodTB);
        else return;
            if (isTextBoxEmpty(creditTB, "学分")) ClassDetail.credit = getText(creditTB);
        else return;
        if (isTextBoxEmpty(locationTB, "开课地点")) ClassDetail.location = getText(locationTB);
        else return;
        ClassDetail.remark=getText(remarkTB);
        try
        {
            classdetailBLL ClassDetailBLL = new classdetailBLL();
            ClassDetailBLL.Add(ClassDetail);
        }
        catch(Exception ex)
        {
            MessageBox.Show(this, "添加失败!");
            Console.WriteLine(ex.Message);

        }
        MessageBox.Show(this, "添加成功!");
    }
 protected void initial(int Id)
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     classdetail ClassDetail = ClassDetailBLL.GetModel(Id);
     try
     {
         nameTB.Text = ClassDetail.name;
         typeDDL.SelectedValue = ClassDetail.type.ToString();
         teacherTB.Text = ClassDetail.teacher;
         startYearTB.Text = ClassDetail.startTime.Year.ToString();
         startMonthTB.Text = ClassDetail.startTime.Month.ToString();
         startDayTB.Text = ClassDetail.startTime.Day.ToString();
         endYearTB.Text = ClassDetail.endTime.Year.ToString();
         endMonthTB.Text = ClassDetail.endTime.Month.ToString();
         endDayTB.Text = ClassDetail.endTime.Day.ToString();
         periodTB.Text = ClassDetail.period;
         creditTB.Text = ClassDetail.credit;
         locationTB.Text = ClassDetail.location;
         remarkTB.Text = ClassDetail.remark;
     }
     catch
     {
         MessageBox.Show(this, "该课程不存在!");
         Response.Write("<script language=javascript>history.go(-2);</script>");
     }
     finally { };
 }
    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 DataSet getClassDetail()
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     return ClassDetailBLL.GetList("");
 }
 protected void searchBtn_Click(object sender, EventArgs e)
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     ds = ClassDetailBLL.Select(keyWordTB.Text.ToString(), searchTypeDDL.SelectedItem.Value);
     if (ds == null) MessageBox.Show(this, "未找到符合条件的课程!");
     else
     {
         ViewState["source"] = ds;
         GridViewDataBind(GridView1, ds);
     }
 }
 protected bool isClassIdExisted(int classId)
 {
     classdetailBLL ClassDetailBLL = new classdetailBLL();
     return ClassDetailBLL.Exists(classId);
 }