Esempio n. 1
0
 private void btnNextCatalog_Click(object sender, EventArgs e)
 {
     if (tb.CurrentCatalog + 1 < tb.Catalogs.Count)
     {
         tb.CurrentCatalog++;
         CatalogPuple puple = tb.Catalogs[tb.CurrentCatalog];
         this.pContent.Controls[0].Text = puple.Content;
     }
 }
Esempio n. 2
0
 private void btnPrevCatalog_Click(object sender, EventArgs e)
 {
     if (tb.CurrentCatalog > 0)
     {
         tb.CurrentCatalog--;
         CatalogPuple puple = tb.Catalogs[tb.CurrentCatalog];
         this.pContent.Controls[0].Text = puple.Content;
     }
 }
Esempio n. 3
0
 private void ShowCatalog()
 {
     for (int i = 0; i < tb.Catalogs.Count; i++)
     {
         CatalogPuple      cp = tb.Catalogs[i];
         ToolStripMenuItem tsmiCatalogItem = new ToolStripMenuItem(cp.Name);
         tsmiCatalogItem.Name   = string.Format("catalogs{0}", i);
         tsmiCatalogItem.Click += new EventHandler(tsmiCatalogItem_Click);
         AddCatalog(tsmiCatalogItem);
     }
 }
Esempio n. 4
0
        private void btnNextCatalog_Click(object sender, EventArgs e)
        {
            if (tb.CurrentCatalog + 1 < tb.Catalogs.Count)
            {
                tb.CurrentCatalog++;
                CatalogPuple puple = tb.Catalogs[tb.CurrentCatalog];
                this.panelContent.Controls[0].Text = puple.Content;

                this.Text = string.Format(APPLICATION_CAPTION, this.tb.Author, "-" + this.tb.BookName, "~" + puple.Name + "        ");
            }
        }
Esempio n. 5
0
        void tsmiCatalogItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
            Regex             re   = new Regex("\\d+");
            Match             m    = re.Match(tsmi.Name);

            int position = int.Parse(m.Value);

            tb.CurrentCatalog = position;

            CatalogPuple puple = tb.Catalogs[tb.CurrentCatalog];

            this.pContent.Controls[0].Text = puple.Content;
            this.Text = string.Format(APPLICATION_CAPTION, this.tb.Author, "-" + this.tb.BookName, "~" + puple.Name + "        ");
        }
Esempio n. 6
0
        public static void NewCatalog(ref TextBook tb)
        {
            Catalogs catalogs = new Catalogs();
            //以文本方式打开小说
            BufferedStream bs       = new BufferedStream(File.OpenRead(tb.FullName));
            StreamReader   sr       = new StreamReader(bs, Encoding.Default);
            long           position = 0;
            string         buffer;
            Regex          re = new Regex("书名:\\w{1,50}", RegexOptions.IgnorePatternWhitespace);

            while (string.IsNullOrEmpty(tb.BookName))
            {
                buffer = sr.ReadLine();
                tb.Lines++;
                if (!string.IsNullOrEmpty(buffer))
                {
                    position += buffer.Length;
                    Match m = re.Match(buffer);
                    if (m.Success)
                    {
                        tb.BookName = m.Value;
                        break;
                    }
                }
            }

            re = new Regex("作者:\\w{1,50}", RegexOptions.IgnorePatternWhitespace);

            while (string.IsNullOrEmpty(tb.Author))
            {
                buffer = sr.ReadLine();
                tb.Lines++;
                if (!string.IsNullOrEmpty(buffer))
                {
                    position += buffer.Length;
                    Match m = re.Match(buffer);
                    if (m.Success)
                    {
                        tb.Author = m.Value;
                        break;
                    }
                }
            }

            re = new Regex(@"第(一|二|三|四|五|六|七|八|九|十|零|百|千|万|\d){1,50}章.+\s", RegexOptions.IgnorePatternWhitespace);

            CatalogPuple  cp = null;
            StringBuilder sb = new StringBuilder();

            while (!sr.EndOfStream)
            {
                buffer = sr.ReadLine();
                tb.Lines++;
                if (!string.IsNullOrEmpty(buffer))
                {
                    position += buffer.Length;

                    Match m = re.Match(buffer);
                    //判断章节
                    if (m.Success)
                    {
                        position += Environment.NewLine.Length;

                        if (cp != null)
                        {
                            //是章节保存内容
                            cp.Content = sb.ToString();
                            sb.Remove(0, sb.Length);
                        }

                        cp          = new CatalogPuple();
                        cp.Position = position;
                        cp.Name     = m.Value;
                        cp.Begin    = tb.Lines;
                        if (catalogs.Count > 1)
                        {
                            catalogs[catalogs.Count - 1].End = cp.Begin - 1;
                        }
                        catalogs.Add(cp);
                    }
                    else
                    {
                        if (cp != null)
                        {
                            //不是章节则是内容
                            sb.AppendLine(buffer);
                        }
                    }
                }
            }
            sr.Close();
            tb.Catalogs = catalogs;
        }