?? main.pas
字號:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables, StdCtrls, Mask, DBCtrls;
type
TForm1 = class(TForm)
yearlb: TLabel;
stationcb: TComboBox;
stationlb: TLabel;
monthlb: TLabel;
yearcb: TComboBox;
monthcb: TComboBox;
Button1: TButton;
Button2: TButton;
Query1: TQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
searchQuery: TQuery;
DataSource2: TDataSource;
DBGrid2: TDBGrid;
differenceQuery: TQuery;
differenceDataSource: TDataSource;
differenceDBGrid: TDBGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
SqlStr : String;
begin
SqlStr:= ' SELECT AVG(rainfall) as 降雨量平均值,AVG(temperature) as 溫度平均值 ';
SqlStr:=SqlStr+' FROM CYQ ';
SqlStr:=SqlStr+' WHERE ';
if (stationcb.Text<>'') then
SqlStr:=SqlStr+' Station='+''''+stationcb.Text+'''' ;
if (yearcb.Text<>'') then
SqlStr:=SqlStr+' AND CYQYear='+''''+yearcb.Text+'''';
if (monthcb.Text<>'') then
SqlStr:=SqlStr+' AND CYQMonth='+''''+monthcb.Text+'''';
searchQuery.Close;
searchQuery.SQL.Clear;
searchQuery.SQL.Add(SqlStr);
searchQuery.Prepare;
searchQuery.Open;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
SqlStr : String;
begin
//SqlStr:= ' select CYQ.rainfall-CYQ002.avg1 as 各月降雨量差值, CYQ.temperature-CYQ002.avg2 as 各月溫度差值 ';
SqlStr:= 'select Station,CYQ.CYQYear,CYQ.CYQMonth, CYQ.rainfall-CYQ002.avg1 as 各月降雨量差值, CYQ.temperature-CYQ002.avg2 as 各月溫度差值 ';
SqlStr:=SqlStr+' FROM CYQ,';
SqlStr:=SqlStr+ ' (SELECT AVG(rainfall) as avg1,AVG(temperature) as avg2 ';
SqlStr:=SqlStr+' FROM CYQ ';
SqlStr:=SqlStr+' WHERE ';
if (stationcb.Text<>'') then
SqlStr:=SqlStr+' Station='+''''+stationcb.Text+'''' ;
if (yearcb.Text<>'') then
SqlStr:=SqlStr+' AND CYQYear='+''''+yearcb.Text+'''';
if (monthcb.Text<>'') then
SqlStr:=SqlStr+' AND CYQMonth='+''''+monthcb.Text+'''';
SqlStr:=SqlStr+' ) as CYQ002 ';
SqlStr:=SqlStr+' WHERE ';
if (stationcb.Text<>'') then
SqlStr:=SqlStr+' Station='+''''+stationcb.Text+'''' ;
if (yearcb.Text<>'') then
SqlStr:=SqlStr+' AND CYQYear='+''''+yearcb.Text+'''';
if (monthcb.Text<>'') then
SqlStr:=SqlStr+' AND CYQMonth='+''''+monthcb.Text+'''';
differenceQuery.Close;
differenceQuery.SQL.Clear;
differenceQuery.SQL.Add(SqlStr);
differenceQuery.Prepare;
differenceQuery.Open;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -