 

var
  ts1:TTabSheet;
  lblDefaultPNG:TLabel;
  cbbDefaultPNG:TComboBox;
  img1:TImage;
  LotteryW,LotteryH:integer;
        ItemLst,ItemValLst,LotteryValue:TStrings;
	Tempi:integer;
	LotteryHint, 
	LotteryTag:string; //彩票字母标识
 
procedure InitSetting;
var
	s,s1,s2:string;
	inifn:TIniFile;
	indexi:integer;
begin
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  begin
    try
     
    s1:=ReadString('Item0','BitmapName','ssq'); //.\images\ssq.png
    s1:=StrBetween(s1,'images\','.png');
    LotteryTag:=s1;
    case s1 of
      'sd' : indexi:=0;
      'pls': indexi:=1;
      'plw': indexi:=2;
      'qxc': indexi:=3;
      'qlc': indexi:=4;
      'eexw':indexi:=5;
      'syxq':indexi:=6;
      'ssq': indexi:=7;
      'dlt': indexi:=8;
    end; 
    cbbDefaultPNG.itemindex:=indexi;

    finally
      inifn.free;
    end; 
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
  lst:TStrings;
  i:integer;
  s,sVal:string;
  inifn:TIniFile;

  //计算要显示的文字/球的数量和颜色
procedure ShowLottery(value:string);
var
  lst:TStrings;
  s,s1,s2:string;
  i,j,recti,rectj:integer;
 
begin
{ sd  :8,0,7
  pls :7,9,0
  plw :7,9,0,6,3
  qxc :4,2,6,0,1,1,3
  qlc :05,06,08,14,16,28,30|03
  eexw:02,12,13,19,21
  slxq:06,09,16,26,27,36|07
  ssq :10,14,22,28,29,33|02
  ejxq:06,09,11,18,19,26,27|14
  dlt :03,07,20,33,35|04,07    }
  
    lst:=TStringList.create;
    Itemlst:=TStringList.create; 
    ItemValLst:=TStringList.create; 
    LotteryValue:=TStringList.create; 
  if Pos('|',value)>0 then 
    begin
    s1:=copy(value,1,Pos('|',value)-1);
    s2:=copy(value,Pos('|',value)+1,Length(value)-Pos('|',value));
    StrToStrings(s1+','+s2,lst,',');
    end
    else 
    StrToStrings(value,lst,',');

    StrToStrings('Item1,Item2,Item3,Item4,Item5,Item6,Item7,Item8,Item9,',Itemlst,',');
    StrToStrings('0,0,0,0,0,0,0,0,0,',ItemValLst,',');
    StrToStrings(',,,,,,,,,',LotteryValue,',');
    for Tempi:=0 to Itemlst.count-1 do 
      begin
      inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
      inifn.WriteString('Item11','Item'+IntToStr(Tempi),LotteryValue[Tempi]);
      end;
  //showmessage(lst.text);
  recti:=0; rectj:=0;
  try
    if lst.count>0 then 
      case LotteryTag of
        'sd'  :begin
        StrToStrings('1,1,1,0,0,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
          inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(3+33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'pls' :begin
        StrToStrings('1,1,1,0,0,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(3+33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'plw' :begin
        StrToStrings('1,1,1,1,1,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(3+33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'qxc' :begin
        StrToStrings('1,1,1,1,1,1,1,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(3+33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'qlc' :begin
        StrToStrings('1,1,1,1,1,1,1,1,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'eexw':begin
        StrToStrings('1,1,1,1,1,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'syxq':begin
        StrToStrings('1,1,1,1,1,1,1,1,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end;
        'ssq' :begin 
        StrToStrings('1,1,1,1,1,1,0,1,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin 
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	end; 
        'dlt' :begin
        StrToStrings('1,1,1,1,1,0,0,1,1,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:=''; 
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  inifn.WriteString('Item11','Item'+IntToStr(Tempi)+'Rect',IntToStr(33*rectj)+'/0/36/23/23');
	  inc(rectj);
	  end;
	  
	end; 
      end; 
    inifn.WriteString('Item0','hint',LotteryHint);
    
  finally
    lst.free; Itemlst.free; ItemValLst.free; LotteryValue.free;
   
  end;
end;


begin
  //sVal:=GetHttpStr('http://lottery.sports.sohu.com/open/'); 	
  sVal:=SendURL22('http://lottery.sports.sohu.com/open/'); 	
  lst:=TStringList.create;
  inifn:=TIniFile.create(SkinFileName);
  try
    if sVal<>'' then
    begin
    lst.text:=sVal; 
    if lst.count>0 then
      for i:=0 to lst.count-1 do
      begin
        if pos('formatResult('''+LotteryTag,lst.strings[i])>0 then  
        begin
          s:=StrBetween(lst.strings[i],',''',''');');  
          LotteryHint:='彩票：'+GetLotteryName(LotteryTag)+'<#C_CR>'+
	               '期数：'+StrBetween(lst.strings[i-3],'center">','期</td>')+'<#C_CR>'+
		       '日期：'+StrBetween(lst.strings[i-2],'center">','</td>');
           
          ShowLottery(s);
          break;
           
        end;
      end;
    end;
   
  inifn.WriteString('Item0','hint',LotteryHint);
  result:=true;
  //SwitchSkinForm(SkinFileName,SkinFileName);
  InitSkin; 
    
  finally
    lst.free; inifn.free; 
  end;
 
  
  
end;

procedure CreateTab1;
begin
  //--- Tab 1 ---
  ts1:=TTabSheet.Create(pgc);
  ts1.PageControl:=pgc; 
  ts1.Caption:='彩票设置';
   
 
  lblDefaultPNG:=TLabel.create(ts1);
  with lblDefaultPNG do
  begin
    parent:=ts1;
    left:=20; top:=42; 
    caption:='彩票开奖频道:';
  end;
  
  cbbDefaultPNG:=TComboBox.Create(ts1);
  with cbbDefaultPNG do
  begin
    
    Left:=100; Top:=38; width:=100;
    DropDownCount:=9;
    Parent:=ts1;
    Style:=csDropDownList;
    with Items do
    begin 
      add('福彩3D');
      add('排列三');
      add('排列五');
      add('七星彩');
      add('七乐彩');
      add('22选5');
      add('31选7');
      add('双色球');
      add('超级大乐透');
    end;
    OnChange:=@DefaultPNGClick;
    ItemIndex:=7;
  end;

  img1:=TImage.create(nil);
  with img1 do
  begin
     
    AutoSize:=True;
    left:=1; top:=1;
    Visible:=False;
  end;
end;
  
procedure DefaultPNGClick(Sender: TObject);
var  inifn:TIniFile;
i:integer; s:string;
  function GetLotteryTag(value:string):string;
  begin
  case value of
    '福彩3D': result:='sd';
    '排列三': result:='pls';
    '排列五': result:='plw';
    '七星彩': result:='qxc';
    '七乐彩': result:='qlc';
    '22选5': result:='eexw';
    '31选7': result:='syxq';
    '双色球': result:='ssq'; 
    '超级大乐透': result:='dlt';
  else
    result:='';
  end;
  end;
begin
try
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
    begin
    s:=GetLotteryTag(cbbDefaultPNG.Items[cbbDefaultPNG.ItemIndex]);
    LotteryTag:=s;
    inifn.WriteString('Item0','BitmapName','.\images\'+s+'.png');
    img1.Picture.LoadFromFile(SkinPath+'\images\'+s+'.png'); 
    LotteryW:=img1.Picture.Width; 
    LotteryH:=img1.Picture.Height;  
    //Rect=0/0/311/77
    inifn.WriteString('Item0','Rect','0/0/'+IntToStr(LotteryW)+'/'+IntToStr(LotteryH));
    
    end;
finally
  inifn.free;
end;
end;

function GetLotteryName(value:string):string;
begin
  case value of
    'sd':  result:='福彩3D';
    'pls': result:='排列三';
    'plw': result:='排列五';
    'qxc': result:='七星彩';
    'qlc': result:='七乐彩';
    'eexw':result:='22选5';
    'syxq':result:='31选7';
    'ssq': result:='双色球';
    'dlt': result:='超级大乐透';
  else
    result:='';
  end;
end;


 

begin
 
    CreateTab1;
    InitSetting;
   
 
end.