procedure TForm1.Button1Click(Sender: TObject);
type
TSqlItem = record
BiShu: Integer;
Amount: Integer;
TradeStatus: Integer;
end;
TSqlItemAry = array of TSqlItem;
var
LRead, LWrite: TextFile;
LMonth: Integer;
LSqlAry: TSqlItemAry;
LLine: string;
LStrList: TStringList;
LJinE, LDianHuaKa, LWangYin: Integer;
LIndex: Integer;
I: Integer;
LTotal: Integer;
begin
Randomize;
LStrList := TStringList.Create;
LStrList.Delimiter := #9;
LStrList.StrictDelimiter := True;
LStrList.Duplicates := dupAccept;
for LMonth := 8 to 12 do
begin
AssignFile(LRead, Format('%d.txt', [Integer(LMonth)]));
AssignFile(LWrite, Format('%d.sql', [Integer(LMonth)]));
Reset(LRead);
Rewrite(LWrite);
SetLength(LSqlAry, 0);
while not Eof(LRead) do
begin
Readln(LRead, LLine);
LLine := Trim(LLine);
if Length(LLine) > 0 then
begin
LStrList.DelimitedText := LLine;
if LStrList.Count <> 3 then
raise Exception.Create('<>3');
LJinE := StrToIntDef(LStrList[0], 0);
LDianHuaKa := Round(StrToFloatDef(LStrList[1], 0.0));
LWangYin := Round(StrToFloatDef(LStrList[2], 0.0));
if LJinE > 0 then
begin
if LDianHuaKa > 0 then
begin
LIndex := Length(LSqlAry);
SetLength(LSqlAry, LIndex + 1);
LSqlAry[LIndex].BiShu := LDianHuaKa;
LSqlAry[LIndex].Amount := LJinE;
end;
if LWangYin > 0 then
begin
LIndex := Length(LSqlAry);
SetLength(LSqlAry, LIndex + 1);
LSqlAry[LIndex].BiShu := LWangYin;
LSqlAry[LIndex].Amount := LJinE;
end;
end;
end;
end;
begin
LTotal := 0;
for I := Low(LSqlAry) to High(LSqlAry) do
Inc(LTotal, LSqlAry[I].BiShu);
LIndex := Random(Length(LSqlAry));
if Random(LTotal) < LSqlAry[LIndex].BiShu then
begin
LLine := Format('I', [
LMonth, LSqlAry[LIndex].Amount, LSqlAry[LIndex].TradeStatus]);
Writeln(LWrite, LLine);
Dec(LSqlAry[LIndex].BiShu);
if LSqlAry[LIndex].BiShu <= 0 then
begin
for I := LIndex to High(LSqlAry) - 1 do
begin
LSqlAry[I] := LSqlAry[I + 1];
end;
SetLength(LSqlAry, Length(LSqlAry) - 1);
end;
end;
end;
CloseFile(LRead);
CloseFile(LWrite);
end;
LStrList.Free;
end;