delphi语言 使adotable1当前指针指向第一行记录的程序代码
1个回答
展开全部
首先我也是菜鸟,我是利用暑假时间才开始关注Delphi的,按照你的界面设计,以下代码供参考,还需进一步完善,如数据合法性验证等功能。 上图是我编译后的结果。不过本月总业绩这个位置遗漏了。可参考查询窗体中的部分代码。 SQL查询条件改成取本月的时间范围差茄升洞。
unit Unit1; //主窗体
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,unit2, DB, ADODB, Mask, DBCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Edit8: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
Edit1: TEdit;
DBEdit7: TDBEdit;
DBEdit8: TDBEdit;
DBEdit9: TDBEdit;
DBEdit10: TDBEdit;
DBEdit11: TDBEdit;
DBEdit12: TDBEdit;
DateTimePicker1: TDateTimePicker;
DBEdit13: TDBEdit;
Button5: TButton;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure DBEdit13Click(Sender: TObject);
procedure DateTimePicker1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button4Click(Sender: TObject);//虚笑察关闭
begin
Close;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2,Form2);
Form2.ShowModal;
Form2.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Button2.Enabled:=false;
Button3.Enabled:=true;
datasource1.dataset.Append;
end;
procedure TForm1.Button3Click(Sender: TObject); //保存
Var sqlstr:string;
begin
Button3.Enabled:=false;
Button2.Enabled:=true;
sqlstr:='insert so_det (so_date,achive1,memo1,achive2,memo2,achive3,memo3,achive4,memo4,achive5,memo5,achive6,memo6,achiveTotal)';
sqlstr:=sqlstr+'values('''+datetostr(DateTimePicker1.time)+''','''+dbedit1.text+''','''+dbedit7.text+''','''+dbedit2.text+''','''+dbedit8.text+''','''+dbedit3.text+''','''+dbedit9.text+''','''+dbedit4.text+''','''+dbedit10.text+''','''+dbedit5.text+''','''+dbedit11.text+''','''+dbedit6.text+''','''+dbedit12.text+''','''+dbedit13.text+''')';
// 在Delphi环境中,SQL语句最好不要换行,呵呵,换行还是可以的,只是有些麻烦
//so_det 是SQL数据库中的表,字段如上面的语句所示。
if trim(dbedit1.Text)<>'' then
begin
try
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(sqlstr);
ADOQuery1.ExecSQL;
Application.MessageBox('增加记录成功','提示',64);
self.OnShow(Sender);
dbedit1.SetFocus;
except
Application.MessageBox('增加记录失败','提示',64);
Close;
end;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from so_det order by so_date');
ADOQuery1.Open;
end;
procedure TForm1.Button5Click(Sender: TObject); //刷新数据
begin
self.OnShow(Sender);
Button2.Enabled:=true;
end;
procedure TForm1.DBEdit13Click(Sender: TObject); //数据汇总
begin
dbedit13.Text:=inttostr(strtoint(Trim(dbedit1.Text))+ strtoint(Trim(dbedit2.Text))+ strtoint(Trim(dbedit3.Text))+ strtoint(Trim(dbedit4.Text))+ strtoint(Trim(dbedit5.Text))+ strtoint(Trim(dbedit6.Text)));
end;
procedure TForm1.DateTimePicker1Change(Sender: TObject); //根据选定的日期刷新数据
Var A:string;
begin
A:=datetostr(DateTimePicker1.Date);
Adoquery1.Close;
Adoquery1.SQL.Clear;
Adoquery1.SQL.Add('select * from so_det where so_date='''+A+'''');
Adoquery1.open;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.
-------------------------
//unit Unit2; 查询窗体
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, ADODB;
type
TForm2 = class(TForm)
Label1: TLabel;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Label2: TLabel;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
Var A,B: string;
begin
A:=datetostr(DateTimePicker1.Date);
B:=datetostr(DateTimePicker2.Date);
Adoquery1.Close;
Adoquery1.SQL.Clear;
Adoquery1.SQL.Add
('select sum(ahiveTotal) as total from so_det where so_date>='''+A+''' and so_date<='''+B+''''); //SQL语句分行的时候需留意,我一般写成一行
Adoquery1.open;
edit2.Text:=Adoquery1.fieldbyname('total').AsString; //显示查询结果在文本框中
end;
end.
unit Unit1; //主窗体
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,unit2, DB, ADODB, Mask, DBCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Edit8: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
Edit1: TEdit;
DBEdit7: TDBEdit;
DBEdit8: TDBEdit;
DBEdit9: TDBEdit;
DBEdit10: TDBEdit;
DBEdit11: TDBEdit;
DBEdit12: TDBEdit;
DateTimePicker1: TDateTimePicker;
DBEdit13: TDBEdit;
Button5: TButton;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure DBEdit13Click(Sender: TObject);
procedure DateTimePicker1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button4Click(Sender: TObject);//虚笑察关闭
begin
Close;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2,Form2);
Form2.ShowModal;
Form2.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Button2.Enabled:=false;
Button3.Enabled:=true;
datasource1.dataset.Append;
end;
procedure TForm1.Button3Click(Sender: TObject); //保存
Var sqlstr:string;
begin
Button3.Enabled:=false;
Button2.Enabled:=true;
sqlstr:='insert so_det (so_date,achive1,memo1,achive2,memo2,achive3,memo3,achive4,memo4,achive5,memo5,achive6,memo6,achiveTotal)';
sqlstr:=sqlstr+'values('''+datetostr(DateTimePicker1.time)+''','''+dbedit1.text+''','''+dbedit7.text+''','''+dbedit2.text+''','''+dbedit8.text+''','''+dbedit3.text+''','''+dbedit9.text+''','''+dbedit4.text+''','''+dbedit10.text+''','''+dbedit5.text+''','''+dbedit11.text+''','''+dbedit6.text+''','''+dbedit12.text+''','''+dbedit13.text+''')';
// 在Delphi环境中,SQL语句最好不要换行,呵呵,换行还是可以的,只是有些麻烦
//so_det 是SQL数据库中的表,字段如上面的语句所示。
if trim(dbedit1.Text)<>'' then
begin
try
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(sqlstr);
ADOQuery1.ExecSQL;
Application.MessageBox('增加记录成功','提示',64);
self.OnShow(Sender);
dbedit1.SetFocus;
except
Application.MessageBox('增加记录失败','提示',64);
Close;
end;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from so_det order by so_date');
ADOQuery1.Open;
end;
procedure TForm1.Button5Click(Sender: TObject); //刷新数据
begin
self.OnShow(Sender);
Button2.Enabled:=true;
end;
procedure TForm1.DBEdit13Click(Sender: TObject); //数据汇总
begin
dbedit13.Text:=inttostr(strtoint(Trim(dbedit1.Text))+ strtoint(Trim(dbedit2.Text))+ strtoint(Trim(dbedit3.Text))+ strtoint(Trim(dbedit4.Text))+ strtoint(Trim(dbedit5.Text))+ strtoint(Trim(dbedit6.Text)));
end;
procedure TForm1.DateTimePicker1Change(Sender: TObject); //根据选定的日期刷新数据
Var A:string;
begin
A:=datetostr(DateTimePicker1.Date);
Adoquery1.Close;
Adoquery1.SQL.Clear;
Adoquery1.SQL.Add('select * from so_det where so_date='''+A+'''');
Adoquery1.open;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.
-------------------------
//unit Unit2; 查询窗体
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, ADODB;
type
TForm2 = class(TForm)
Label1: TLabel;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Label2: TLabel;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
Var A,B: string;
begin
A:=datetostr(DateTimePicker1.Date);
B:=datetostr(DateTimePicker2.Date);
Adoquery1.Close;
Adoquery1.SQL.Clear;
Adoquery1.SQL.Add
('select sum(ahiveTotal) as total from so_det where so_date>='''+A+''' and so_date<='''+B+''''); //SQL语句分行的时候需留意,我一般写成一行
Adoquery1.open;
edit2.Text:=Adoquery1.fieldbyname('total').AsString; //显示查询结果在文本框中
end;
end.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询