示例#1
0
        protected void btnSave_Click(object sender, ImageClickEventArgs e)
        {
            string strId        = Request.QueryString.Get("id");
            string strMode      = ViewState["mode"].ToString();
            string strStartMode = ViewState["startmode"].ToString();

            if (ViewState["mode"].ToString() == "ReadOnly")
            {
                //if (strStartMode == "Edit")
                //{
                //    Response.Redirect("SelectEmployeeDetailNew.aspx?startmode=Edit&mode=Edit&id=" + strId);
                //    return;
                //}
                //else
                //{
                //    Response.Redirect("SelectEmployeeDetailNew.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strId);
                //    return;
                //}

                Response.Redirect("SelectEmployeeDetailNew.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strId);
                return;
            }

            if (Pub.HasPaper(Convert.ToInt32(strId)))
            {
                Response.Write("<script>alert('该考试已生成试卷,不能被编辑!');window.close();</script>");
                return;
            }

            RandomExamStrategyBLL psbcBll = new RandomExamStrategyBLL();

            int Ncount = psbcBll.GetRandomExamStrategysByExamID(int.Parse(strId)).Count;

            if (Ncount == 0)
            {
                SessionSet.PageMessage = "请添加策略!";
                return;
            }

            RandomExamSubjectBLL  subjectBLL  = new RandomExamSubjectBLL();
            RandomExamStrategyBLL strategyBLL = new RandomExamStrategyBLL();
            ItemBLL           itemBLL         = new ItemBLL();
            RandomExamItemBLL randomItemBLL   = new RandomExamItemBLL();


            IList <RandomExamSubject> randomExamSubjects = subjectBLL.GetRandomExamSubjectByRandomExamId(int.Parse(strId));
            int ExamItemCounts = 0;

            for (int i = 0; i < randomExamSubjects.Count; i++)
            {
                int     nSubjectId      = randomExamSubjects[i].RandomExamSubjectId;
                decimal nTotalItemCount = randomExamSubjects[i].ItemCount;

                IList <RandomExamStrategy> strategys = strategyBLL.GetRandomExamStrategys(nSubjectId);
                int nItemCount = 0;
                for (int j = 0; j < strategys.Count; j++)
                {
                    nItemCount += strategys[j].ItemCount;  //改动2011-10-17
                }

                ExamItemCounts += nItemCount;
                if (nItemCount != nTotalItemCount)
                {
                    SessionSet.PageMessage = "大题设定的试题数和取题范围设定的总题数不相等,请重新设置!";
                    return;
                }
            }

            if (ExamItemCounts == 0)
            {
                SessionSet.PageMessage = "考试的总题数不能为0,请重新设置!";
                return;
            }

            RandomExamBLL objBll = new RandomExamBLL();

            RailExam.Model.RandomExam obj = objBll.GetExam(Convert.ToInt32(strId));
            int year = obj.BeginTime.Year;

            randomItemBLL.DeleteItems(int.Parse(strId), year);

            Hashtable htItemID = new Hashtable();
            int       count    = 0;

            for (int i = 0; i < randomExamSubjects.Count; i++)
            {
                IList <RailExam.Model.Item> itemList = new List <RailExam.Model.Item>();
                int     nSubjectId = randomExamSubjects[i].RandomExamSubjectId;
                decimal nUnitScore = randomExamSubjects[i].UnitScore;

                IList <RandomExamStrategy> strategys = strategyBLL.GetRandomExamStrategys(nSubjectId);
                for (int k = 0; k < strategys.Count; k++)
                {
                    //策略
                    int    nChapterId    = strategys[k].RangeId;
                    int    nRangeType    = strategys[k].RangeType;
                    int    typeId        = strategys[k].ItemTypeId;
                    int    StrategyId    = strategys[k].RandomExamStrategyId;
                    string strExcludeIDs = strategys[k].ExcludeChapterId;
                    int    ndr           = 0;
                    IList <RailExam.Model.Item> itemListTemp = new List <RailExam.Model.Item>();
                    itemListTemp = itemBLL.GetItemsByStrategy(nRangeType, ndr, nChapterId, typeId, strExcludeIDs, StrategyId);

                    if (itemListTemp.Count < strategys[k].ItemCount)
                    {
                        SessionSet.PageMessage = "大题" + (i + 1).ToString() + "在设定的取题范围内的试题量不够,请重新设置取题范围!";
                        return;
                    }

                    Hashtable htChapter = new Hashtable();
                    for (int m = 0; m < itemListTemp.Count; m++)
                    {
                        itemListTemp[m].StrategyId = StrategyId;
                        if (itemListTemp[m].StatusId == 1)
                        {
                            if (htChapter.ContainsKey(itemListTemp[m].ChapterId))
                            {
                                ArrayList objList = (ArrayList)htChapter[itemListTemp[m].ChapterId];

                                if (objList.IndexOf(itemListTemp[m].MotherCode) < 0)
                                {
                                    itemList.Add(itemListTemp[m]);
                                    if (itemListTemp[m].MotherCode != "" && itemListTemp[m].MotherCode != null)
                                    {
                                        objList.Add(itemListTemp[m].MotherCode);
                                    }
                                }
                            }
                            else
                            {
                                ArrayList objList = new ArrayList();
                                if (itemListTemp[m].MotherCode != "" && itemListTemp[m].MotherCode != null)
                                {
                                    objList.Add(itemListTemp[m].MotherCode);
                                }

                                itemList.Add(itemListTemp[m]);

                                htChapter.Add(itemListTemp[m].ChapterId, objList);
                            }
                        }
                    }
                }

                if (itemList.Count < randomExamSubjects[i].ItemCount)
                {
                    SessionSet.PageMessage = "大题" + (i + 1).ToString() + "在设定的取题范围内的试题量不够,请重新设置取题范围!";
                    return;
                }

                IList <RandomExamItem> randomExamItems = new List <RandomExamItem>();

                int n = 0;
                foreach (RailExam.Model.Item item in itemList)
                {
                    if (string.IsNullOrEmpty(item.StandardAnswer) && (item.TypeId == PrjPub.ITEMTYPE_SINGLECHOOSE || item.TypeId == PrjPub.ITEMTYPE_MULTICHOOSE || item.TypeId == PrjPub.ITEMTYPE_JUDGE))
                    {
                        n = n + 1;
                        break;
                    }
                    if (!htItemID.ContainsKey(item.ItemId))
                    {
                        htItemID.Add(item.ItemId, item.ItemId);
                    }
                    else
                    {
                        count = count + 1;
                        break;
                    }

                    RandomExamItem paperItem = new RandomExamItem();
                    paperItem.SubjectId      = nSubjectId;
                    paperItem.StrategyId     = item.StrategyId;
                    paperItem.RandomExamId   = int.Parse(strId);
                    paperItem.AnswerCount    = item.AnswerCount;
                    paperItem.BookId         = item.BookId;
                    paperItem.CategoryId     = item.CategoryId;
                    paperItem.ChapterId      = item.ChapterId;
                    paperItem.CompleteTime   = item.CompleteTime;
                    paperItem.Content        = item.Content;
                    paperItem.CreatePerson   = item.CreatePerson;
                    paperItem.CreateTime     = item.CreateTime;
                    paperItem.Description    = item.Description;
                    paperItem.DifficultyId   = item.DifficultyId;
                    paperItem.ItemId         = item.ItemId;
                    paperItem.Memo           = item.Memo;
                    paperItem.OrganizationId = item.OrganizationId;
                    paperItem.OutDateDate    = item.OutDateDate;
                    paperItem.Score          = nUnitScore;
                    paperItem.SelectAnswer   = item.SelectAnswer;
                    paperItem.Source         = item.Source;
                    paperItem.StandardAnswer = item.StandardAnswer;
                    paperItem.StatusId       = item.StatusId;
                    paperItem.TypeId         = item.TypeId;
                    paperItem.UsedCount      = item.UsedCount;
                    paperItem.Version        = item.Version;
                    paperItem.ParentItemID   = 0;
                    paperItem.MotherCode     = item.MotherCode;
                    paperItem.ItemIndex      = item.ItemIndex;
                    randomExamItems.Add(paperItem);

                    //完型填空
                    if (item.TypeId == PrjPub.ITEMTYPE_FILLBLANK)
                    {
                        IList <RailExam.Model.Item> itemDetails = itemBLL.GetItemsByParentItemID(item.ItemId);

                        foreach (RailExam.Model.Item itemDetail in itemDetails)
                        {
                            paperItem                = new RandomExamItem();
                            paperItem.SubjectId      = nSubjectId;
                            paperItem.StrategyId     = itemDetail.StrategyId;
                            paperItem.RandomExamId   = int.Parse(strId);
                            paperItem.AnswerCount    = itemDetail.AnswerCount;
                            paperItem.BookId         = itemDetail.BookId;
                            paperItem.CategoryId     = itemDetail.CategoryId;
                            paperItem.ChapterId      = itemDetail.ChapterId;
                            paperItem.CompleteTime   = itemDetail.CompleteTime;
                            paperItem.Content        = itemDetail.Content;
                            paperItem.CreatePerson   = itemDetail.CreatePerson;
                            paperItem.CreateTime     = itemDetail.CreateTime;
                            paperItem.Description    = itemDetail.Description;
                            paperItem.DifficultyId   = itemDetail.DifficultyId;
                            paperItem.ItemId         = itemDetail.ItemId;
                            paperItem.Memo           = itemDetail.Memo;
                            paperItem.OrganizationId = itemDetail.OrganizationId;
                            paperItem.OutDateDate    = itemDetail.OutDateDate;
                            paperItem.Score          = Math.Round(nUnitScore / itemDetails.Count, 2);
                            paperItem.SelectAnswer   = itemDetail.SelectAnswer;
                            paperItem.Source         = itemDetail.Source;
                            paperItem.StandardAnswer = itemDetail.StandardAnswer;
                            paperItem.StatusId       = itemDetail.StatusId;
                            paperItem.TypeId         = itemDetail.TypeId;
                            paperItem.UsedCount      = itemDetail.UsedCount;
                            paperItem.Version        = itemDetail.Version;
                            paperItem.ParentItemID   = item.ItemId;
                            paperItem.MotherCode     = itemDetail.MotherCode;
                            paperItem.ItemIndex      = itemDetail.ItemIndex;
                            randomExamItems.Add(paperItem);
                        }
                    }
                }

                if (count == 1)
                {
                    SessionSet.PageMessage = "组卷策略不能重复,请重新设置取题范围!";
                    return;
                }

                if (n == 1)
                {
                    SessionSet.PageMessage = "大题" + (i + 1).ToString() + "有无标准答案的试题,请重新设置取题范围!";
                    return;
                }

                if (randomExamItems.Count > 0)
                {
                    randomItemBLL.AddItem(randomExamItems, year);
                }
            }

            Hashtable hashTableItemIds = new Hashtable();

            for (int i = 0; i < randomExamSubjects.Count; i++)
            {
                int nSubjectId = randomExamSubjects[i].RandomExamSubjectId;
                //int nItemCount = randomExamSubjects[i].ItemCount;

                IList <RandomExamStrategy> strategys = strategyBLL.GetRandomExamStrategys(nSubjectId);
                for (int j = 0; j < strategys.Count; j++)
                {
                    int nStrategyId = strategys[j].RandomExamStrategyId;
                    int nItemCount  = strategys[j].ItemCount;

                    IList <RandomExamItem> itemList = randomItemBLL.GetItemsByStrategyId(nStrategyId, year);
                    Random    ObjRandom             = new Random();
                    Hashtable hashTable             = new Hashtable();
                    Hashtable hashTableCount        = new Hashtable();
                    while (hashTable.Count < nItemCount)
                    {
                        int k = ObjRandom.Next(itemList.Count);
                        hashTableCount[k] = k;
                        int itemID = itemList[k].ItemId;
                        if (!hashTableItemIds.ContainsKey(itemID))
                        {
                            hashTable[itemID]        = itemID;
                            hashTableItemIds[itemID] = itemID;
                        }
                        if (hashTableCount.Count == itemList.Count && hashTable.Count < nItemCount)
                        {
                            SessionSet.PageMessage = "随机考试在设定的取题范围内的试题量不够,请重新设置取题范围!";
                            return;
                        }
                    }
                }
            }

            objBll.UpdateVersion(Convert.ToInt32(strId));

            if (obj.IsComputerExam)
            {
                Response.Redirect("SelectEmployeeDetailNew.aspx?startmode=" + strStartMode + "&mode=" + strMode + "&id=" + strId);
            }
            else
            {
                Response.Write("<script>top.window.opener.form1.Refresh.value='true';top.window.opener.form1.submit();top.window.close();</script>");
            }
        }
        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);
            }
        }