Esempio n. 1
0
        public static void Topo(string className)
        {
            var featurePath    = string.Format("{0}\\{1}", ParameterManager.MDBFilePath, className);
            var outFeatureName = string.Format("{0}_loowootech", className);

            var intersectPath = string.Format("{0}\\{1}", ParameterManager.MDBFilePath, outFeatureName);

            if (Cross(string.Format("{0};{1}", featurePath, featurePath), intersectPath))
            {
                var intersectfeatureClass = ParameterManager.Workspace.GetFeatureClass(outFeatureName);
                if (intersectfeatureClass == null)
                {
                    QuestionManager.Add(new Question {
                        Code = "4101", Name = "拓扑关系", Project = CheckProject.拓扑关系, Description = "无法获取拓扑结果"
                    });
                }
                else
                {
                    Run(intersectfeatureClass, className, "XZCMC", "TBBH");
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(intersectfeatureClass);
                    DeleteFeatureClass2(outFeatureName);
                    //DeleteFeatureClass(intersectPath);
                }
            }
            else
            {
                QuestionManager.Add(new Question {
                    Code = "4101", Name = "拓扑关系", Project = CheckProject.拓扑关系, Description = "执行intersect发生错误"
                });
            }
        }
        public bool Check()
        {
            DirectoryInfo info       = new DirectoryInfo(Folder);
            var           folderName = info.Name.Replace(Title, "").Replace("(", ",").Replace(")", "").Replace("(", ",").Replace(")", "");
            var           array      = folderName.Split(',');

            if (array.Length == 2)
            {
                CityName = array[0];
                Code     = array[1];
                if (!XmlManager.Exist(string.Format("/Citys/City[@Code='{0}'][@Name='{1}']", CityName, Code), XmlEnum.City))
                {
                    var str = string.Format("未查询到行政区名称:{0};行政区代码:{1}的相关记录!", CityName, Code);
                    Console.WriteLine(str);
                    QuestionManager.Add(new Models.Question {
                        Code = "1101", Name = "质检路径命名规则", Description = str
                    });
                    return(false);
                }
                return(true);
            }
            QuestionManager.Add(new Models.Question {
                Code = "1101", Name = "质检路径命名规则", Description = "无法解析行政区名称、行政区代码信息"
            });
            Console.WriteLine("无法解析行政区名称、行政区代码信息");
            return(false);
        }
    protected void createQuestion(object sender, EventArgs e)
    {
        ILog logger = LogManager.GetLogger(typeof(Question));

        using (FileStream stream = File.OpenRead("d://000/hhyq.docx"))
        {
            XWPFDocument    docx = new XWPFDocument(stream);
            string[]        strs = new string[7];
            Regex           regA = new Regex("^[ABCDabcd]{1}.|、", RegexOptions.IgnoreCase);          //以A|B|C|D开头  选项
            Regex           regNO = new Regex("^[0-9]+.|、", RegexOptions.IgnoreCase);                //以数字开头  题干
            Regex           regChapter = new Regex("^第[一二三四五六七八九十]{1,3}章", RegexOptions.IgnoreCase); //章节标题
            Regex           regnode = new Regex("^第[一二三四五六七八九十]{1,3}节", RegexOptions.IgnoreCase);
            Chapter         chapter = null, node = null;
            ChapterManager  chaptermanager = new ChapterManager();
            Question        question       = null;
            QuestionManager questonmanager = new QuestionManager();
            foreach (var para in docx.Paragraphs)
            {
                string text = para.ParagraphText.Trim();
                if (!string.IsNullOrWhiteSpace(text) && !string.IsNullOrEmpty(text))//非空
                {
                    if (regChapter.IsMatch(text))
                    {
                        chapter                 = new Chapter();
                        chapter.TextBookId      = 1;
                        chapter.IsVerified      = true;
                        chapter.ChapterDeep     = 0;
                        chapter.ChapterName     = regChapter.Replace(text, "").Trim();
                        chapter.ChapterParentNo = 0;
                        chapter.ChapterRemark   = chapter.ChapterName;
                        chaptermanager          = new ChapterManager();
                        chapter.ChapterId       = chaptermanager.Add(chapter);
                    }
                    else if (regnode.IsMatch(text))
                    {
                        node                 = new Chapter();
                        node.ChapterName     = regnode.Replace(text, "").Trim();
                        node.ChapterParentNo = chapter.ChapterId;
                        node.ChapterDeep     = 1;
                        node.ChapterRemark   = node.ChapterName;
                        node.TextBookId      = 1;
                        node.IsVerified      = true;
                        node.ChapterId       = chaptermanager.Add(node);
                    }
                    else
                    {
                        string[] paratext = text.Split(new string[] { "A.", "B.", "C.", "D." }, StringSplitOptions.RemoveEmptyEntries);
                        question            = StringsTOQuestion(paratext, "D");
                        question.QuestionId = questonmanager.Add(question);
                        Console.WriteLine(question.QuestionId + "  添加成功。");
                    }
                }
                System.Threading.Thread.Sleep(300);
            }
        }
    }
