using System;
using System.Collections.Generic;
using System.Xml;
using CB.Common;
using CB.Entity;
using CB.Entity.Frequency;
using CB.Interface.Infrastructure.Frequency;
using CB.LotteryCatchData.Entity;
using CB.LotteryCatchData.Interface;
namespace CB.LotteryCatchData.Opencai
{
///
/// 重庆 高频11选5
///
public class GP11x5_ChongQing : CatchRepository, ICatchDataProvider
{
public override LotteryParamKeys GetLotteryParamKeys(string fileName)
{
return GetLotteryParamKeysDefault(fileName);
}
public override LotteryOpenCode GetLatestOpenCode()
{
return CB.Data.Frequency.GP11x5ChongQingService.GetLatestOpenCodeForCatch();
}
public override IList CatchData(LotteryConfigInfo config, LotteryParamKeys keys)
{
if (!this.IsCatchData(config, keys))
return null;
XmlDocument doc = new XmlDocument();
try
{
doc.Load(config.DataUrl);
var nodeList = doc.SelectNodes("xml/row");
if (null == nodeList || 0 >= nodeList.Count)
return null;
IList list = new List();
LotteryOpenCode entity = null;
string qi = "";
string[] data;
foreach (XmlNode node in nodeList)
{
qi = node.Attributes["expect"].Value.Trim();
if (0 <= keys.LocalTerm.CompareTo(qi))
continue;
data = node.Attributes["opencode"].Value.Trim().Split(',');
entity = new LotteryOpenCode()
{
Term = long.Parse(qi)
};
entity.OpenCode = new List();
entity.OpenCode.Add(TypeConverter.StrToInt(data[0]));
entity.OpenCode.Add(TypeConverter.StrToInt(data[1]));
entity.OpenCode.Add(TypeConverter.StrToInt(data[2]));
entity.OpenCode.Add(TypeConverter.StrToInt(data[3]));
entity.OpenCode.Add(TypeConverter.StrToInt(data[4]));
entity.Addtime = DateTime.Now;
entity.OpenTime = GetRealOpenTime(config.StartTime, config.OpenPeriod, qi, TypeConverter.StrToDateTime(node.Attributes["opentime"].Value.Trim(), entity.Addtime), 8, 2);
list.Add(entity);
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
public override int SaveData(IList list, ref LotteryParamKeys keys)
{
if (null == list || 0 >= list.Count)
return -1;
int n = 0;
long term = Convert.ToInt64(keys.LocalTerm);
DateTime t = keys.LastOpenTime;
GP11x5Info_ChongQing entity = null;
foreach (var item in list)
{
entity = new GP11x5Info_ChongQing()
{
Term = item.Term,
OpenCode1 = item.OpenCode[0],
OpenCode2 = item.OpenCode[1],
OpenCode3 = item.OpenCode[2],
OpenCode4 = item.OpenCode[3],
OpenCode5 = item.OpenCode[4],
OpenTime = item.OpenTime,
Addtime = item.Addtime
};
if (CB.Data.Frequency.GP11x5ChongQingService.Save(entity))
{
n++;
if (term < item.Term)
term = item.Term;
if (t < item.OpenTime)
t = item.OpenTime;
}
}
if (0 < n)
{
keys.IsCatch = 1;
keys.LocalTerm = term.ToString();
keys.LastOpenTime = t;
}
return n;
}
}
}