初学Delphi
1,加载时把数据动态显示到下拉列表中
2,加载时获取当前系统时间显示到下拉列表中
3,定义变量
4,查询值显示到Tchart中
5,抓图打印
6,连接并查询数据库
7,if,for,while写法
8,截取字符串
unit lltjFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, DB, ADODB, Series,
RpDefine, RpRender, RpRenderCanvas, RpRenderPrinter, Printers, Clipbrd ;
type
TFrmLltj = class(TForm)
chart: TChart;
ADOConnection1: TADOConnection;
lltjquery: TADOQuery;
DataSource1: TDataSource;
fstlnsrsSeries1: TFastLineSeries;
PrintDialog1: TPrintDialog;
GroupBox2: TGroupBox;
lbl1: TLabel;
grp2_lbl_lltj_sj: TLabel;
grp2_lbl_qs: TLabel;
grp2_lbl_qs_n: TLabel;
grp2_lbl_qs_y: TLabel;
grp2_lbl_qs_r: TLabel;
grp2_lbl_qs_s: TLabel;
grp2_lbl_qs_f: TLabel;
grp2_lbl_js: TLabel;
grp2_lbl_js_n: TLabel;
grp2_lbl_js_y: TLabel;
grp2_lbl_js_r: TLabel;
grp2_lbl_js_s: TLabel;
grp2_lbl_js_f: TLabel;
grp2_lbl_lk: TLabel;
GroupBox1: TGroupBox;
lbl_xzlk: TLabel;
lbl_lltjsj: TLabel;
lbl_qs: TLabel;
lbl_qs_n: TLabel;
lbl_qs_y: TLabel;
lbl_qs_r: TLabel;
lbl_qs_s: TLabel;
lbl_qs_f: TLabel;
lbl_js: TLabel;
lbl_js_n: TLabel;
lbl_js_y: TLabel;
lbl_js_r: TLabel;
lbl_js_s: TLabel;
lbl_js_f: TLabel;
cbb_xzlk: TComboBox;
Button1: TButton;
cbb_qs_n: TComboBox;
cbb_qs_y: TComboBox;
cbb_qs_r: TComboBox;
cbb_qs_s: TComboBox;
cbb_qs_f: TComboBox;
cbb_js_n: TComboBox;
cbb_js_y: TComboBox;
cbb_js_r: TComboBox;
cbb_js_s: TComboBox;
cbb_js_f: TComboBox;
Button2: TButton;
Button3: TButton;
procedure FormActivate(Sender: TObject);
procedure cbb_xzlkChange(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLltj : TFrmLltj;
kkdh : AnsiString ;//卡口代号
kkmc : array[1..10000000] of AnsiString;//定义卡口名称数组
kkgs : Integer ;//卡口个数
yll : array[1..12] of Integer;//月流量
rll : array[1..31] of Integer;//日流量
sll : array[1..24] of Integer;//时流量
fll : array[1..60] of Integer;//分流量
implementation
{$R *.dfm}
uses LltjQRFrm;
//李猛,09-5-19
procedure TFrmLltj.FormActivate(Sender: TObject);
var
Present : TDateTime;//声明一个TDateTime类型
Year, Month, Day, Hour, Min, Sec, MSec : Word;//word类型用来显示年月日,时分秒毫秒
begin //1
Present := Now;//获取系统当前时间
DecodeDate(Present, Year, Month, Day);//获取年月日
DecodeTime(Present, Hour, Min, Sec, MSec);//获取时分秒毫秒
cbb_qs_n.Text := IntToStr(Year);//显示年
cbb_qs_y.Text := FormatDateTime('mm',Present);//显示月
cbb_qs_r.Text := FormatDateTime('dd',Present);//显示日
cbb_qs_s.Text := FormatDateTime('hh',Present);//显示时
cbb_qs_f.Text := FormatDateTime('nn',Present);//显示分
cbb_js_n.Text := IntToStr(Year);//显示年
cbb_js_y.Text := FormatDateTime('mm',Present);//显示月
cbb_js_r.Text := FormatDateTime('dd',Present);//显示日
cbb_js_s.Text := FormatDateTime('hh',Present);//显示时
cbb_js_f.Text := FormatDateTime('nn',Present);//显示分
cbb_xzlk.Clear;//清空选择路口下拉列表
lltjquery.Close;//关闭ADOQuery
lltjquery.SQL.Clear;//清除ADOQuery中SQL
lltjquery.SQL.Add('select * from kk.kkdj ');//添加ADOQuery中SQL语句
lltjquery.Open;//打开ADOQuery
while (not lltjquery.Eof) do
begin
cbb_xzlk.Items.Add(lltjquery.FieldByName('kkmc').AsString);//把kk.kkdj表中kkmc字段的值装到选择卡口下拉列表中
lltjquery.Next;
end;
chart.Series[0].Clear;
chart.Title.Text.Clear;
chart.Title.Text.Add('路口流量统计');
chart.AutoRepaint := true;
end; //1
procedure TFrmLltj.cbb_xzlkChange(Sender: TObject);
begin //2
// AnsiString kkdh;//卡口代号(用于查看图片模块的查询)
if Trim(cbb_xzlk.Text)<>'' then
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select * from kk.kkdj where kkmc like '''+Trim(cbb_xzlk.Text)+'''');
lltjquery.Open;
kkdh := lltjquery.FieldByName('kkdh').AsString; //保存kkdh的值
end else
Showmessage('选择好想要查看的路口!');
end; //2
procedure TFrmLltj.Button3Click(Sender: TObject);
var
i : Int64 ;
j : Longint ;
begin //3
i := 0;
chart.Repaint;
chart.Series[0].Clear; //清空chart里的值
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select * from kk.kkdj order by kkdh');
lltjquery.Open;
while (not lltjquery.Eof) do
begin
//kkmc[i] := lltjquery.FieldByName('kkdh').AsString + lltjquery.FieldByName('kkmc').AsString;//原来是把kkdh和kkmc加一起的,现在只留kkdh
kkmc[i] := lltjquery.FieldByName('kkdh').AsString ;
i := i + 1;
lltjquery.Next;
end;
kkgs := lltjquery.RecordCount;
for j := 0 to (kkgs - 1) do
begin
lltjquery.Close;
lltjquery.SQL.Clear;
//lltjquery.SQL.Add('select * from kk.kkcltj where kkdd = '+copy(kkmc[j],1,4)+'');
if kkmc[j] = '' then //kkmc里没值则跳出
begin
Break;
end else
lltjquery.SQL.Add('select zpsj,kkdd,xsfx,xscd,xzsd,sjsd,csbz,hphm,hpzl,zpdx,xh from kk.kkcltj where kkdd = '''+copy(kkmc[j],1,4)+'''');
lltjquery.Open;
//ShowMessage(IntToStr(j));
//ShowMessage(copy(kkmc[j],5,(Length(kkmc[j])-2)));
//ShowMessage(IntToStr(lltjquery.RecordCount));
chart.SeriesList.Series[0].Add(lltjquery.RecordCount,copy(kkmc[j],5,(Length(kkmc[j])-2)),clRed);//画chart
end;
end; //3
procedure TFrmLltj.Button2Click(Sender: TObject);
var
j : Longint ;
a, b, c, d, e, f, g, h, i, k, m, n, c1, e1, m1, n1, g1, i1, a1, m2, n2, m3, n3 : Integer;
begin //4
//如果选择了卡口,则按照所选定的时间显示,如:选择了年,则按月来分布;如选择了月,则按日来分布;
//如果没有选择卡口,则显示所有卡口的流量的分布;
chart.Series[0].Clear;
if Trim(cbb_xzlk.Text) <>'' then //判断 选择路口是否为空
begin //5
if Trim(cbb_qs_f.Text) = '' then //判断起始分是否为空
begin //6
//按年查询
//起始年不为空,其他起始时间为空
if (not(Trim(cbb_qs_n.Text) = '')) and (Trim(cbb_qs_y.Text) = '') and (Trim(cbb_qs_r.Text) = '') and (Trim(cbb_qs_s.Text) = '') and (Trim(cbb_qs_f.Text) = '') then
begin //8
// Form1->FormActivate(NULL);
for j := 1 to 12 do
begin //9
if j = 12 then
begin //10
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and (zpsj > to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00',12) + '-01'',''yyyy-mm-dd'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00',12) + '-31'',''yyyy-mm-dd'') ) ');
lltjquery.Open;
yll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[j-1],IntToStr(j)+'月',clDefault);
end else
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00',j) + '-01'',''yyyy-mm-dd'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00',j+1) + '-01'',''yyyy-mm-dd''))');
lltjquery.Open;
yll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[j-1],IntToStr(j)+'月',clDefault);
end; //10
end; //9
end; //8
//按月查询
//起始年月不为空,其他起始时间为空
if (not(Trim(cbb_qs_n.Text) = '')) and (not(Trim(cbb_qs_y.Text) = '')) and (Trim(cbb_qs_r.Text) = '') and (Trim(cbb_qs_s.Text) = '') and (Trim(cbb_qs_f.Text) = '') then
begin //11
if Trim(cbb_qs_y.Text) = '02' then
begin //12
if StrToInt(Trim(cbb_qs_n.Text)) mod 400 = 0 then //判断是否闰年
begin //13
for j := 1 to 29 do
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open();
rll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[j-1],IntToStr(j)+'日',clDefault);
end;
end //13
else if StrToInt(Trim(cbb_qs_n.Text)) mod 4 = 0 then //判断是否闰年
begin
for j := 1 to 29 do //闰年
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[j-1],IntToStr(j)+'日',clDefault);
end;
end else
begin
for j := 1 to 28 do //不是闰年
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[j-1],IntToStr(j)+'日',clDefault);
end;
end; //13
end
else if (Trim(cbb_qs_y.Text) = '04') or (Trim(cbb_qs_y.Text) = '06') or (Trim(cbb_qs_y.Text) = '09') or (Trim(cbb_qs_y.Text) = '11') then //30天的月份
begin
for j := 1 to 30 do
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[j-1],IntToStr(j)+'日',clDefault);
end;
end else
begin
for j := 1 to 31 do //31天的月份
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00',j)+' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
// rll[j-1]=lltjquery->RecordCount;
chart.Series[0].Add(rll[j-1],IntToStr(j)+'日',clDefault);
end;
end; //12
end; //11
//按天查询
//起始年月日不为空,其他起始时间为空
if (not (Trim(cbb_qs_n.Text) = '')) and (not (Trim(cbb_qs_y.Text) = '')) and (not (Trim(cbb_qs_r.Text) = '')) and (Trim(cbb_qs_s.Text) = '') and (Trim(cbb_qs_f.Text) = '') then
begin //14
for j := 0 to (24 -1) do
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text +' '+FormatFloat('00',j)+':00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text +' '+FormatFloat('00',j)+':59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
sll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(sll[j-1],IntToStr(j)+'时',clDefault);
end
end; //14
//按分钟查询
//起始年月时不为空,其他起始时间为空
if (not(Trim(cbb_qs_n.Text) = '')) and (not (Trim(cbb_qs_y.Text) = '')) and (not (Trim(cbb_qs_r.Text) = '')) and (not(Trim(cbb_qs_s.Text) = '')) and (Trim(cbb_qs_f.Text) = '') then
begin //15
for j := 0 to (60 -1) do
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text +' '+cbb_qs_s.Text+':'+FormatFloat('00',j)+':00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text +' '+ cbb_qs_s.Text +':'+FormatFloat('00',j)+':59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
fll[j-1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(fll[j-1],IntToStr(j)+'分',clDefault);
end
end; //15
end else //判断两种查询方式的条件 //6
begin //7
//第二判断条件
c := StrToInt(cbb_qs_s.Text);//起始时赋给c
d := StrToInt(cbb_js_s.Text);//结束时赋给d
e := StrToInt(cbb_qs_r.Text);//起始日赋给e
f := StrToInt(cbb_js_r.Text);//结束日赋给f
g := StrToInt(cbb_qs_f.Text);//起始分赋给g
h := StrToInt(cbb_js_f.Text);//结束分赋给h
i := StrToInt(cbb_qs_y.Text);//起始月赋给i
k := StrToInt(cbb_js_y.Text);//结束月赋给k
a := StrToInt(cbb_qs_n.Text);//起始年赋给a
b := StrToInt(cbb_js_n.Text);//结束年赋给b
m := 23 - c + 1; //剩余小时
n := d + 1;
c1 := d - c + 1;//某段时间小时数
e1 := f - e + 1;//某段时间天数
m1 := 59 - g + 1;//剩余分钟
n1 := h + 1;
g1 := h - g + 1;//某段时间秒数
i1 := k - i + 1;//某段时间月数
// a1=b-a+1;//某段时间年数
m3 := 12 - i + 1;//剩余月数
n3 := k;
if Trim(cbb_qs_y.Text) = '02' then //剩余天数
begin //16
if StrToInt(Trim(cbb_qs_n.Text)) mod 400 = 0 then
begin //17
m2 := 29 - e + 1;
end else
begin
if StrToInt(Trim(cbb_qs_n.Text)) mod 4 = 0 then
begin
m2 := 29 - e + 1;
end else
begin
m2 := 28 - e + 1;
end
end; //17
end
else if (Trim(cbb_qs_y.Text) = '04') or (Trim(cbb_qs_y.Text) = '06') or (Trim(cbb_qs_y.Text) = '09') or (Trim(cbb_qs_y.Text) = '11') then //起始月为30天
begin
m2 := 30 - e + 1;
end else
begin
m2 := 31 - e + 1;
end; //16
n2 := f;
//时间段不同分钟查询
//起始和结束的年月日相同,其他为空
if (cbb_qs_n.Text = cbb_js_n.Text) and (cbb_qs_y.Text = cbb_js_y.Text) and (cbb_qs_r.Text = cbb_js_r.Text) and (not(Trim(cbb_qs_s.Text) = '')) and (not(Trim(cbb_js_s.Text) = '')) and (not(Trim(cbb_qs_f.Text) = '')) and (not(Trim(cbb_js_f.Text) = '')) then
begin //18
if d < c then
begin //19
Application.MessageBox(('日期错误!'), '注意', MB_OK );
end else
begin
if (d = c + 1) or (d = c) then //添加一个条件补充
begin //20
if d = (c + 1) then
begin //21
for j := 0 to (m1 + n1 - 1) do
begin //22
if (j < m1) then
begin //23
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + cbb_qs_s.Text + ':' + FormatFloat('00', g + j) + ':00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + cbb_qs_s.Text + ':' + FormatFloat('00', g + j) + ':59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
fll[g + j] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(fll[g + j], IntToStr(c) + '时' + IntToStr(g + j) + '分', clDefault);
end;
if (j >= m1) then
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_js_n.Text + '-' + cbb_js_y.Text + '-' + cbb_js_r.Text + ' ' + cbb_js_s.Text + ':' + FormatFloat('00', j - m1) + ':00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_js_n.Text + '-' + cbb_js_y.Text + '-' + cbb_js_r.Text + ' ' + cbb_js_s.Text + ':' + FormatFloat('00', j - m1) + ':59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
fll[j - m1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(fll[j - m1], IntToStr(d) + '时' + IntToStr(j - m1) + '分', clDefault);
end; //23
end; //22
end; //21
if (d = c) then
begin //24
for j := 0 to (g1 - 1) do
begin //25
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + cbb_qs_s.Text + ':' + FormatFloat('00', g + j) + ':00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + cbb_qs_s.Text + ':' + FormatFloat('00', g + j) + ':59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
fll[g + j] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(fll[g + j], IntToStr(c) + '时' + IntToStr(g + j) + '分', clDefault);
end;//25
end; //24
end else //添加一个条件补充
begin
for j := 0 to (c1 - 1) do
begin //26
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + FormatFloat('00', c + j) + ':00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + FormatFloat('00', c + j) + ':59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
sll[c + j] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(sll[c + j], IntToStr(c + j) + '时', clDefault);
end; //26
end; //20
end; //19
end
//时间段不同日期查询
//起始和结束的年月相同,其他为空
else if (cbb_qs_n.Text = cbb_js_n.Text) and (cbb_qs_y.Text = cbb_js_y.Text) and (not(Trim(cbb_qs_r.Text) = '')) and (not(Trim(cbb_js_r.Text) = '')) and (not(Trim(cbb_qs_f.Text) = '')) and (not(Trim(cbb_js_s.Text) = '')) and (not(Trim(cbb_qs_s.Text) = '')) and (not(Trim(cbb_js_f.Text) = '')) then
begin
if (f < e) then
begin //27
Application.MessageBox(('日期错误!'), '注意', MB_ICONINFORMATION);
end else
begin
if (f = (e + 1)) or (f = e) then//判断条件
begin //28
if (f = (e + 1)) then
begin //29
for j := 0 to (m + n - 1) do
begin //30
if (j < m) then
begin //31
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + FormatFloat('00', c + j) + ':00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + FormatFloat('00', c + j) + ':59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
sll[c + j] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(sll[c + j], IntToStr(e) + '日' + IntToStr(c + j) + '时', clDefault);
end; //31
if (j >= m) then
begin //32
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_js_n.Text + '-' + cbb_js_y.Text + '-' + cbb_js_r.Text + ' ' + FormatFloat('00', j - m) + ':00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_js_n.Text + '-' + cbb_js_y.Text + '-' + cbb_js_r.Text + ' ' + FormatFloat('00', j - m) + ':59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
sll[j - m] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(sll[j - m], IntToStr(f) + '日' + IntToStr(j - m) + '时', clDefault);
end; //32
end; //30
end; //29
if (f = e) then
begin //33
for j := 0 to (c1 - 1) do
begin //34
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + FormatFloat('00', c + j) + ':00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + cbb_qs_r.Text + ' ' + FormatFloat('00', c + j) + ':59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
sll[c + j] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(sll[c + j], IntToStr(e) + '日' + IntToStr(c + j) + '时', clDefault);
end; //34
end; //33
end else //判断条件
begin
for j := 0 to (e1 - 1) do
begin //35
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00', e + j) + ' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00', e + j) + ' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[e + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[e + j - 1], IntToStr(e + j) + '日', clDefault);
end; //35
end; //28
end; //27
//时间段不同月份查询
//起始和结束的年相同,其他为空
end
else if (cbb_qs_n.Text = cbb_js_n.Text) and (not(Trim(cbb_qs_y.Text) = '')) and (not(Trim(cbb_js_y.Text) = '')) and (not(Trim(cbb_qs_r.Text) = '')) and (not(Trim(cbb_js_r.Text) = '')) and (not(Trim(cbb_qs_f.Text) = '')) and (not(Trim(cbb_js_s.Text) = '')) and (not(Trim(cbb_qs_s.Text) = '')) and (not(Trim(cbb_js_f.Text) = '')) then
begin
if (k < i) then
begin //36
Application.MessageBox(('日期错误!'), '注意', MB_ICONINFORMATION);
end else
begin
if (k = i + 1) or (k = i) then //添加的一个判断条件
begin //37
if (k = i + 1) then
begin //38
for j := 0 to (m2 + n2 - 1) do
begin //39
if (j < m2) then
begin //40
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00', e + j) + ' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00', e + j) + ' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[e + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[e + j - 1], IntToStr(i) + '月' + IntToStr(e + j) + '日', clDefault);
end; //40
if (j >= m2) then
begin //41
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_js_n.Text + '-' + cbb_js_y.Text + '-' + FormatFloat('00', j - m2 + 1) + ' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_js_n.Text + '-' + cbb_js_y.Text + '-' + FormatFloat('00', j - m2 + 1) + ' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open();
rll[j - m2] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[j - m2], IntToStr(k) + '月' + IntToStr(j - m2 + 1) + '日', clDefault);
end; //41
end; //39
end; //38
if (k = i) then
begin //42
for j := 0 to (e1 - 1) do
begin //43
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00', e + j) + ' 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + cbb_qs_y.Text + '-' + FormatFloat('00', e + j) + ' 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
rll[e + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(rll[e + j - 1], IntToStr(i) + '月' + IntToStr(e + j) + '日', clDefault);
end; //43
end; //42
end else //添加的一个判断条件
begin
for j := 0 to (i1 - 1) do
begin //44
if (i + j = 12) then
begin //45
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', 12) + '-01 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', 12) + '-31 23:59:59'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
yll[i + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[i + j - 1], IntToStr(i + j) + '月', clDefault);
end else
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', i + j) + '-01 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', i + j + 1) + '-01 00:00:00'',''yyyy-mm-dd hh24:mi:ss''))');
lltjquery.Open;
yll[i + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[i + j - 1], IntToStr(i + j) + '月', clDefault);
end; //45
end; //44
end; //37
end; //36
//对应不同年份查询
//起始和结束的年月日时分全不为空
end
else if (not(Trim(cbb_qs_n.Text) = '')) and (not(Trim(cbb_js_n.Text) = '')) and (not(Trim(cbb_qs_y.Text) = '')) and (not(Trim(cbb_js_y.Text) = '')) and (not(Trim(cbb_qs_r.Text) = '')) and (not(Trim(cbb_js_r.Text) = '')) and (not(Trim(cbb_qs_f.Text) = '')) and (not(Trim(cbb_js_s.Text) = '')) and (not(Trim(cbb_qs_s.Text) = '')) and (not(Trim(cbb_js_f.Text) = '')) then
begin
if (b < a) then
begin //46
Application.MessageBox(('日期错误!'), '注意', MB_ICONINFORMATION);
end else
begin
if (b = a + 1) then
begin //47
for j := 0 to (m3 + n3 - 1) do
begin //48
if (j < m3) then
begin //49
if (i + j = 12) then
begin //51
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', 12) + '-01'',''yyyy-mm-dd'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', 12) + '-31'',''yyyy-mm-dd''))');
lltjquery.Open;
yll[i + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[i + j - 1], IntToStr(a) + '年' + IntToStr(i + j) + '月', clDefault);
end else
begin
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', i + j) + '-01'',''yyyy-mm-dd'') and zpsj < to_date(''' + cbb_qs_n.Text + '-' + FormatFloat('00', i + j + 1) + '-01'',''yyyy-mm-dd''))');
lltjquery.Open;
yll[i + j - 1] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[i + j - 1], IntToStr(a) + '年' + IntToStr(i + j) + '月', clDefault);
end; //51
end; //49
if j >= m3 then
begin //50
lltjquery.Close;
lltjquery.SQL.Clear;
lltjquery.SQL.Add('select count(*) from kk.kkcltj where (kkdd = '+kkdh+') and ( zpsj > to_date(''' + cbb_js_n.Text + '-' + FormatFloat('00', j - m3 + 1) + '-01'',''yyyy-mm-dd'') and zpsj < to_date(''' + cbb_js_n.Text + '-' + FormatFloat('00', j - m3 + 2) + '-01'',''yyyy-mm-dd''))');
lltjquery.Open;
yll[j - m3] := lltjquery.FieldByName('count(*)').AsInteger;
chart.Series[0].Add(yll[j - m3], IntToStr(b) + '年' + IntToStr(j - m3 + 1) + '月', clDefault);
end; //50
end; //48
end; //47
end; //46
end; //18
end;//判断两种查询方式的条件的结束符号 //7
end;//判断 选择路口是否为空 //5
end; //4
procedure TFrmLltj.Button1Click(Sender: TObject);
var
//FrmQr : TQRFrmLltj;
FormImage: TBitmap;
MyImage:TImage;
r1:TRect;
begin //52
cbb_xzlk.Width := 100;
grp2_lbl_lk.Caption := cbb_xzlk.Text; //选择的路口赋
grp2_lbl_qs_n.Caption := cbb_qs_n.Text + ' 年'; //选择的年
grp2_lbl_qs_y.Caption := cbb_qs_y.Text + ' 月'; //选择的月
grp2_lbl_qs_r.Caption := cbb_qs_r.Text + ' 日'; //选择的日
grp2_lbl_qs_s.Caption := cbb_qs_s.Text + ' 时'; //选择的时
grp2_lbl_qs_f.Caption := cbb_qs_f.Text + ' 分'; //选择的分
grp2_lbl_js_n.Caption := cbb_js_n.Text + ' 年'; //选择的年
grp2_lbl_js_y.Caption := cbb_js_y.Text + ' 月'; //选择的月
grp2_lbl_js_r.Caption := cbb_js_r.Text + ' 日'; //选择的日
grp2_lbl_js_s.Caption := cbb_js_s.Text + ' 时'; //选择的时
grp2_lbl_js_f.Caption := cbb_js_f.Text + ' 分'; //选择的分
GroupBox1.Visible := False; //打印起始时隐藏GroupBox1
FormImage := GetFormImage; //抓图
MyImage := TImage.Create(nil); //
try //53
Clipboard.Assign(FormImage);
MyImage.Picture.Assign(Clipboard);
r1:=Rect(50,50,1500,1500); //设置x坐标,y坐标,横大小,竖大小
if printdialog1.execute then //弹出打印属性框
begin //54
printer.begindoc; //开始打印
Printer.Canvas.StretchDraw(r1,MyImage.Picture.Graphic); //打印中
//Printer.Canvas.draw(0,0,MyImage.Picture.Bitmap);
printer.enddoc; //结束打印
end; //54
//MyImage.Picture.SaveToFile('D:/xxx.bmp');
finally
begin //55
MyImage.Free; //释放资源
FormImage.Free;//释放资源
GroupBox1.Visible := True; //打印结束后显示GroupBox1
end; //55
end; //53
end; //52
end.
黑色头发:http://heisetoufa.iteye.com/