コード例 #1
0
        public static void UpdateTestSetting(int companyID, int productID, TestSettingInfo testSetting)
        {
            //删除已有记录
            TestSettingInfo currentTestSetting = TestSettingBLL.ReadCompanyTestSetting(companyID, productID);

            if (currentTestSetting != null)
            {
                DeleteTestSetting(currentTestSetting.Id);
            }

            if (testSetting.PaperScore > 0 || testSetting.TestTimeLength > 0 || testSetting.TestQuestionsCount > 0 || testSetting.LowScore > 0 || testSetting.TestStartTime.HasValue || testSetting.TestEndTime.HasValue)
            {
                //取得公司通用考试设置
                TestSettingInfo systemTestSetting = ReadTestSetting(companyID);
                testSetting.CompanyId = companyID;
                testSetting.CourseId  = productID;

                //内容不合法的,都重置公司默认设置
                if (testSetting.PaperScore <= 0)
                {
                    testSetting.PaperScore = systemTestSetting.PaperScore;
                }
                if (testSetting.TestTimeLength <= 0)
                {
                    testSetting.TestTimeLength = systemTestSetting.TestTimeLength;
                }
                if (testSetting.TestQuestionsCount <= 0)
                {
                    testSetting.TestQuestionsCount = systemTestSetting.TestQuestionsCount;
                }
                if (testSetting.LowScore <= 0)
                {
                    testSetting.LowScore = systemTestSetting.LowScore;
                }
                if (testSetting.TestInterval <= 0)
                {
                    testSetting.TestInterval = systemTestSetting.TestInterval;
                }

                //下面两项任一项为空,都采用公司默认设置
                if (testSetting.TestStartTime == null || testSetting.TestEndTime == null)
                {
                    testSetting.TestStartTime = systemTestSetting.TestStartTime;
                    testSetting.TestEndTime   = systemTestSetting.TestEndTime;
                }
                AddTestSetting(testSetting);
            }
        }
コード例 #2
0
ファイル: TestPaperBLL.cs プロジェクト: xuefuruanjian/ems
        /// <summary>
        /// 计算考试成绩
        /// </summary>
        /// <returns></returns>
        public static TestPaperInfo CalcTestResult(int companyID, int userID, int productID)
        {
            TestPaperInfo       PaperModel  = new TestPaperInfo();
            string              filePath    = ReadTestPaperPath(userID, productID);
            TestPaperReportInfo testPaper   = ReadTheLatestPaper(userID, productID);
            TestSettingInfo     testSetting = TestSettingBLL.ReadTestSetting(companyID, productID);

            if (File.Exists(filePath) && (testPaper.TestDate == DateTime.MinValue || (DateTime.Now - testPaper.TestDate).TotalHours >= testSetting.TestInterval))
            {
                XmlHelper XmlDoc = new XmlHelper(filePath);

                int QuestionNum = int.Parse(XmlDoc.ReadAttribute("TestPaper", "QuestionNum"));

                decimal Scorse   = 0; //试卷得分
                int     RightNum = 0; //正确的题目数量

                //从xml里读取答案,进行校卷
                string QuestionList   = string.Empty;
                string UserAnswerList = string.Empty;
                for (int StyleId = 1; StyleId <= 3; StyleId++)
                {
                    string NodeName = GetTestPaperStyleNodeName(StyleId);
                    //判断题型库里是否有考题
                    XmlNode Node = XmlDoc.ReadNode(NodeName);
                    if (Node != null && Node.HasChildNodes)
                    {
                        XmlNodeList NodeList = XmlDoc.ReadChildNodes(NodeName);
                        //遍历节点
                        foreach (XmlNode node in NodeList)
                        {
                            QuestionList   = QuestionList + "," + node.ChildNodes[9].InnerText;
                            UserAnswerList = UserAnswerList + "," + node.ChildNodes[6].InnerText;
                            if (node.ChildNodes[6].InnerText.ToLower() == node.ChildNodes[5].InnerText.ToLower())
                            {
                                RightNum = RightNum + 1;
                            }
                        }
                    }
                }

                //UserInfo user = UserBLL.ReadUser(userID);
                //TestSettingInfo testSetting = TestSettingBLL.ReadTestSetting(companyID, productID);
                if (QuestionNum == 0)
                {
                    Scorse = 0;
                }
                else
                {
                    Scorse = Convert.ToDecimal(Math.Round((decimal.Parse(testSetting.PaperScore.ToString()) * RightNum / QuestionNum), 1));//这样计算的总分更准备
                }
                if (QuestionList != string.Empty && QuestionList.StartsWith(","))
                {
                    QuestionList   = QuestionList.Substring(1);
                    UserAnswerList = UserAnswerList.Substring(1);
                }

                PaperModel.CateId     = productID;
                PaperModel.PaperName  = ProductBLL.ReadProduct(productID).Name;
                PaperModel.CompanyId  = companyID;
                PaperModel.UserId     = userID;
                PaperModel.QuestionId = QuestionList;
                PaperModel.Answer     = UserAnswerList;
                PaperModel.Scorse     = Scorse;
                if (Scorse >= testSetting.LowScore)
                {
                    PaperModel.Point  = 2;
                    PaperModel.IsPass = 1;
                }
                else
                {
                    PaperModel.IsPass = 0;
                }

                UserLogBLL.AddUserLog(ShopLanguage.ReadLanguage("ApplyTest"), ShopLanguage.ReadLanguage("TestPaper"), ProductBLL.ReadProduct(productID).Name);
                TestPaperBLL.AddPaper(PaperModel);
                File.SetLastWriteTime(filePath, DateTime.Now);
            }
            if ((testPaper.TestDate > DateTime.MinValue && (DateTime.Now - testPaper.TestDate).TotalHours < testSetting.TestInterval))
            {
                PaperModel.Scorse = testPaper.Score;
            }

            //解除本课程的考试限制
            //TestSettingBLL.TestEnd(userID, productID);

            return(PaperModel);
        }
