예제 #1
0
        private void menuSQLTest_Click(object sender, EventArgs e)
        {
            SQLUtils sqlUtils = SQLUtils.getInstance();

            conventionRead = null;
            try
            {
                sqlUtils.makeConnect();
                if (sqlUtils.isConnected)
                {
                    MessageBox.Show("连接成功");
                    this.toolStripStatusLabel1.Text = "连接成功";
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("连接失败");
                this.toolStripStatusLabel1.Text = "连接失败" + err.Message;
            }
        }
예제 #2
0
        // /Uploads/imagesrc/neihechuanbo/num5/2006

        private void btnWordRead_Click(object sender, EventArgs e)
        {
            if (this.tbHtmlPath.Text != string.Empty && this.tbParentGuid.Text != string.Empty &&
                this.tbParentDepth.Text != string.Empty && this.tbParentIDfolder.Text != string.Empty &&
                this.tbParentTitleCnFolder.Text != string.Empty && this.tbFilesPath.Text != string.Empty)
            {
                try
                {
                    conventionRead = new ConventionRead();
                    conventionRead.imageFilePath = tbFilesPath.Text;
                    ConventionRow rootNode = new ConventionRow(new Guid(this.tbParentGuid.Text), int.Parse(this.tbParentDepth.Text),
                                                               this.tbParentIDfolder.Text, this.tbParentTitleCnFolder.Text);
                    conventionRead.htmlPath = tbHtmlPath.Text;
                    if (rdbtTitle1Bold.Checked)
                    {
                        if (this.tbTitle1Xpath.Text != string.Empty && tbTitle2Xpath.Text.Trim() != String.Empty)
                        {
                            conventionRead.title1_select = tbTitle1Xpath.Text;
                            conventionRead.title2_select = tbTitle2Xpath.Text;
                            conventionRead.method        = ReadMethod.TITLE_CLASS;
                        }
                    }
                    else if (rdbtTitleHTag.Checked)
                    {
                        if (tbTitle1TagName.Text.Trim() != string.Empty && tbTitle2TagName.Text.Trim() != string.Empty)
                        {
                            conventionRead.title1_select = tbTitle1TagName.Text;
                            conventionRead.title2_select = tbTitle2TagName.Text;
                            conventionRead.method        = ReadMethod.TITLE_TAG;
                        }
                    }
                    else
                    {
                        if (tbTitle1SpanStyle.Text.Trim() != String.Empty && tbTitle2SpanStyle.Text.Trim() != String.Empty)
                        {
                            conventionRead.title1_select = tbTitle1SpanStyle.Text;
                            conventionRead.title2_select = tbTitle2SpanStyle.Text;
                            conventionRead.method        = ReadMethod.TITLE_SPANSTYLE;
                        }
                    }
                    info = conventionRead.ReadHtml(rootNode);
                    this.toolStripStatusLabel1.Text = "Html识别成功:一级目录有" + info.title1s.Count +
                                                      "个,二级目录共有" + info.title2s.Count + "个" + "一级标题直接内容有" + info.title1ContentsNum + "个,图片识别结果 " + info.picResult;
                    this.tbTitle1Guids.Text = "";
                    for (int i = 0; i < info.title1Guids.Count; i++)
                    {
                        this.tbTitle1Guids.Text += info.title1s[i] + "\r\n";// " : "+info.title1Guids[i]+"\r\n";
                    }
                    this.tbTitle1Guids.Text += "\r\n\r\n";
                    for (int i = 0; i < info.titles.Count; i++)
                    {
                        this.tbTitle1Guids.Text += info.titles[i] + "\r\n";
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                    this.toolStripStatusLabel1.Text = err.Message;
                }
            }
            else
            {
                MessageBox.Show("请输入信息!");
            }
            #region 废弃代码
            // ConventionRow rootNode=new ConventionRow(new Guid("1b506d0f-8956-46d3-a023-78d24e300ed0"),2,ConventionOptions.CATEGORY.IS_CATEGORY);
            // conventionRead.ReadCatalogue(rootNode);
            //    Word.Application app = new Word.Application();
            //    Word.Document doc = null;
            //    object unknow = Type.Missing;
            //    app.Visible = false;
            //    string str = @"D:\work\WordRead\test.docx";
            //    object file = str;
            //    doc = app.Documents.Open(ref file,
            //        ref unknow, ref unknow, ref unknow, ref unknow,
            //        ref unknow, ref unknow, ref unknow, ref unknow,
            //        ref unknow, ref unknow, ref unknow, ref unknow,
            //        ref unknow, ref unknow, ref unknow);
            //    string temp;
            //    //int paraCount = doc.Paragraphs.Count;
            //    //for (int i = 1; i < paraCount + 1; i++)
            //    //{
            //    //    temp = doc.Paragraphs[i].Range.Text.Trim();
            //    //    Console.WriteLine(temp);
            //    //}
            //    doc.ActiveWindow.Selection.WholeStory();
            //    doc.ActiveWindow.Selection.Copy();
            //    IDataObject data = Clipboard.GetDataObject();
            //    temp = data.GetData(DataFormats.Text).ToString();
            //    //回车换行使用了\r\n   和   \n
            //    string pattern_title1 = @"第\d{1,}章 {1,2}[\w ]+\r";//查找一级标题
            //    string pattern_title2 = @"(?<=\r\n|\r\n\s{1,})\d{1,}\s{1,}\w[^,。]+?\r";//查找二级标题
            //    string pattern_zhengwen = @"(?<=(?<=\r\n|\r\n\s{1,})\d{1,}\s{1,}\w[^,。]+?\r)" +
            //        @"[\s\S]+?(?=((?<=\r\n|\r\n\s{1,})\d{1,}\s{1,}\w[^,。]+?\r)|" +
            //        @"第\d{1,}章 {1,2}[\w ]+\r\n|(?<=\n|\n\s+)附录[\w\W]+?(?=\r\n)|$)";//查找正文
            //    string pattern_fulu = @"(?<=\n|\n\s+)附录[\w\W]+?(?=\r\n)"; //查找附录
            //    /*******缩进*********/
            //    string pattern_suojin1 = @"(?<=\n|^)[ \t\s]*(?=\d+[\..]\d+)";//匹配1.1、1.1.1缩进,替换顶行无缩进
            //    string pattern_suojin2 = @"(?<=\n)[ \t\s]*(?=[((]\d+[))])";//查找正文中的(1)替换为2空格
            //    string pattern_suojin3 = @"(?<=\n)[ \t\s]*(?=[①②③④⑤⑥⑦⑧⑨⑩])";//匹配 ①缩进,替换为6空格
            //    string pattern_suojin4 = @"(?<=\n)[ \t\s]*(?=[((][a-z]+[))])";//匹配(a)缩进,替换为8空格
            //    Regex.Replace(temp, pattern_suojin1, "");
            //    Regex.Replace(temp, pattern_suojin2, "  ");
            //    Regex.Replace(temp, pattern_suojin3, "      ");
            //    Regex.Replace(temp, pattern_suojin4, "        ");
            //    /****************/
            //    //FileStream mytxt = new FileStream(@"D:\work\WordRead\testResult.txt",
            //    //    FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //    MatchCollection mymatches = Regex.Matches(temp, pattern_zhengwen);
            //    foreach (Match match in mymatches)
            //    {
            //        File.AppendAllText(@"D:\work\WordRead\testResult.txt", match.Value);
            //        File.AppendAllText(@"D:\work\WordRead\testResult.txt", "\r\n\r\n\r\n\r\n完成一段正文。\r\n\r\n\r\n\r\n");
            //    }
            //    Console.WriteLine(mymatches.Count);
            //    Console.WriteLine("\nFinished");
            //    doc.Close();
            #endregion
        }