protected void btn_Save_Click(object sender, EventArgs e) { bool issucess = false; try { if (string.IsNullOrEmpty(tb_Code.Text)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划编号不能为空!');</script>"); return; } if (CY.GFive.Core.Business.CoursePlan.GetInstance(tb_Code.Text) != null) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('已存在相同编号的记录!');</script>"); return; } if (DDLGrade.SelectedValue.ToString() == "0") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划年级不能为空,且应该为正确格式!');</script>"); return; } if (ddlYear.SelectedValue == "0") { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划年份不能为空,且应该为正确格式!');</script>"); return; } if (string.IsNullOrEmpty(ddl_Profess.SelectedValue)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('所选专业不能为空!');</script>"); return; } string[] courses = Request.Form.GetValues("course"); string[] teachers = Request.Form.GetValues("teacher"); string[] scores = Request.Form.GetValues("score"); string[] times = Request.Form.GetValues("time"); string clsCode = Request.Form.Get("select_classinfo"); if (isInputValidata(courses, teachers, scores, times) && !string.IsNullOrEmpty(clsCode) && CY.GFive.Core.Business.ClassInfo.IsExist(clsCode)) { CY.GFive.Core.Business.CoursePlan plan = new CY.GFive.Core.Business.CoursePlan(); plan.PlanCode = tb_Code.Text; plan.PlanGrade = DDLGrade.SelectedItem.Text; plan.ProCode = ddl_Profess.SelectedValue; plan.PlanTerm = Request.Form.Get("ddlTeam"); plan.PlanYear = ddlYear.SelectedItem.Text; plan.ClsCode = clsCode; CY.GFive.Core.Business.PlanCourse course = null; for (int i = 0; i < courses.Length; i++) { course = new CY.GFive.Core.Business.PlanCourse(); course.PlanCode = plan.PlanCode; course.CourseCode = courses[i]; course.TeacherCode = teachers[i]; course.CourseScore = int.Parse(scores[i]); course.CourseNum = int.Parse(times[i]); course.Save(); } plan.Save(); issucess = true; } } catch (Exception ex) { throw ex; } finally { if (issucess) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('添加课程计划成功!');window.location.href='CoursePlanList.aspx'</script>"); } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('添加课程计划失败,请检查输入是否正确并联系管理员!');</script>"); } } }
protected void btn_Save_Click(object sender, EventArgs e) { bool issucess = false; try { int temp = default(int); if (string.IsNullOrEmpty(tb_Year.Text) || !IsNumber(tb_Year.Text)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划年份不能为空,并且格式必须正确!')</script>"); } if (string.IsNullOrEmpty(ddl_Term.SelectedValue) || !int.TryParse(ddl_Term.SelectedValue, out temp) || temp > 2 || temp < 1) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划学期不能为空!')</script>"); } if (string.IsNullOrEmpty(ddl_Pro.SelectedValue)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划专业不能为空!')</script>"); } if (string.IsNullOrEmpty(tb_Grade.Text) || !IsNumber(tb_Grade.Text)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('计划年级不能为空,并且格式必须正确!')</script>"); } string[] courses = Request.Form.GetValues("course"); string[] teachers = Request.Form.GetValues("teacher"); string[] scores = Request.Form.GetValues("score"); string[] times = Request.Form.GetValues("time"); if (isQueryStringValidate && isInputValidata(courses, teachers, times, scores)) { CY.GFive.Core.Business.CoursePlan plan = CY.GFive.Core.Business.CoursePlan.GetInstance(QueryString); if (plan != null) { // need to indentify the Grade Profess is Exist plan.PlanGrade = tb_Grade.Text.Trim(); plan.PlanTerm = ddl_Term.SelectedValue.Trim(); plan.PlanYear = tb_Year.Text.Trim(); plan.ProCode = ddl_Pro.SelectedValue.Trim(); CY.GFive.Core.Business.PlanCourse course = null; if (courses != null) { for (int i = 0; i < courses.Length; i++) { course = new CY.GFive.Core.Business.PlanCourse(); course.CourseCode = courses[i]; course.TeacherCode = teachers[i]; course.PlanCode = plan.PlanCode; course.CourseNum = Convert.ToInt32(times[i]); course.CourseScore = Convert.ToInt32(scores[i]); course.Save(); } } plan.Save(); issucess = true; } } } catch (Exception ex) { throw ex; } finally { if (issucess) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('修改成功!')</script>"); } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('修改失败,请检查输入数据格式是否正确或联系管理员!')</script>"); } GvCourseDataBind(); } }