コード例 #3
0
ファイル: QuestionBLL.cs プロジェクト: xuefuruanjian/ems
        /// <summary>
        /// 根据productId读取符合条件随机抽取指定数量的考题创建xml文档
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="CourseId">题库ID</param>
        /// <param name="companyId">用户的公司ID</param>
        public static void ReadQuestionXmlList(int productId, string CourseId, int companyId, int userId)
        {
            TestSettingInfo TestSettingModel = TestSettingBLL.ReadTestSetting(companyId, productId);
            QuestionInfo    Model            = new QuestionInfo();

            Model.QuestionNum = " Top " + TestSettingModel.TestQuestionsCount.ToString() + " * ";
            Model.IdCondition = CourseId;
            Model.Condition   = CompanyBLL.SystemCompanyId.ToString();//默认情况下都读取系统考题
            Model.Field       = "CompanyId";
            List <QuestionInfo> TempQuestionList = ReadList(Model);

            //写入xml文件
            XmlHelper xmldoc = new XmlHelper();

            xmldoc.InsertNode("TestPaper");
            xmldoc.InsertElement("TestPaper", "CateId", productId.ToString());
            xmldoc.InsertNode("TestPaper", "Single", "");
            xmldoc.InsertNode("TestPaper", "Multi", "");
            xmldoc.InsertNode("TestPaper", "PanDuan", "");
            int QuestionIndex = 0;
            int SingleNum     = 0;
            int MultiNum      = 0;
            int PanDuanNum    = 0;

            foreach (QuestionInfo Item in TempQuestionList)
            {
                string NodeName = "TestPaper";
                QuestionIndex = QuestionIndex + 1;
                if (Item.Style == "1")
                {
                    SingleNum = SingleNum + 1;
                    NodeName  = NodeName + "/Single/QuestionInfo" + SingleNum.ToString();
                    xmldoc.InsertElement("TestPaper/Single", "QuestionInfo" + SingleNum.ToString(), "id", Item.QuestionId.ToString(), "");
                }
                else if (Item.Style == "2")
                {
                    MultiNum = MultiNum + 1;
                    NodeName = NodeName + "/Multi/QuestionInfo" + MultiNum.ToString();
                    xmldoc.InsertElement("TestPaper/Multi", "QuestionInfo" + MultiNum.ToString(), "id", Item.QuestionId.ToString(), "");
                }
                else if (Item.Style == "3")
                {
                    PanDuanNum = PanDuanNum + 1;
                    NodeName   = NodeName + "/PanDuan/QuestionInfo" + PanDuanNum.ToString();
                    xmldoc.InsertElement("TestPaper/PanDuan", "QuestionInfo" + PanDuanNum.ToString(), "id", Item.QuestionId.ToString(), "");
                }
                xmldoc.InsertNode(NodeName, "Question", Item.Question);//.Replace("~","")

                //单项选择题四个选项随机排序
                string answer = Item.Answer.ToUpper();
                if (Item.Style == "1")
                {
                    string[,] optionArrray = new string[4, 2] {
                        { "A", Item.A }, { "B", Item.B }, { "C", Item.C }, { "D", Item.D }
                    };

                    optionArrray = RandomHelper.GetRandomOptionArray <string>(optionArrray, ref answer);
                    for (int i = 0; i <= optionArrray.GetUpperBound(0); i++)
                    {
                        xmldoc.InsertNode(NodeName, optionArrray[i, 0], optionArrray[i, 1]);
                    }
                }
                else
                {
                    xmldoc.InsertNode(NodeName, "A", Item.A);
                    xmldoc.InsertNode(NodeName, "B", Item.B);
                    xmldoc.InsertNode(NodeName, "C", Item.C);
                    xmldoc.InsertNode(NodeName, "D", Item.D);
                }
                xmldoc.InsertNode(NodeName, "Answer", answer);
                xmldoc.InsertNode(NodeName, "CustomerAnswer", "");
                xmldoc.InsertNode(NodeName, "Style", Item.Style);
                xmldoc.InsertNode(NodeName, "CompanyId", Item.CompanyId.ToString());
                xmldoc.InsertNode(NodeName, "QuestionId", Item.QuestionId.ToString());
            }
            xmldoc.InsertElement("TestPaper", "QuestionNum", QuestionIndex.ToString());
            xmldoc.InsertElement("TestPaper", "SingleNum", SingleNum.ToString());
            xmldoc.InsertElement("TestPaper", "MultiNum", MultiNum.ToString());
            xmldoc.InsertElement("TestPaper", "PanDunNum", PanDuanNum.ToString());

            //保存创建好的XML文档
            if (Directory.Exists(ServerHelper.MapPath("~/xml")) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(ServerHelper.MapPath("~/xml"));
            }
            xmldoc.Save(ServerHelper.MapPath("~/xml/") + userId.ToString() + "_" + productId.ToString() + ".xml");
        }