using System;
using System.IO;
using System.Text;

namespace BeWo.Service.Core
{
    [Serializable]
    public class ExcelDownload
    {
        private string[][] _Content;

        private string[] _Header;

        public ExcelDownload(string[] pHeader, string[][] pContent)
        {
            this._Header = pHeader;
            this._Content = pContent;
        }

        public ExcelDownload()
        {
        }

        public string[][] Content
        {
            get
            {
                return this._Content;
            }

            set
            {
                this._Content = value;
            }
        }

        public string[] Header
        {
            get
            {
                return this._Header;
            }

            set
            {
                this._Header = value;
            }
        }

        public string CreateExcelOutputString()
        {
            var lSb = new StringBuilder();

            lSb.Append("<HTML xmlns:o=\"urn:schemas-microsoft-com:office:office\">");

            lSb.Append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");

            lSb.Append("<HEAD>");
            lSb.Append("<title></title>");
            lSb.Append("<!--[if gte mso 9]><xml>");
            lSb.Append("<o:DocumentProperties>");
            lSb.Append("<o:Created><%= now %></o:Created>");
            lSb.Append("</o:DocumentProperties>");
            lSb.Append("</xml><![endif]-->");

            lSb.Append("<style>");
            lSb.Append(".head { font-weight:bold}");
            lSb.Append(".cell, .head { border: thin solid black}");
            lSb.Append("</style>");
            lSb.Append("</HEAD>");

            lSb.Append("<body>");

            lSb.Append("<table><tr>");

            foreach (string iHeader in _Header)
            {
                lSb.Append("<td class=\"head\">");
                lSb.Append(iHeader);
                lSb.Append("</td>");
            }

            lSb.Append("</tr>");

            foreach (var t in _Content)
            {
                lSb.Append("<tr>");
                foreach (var t1 in t)
                {
                    lSb.Append("<td class=\"cell\">");
                    lSb.Append(t1);
                    lSb.Append("</td>");
                }

                lSb.Append("</tr>");
            }

            lSb.Append("</table>");

            lSb.Append("</body>");
            lSb.Append("</HTML>");

            return lSb.ToString();
        }
    }
}