Esempio n. 4
0
 public IActionResult Create([Bind("Id,QuestionPhrase,CourseId")] QuestionViewModel QuestionViewModel)
 {
     if (ModelState.IsValid)
     {
         Question Question = MapToQuestion(QuestionViewModel);
         _questionManager.Add(Question);
         return(RedirectToAction(nameof(Index), new { message = "create" }));
     }
     return(View());
 }
Esempio n. 5
0
        public void Program()
        {
            QuestionManager.Clear();
            LogManager.Init();
            ParameterManager.Init(Folder);
            DCDYTBManager.Init();
            ExcelParameterManager.Clear();
            if (!Init())
            {
                OutputMessage("00", "初始化失败,程序终止", ProgressResultTypeEnum.Fail);
                return;
            }
            OutputMessage("00", "成功初始化", ProgressResultTypeEnum.Pass);
            foreach (var id in _ruleIds)
            {
                var rule = _rules.FirstOrDefault(e => e.ID == id.ToString());
                if (rule != null)
                {
                    var sb     = new StringBuilder(rule.RuleName);
                    var result = ProgressResultTypeEnum.Pass;
                    try
                    {
                        rule.Check();
                    }
                    catch (AggregateException ae)
                    {
                        foreach (var exp in ae.InnerExceptions)
                        {
                            sb.Append(exp.Message + "\r\n");
                        }
                        result = ProgressResultTypeEnum.Fail;
                    }
                    catch (Exception ex)
                    {
                        result = ProgressResultTypeEnum.Fail;
                        sb.Append(ex.ToString());
                    }

                    if (result != ProgressResultTypeEnum.Pass)
                    {
                        QuestionManager.Add(new Question {
                            Code = rule.ID, Name = rule.RuleName, Description = sb.ToString()
                        });
                    }
                    if (OutputMessage(rule.ID, sb.ToString(), result) == true)
                    {
                        break;
                    }
                }
            }
            _reportPath = QuestionManager.Save(ReportPath);
            //PDFHelper.Save(_reportPath, ReportPDFPath);
            //PdfHelper2.SavePdf(_reportPath, ReportPDFPath);
            PdfHelper2.Convert(_reportPath, ReportPDFPath);
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="featureClass">intersectfeatureClass</param>
        /// <param name="fidName">DCDYTB</param>
        /// <param name="titleName1">XZCMC</param>
        /// <param name="titleName2">TBBH</param>
        private static void Run(IFeatureClass featureClass, string fidName, string titleName1, string titleName2)
        {
            var fid1 = featureClass.Fields.FindField(string.Format("FID_{0}", fidName));
            var fid2 = featureClass.Fields.FindField(string.Format("FID_{0}_1", fidName));

            var title11 = featureClass.Fields.FindField(titleName1);
            var title12 = featureClass.Fields.FindField(titleName1 + "_1");

            var title21 = featureClass.Fields.FindField(titleName2);
            var title22 = featureClass.Fields.FindField(titleName2 + "_1");


            IFeatureCursor featureCursor = featureClass.Search(null, false);
            IFeature       feature       = featureCursor.NextFeature();

            while (feature != null)
            {
                try
                {
                    var valOne = feature.get_Value(fid1);
                    var valTwo = feature.get_Value(fid2);
                    if (valOne.ToString() != valTwo.ToString())//存在不相等,则表示存在相交
                    {
                        var val  = feature.get_Value(title11).ToString();
                        var tbbh = feature.get_Value(title21);
                        var str1 = string.Format("{0}:【{1}】--{2}:【{3}】存在图斑相交", titleName1, val, titleName2, tbbh);
                        QuestionManager.Add(new Question {
                            Code              = "4101",
                            Name              = "拓扑关系",
                            Project           = CheckProject.拓扑关系,
                            TableName         = fidName,
                            BSM               = val,
                            Description       = str1,
                            RelationClassName = fidName,
                            ShowType          = ShowType.Space,
                            WhereClause       = string.Format("[{0}] = '{1}' AND [{2}] = '{3}'", titleName1, val, titleName2, tbbh)
                        });
                    }
                }
                catch (Exception ex)
                {
                    var error = string.Format("获取对比的FID组发生错误,错误信息:{0}", ex.Message);
                    QuestionManager.Add(new Question {
                        Code = "4101", Name = "拓扑关系", Project = CheckProject.拓扑关系, Description = error
                    });
                }


                feature = featureCursor.NextFeature();
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
        }
 /// <summary>
 /// Creates a question for a quiz
 /// </summary>
 /// <param name="questionViewModel">The question created</param>
 public void CreateQuestion(QuestionViewModel questionViewModel)
 {
     try
     {
         if (questionViewModel != null)
         {
             Question question = ObjectMapper.Map <QuestionViewModel, Model.Entities.Question>(questionViewModel);
             question = QuestionManager.Add(question);
         }
     }
     catch (Exception ex)
     {
         ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing);
     }
 }
Esempio n. 8
0
        public static void CheckCoordinate(string className, string ruleName)
        {
            var info         = string.Empty;
            var featureClass = ParameterManager.Workspace.GetFeatureClass(className);

            if (featureClass != null)//本工具只对存在的要素类进行坐标系核对,不存在不做坐标系核对操作
            {
                var spatialReference = SpatialReferenceManager.GetSpatialReference(featureClass);
                if (spatialReference.Name.Trim() != ParameterManager.CurrentSpatialReference.Name.Trim())
                {
                    info = string.Format("图层:{0}不符合2201(平面坐标系是否采用‘1980 西安坐标系’、3度带、带带号,检查高程系统是否采用‘1985 国家高程基准’,检查投影方式是否采用高斯-克吕格投影)", className);
                    QuestionManager.Add(new Question {
                        Code = "2201", Name = ruleName, Project = CheckProject.数学基础, TableName = className, Description = info
                    });
                }
            }
        }
Esempio n. 9
0
 public bool Check()
 {
     foreach (var file in FileNames)
     {
         var fullPath = System.IO.Path.Combine(_folder, file.Replace("{Name}", CityName).Replace("{Code}", Code));
         var str      = string.Empty;
         if (!System.IO.File.Exists(fullPath))
         {
             str = string.Format("文件路径:{0}不存在,请核对", fullPath);
             LogManager.Log(str);
             _messages.Add(str);
             QuestionManager.Add(new Models.Question {
                 Code = "1102", Name = "文件", Project = Models.CheckProject.目录及文件规范性, Description = str
             });
             return(false);
         }
     }
     return(_messages.Count == 0);
 }
Esempio n. 10
0
        public IActionResult Post([FromBody] Question question)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Question newQuestion = questionManager.Add(question);

                return(Created($"questions/{newQuestion.QuestionId}", newQuestion));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to insert question: {ex}");
                return(BadRequest(config["Error:Default"]));
            }
        }
        public bool Check(OleDbConnection connection)
        {
            var obj   = ADOSQLHelper.ExecuteScalar(connection, string.IsNullOrEmpty(WhereClause) ? string.Format("Select Count(*) from {0}", TableName) : string.Format("Select Count(*) from {0} where {1}", TableName, WhereClause));
            var count = 0;

            if (int.TryParse(obj.ToString(), out count))
            {
                if (count == 0)
                {
                    var info = string.IsNullOrEmpty(WhereClause) ? string.Format("表:{0}数据量为空", TableName) : string.Format("表:{0}在条件:{1}下数据量为空", TableName, WhereClause);
                    Console.WriteLine(info);
                    QuestionManager.Add(new Models.Question {
                        Code = "2101", Name = Name, Project = Models.CheckProject.图层完整性, TableName = TableName, Description = info
                    });
                }
                return(true);
            }
            return(false);
        }
