using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CB.Common;
using CB.Data;
using CB.Entity;
using CB.Framework;

namespace CB.Wap.column
{
    public partial class tool_3dlssdjt : WebPage
    {
        protected string columnName = "", css = "", openDay = "", openInfo = "", columnAbout, logo = "";
        protected StringBuilder others = new StringBuilder();
        protected string columnNav = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            InitData();
        }

        protected override void InitData()
        {
            int term = WRequest.GetQueryInt("term");
            var entity = CB.Data.Caches.GetColumnInfo("3dlssdjt");
            if (null == entity)
            {
                ShowError();
                return;
            }

            columnName = entity.Name;
            header1.ColumnName = columnName;
            columnAbout = entity.About;
            logo = entity.Logo;
            pageTitle = entity.hTitle;
            pageKeyWords = entity.hKeywords;
            pageDescription = entity.hDescription;
           

            var info = Caches.GetFC3DInfo(term, OpenCodeType.KaiJiangHao);
            term = (int)info.Term;
            var list = Caches.GetFC3DHistorySameTerm(term, OpenCodeType.KaiJiangHao);
            if (null != list && 0 < list.Count)
            {
                int i = 1;
                foreach (var item in list)
                {
                    IList<int> d = item.ShiJiHao.ToIntArray(',');
                    if (null == d)
                        break;
                    if (0 == i % 2)
                    { others.AppendLine("                	<tr class=\"grey\">"); }
                    else
                    { others.AppendLine("                	<tr>"); }
                    others.AppendLine("                    	<td>" + item.Term.ToString() + "</td>");
                    others.AppendLine("                        <td>" + item.OpenTime.ToString("yyyy.MM.dd") + "</td>");
                    others.AppendLine("                        <td>" + item.ShiJiHao.Replace(",", ",") + "</td>");
                    others.AppendLine("                        <td>" + CB.Common.LotteryUtils.GetSum(d).ToString() + "</td>");
                    if (0 <= item.OpenCode1)
                    {
                        others.AppendLine("                        <td><span>" + item.OpenCode1 + "," + item.OpenCode2 + "," + item.OpenCode3 + "</span></td>");
                        others.AppendLine("                        <td>" + CB.Common.LotteryUtils.GetSum(item.OpenCode).ToString() + "</td>");
                        others.AppendLine("                        <td>" + GetContains(item.OpenCode, item.ShiJiHao) + "</td>");
                    }
                    else
                    {
                        others.AppendLine("                        <td>---</td>");
                        others.AppendLine("                        <td>---</td>");
                        others.AppendLine("                        <td>---</td>");
                    }
                    others.AppendLine("                    </tr>");
                    i++;
                }
            }

            columnNav = GetColumnNavForWap(entity.Lottery);

            base.InitData();

        }
        private string GetContains(IList<int> list, string numbers)
        {
            if (null == list || 0 >= list.Count || string.IsNullOrEmpty(numbers))
                return "";
            IList<int> d = numbers.ToIntArray(',');
            if (null == d || 0 >= d.Count)
                return "";
            int i = 0;
            foreach (var item in d)
            {
                if (list.Contains(item))
                    i++;
            }
            return 0 == i ? "" : i.ToString();
        }
    }
}