unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, RzButton, DB, ADODB, StdCtrls, RzLabel, ComCtrls, ExtCtrls,DateUtils;
type
TForm1 = class(TForm)
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
RzLabel1: TRzLabel;
RzLabel2: TRzLabel;
ADODataSet1: TADODataSet;
que1: TADOQuery;
ADOConn: TADOConnection;
RzButton1: TRzButton;
RzLabel3: TRzLabel;
procedure RzButton1Click(Sender: TObject);
Function SecondToTime(I:integer):string;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Year,Month,Day : word;
i:integer;
j,n,k:variant;
Num:array[ 1 ..10000000] of integer;//66043
implementation
{$R *.dfm}
Function TForm1.SecondToTime(I: integer): string; //将秒数转化成hh:mm:ss
begin
Result := TimeToStr(I/86400);
end;
procedure TForm1.RzButton1Click(Sender: TObject);
begin
j :=IntToStr(DaysBetWeen(DateTimePicker1.Date,DateTimePicker2.Date));//计算两日期之间相差的天数
k :=86400*j;
ADOConn.Close;
// ADOConn.ConnectionString :=
// 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyData;Data Source=7F119C8C20DE4DB';
ADOConn.Open;
ADODataSet1.Active := false;
ADODataSet1.Active := true;
Randomize;
i:= 1;
while I<k do
begin
RzLabel3.Caption:='正在写数,请稍等!';
ADODataSet1.Append;
Num[I]:=50+Random(10);
que1.SQL.clear;
que1.SQL.Add('insert into JSJG06(ID,Times,Data,JsjgCode)');
que1.SQL.Add('values(:ID,:Times,:Data,:JsjgCode)');
Year:=StrToInt( FormatDateTime('yyyy',DateTimePicker1.Date));
Month :=StrToInt(FormatDateTime('mm',DateTimePicker1.Date));
Day :=StrToInt( FormatDateTime('dd',DateTimePicker1.Date));
with ADODataSet1 do
begin
FieldByName('ID').value:=I;
if I>=86400 then
begin
n :=I/86400;
decodedate(DateTimePicker1.Date,Year,Month,Day);
Day:=Day+n;
FieldByName('Times').value:=IntToStr(Year)+'-'
+IntToStr(Month)+'-'
+IntToStr(Day)+' '+SecondToTime(I);
end
else
begin
decodedate(DateTimePicker1.Date,Year,Month,Day);
FieldByName('Times').value:=IntToStr(Year)+'-'
+IntToStr(Month)+'-'
+IntToStr(Day+n)+' '+SecondToTime(I);
end;
FieldByName('Data').value:=Num[I];
FieldByName('JsjgCode').value:='06';
end;
ADODataSet1.Requery();
i:=i+1;
end;
RzLabel3.Caption:='写数完成!';
ShowMessage('数据保存成功');
RzLabel3.Caption:='';
end;
end.