Esempio n. 12
0
        public static void XZQ(string className1, string className2)
        {
            var featurePath1        = string.Format("{0}/{1}", ParameterManager.MDBFilePath, className1); //XZQ_XZC
            var featurePath2        = string.Format("{0}/{1}", ParameterManager.MDBFilePath, className2); //DCDYTB
            var outfeatureClassName = string.Format("{0}_loowootech", className1);
            var outfeaturePath      = string.Format("{0}\\{1}", ParameterManager.MDBFilePath, outfeatureClassName);

            if (Cross(string.Format("{0};{1}", featurePath1, featurePath2), outfeaturePath))
            {
                var outfeatureClass = ParameterManager.Workspace.GetFeatureClass(outfeatureClassName);
                if (outfeatureClass == null)
                {
                    QuestionManager.Add(new Question {
                        Code = "", Name = "", Project = CheckProject.图层内属性一致性, Description = ""
                    });
                }
                else
                {
                    var list = RunXZQ(outfeatureClass, className1);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(outfeatureClass);
                    DeleteFeatureClass2(outfeatureClassName);
                    //DeleteFeatureClass(outfeaturePath);
                    QuestionManager.AddRange(list);
                    //QuestionManager.AddRange(
                    //    list.Select(e =>
                    //    new Question
                    //    {
                    //        Code = "5101",
                    //        Name = "行政区(空间)",
                    //        TableName = className1,
                    //        Description = e
                    //    }).ToList());
                }
            }
            else
            {
                QuestionManager.Add(new Question {
                    Code = "", Name = "", Project = CheckProject.图层内属性一致性, Description = ""
                });
            }
        }
