protected void btnSave_Click(object sender, ImageClickEventArgs e) { DataTable dataTable = BindGrid(); if (txtMET2.Text == "") { txtMET2.Text = "1"; } if (chkHasTrainClass.Checked) { if (hfPostID.Value == "") { SessionSet.PageMessage = "带有培训班的考试,必须选择职名!"; return; } } RandomExamBLL examBLL = new RandomExamBLL(); RailExam.Model.RandomExam exam = new RailExam.Model.RandomExam(); string strID = string.Empty; string strMode = ViewState["mode"].ToString(); string strStartMode = ViewState["startmode"].ToString(); RandomExamTrainClassBLL objTrainClassBll = new RandomExamTrainClassBLL(); string[] strPost = hfPostID.Value.Split(','); string strErrorMessage = ""; OracleAccess db = new OracleAccess(); if (strMode == "Insert") { string strExam = "select * from Random_Exam where Exam_Name='" + txtExamName.Text + "'"; if (db.RunSqlDataSet(strExam).Tables[0].Rows.Count > 0) { SessionSet.PageMessage = "该考试名称在系统中已经存在,请重新输入!"; txtExamName.Focus(); return; } if (chkHasTrainClass.Checked) { foreach (DataRow dr in dataTable.Rows) { for (int i = 0; i < strPost.Length; i++) { IList <RandomExamTrainClass> objList = objTrainClassBll.GetRandomExamTrainClassCount(Convert.ToInt32(dr["TrainClassID"].ToString()), Convert.ToInt32(dr["TrainClassSubjectID"].ToString()), Convert.ToInt32(strPost[i])); if (objList.Count > 0) { strErrorMessage = "培训班“" + dr["TrainClassName"] + "”的考试科目“" + dr["TrainClassSubjectName"] + "”已新增当前所选职名的试卷!"; } } } } if (strErrorMessage != "") { SessionSet.PageMessage = strErrorMessage; return; } exam.CategoryId = int.Parse(hfCategoryId.Value); exam.ExamName = txtExamName.Text; exam.Memo = txtMemo.Text; exam.CreatePerson = PrjPub.CurrentLoginUser.EmployeeName; exam.ExamModeId = 1; exam.PassScore = Convert.ToDecimal(txtPassScore.Text); if (rbnExamMode1.Checked) { exam.IsComputerExam = true; } else { exam.IsComputerExam = false; } if (rbnStartMode1.Checked) { exam.StartMode = 1; } else { exam.StartMode = 2; } if (rbnStyle1.Checked) { exam.ExamStyle = 1; } else { exam.ExamStyle = 2; } exam.IsAutoScore = chAutoScore.Checked; exam.CanSeeAnswer = chkCanSeeAnswer.Checked; exam.CanSeeScore = chSeeScore.Checked; exam.IsPublicScore = chPublicScore.Checked; exam.IsUnderControl = chUD.Checked; exam.MaxExamTimes = int.Parse(txtMET2.Text); exam.MinExamTimes = 1; exam.BeginTime = DateTime.Parse(dateBeginTime.DateValue.ToString()); exam.EndTime = DateTime.Parse(dateEndTime.DateValue.ToString()); exam.ExamTypeId = 1; exam.CreateTime = DateTime.Now; exam.Description = txtDescription.Text; exam.ExamTime = int.Parse(txtExamTime.Text); exam.StatusId = 1; exam.PostID = hfPostID.Value; exam.RandomExamModularTypeID = Convert.ToInt32(ddlModularType.SelectedValue); exam.IsReduceError = chkIsReduceScore.Checked; exam.AutoSaveInterval = chkAllItem.Checked ? 1 : 0; if (saveTd.Visible) { exam.SaveStatus = Convert.ToInt32(ddlDate.SelectedValue); if (dateSaveDate.Visible) { if (dateSaveDate.DateValue == null) { SessionSet.PageMessage = "请选择一个存档时间!"; return; } exam.SaveDate = Convert.ToDateTime(dateSaveDate.DateValue); } } else { exam.SaveStatus = 0; exam.SaveDate = null; } //exam.AutoSaveInterval = 0; exam.OrgId = PrjPub.CurrentLoginUser.StationOrgID; exam.HasTrainClass = chkHasTrainClass.Checked; int id = examBLL.AddExam(exam); strID = id.ToString(); if (_isWuhanOnly) { //当考试来源为培训班时,需自动添加考生。 if (chkHasTrainClass.Checked) { foreach (DataRow dr in dataTable.Rows) { RandomExamTrainClass obj = new RandomExamTrainClass(); obj.RandomExamID = Convert.ToInt32(strID); obj.TrainClassID = Convert.ToInt32(dr["TrainClassID"].ToString()); obj.TrainClassSubjectID = Convert.ToInt32(dr["TrainClassSubjectID"].ToString()); objTrainClassBll.AddRandomExamTrainClass(obj); } //ClientScript.RegisterStartupScript(GetType(), // "jsSelectFirstNode", // @"SaveArrange(" + strID + ",'" + strStartMode + "','" + strMode + "');", // true); //string strClause = strID + "|" + strStartMode + "|" + strMode; //ClientScript.RegisterStartupScript(GetType(), "import", "inputCallback.callback('" + strClause + "');", true); try { SaveRandomExamArrange(strID, hfTrainClassID.Value, hfPostID.Value); } catch { SessionSet.PageMessage = "添加考生失败"; return; } Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } else { Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else { Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else if (strMode == "Edit") { strID = Request.QueryString.Get("id"); if (Pub.HasPaper(Convert.ToInt32(strID))) { Response.Write("<script>alert('该考试已生成试卷,不能被编辑!');window.close();</script>"); return; } string strExam = "select * from Random_Exam where Random_Exam_ID!=" + strID + " and Exam_Name='" + txtExamName.Text + "'"; if (db.RunSqlDataSet(strExam).Tables[0].Rows.Count > 0) { SessionSet.PageMessage = "该考试名称在系统中已经存在,请重新输入!"; txtExamName.Focus(); return; } string strSql = "select * from Random_Exam_Computer_Server where Has_Paper=1 and Random_Exam_ID=" + strID; DataTable dt = db.RunSqlDataSet(strSql).Tables[0]; if (dt.Rows.Count > 0) { SessionSet.PageMessage = "当前考试已经生成试卷,不能继续编辑!"; return; } if (chkHasTrainClass.Checked && ViewState["TrainClass"].ToString() != hfTrainClassID.Value) { foreach (DataRow dr in dataTable.Rows) { for (int i = 0; i < strPost.Length; i++) { IList <RandomExamTrainClass> objList = objTrainClassBll.GetRandomExamTrainClassCount(Convert.ToInt32(dr["TrainClassID"].ToString()), Convert.ToInt32(dr["TrainClassSubjectID"].ToString()), Convert.ToInt32(strPost[i])); if (objList.Count > 0) { if (objList[0].RandomExamID.ToString() != strID) { strErrorMessage = "培训班“" + dr["TrainClassName"] + "”的考试科目“" + dr["TrainClassSubjectName"] + "”已新增当前所选职名的试卷!"; } } } } } if (strErrorMessage != "") { SessionSet.PageMessage = strErrorMessage; return; } exam.CategoryId = Convert.ToInt32(hfCategoryId.Value); exam.ExamName = txtExamName.Text; exam.Memo = txtMemo.Text; exam.RandomExamId = int.Parse(strID); exam.ExamTime = int.Parse(txtExamTime.Text); exam.ExamModeId = 1; exam.PassScore = Convert.ToDecimal(txtPassScore.Text); if (rbnExamMode1.Checked) { exam.IsComputerExam = true; } else { exam.IsComputerExam = false; } if (rbnStartMode1.Checked) { exam.StartMode = 1; } else { exam.StartMode = 2; } if (rbnStyle1.Checked) { exam.ExamStyle = 1; } else { exam.ExamStyle = 2; } exam.BeginTime = DateTime.Parse(dateBeginTime.DateValue.ToString()); exam.EndTime = DateTime.Parse(dateEndTime.DateValue.ToString()); exam.IsAutoScore = chAutoScore.Checked; exam.CanSeeAnswer = chkCanSeeAnswer.Checked; exam.CanSeeScore = chSeeScore.Checked; exam.IsPublicScore = chPublicScore.Checked; exam.IsUnderControl = chUD.Checked; exam.MaxExamTimes = int.Parse(txtMET2.Text); exam.MinExamTimes = 1; exam.ExamTypeId = 1; exam.Description = txtDescription.Text; //exam.AutoSaveInterval = 0; exam.RandomExamModularTypeID = Convert.ToInt32(ddlModularType.SelectedValue); exam.IsReduceError = chkIsReduceScore.Checked; exam.AutoSaveInterval = chkAllItem.Checked ? 1 : 0; if (saveTd.Visible) { exam.SaveStatus = Convert.ToInt32(ddlDate.SelectedValue); if (dateSaveDate.Visible) { if (dateSaveDate.DateValue == null) { SessionSet.PageMessage = "请选择一个存档时间!"; return; } exam.SaveDate = Convert.ToDateTime(dateSaveDate.DateValue); } } else { exam.SaveStatus = 0; exam.SaveDate = null; } RandomExamArrangeBLL objArrangeBll = new RandomExamArrangeBLL(); //当是否为培训班改变或则培训班改变时,需删除考试安排 if (Convert.ToBoolean(ViewState["HasTrainClass"].ToString()) != chkHasTrainClass.Checked || ViewState["TrainClass"].ToString() != hfTrainClassID.Value || ViewState["PostID"].ToString() != hfPostID.Value) { objArrangeBll.DeleteRandomExamArrangeByRandomExamID(Convert.ToInt32(strID)); } if ((Convert.ToBoolean(ViewState["HasTrainClass"].ToString()) != chkHasTrainClass.Checked && !chkHasTrainClass.Checked) || ViewState["TrainClass"].ToString() != hfTrainClassID.Value) { objTrainClassBll.DeleteRandomExamTrainClassByRandomExamID(Convert.ToInt32(strID)); } exam.HasTrainClass = chkHasTrainClass.Checked; exam.PostID = hfPostID.Value; exam.Version = exam.Version + 1; examBLL.UpdateExam(exam); if (_isWuhanOnly) { if (chkHasTrainClass.Checked) { //当培训班或职名发生变化时,更改考生名单 if (ViewState["TrainClass"].ToString() != hfTrainClassID.Value || ViewState["PostID"].ToString() != hfPostID.Value) { objTrainClassBll.DeleteRandomExamTrainClassByRandomExamID(Convert.ToInt32(strID)); foreach (DataRow dr in dataTable.Rows) { RandomExamTrainClass obj = new RandomExamTrainClass(); obj.RandomExamID = Convert.ToInt32(strID); obj.TrainClassID = Convert.ToInt32(dr["TrainClassID"].ToString()); obj.TrainClassSubjectID = Convert.ToInt32(dr["TrainClassSubjectID"].ToString()); objTrainClassBll.AddRandomExamTrainClass(obj); } //ClientScript.RegisterStartupScript(GetType(), //"jsSelectFirstNode", //@"SaveArrange(" + strID + ",'" + strStartMode + "','" + strMode + "');", //true); //string strClause = strID + "|" + strStartMode + "|" + strMode; //ClientScript.RegisterStartupScript(GetType(), "import", "inputCallback.callback('" + strClause + "');", true); try { SaveRandomExamArrange(strID, hfTrainClassID.Value, hfPostID.Value); } catch { SessionSet.PageMessage = "添加考生失败"; return; } Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } else { Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else { Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else { Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else { strID = Request.QueryString.Get("id"); Response.Redirect("RandomExamManageSecond.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } }
protected void btnSave_Click(object sender, ImageClickEventArgs e) { DataTable dataTable = BindGrid(); if (txtMET2.Text == "") { txtMET2.Text = "1"; } if (!rbnSubject1.Checked && !rbnSubject2.Checked) { SessionSet.PageMessage = "请选择考试科目类别!"; return; } RandomExamBLL examBLL = new RandomExamBLL(); RailExam.Model.RandomExam exam = new RailExam.Model.RandomExam(); string strID = string.Empty; string strMode = ViewState["mode"].ToString(); string strStartMode = ViewState["startmode"].ToString(); RandomExamTrainClassHaBLL objTrainClassBll = new RandomExamTrainClassHaBLL(); string[] strPost = hfPostID.Value.Split(','); string strErrorMessage = ""; if (strMode == "Insert") { if (chkHasTrainClass.Checked) { foreach (DataRow dr in dataTable.Rows) { for (int i = 0; i < strPost.Length; i++) { IList <RandomExamTrainClassHa> objList = objTrainClassBll.GetRandomExamTrainClassCount(dr["TrainClassID"].ToString(), rbnSubject1.Checked?1:2, Convert.ToInt32(strPost[i])); if (objList.Count > 0) { strErrorMessage = "培训班“" + dr["TrainClassName"] + "”的考试科目“" + (rbnSubject1.Checked ? "安全" : "理论") + "”已新增当前所选职名的试卷!"; } } } } if (strErrorMessage != "") { SessionSet.PageMessage = strErrorMessage; return; } if (DateTime.Parse(dateBeginTime.DateValue.ToString()) < DateTime.Today) { SessionSet.PageMessage = "开始时间不能小于当前日期!"; return; } exam.CategoryId = int.Parse(hfCategoryId.Value); exam.ExamName = txtExamName.Text; exam.Memo = txtMemo.Text; exam.CreatePerson = PrjPub.CurrentLoginUser.EmployeeName; exam.ExamModeId = 1; exam.PassScore = Convert.ToDecimal(txtPassScore.Text); if (rbnExamMode1.Checked) { exam.IsComputerExam = true; } else { exam.IsComputerExam = false; } if (rbnStartMode1.Checked) { exam.StartMode = 1; } else { exam.StartMode = 2; } if (rbnStyle1.Checked) { exam.ExamStyle = 1; } else { exam.ExamStyle = 2; } exam.IsAutoScore = chAutoScore.Checked; exam.CanSeeAnswer = chSeeAnswer.Checked; exam.CanSeeScore = chSeeScore.Checked; exam.IsPublicScore = chPublicScore.Checked; exam.IsUnderControl = chUD.Checked; exam.MaxExamTimes = int.Parse(txtMET2.Text); if (rbnSubject1.Checked) { exam.MinExamTimes = 1; } else if (rbnSubject2.Checked) { exam.MinExamTimes = 2; } exam.BeginTime = DateTime.Parse(dateBeginTime.DateValue.ToString()); exam.EndTime = DateTime.Parse(dateEndTime.DateValue.ToString()); exam.ExamTypeId = 1; exam.CreateTime = DateTime.Now; exam.Description = txtDescription.Text; exam.ExamTime = int.Parse(txtExamTime.Text); exam.StatusId = 1; exam.PostID = hfPostID.Value; exam.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue); exam.IsGroupLeader = Convert.ToInt32(ddlIsGroup.SelectedValue); exam.AutoSaveInterval = 0; exam.OrgId = PrjPub.CurrentLoginUser.StationOrgID; exam.HasTrainClass = chkHasTrainClass.Checked; int id = examBLL.AddExam(exam); strID = id.ToString(); //当考试来源为培训班时,需自动添加考生。 if (chkHasTrainClass.Checked) { foreach (DataRow dr in dataTable.Rows) { RandomExamTrainClassHa obj = new RandomExamTrainClassHa(); obj.RandomExamID = Convert.ToInt32(strID); obj.ArchivesID = dr["TrainClassID"].ToString(); objTrainClassBll.AddRandomExamTrainClass(obj); } //ClientScript.RegisterStartupScript(GetType(), // "jsSelectFirstNode", // @"SaveArrange(" + strID + ",'" + strStartMode + "','" + strMode + "');", // true); string strClause = strID + "|" + strStartMode + "|" + strMode; ClientScript.RegisterStartupScript(GetType(), "import", "inputCallback.callback('" + strClause + "');", true); } else { Response.Redirect("RandomExamSubjectInfo.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else if (strMode == "Edit") { strID = Request.QueryString.Get("id"); if (chkHasTrainClass.Checked && (ViewState["TrainClass"].ToString() != hfTrainClassID.Value || ViewState["Subject"].ToString() != (rbnSubject1.Checked ? 1 : 2).ToString())) { foreach (DataRow dr in dataTable.Rows) { for (int i = 0; i < strPost.Length; i++) { IList <RandomExamTrainClassHa> objList = objTrainClassBll.GetRandomExamTrainClassCount(dr["TrainClassID"].ToString(), rbnSubject1.Checked ? 1 : 2, Convert.ToInt32(strPost[i])); if (objList.Count > 0) { if (objList[0].RandomExamID.ToString() != strID) { strErrorMessage = "培训班“" + dr["TrainClassName"] + "”的考试科目“" + (rbnSubject1.Checked ? "安全" : "理论") + "”已新增当前所选职名的试卷!"; } } } } } if (strErrorMessage != "") { SessionSet.PageMessage = strErrorMessage; return; } if (DateTime.Parse(dateBeginTime.DateValue.ToString()) < DateTime.Today && ViewState["BeginTime"].ToString() != dateBeginTime.DateValue.ToString()) { SessionSet.PageMessage = "开始时间不能小于当前日期!"; return; } exam.ExamName = txtExamName.Text; exam.Memo = txtMemo.Text; exam.RandomExamId = int.Parse(strID); exam.ExamTime = int.Parse(txtExamTime.Text); exam.ExamModeId = 1; exam.PassScore = Convert.ToDecimal(txtPassScore.Text); if (rbnExamMode1.Checked) { exam.IsComputerExam = true; } else { exam.IsComputerExam = false; } if (rbnStartMode1.Checked) { exam.StartMode = 1; } else { exam.StartMode = 2; } if (rbnStyle1.Checked) { exam.ExamStyle = 1; } else { exam.ExamStyle = 2; } exam.BeginTime = DateTime.Parse(dateBeginTime.DateValue.ToString()); exam.EndTime = DateTime.Parse(dateEndTime.DateValue.ToString()); exam.IsAutoScore = chAutoScore.Checked; exam.CanSeeAnswer = chSeeAnswer.Checked; exam.CanSeeScore = chSeeScore.Checked; exam.IsPublicScore = chPublicScore.Checked; exam.IsUnderControl = chUD.Checked; exam.MaxExamTimes = int.Parse(txtMET2.Text); if (rbnSubject1.Checked) { exam.MinExamTimes = 1; } else if (rbnSubject2.Checked) { exam.MinExamTimes = 2; } exam.ExamTypeId = 1; exam.Description = txtDescription.Text; exam.AutoSaveInterval = 0; exam.PostID = hfPostID.Value; exam.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue); exam.IsGroupLeader = Convert.ToInt32(ddlIsGroup.SelectedValue); RandomExamArrangeBLL objArrangeBll = new RandomExamArrangeBLL(); //当是否为培训班改变或所选培训班改变时,需删除考试安排 if (Convert.ToBoolean(ViewState["HasTrainClass"].ToString()) != chkHasTrainClass.Checked || ViewState["TrainClass"].ToString() != hfTrainClassID.Value || ViewState["PostID"].ToString() != hfPostID.Value) { objArrangeBll.DeleteRandomExamArrangeByRandomExamID(Convert.ToInt32(strID)); } if ((Convert.ToBoolean(ViewState["HasTrainClass"].ToString()) != chkHasTrainClass.Checked && !chkHasTrainClass.Checked) || ViewState["TrainClass"].ToString() != hfTrainClassID.Value) { objTrainClassBll.DeleteRandomExamTrainClassByRandomExamID(Convert.ToInt32(strID)); } exam.HasTrainClass = chkHasTrainClass.Checked; examBLL.UpdateExam(exam); examBLL.UpdateVersion(Convert.ToInt32(strID)); if (chkHasTrainClass.Checked) { if (ViewState["TrainClass"].ToString() != hfTrainClassID.Value || ViewState["PostID"].ToString() != hfPostID.Value) { foreach (DataRow dr in dataTable.Rows) { RandomExamTrainClassHa obj = new RandomExamTrainClassHa(); obj.RandomExamID = Convert.ToInt32(strID); obj.ArchivesID = dr["TrainClassID"].ToString(); objTrainClassBll.AddRandomExamTrainClass(obj); } //ClientScript.RegisterStartupScript(GetType(), //"jsSelectFirstNode", //@"SaveArrange(" + strID + ",'" + strStartMode + "','" + strMode + "');", //true); string strClause = strID + "|" + strStartMode + "|" + strMode; ClientScript.RegisterStartupScript(GetType(), "import", "inputCallback.callback('" + strClause + "');", true); } else { Response.Redirect("RandomExamSubjectInfo.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else { Response.Redirect("RandomExamSubjectInfo.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } } else { strID = Request.QueryString.Get("id"); Response.Redirect("RandomExamSubjectInfo.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strID); } }