//ライセンス情報はAgeOnフォルダのLISENCEフォルダを参照してください
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml.Linq;
using System.Windows.Forms;

namespace nispi
{
    partial class Shiori
    {
        public void RemoveShiori()
        {
            if (beforeShioriStr.Length != 0)
            {
                string searchtxt = "shiori" + beforeShioriStr + "x";
                //HtmlElement tag = null;

                HtmlDocument doc = browserParts.Document;

                mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)doc.DomDocument;
                mshtml.IHTMLTxtRange textRange = ((mshtml.IHTMLBodyElement)dom.body).createTextRange();

                foreach (HtmlElement tags in doc.GetElementsByTagName("table"))
                {
                    if (tags.Name.IndexOf(searchtxt) == 0)
                    {
                        tags.InnerText = "";
                        //tags.OuterText = "";
                        tags.SetAttribute("width", "0");
                        tags.SetAttribute("height", "0");
                    }
                }
            }
        }

        public void SetShiori(string resStr)
        {
            int num = 0;

            if (resStr.Length == 0)
                return;
            else if (Int32.TryParse(resStr,out num) == false)
                return;
            else
                beforeShioriStr = resStr;

            SaveToFile();

            string searchtxt = "shiori" + beforeShioriStr + "x";
            //HtmlElement tag = null;

            HtmlDocument doc = browserParts.Document;

            mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)doc.DomDocument;
            mshtml.IHTMLTxtRange textRange = ((mshtml.IHTMLBodyElement)dom.body).createTextRange();

            foreach (HtmlElement tags in doc.GetElementsByTagName("table"))
            {
                if (tags.Name.IndexOf(searchtxt) == 0)
                {
                    tags.OuterHtml = string.Format("<table name={0} width='400' border='0' cellspacing='1' bgcolor='#ff6633'>" +
                        "<tr>" +
                        "<th bgcolor='#ff6633'><font color='#ffffff'>しおり:{1}</font></th>" +
                        "</tr>" +
                        "</table>", searchtxt, DateTime.Now.ToString());

                    tags.SetAttribute("width", "400");
                    tags.SetAttribute("height", "30");
                }
            }
        }
    }
}