Esempio n. 13
0
        public void Add_WhenQuestionIsValid_ReturnSuccess()
        {
            //Arrange
            //Act
            Question question = new Question {
                Title = "test", Body = _fixture.Create <string>(), Topic = _fixture.Create <string>().Substring(0, 5)
            };

            _mockRepository.Setup(m => m.Find(p => p.Title == "test")).Returns((Question)null).Verifiable();
            _mockRepository.Setup(m => m.Add(question)).Verifiable();
            _mockDal.Setup(m => m.Find(p => p.Title == "test")).Returns((Question)null).Verifiable();
            _mockDal.Setup(m => m.Add(new Question())).Verifiable();
            _service.Find(p => p.Title == "test");
            var result = _service.Add(question);

            //Assert
            // result.ShouldBe(new SuccessResult("Your Question successfully posted"));
            result.ShouldBeEquivalentTo(new SuccessResult("Your Question successfully posted"));
            _mockDal.Verify(m => m.Find(p => p.Title == "test"), Times.Once);
            _mockDal.Verify(m => m.Add(question), Times.Once);
        }
Esempio n. 14
0
        private void Check(string folder, string filter)
        {
            var files = Directory.GetFiles(folder, filter);

            foreach (var file in files)
            {
                if (!Open(file))
                {
                    QuestionManager.Add(
                        new Question
                    {
                        Code        = ID,
                        Name        = RuleName,
                        Project     = CheckProject.数据有效性,
                        Description = string.Format("文件:{0}不能打开,请核对", file),
                        ShowType    = ShowType.Folder,
                        Folder      = System.IO.Path.GetDirectoryName(file)
                    });
                }
            }
        }
