Example #1
0
        private List <M_Poem> ReadSongciBook(string fileName, int bookNo)
        {
            using (StreamReader reader = new StreamReader(fileName, System.Text.Encoding.UTF8))
            {
                List <M_Poem>   poems    = new List <M_Poem>();
                List <M_Author> Auths    = LinqSqlHelp.GetAllAuthor();
                List <M_Cipai>  Cipais   = LinqSqlHelp.GetAllCipai();
                M_Poem          poemItem = null;
                int             sectNo   = 0;
                int             no       = 0;
                string          title    = "";
                string          auth     = "";
                string          cipai    = "";
                StringBuilder   content  = null;
                string          text     = reader.ReadLine();

                while (text != null)
                {
                    //作成者変更
                    string tempAuth;
                    if (TryParseAuth(Auths, text, out tempAuth))
                    {
                        sectNo++;
                        if (poemItem != null)
                        {
                            poemItem.MainBody = FormatPoemText(content.ToString());
                            poemItem.Title    = title;
                            FormatCiPoemItem(poemItem);
                            poems.Add(poemItem);
                        }
                        auth     = tempAuth;
                        poemItem = null;
                        no       = 0;
                        text     = reader.ReadLine();
                        continue;
                    }

                    string tempCipai;
                    string tempTitle;
                    if (TryParseCipai(Cipais, text, out tempCipai, out tempTitle))
                    {
                        if (poemItem != null)
                        {
                            poemItem.MainBody = FormatPoemText(content.ToString());
                            FormatCiPoemItem(poemItem);
                            poems.Add(poemItem);
                        }
                        no++;
                        cipai    = tempCipai;
                        title    = tempTitle;
                        content  = new StringBuilder();
                        poemItem = new M_Poem()
                        {
                            BookNo    = bookNo,
                            SectionNo = sectNo,
                            PoemNo    = no,
                            Cipai     = cipai,
                            Title     = title,
                            Author    = auth,
                            Dynasty   = "宋",
                            PoemType  = "词"
                        };
                    }
                    else
                    {
                        if (content != null)
                        {
                            content.AppendLine(text.Trim());
                        }
                    }
                    text = reader.ReadLine();
                }
                //最後の内容
                if (poemItem != null)
                {
                    poemItem.MainBody = FormatPoemText(content.ToString());
                    poems.Add(poemItem);
                }
                return(poems);
            }
        }