private void GetPaper()
        {
            // 根据 ProgressBar.htm 显示进度条界面
            string       templateFileName = Path.Combine(Server.MapPath("."), "ProgressBar.htm");
            StreamReader reader           = new StreamReader(@templateFileName, System.Text.Encoding.GetEncoding("gb2312"));
            string       html             = reader.ReadToEnd();

            reader.Close();
            Response.Write(html);
            Response.Flush();
            System.Threading.Thread.Sleep(200);

            string jsBlock;

            ViewState["BeginTime"] = DateTime.Now.ToString();
            string strId = Request.QueryString.Get("RandomExamID");

            //获取当前考试的生成试卷的状态和次数
            RandomExamBLL objBll = new RandomExamBLL();

            RailExam.Model.RandomExam obj = objBll.GetExam(Convert.ToInt32(strId));

            int year      = obj.BeginTime.Year;
            int ExamCount = obj.MaxExamTimes;

            RandomExamArrangeBLL eaBll = new RandomExamArrangeBLL();
            IList <RailExam.Model.RandomExamArrange> ExamArranges = eaBll.GetRandomExamArranges(int.Parse(strId));
            string       strChooseID = "";
            OracleAccess db          = new OracleAccess();
            OracleAccess dbCenter    = new OracleAccess(System.Configuration.ConfigurationManager.ConnectionStrings["OracleCenter"].ConnectionString);

            string strSql;

            if (ExamArranges.Count > 0)
            {
                strSql = "select a.* from Random_Exam_Arrange_Detail a "
                         + " inner join Computer_Room b on a.Computer_Room_ID=b.Computer_Room_ID"
                         + " inner join Computer_Server c on c.Computer_server_ID=b.Computer_Server_ID"
                         + " where c.Computer_Server_No='" + PrjPub.ServerNo + "' "
                         + " and Random_Exam_ID=" + strId;

                DataSet ds = db.RunSqlDataSet(strSql);

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (string.IsNullOrEmpty(strChooseID))
                    {
                        strChooseID += dr["User_Ids"].ToString();
                    }
                    else
                    {
                        strChooseID += "," + dr["User_Ids"];
                    }
                }
            }
            else
            {
                strChooseID = "";
            }

            if (strChooseID == "")
            {
                Response.Write("<script>top.returnValue='本场考试未在本单位安排考生!';window.close();</script>");
                return;
            }

            if (db.GetCount("RANDOM_EXAM_ITEM_TEMP_" + year, "TABLE") == 0)
            {
                strSql = "create table RANDOM_EXAM_ITEM_TEMP_" + year + "  as select * from RANDOM_EXAM_ITEM_" + year + " where 1=2 ";
                db.ExecuteNonQuery(strSql);
            }
            strSql = "insert into RANDOM_EXAM_ITEM_TEMP_" + year + " select * from RANDOM_EXAM_ITEM_" + year + " where Random_Exam_ID=" + strId;
            db.ExecuteNonQuery(strSql);

            if (!PrjPub.IsServerCenter)
            {
                if (dbCenter.GetCount("RANDOM_EXAM_ITEM_TEMP_" + year, "TABLE") == 0)
                {
                    strSql = "create table RANDOM_EXAM_ITEM_TEMP_" + year + "  as select * from RANDOM_EXAM_ITEM_" + year + " where 1=2 ";
                    dbCenter.ExecuteNonQuery(strSql);
                }
                strSql = "insert into RANDOM_EXAM_ITEM_TEMP_" + year + " select * from RANDOM_EXAM_ITEM_" + year + " where Random_Exam_ID=" + strId;
                dbCenter.ExecuteNonQuery(strSql);
            }

            System.Threading.Thread.Sleep(10);
            jsBlock = "<script>SetPorgressBar('正在计算生成试卷数量,请等待......','" + ((1 * 100) / ((double)2) + "'); </script>");
            Response.Write(jsBlock);
            Response.Flush();


            //每次生成试卷之前删除已生成的考试试卷
            RandomExamResultCurrentBLL randomExamResultBLL = new RandomExamResultCurrentBLL();

            randomExamResultBLL.DelRandomExamResultCurrent(Convert.ToInt32(strId));
            System.Threading.Thread.Sleep(10);
            jsBlock = "<script>SetPorgressBar('正在计算生成试卷数量,请等待......','" + ((2 * 100) / ((double)2) + "'); </script>");
            Response.Write(jsBlock);
            Response.Flush();

            System.Threading.Thread.Sleep(200);
            jsBlock = string.Empty;

            string[] str = strChooseID.Split(',');

            RandomExamResultAnswerCurrentBLL randomExamResultAnswerBLL = new RandomExamResultAnswerCurrentBLL();
            //定义全局答卷对象List
            IList <RandomExamResultAnswerCurrent> randomExamResultAnswersCurrentAll = new List <RandomExamResultAnswerCurrent>();
            //定义一个考生一次答卷对象List
            IList <RandomExamResultAnswerCurrent> randomExamResultAnswers = null;

            int progressNum = 1;

            for (int n = 1; n <= ExamCount; n++)
            {
                for (int m = 0; m < str.Length; m++)
                {
                    RandomExamResultCurrent randomExamResult = new RandomExamResultCurrent();

                    randomExamResult.RandomExamId    = int.Parse(strId);
                    randomExamResult.AutoScore       = 0;
                    randomExamResult.BeginDateTime   = DateTime.Parse(ViewState["BeginTime"].ToString());
                    randomExamResult.CurrentDateTime = DateTime.Parse(ViewState["BeginTime"].ToString());
                    randomExamResult.ExamTime        = 0;
                    randomExamResult.EndDateTime     = DateTime.Parse(ViewState["BeginTime"].ToString());
                    randomExamResult.Score           = 0;
                    randomExamResult.OrganizationId  = int.Parse(ConfigurationManager.AppSettings["StationID"]);
                    randomExamResult.Memo            = "";
                    randomExamResult.StatusId        = 0;
                    randomExamResult.AutoScore       = 0;
                    randomExamResult.CorrectRate     = 0;
                    randomExamResult.ExamineeId      = int.Parse(str[m]);
                    randomExamResult.ExamSeqNo       = n;

                    int nRandomExamResultPK = randomExamResultBLL.AddRandomExamResultCurrent(randomExamResult);
                    ViewState["RandomExamResultPK"] = nRandomExamResultPK;

                    strSql = "select a.* from Random_Exam_Arrange_Detail a "
                             + " where ','||User_Ids||',' like '%," + str[m] + ",%' "
                             + " and Random_Exam_ID=" + strId;
                    DataRow dr = db.RunSqlDataSet(strSql).Tables[0].Rows[0];

                    //strSql = "insert into Random_Exam_Result_Detail(Random_Exam_Result_Detail_ID,"
                    //         + "Random_Exam_Result_ID,Random_Exam_ID,Employee_ID,Computer_Room_SEAT,Computer_Room_ID) "
                    //         + "values(Random_Exam_Result_Detail_SEQ.NextVal,"
                    //         + nRandomExamResultPK + ","
                    //         + randomExamResult.RandomExamId + ","
                    //         + randomExamResult.ExamineeId + ","
                    //         + "0," + dr["Computer_Room_ID"] + ") ";
                    //db.ExecuteNonQuery(strSql);

                    strSql = "insert into Random_Exam_Result_Detail_Temp(Random_Exam_Result_Detail_ID,"
                             + "Random_Exam_Result_ID,Random_Exam_ID,Employee_ID,Computer_Room_SEAT,Computer_Room_ID,Is_Remove) "
                             + "values(Random_Exam_Result_Detail_SEQ.NextVal,"
                             + nRandomExamResultPK + ","
                             + randomExamResult.RandomExamId + ","
                             + randomExamResult.ExamineeId + ","
                             + "0," + dr["Computer_Room_ID"] + ",0) ";
                    db.ExecuteNonQuery(strSql);

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

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

                    if (randomExamSubjects != null)
                    {
                        Hashtable hashTableItemIds = new Hashtable();
                        Hashtable htSubjectItemIds = new Hashtable();
                        for (int i = 0; i < randomExamSubjects.Count; i++)
                        {
                            RandomExamSubject paperSubject = randomExamSubjects[i];
                            int nSubjectId = paperSubject.RandomExamSubjectId;
                            //  int nItemCount = paperSubject.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);

                                // IList<RandomExamItem> itemList = randomItemBLL.GetItemsBySubjectId(nSubjectId);

                                Random    ObjRandom      = new Random();
                                Hashtable hashTable      = new Hashtable();
                                Hashtable hashTableCount = new Hashtable();
                                int       index          = 0;
                                while (hashTable.Count < nItemCount)
                                {
                                    int k = ObjRandom.Next(itemList.Count);
                                    hashTableCount[index] = k;
                                    index = index + 1;
                                    int itemID     = itemList[k].ItemId;
                                    int examItemID = itemList[k].RandomExamItemId;
                                    if (!hashTableItemIds.ContainsKey(itemID))
                                    {
                                        hashTable[examItemID]        = examItemID;
                                        hashTableItemIds[itemID]     = itemID;
                                        htSubjectItemIds[examItemID] = examItemID;
                                    }
                                    //if (hashTableCount.Count == itemList.Count && hashTable.Count < nItemCount)
                                    //{
                                    //    SessionSet.PageMessage = "随机考试在设定的取题范围内的试题量不够,请重新设置取题范围!";
                                    //    return;
                                    //}
                                }
                            }
                        }


                        foreach (int key in htSubjectItemIds.Keys)
                        {
                            string         strItemId = htSubjectItemIds[key].ToString();
                            RandomExamItem item      = randomItemBLL.GetRandomExamItem(Convert.ToInt32(strItemId), year);

                            string nowSelectAnswer   = string.Empty;
                            string nowStandardAnswer = string.Empty;
                            if (item.TypeId != PrjPub.ITEMTYPE_FILLBLANK)
                            {
                                Pub.GetNowAnswer(item, out nowSelectAnswer, out nowStandardAnswer);
                            }

                            RandomExamResultAnswerCurrent randomExamResultAnswer = new RandomExamResultAnswerCurrent();
                            randomExamResultAnswer.RandomExamResultId = nRandomExamResultPK;
                            randomExamResultAnswer.RandomExamItemId   = int.Parse(strItemId);
                            randomExamResultAnswer.JudgeStatusId      = 0;
                            randomExamResultAnswer.JudgeRemark        = string.Empty;
                            randomExamResultAnswer.ExamTime           = 0;
                            randomExamResultAnswer.Answer             = string.Empty;
                            randomExamResultAnswer.SelectAnswer       = nowSelectAnswer;
                            randomExamResultAnswer.StandardAnswer     = nowStandardAnswer;
                            randomExamResultAnswerBLL.AddExamResultAnswerCurrent(randomExamResultAnswer);

                            //完型填空子题
                            IList <RandomExamItem> randomExamItems = randomItemBLL.GetItemsByParentItemID(item.ItemId, obj.RandomExamId, year);
                            foreach (RandomExamItem randomExamItem in randomExamItems)
                            {
                                Pub.GetNowAnswer(randomExamItem, out nowSelectAnswer, out nowStandardAnswer);

                                randomExamResultAnswer = new RandomExamResultAnswerCurrent();
                                randomExamResultAnswer.RandomExamResultId = nRandomExamResultPK;
                                randomExamResultAnswer.RandomExamItemId   = randomExamItem.RandomExamItemId;
                                randomExamResultAnswer.JudgeStatusId      = 0;
                                randomExamResultAnswer.JudgeRemark        = string.Empty;
                                randomExamResultAnswer.ExamTime           = 0;
                                randomExamResultAnswer.Answer             = string.Empty;
                                randomExamResultAnswer.SelectAnswer       = nowSelectAnswer;
                                randomExamResultAnswer.StandardAnswer     = nowStandardAnswer;
                                randomExamResultAnswerBLL.AddExamResultAnswerCurrent(randomExamResultAnswer);
                            }

                            System.Threading.Thread.Sleep(10);
                            jsBlock = "<script>SetPorgressBar('正在生成试卷,请等待......','" + ((progressNum * 100) / ((double)ExamCount * str.Length * htSubjectItemIds.Count)).ToString("0.00") + "'); </script>";
                            Response.Write(jsBlock);
                            Response.Flush();

                            progressNum++;
                        }
                    }
                    else
                    {
                        SessionSet.PageMessage = "未找到记录!";
                    }
                }
            }

            bool isRefresh = true;

            try
            {
                objBll.UpdateHasPaper(Convert.ToInt32(strId), PrjPub.ServerNo, true);
            }
            catch
            {
                strSql =
                    @"  update Random_Exam_Computer_Server set  has_paper=1
                      where random_exam_id=" + strId + @" and Computer_server_no='" + PrjPub.ServerNo + @"'";
                dbCenter.ExecuteNonQuery(strSql);
                strSql = @"select count(*)  from Random_Exam_Computer_Server where has_paper=1 and  random_exam_id=" + strId;
                int count = Convert.ToInt32(dbCenter.RunSqlDataSet(strSql).Tables[0].Rows[0][0]);
                if (count > 0)
                {
                    strSql = @"update Random_Exam set has_paper=1 where random_exam_id=" + strId;
                    dbCenter.ExecuteNonQuery(strSql);
                }
                else
                {
                    strSql = @"update Random_Exam set has_paper=0 where random_exam_id=" + strId;
                    dbCenter.ExecuteNonQuery(strSql);
                }
            }


            //如果考试是随到随考,考试状态自动变为正在进行
            if (obj.StartMode == 1)
            {
                try
                {
                    objBll.UpdateIsStart(Convert.ToInt32(strId), PrjPub.ServerNo, 1);
                    isRefresh = false;
                }
                catch
                {
                    strSql =
                        @"  update Random_Exam_Computer_Server set  Is_Start=1
                      where random_exam_id=" + strId + @" and Computer_server_no='" + PrjPub.ServerNo + @"'";
                    dbCenter.ExecuteNonQuery(strSql);
                    strSql = @"select count(*)  from Random_Exam_Computer_Server where random_exam_id=" + strId;
                    int totalcount = Convert.ToInt32(dbCenter.RunSqlDataSet(strSql).Tables[0].Rows[0][0]);
                    strSql = @"select count(*)  from Random_Exam_Computer_Server where Is_Start=0 and  random_exam_id=" + strId;
                    int count = Convert.ToInt32(dbCenter.RunSqlDataSet(strSql).Tables[0].Rows[0][0]);
                    if (totalcount == count)
                    {
                        strSql = @"update Random_Exam set Is_Start=0 where random_exam_id=" + strId;
                        dbCenter.ExecuteNonQuery(strSql);
                    }
                    else
                    {
                        strSql = @"select count(*)  from Random_Exam_Computer_Server where Is_Start=1 and  random_exam_id=" + strId;
                        count  = Convert.ToInt32(dbCenter.RunSqlDataSet(strSql).Tables[0].Rows[0][0]);
                        if (count > 0)
                        {
                            strSql = @"update Random_Exam set Is_Start=1 where random_exam_id=" + strId;
                            dbCenter.ExecuteNonQuery(strSql);
                        }
                        else
                        {
                            strSql = @"select count(*)  from Random_Exam_Computer_Server where Is_Start=2 and  random_exam_id=" + strId;
                            count  = Convert.ToInt32(dbCenter.RunSqlDataSet(strSql).Tables[0].Rows[0][0]);
                            if (count == totalcount)
                            {
                                strSql = @"update Random_Exam set Is_Start=2 where random_exam_id=" + strId;
                                dbCenter.ExecuteNonQuery(strSql);
                            }
                        }
                    }
                }
            }
            else
            {
                isRefresh = false;
            }

            if (isRefresh)
            {
                objBll.RandomExamRefresh();
            }

            SystemLogBLL objLogBll = new SystemLogBLL();

            objLogBll.WriteLog("“" + obj.ExamName + "”生成所有考试试卷");

            Response.Write("<script>top.returnValue='true';top.close();</script>");
        }