Esempio n. 15
0
        public void Program()
        {
            QuestionManager.Clear();//质检问题初始化

            if (!System.IO.Directory.Exists(Folder))
            {
                LogManager.Log(string.Format("质检路径不存在:{0},请核对!", Folder));
                QuestionManager.Add(new Question()
                {
                    Code = "1102", Name = "质检路径不存在", Project = CheckProject.目录及文件规范性, Description = string.Format("质检路径不存在:{0},请核对!", Folder)
                });
                return;
            }
            var folderTool = new FolderTool {
                Folder = Folder
            };                                                  //对质检路径进行命名规范检查

            folderTool.Check();
            //if (!folderTool.Check())
            //{
            //    return;
            //}
            Code     = folderTool.Code;
            District = folderTool.CityName;



            var resultComplete = new ResultComplete(Folder)
            {
                Children = XmlManager.Get("/Folders/Folder", "Name", XmlEnum.DataTree)
            };

            resultComplete.Check();//对质检路径下的文件夹、文件是否存在,是否能够打开进行检查
            QuestionManager.AddRange(resultComplete.Messages.Select(e => new Question {
                Code = "1102", Name = "成果数据丢露", Project = CheckProject.目录及文件规范性, Description = e
            }).ToList());

            if (OnProgramProcess != null)
            {
                var args = new ProgressEventArgs()
                {
                    Code = "11", Cancel = false, Message = string.Empty
                };
                OnProgramProcess(this, args);
                if (args.Cancel)
                {
                    return;
                }
            }

            _folderTools.AddRange(resultComplete.ExistPath.Select(e => new FileFolder()
            {
                Folder    = e,
                FileNames = XmlManager.GetChildren(string.Format("/Folders/Folder[@Name='{0}']", new DirectoryInfo(e).Name), "Name", XmlEnum.DataTree),
                CityName  = folderTool.CityName,
                Code      = folderTool.Code
            }));

            try
            {
                Parallel.ForEach(_folderTools, tool =>
                {
                    tool.Check();
                });
            }
            catch (AggregateException ae)
            {
                foreach (var exp in ae.InnerExceptions)
                {
                    LogManager.Log(exp.ToString());
                    LogManager.Record(exp.ToString());
                }
            }


            var path = System.IO.Path.Combine(Folder, DataBase);
            //获取空间数据库文件夹下的单位代码表文件,并获取单位代码信息
            var codefileTool = new Tool.FileTool {
                Folder = path, Filter = "*.xls", RegexString = @"^[\u4e00-\u9fa5]+\(\d{6}\)单位代码表.xls$"
            };
            var currentCodeFile = codefileTool.GetFile();

            if (string.IsNullOrEmpty(currentCodeFile))
            {
                LogManager.Log("未识别到单位代码表文件,请核对空间数据库文件下的文件");
            }
            else
            {
                ExcelManager.Init(currentCodeFile);
            }
            //获取空间数据库文件夹下的空间数据库文件,并对数据库进行检查
            var mdbfileTool = new Tool.FileTool()
            {
                Folder = path, Filter = "*.mdb", RegexString = @"^[\u4e00-\u9fa5]+\(\d{6}\)农村存量建设用地调查成功空间数据库.mdb$"
            };
            var currentMdbFile = mdbfileTool.GetFile();

            if (string.IsNullOrEmpty(currentMdbFile))
            {
                LogManager.Log("未识别到数据库文件,请核对农村存量建设用地调查成功空间数据库.mdb文件");
                QuestionManager.Add(new Question {
                    Code = "2101", Name = "适量数据文件", Project = CheckProject.目录及文件规范性, Description = "未识别到数据库文件,请核对农村存量建设用地调查成功空间数据库.mdb文件"
                });
            }
            else
            {
                TableHeart.Program(currentMdbFile, IDS);
                var gisheart = new ArcGISHeart()
                {
                    MDBFilePath = currentMdbFile, FeatureClassNames = XmlManager.Get("/Tables/Table[@IsSpace='true']", "Name", XmlEnum.Field)
                };
                gisheart.Program();
            }
            Console.WriteLine("开始对统计表格进行质检......");
            var collectfolder = System.IO.Path.Combine(Folder, Collect);

            if (!System.IO.Directory.Exists(collectfolder))
            {
                QuestionManager.Add(new Question {
                    Code = "1101", Name = "统计表格文件夹", Project = CheckProject.目录及文件规范性, Description = string.Format("目录:{0}不存在", collectfolder)
                });
            }
            else
            {
                //汇总表质检
                var excel = new ExcelHeart()
                {
                    Folder = collectfolder, MDBFilePath = currentMdbFile, District = folderTool.CityName, Code = folderTool.Code
                };
                excel.Program();
                QuestionManager.AddRange(excel.Questions);
            }
        }
        private void B_Save_Click(object sender, EventArgs e)
        {
            if (ValidateInputs())
            {
                if (IsAdd)
                {
                    question.Title     = TB_Title.Text;
                    question.CreatedOn = DateTime.Now;
                    question.Id        = Guid.NewGuid();

                    // First answer
                    var answer1 = new QuestionItem();
                    answer1.Id    = Guid.NewGuid();
                    answer1.Title = TB_Answer1.Text;
                    question.Items.Add(answer1);

                    // Second answer
                    var answer2 = new QuestionItem();
                    answer2.Id    = Guid.NewGuid();
                    answer2.Title = TB_Answer2.Text;
                    question.Items.Add(answer2);

                    // Third answer
                    var answer3 = new QuestionItem();
                    answer3.Id    = Guid.NewGuid();
                    answer3.Title = TB_Answer3.Text;
                    question.Items.Add(answer3);

                    // Forth answer
                    var answer4 = new QuestionItem();
                    answer4.Id    = Guid.NewGuid();
                    answer4.Title = TB_Answer4.Text;
                    question.Items.Add(answer4);

                    DetermineCorrectAnswer(question, answer1, answer2, answer3, answer4);
                    question.CategoryId = Guid.Parse(CB_Category.SelectedValue.ToString());
                    manager.Add(question);
                    MessageBox.Show("سوال مورد نظر با موفقیت اضافه شد.", "پیام سیستم", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    // Update

                    question.Title = TB_Title.Text;

                    // First answer
                    var answer1 = new QuestionItem();
                    answer1.Id        = question.Items[0].Id;
                    answer1.Title     = TB_Answer1.Text;
                    question.Items[0] = answer1;

                    // Second answer
                    var answer2 = new QuestionItem();
                    answer2.Id    = question.Items[1].Id;
                    answer2.Title = TB_Answer2.Text;

                    question.Items[1] = answer2;

                    // Third answer
                    var answer3 = new QuestionItem();
                    answer3.Id    = question.Items[2].Id;
                    answer3.Title = TB_Answer3.Text;

                    question.Items[2] = answer3;

                    // Forth answer
                    var answer4 = new QuestionItem();
                    answer4.Id    = question.Items[3].Id;
                    answer4.Title = TB_Answer4.Text;

                    question.Items[3] = answer4;

                    DetermineCorrectAnswer(question, answer1, answer2, answer3, answer4);

                    manager.Edit(question);
                    MessageBox.Show("سوال مورد نظر با موفقیت ویرایش شد.", "پیام سیستم", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
    /// <summary>
    /// 将根目录下的Question Libraries下的每个EXCEL文件中的试题导入数据库并创建索引
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button3_Click(object sender, EventArgs e)
    {
        Dictionary <string, string> dic = new Dictionary <string, string>();//主要试题中的科目与数据库中textbookname的名称不一致,这里建立一个对应关系,key是试题中的名称,value是数据库中的名称

        string[] subjectResourse =
        {
            "航海学(航海仪器)",
            "航海学(航海气象与海洋学)",
            "航海学(航海地文、天文)",
            "船舶管理",
            "船舶结构与货运",
            "航海英语",
            "船舶操纵与避碰(船舶操纵)",
            "船舶操纵与避碰(船舶避碰)",
            "基本安全-个人安全与社会责任",
            "基本安全-个人求生",
            "基本安全-防火与灭火",
            "基本安全-基本急救",
            "精通救生艇筏和救助艇培训",
            "高级消防培训",
            "精通急救培训"
        };
        string[] subjectData =
        {
            "航海学(航海地文、天文和仪器)",
            "航海学(航海气象与海洋学)",
            "航海学(航海地文、天文和仪器)",
            "船舶管理(驾驶员)",
            "船舶结构与货运",
            "航海英语(二、三副)",
            "船舶操纵与避碰(船舶操纵)",
            "船舶操纵与避碰(船舶避碰)",
            "个人安全与社会责任",
            "个人求生",
            "防火与灭火",
            "基本急救",
            "救生艇筏和救助艇操作及管理",
            "高级消防",
            "精通医疗急救"
        };
        if (subjectData.Length != subjectResourse.Length)
        {
            throw new ArgumentException("两个科目的长度不一致");
        }
        for (int i = 0; i < subjectData.Length; i++)
        {
            dic.Add(subjectResourse[i], subjectData[i]);
        }
        Difficulty      difficulty      = new DifficultyManager().GetModel(1); //difficultyid为1  是难度不确定
        Users           user            = (Users)Session["User"];              //得到当前登录的用户
        TextBook        textbook        = null;
        Chapter         chapter         = new Chapter();
        Chapter         node            = new Chapter();
        QuestionManager questionmanager = new QuestionManager();

        //获得获取根目录下Question Libraries文件中的试题文件
        string[] QuestionLibraries = Directory.GetFiles(Server.MapPath("~\\Question Libraries"));
        foreach (String path in QuestionLibraries)
        {
            FileStream fs       = new FileStream(path, FileMode.Open, FileAccess.Read);
            IWorkbook  workbook = null;    //获得EXCEL文档
            if (path.IndexOf(".xlsx") > 0) // 2007版本
            {
                workbook = new XSSFWorkbook(fs);
            }
            else if (path.IndexOf(".xls") > 0) // 2003版本
            {
                workbook = new HSSFWorkbook(fs);
            }
            ISheet sheet    = workbook.GetSheetAt(0); //获得文档中的第一个工作表
            IRow   firstrow = sheet.GetRow(0);        //获得工作表中的第一行
            int    column   = firstrow.LastCellNum;   //获得第一行中的列数
            int    rownum   = sheet.LastRowNum;
            for (int i = 1; i < rownum; i++)
            {
                Question question = new Question();
                IRow     row      = sheet.GetRow(i);
                //表格中的数据是从0列开始,分别是0AllID/1Id/2SN/3SNID/4Subject/5Chapter/6Node/7Title/8Choosea/9Chooseb/10Choosec/11Choosed/12Answer/13Explain/14ImageAddress/15Remark
                question.QuestionTitle = row.GetCell(7).StringCellValue.Trim();
                question.AnswerA       = row.GetCell(8).StringCellValue.Trim() + "";
                question.AnswerB       = row.GetCell(9).StringCellValue.Trim() + "";
                question.AnswerC       = row.GetCell(10).StringCellValue.Trim() + "";
                question.AnswerD       = row.GetCell(11).StringCellValue.Trim() + "";
                question.CorrectAnswer = common.tryparse(row.GetCell(12).StringCellValue.Trim());
                question.Explain       = row.GetCell(13).StringCellValue.Trim();
                question.ImageAddress  = row.GetCell(14).StringCellValue.Trim();
                question.DifficultyId  = difficulty.DifficultyId;
                question.UserId        = user.UserId;
                string subjectFromExcel = row.GetCell(4).StringCellValue.Trim();
                string subjectFromDb    = dic[subjectFromExcel].Trim();
                if (textbook == null || textbook.TextBookName != subjectFromDb)
                {
                    textbook = new TextBookManager().GetModel(subjectFromDb)[0];
                }
                question.TextBookId  = textbook.TextBookId;
                question.PaperCodeId = textbook.PaperCodeId;
                //后面开始处理章节标题,先检测章标题,后检测节标题
                //如果章标题不存在,进添加进去,如果节标题不存在,也添加进去
                string chapterFromExcel = row.GetCell(5).StringCellValue.Trim();
                string nodeFromExcel    = row.GetCell(6).StringCellValue.Trim();
                //章标题为空,或者没有,则要新建
                if (chapter.TextBookId != textbook.TextBookId || chapter.ChapterName != chapterFromExcel)
                {
                    ChapterManager chaptermanager = new ChapterManager();
                    List <Chapter> list           = chaptermanager.GetModel(textbook.TextBookId, chapterFromExcel);
                    if (list.Count > 0)
                    {
                        chapter = list[0];
                    }
                    else
                    {
                        chapter                 = new Chapter();
                        chapter.TextBookId      = textbook.TextBookId;
                        chapter.ChapterName     = chapterFromExcel;
                        chapter.ChapterParentNo = 0;
                        chapter.ChapterDeep     = 0;
                        chapter.ChapterRemark   = chapterFromExcel;
                        int resu = new ChapterManager().Add(chapter);
                        if (resu > 0)
                        {
                            chapter.ChapterId = resu;
                        }
                        else
                        {
                            throw new Exception("插入章标题失败。");
                        }
                    }
                }
                if (node.TextBookId != textbook.TextBookId || node.ChapterName != nodeFromExcel)
                {
                    ChapterManager chaptermanager = new ChapterManager();
                    List <Chapter> list           = chaptermanager.GetModel(textbook.TextBookId, nodeFromExcel);
                    if (list.Count > 0)
                    {
                        node = list[0];
                    }
                    else
                    {
                        node                 = new Chapter();
                        node.TextBookId      = textbook.TextBookId;
                        node.ChapterName     = nodeFromExcel;
                        node.ChapterParentNo = chapter.ChapterId;
                        node.ChapterDeep     = 1;
                        node.ChapterRemark   = nodeFromExcel;
                        int resu = new ChapterManager().Add(node);
                        if (resu > 0)
                        {
                            node.ChapterId = resu;
                        }
                        else
                        {
                            throw new Exception("插入节标题失败。");
                        }
                    }
                }
                question.ChapterId = node.ChapterId;
                question.Remark    = row.GetCell(15).StringCellValue.Trim();
                int qr = questionmanager.Add(question);
                question.QuestionId = qr;
                common.CreateIndexofQuestion(new DirectoryInfo(IndexPath), question);
                // Thread.Sleep(5000);
                Debug.WriteLine("科目:" + path + ",  第 " + i + " 题 :" + qr);
            }
            ; //一本试题结束
        }
        ;     //全部结束
        common.ShowMessageBox(this.Page, "全部完成");
    }
Esempio n. 18
0
        private bool Init()
        {
            OutputMessage("00", "正在初始化检查机制", ProgressResultTypeEnum.Other);
            if (!ReadXZQ())//分析读取行政区
            {
                OutputMessage("00", "未分析读取到行政区名称和行政区代码", ProgressResultTypeEnum.Fail);
                return(false);
            }
            if (!SearchFile())//查找单位代码表和数据库文件
            {
                OutputMessage("00", "未找到单位代码表或者数据库文件", ProgressResultTypeEnum.Fail);
                return(false);
            }

            OutputMessage("00", "参数管理器初始化完毕", ProgressResultTypeEnum.Other);
            ExcelManager.Init(ParameterManager.CodeFilePath);//初始化单位代码信息列表
            var tree = new CodeForm()
            {
                Dict = ExcelManager.Dict
            };

            if (tree.ShowDialog() == DialogResult.Cancel)
            {
                return(false);
            }
            if (ExcelManager.Dict.Count == 0)
            {
                QuestionManager.Add(new Question {
                    Code = "00", TableName = "单位代码表", Description = "未获取单位代码表中的相关数据信息"
                });
                OutputMessage("00", "未获取单位代码表中的相关数据信息", ProgressResultTypeEnum.Fail);
            }
            else
            {
                OutputMessage("00", string.Format("成功读取行政区(乡镇)单位代码表信息:{0}条", ExcelManager.Dict.Count), ProgressResultTypeEnum.Other);
            }
            if (ExcelManager.XZQ.Count == 0)
            {
                QuestionManager.Add(new Question {
                    Code = "00", TableName = "单位代码表", Description = "读取到的单位代码表中未填写行政区(乡镇)代码信息"
                });
                OutputMessage("00", "读取到的单位代码表中未填写行政区(乡镇)代码信息", ProgressResultTypeEnum.Fail);
            }
            if (ExcelManager.XZC.Count == 0)
            {
                QuestionManager.Add(new Question {
                    Code = "00", TableName = "单位代码表", Description = "读取到的单位代码表中未填写行政区(村级)代码信息"
                });
                OutputMessage("00", "读取到的单位代码表中未填写行政区(村级)代码信息", ProgressResultTypeEnum.Fail);
            }
            var list = ArcGISManager.GainDCDYTB(ParameterManager.Workspace, DCDYTBManager.ClassName) ?? new List <DCDYTB>();

            if (list.Count == 0)
            {
                OutputMessage("00", "未获取调查单元类型相关基础信息", ProgressResultTypeEnum.Fail);
            }
            QuestionManager.AddRange(list.Where(e => e.Right == false).Select(e =>
                                                                              new Question
            {
                Code        = "3401",
                Name        = "面积一致性",
                TableName   = DCDYTBManager.ClassName,
                Description = string.Format("行政区名称:【{0}】行政区代码:【{1}】图斑编号:【{2}】的MJ:【{3}】图斑实际面积:【{4}】容差超过1平方米", e.XZCMC, e.XZCDM, e.TBBH, e.MJ, e.Area),
                BSM         = e.BSM,
                ShowType    = ShowType.Space,
                WhereClause = string.Format("[BSM] = {0}", e.BSM)
            }).ToList());
            DCDYTBManager.List = list;

            OutputMessage("00", "成功读取调查单元图斑信息", ProgressResultTypeEnum.Other);
            InitRules();
            //ParameterManager.Folder = Folder;

            return(true);
        }
    ///<summary>
    ///按钮事件,将一个文件中的数据导入到数据库并创建索引
    ///<param name="sender"></param>
    ///<param name="e"></param>
    ///</summary>
    protected void Button2_Click(object sender, EventArgs e)
    {
        StringBuilder sb      = new StringBuilder();
        string        txtpath = TextBox1.Text;

        string[] s         = sb.Append(File.ReadAllText(txtpath, Encoding.Default)).ToString().Split(new string[] { "<题目>" }, StringSplitOptions.RemoveEmptyEntries);
        int      useridmax = new OnLineTest.BLL.UsersManager().GetMaxId();

        for (int i = 0; i < s.Length; i++)
        {
            s[i] = Regex.Replace(s[i].Replace("\\r", "").Replace("\n", "").Replace("?", "").Trim(), @"\s+", "").Replace("()", "__________");
            string[] s2 = s[i].Split(new string[] { "<参考答案>" }, StringSplitOptions.RemoveEmptyEntries);
            if (s2.Length == 2)
            {
                string[] s3 = s2[0].Split(new string[] { "A.", "B.", "C.", "D." }, StringSplitOptions.RemoveEmptyEntries);
                if (s3.Length == 5)
                {
                    Question        q  = StringsTOQuestion(new string[] { s3[0], s3[1], s3[2], s3[3], s3[4] }, s2[1]);
                    QuestionManager qm = new QuestionManager();
                    common.CreateIndexofQuestion(new DirectoryInfo(IndexPath), qm.GetModel(qm.Add(q)));
                }
            }
        }
        common.ShowMessageBox(this.Page, "导入数据和创建索引成功。");
    }