Exemplo n.º 2
0
        private void DownLoadData()
        {
            string       templateFileName = Server.MapPath("/RailExamBao/RandomExam/ProgressBar.htm");
            StreamReader reader           = new StreamReader(@templateFileName, System.Text.Encoding.GetEncoding("gb2312"));
            string       html             = reader.ReadToEnd();

            reader.Close();
            Response.Write(html);
            Response.Flush();
            System.Threading.Thread.Sleep(200);
            string jsBlock;

            DateTime           beginTime  = DateTime.Now;
            SynchronizeLog     obj        = new SynchronizeLog();
            SynchronizeLogBLL  objlogdal  = new SynchronizeLogBLL();
            RefreshSnapShotBLL refreshbll = new RefreshSnapShotBLL();

            try
            {
                string strInfo    = string.Empty;
                string proName    = string.Empty;
                int    num        = 5;
                int    selectType = Convert.ToInt32(Request.QueryString.Get("selectType"));
                if (selectType == 0)
                {
                    strInfo = "下载考试试卷";
                    proName = "USP_Refresh_SnapShot_Exam";
                    num     = 6;
                }
                else if (selectType == 1)
                {
                    strInfo = "下载教材与试题";
                    proName = "USP_Refresh_SnapShot_Book";
                    num     = 5;
                }
                else if (selectType == 2)
                {
                    strInfo = "下载职员基本信息和档案信息";
                    proName = "USP_Refresh_SnapShot_Employee";
                    num     = 4;
                }
                else if (selectType == 3)
                {
                    strInfo = "下载基础数据";
                    proName = "USP_Refresh_SnapShot_All";
                    num     = 9;
                }

                if (selectType == 0 || selectType == 3)
                {
                    for (int i = 1; i <= num - 1; i++)
                    {
                        refreshbll.RefreshSnapShot(proName, i);

                        System.Threading.Thread.Sleep(10);
                        jsBlock = "<script>SetPorgressBar('正在" + strInfo + "','" + ((double)(i * 100) / (double)num).ToString("0.00") + "'); </script>";
                        Response.Write(jsBlock);
                        Response.Flush();
                    }

                    string strSql =
                        @"select a.User_Ids from Random_Exam_Arrange_Detail  a
                       where a.Random_Exam_ID in (select Random_Exam_ID from Random_Exam_Computer_Server a 
                       where Computer_Server_No='" + PrjPub.ServerNo + "' and (Has_Paper=0 or Is_Start<2))";
                    OracleAccess dbCenter = new OracleAccess(System.Configuration.ConfigurationManager.ConnectionStrings["OracleCenter"].ConnectionString);
                    string       strwhere = string.Empty;
                    DataSet      ds       = dbCenter.RunSqlDataSet(strSql);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        string[] struserIds = dr["User_Ids"].ToString().Split(',');

                        for (int i = 0; i < struserIds.Length; i++)
                        {
                            if (struserIds[i] == string.Empty)
                            {
                                continue;
                            }

                            if ((" or " + strwhere + " or ").IndexOf(" or Employee_ID=" + struserIds[i] + " or ") <= 0)
                            {
                                strwhere += strwhere == string.Empty
                                                ? "Employee_ID=" + struserIds[i]
                                                : " or Employee_ID=" + struserIds[i];
                            }
                        }
                    }

                    OracleAccess db = new OracleAccess();
                    if (db.GetCount("EMPLOYEE_FINGERPRINT", "MATERIALIZED VIEW") > 0)
                    {
                        strSql = "drop materialized view  Employee_FingerPrint";
                        db.ExecuteNonQuery(strSql);
                    }
                    if (strwhere == string.Empty)
                    {
                        strSql =
                            "create materialized view   Employee_FingerPrint   refresh force on demand as   select   *   from   Employee_FingerPrint@link_sf where 1=2";
                        db.ExecuteNonQuery(strSql);
                    }
                    else
                    {
                        strSql =
                            "create materialized view   Employee_FingerPrint   refresh force on demand as   select   *   from   Employee_FingerPrint@link_sf where  " +
                            strwhere;
                        db.ExecuteNonQuery(strSql);
                    }

                    System.Threading.Thread.Sleep(10);
                    jsBlock = "<script>SetPorgressBar('正在" + strInfo + "','" + ((double)(num * 100) / (double)num).ToString("0.00") + "'); </script>";
                    Response.Write(jsBlock);
                    Response.Flush();
                }
                else
                {
                    for (int i = 1; i <= num; i++)
                    {
                        refreshbll.RefreshSnapShot(proName, i);

                        System.Threading.Thread.Sleep(10);
                        jsBlock = "<script>SetPorgressBar('正在" + strInfo + "','" + ((double)(i * 100) / (double)num).ToString("0.00") + "'); </script>";
                        Response.Write(jsBlock);
                        Response.Flush();
                    }
                }


                obj.OrgID               = PrjPub.CurrentLoginUser.StationOrgID;
                obj.SynchronizeTypeID   = PrjPub.DownloadData;
                obj.SynchronizeStatusID = PrjPub.DownloadSuccess;
                obj.BeginTime           = beginTime;
                obj.EndTime             = DateTime.Now;
                objlogdal.AddSynchronizeLog(obj);
                Response.Write("<script>alert('下载成功!');top.close();</script>");
            }
            catch
            {
                obj.OrgID               = PrjPub.CurrentLoginUser.StationOrgID;
                obj.SynchronizeTypeID   = PrjPub.DownloadData;
                obj.SynchronizeStatusID = PrjPub.DownloadFailed;
                obj.BeginTime           = beginTime;
                obj.EndTime             = DateTime.Now;
                objlogdal.AddSynchronizeLog(obj);
                Response.Write("<script>alert('同步数据失败!请检查站段服务器网络连接是否正常!');top.close();</script>");
            }
        }