SOS---一个刚用DELPHI做课程设计得大三学生得紧急求救!谁能救小妹一命,感激万分!

ququ621 2003-06-27 05:54:04
我用DELPHI做一个学生缴费注册系统。需要做一个复合统计功能!我用到2个COMBOBOX
用来显示字段,如年级,班级等,和逻辑符号。4个DBLOOKUPCOMBOBOX用来显示具体得班机等项目这样输入时不用手写了。2个MEMO,一个用来显示下来菜单选择选中的组合的项目,如:年级=高二;班级《3,等等;另一个MEMO显示统计后的结果
一个按钮;表示统计(该程序执行一次是可以的,执行第2次就出错,说是WHERE语句附近有错误)
现给出所有源码:望高手救急。明天就要交了,我已经辛苦了两星期了unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ADODB, DB, DBCtrls, Buttons, ComCtrls,
DBTables;

type
TForm3 = class(TForm)
Label1: TLabel;
Image1: TImage;
Label2: TLabel;
Panel1: TPanel;
Panel2: TPanel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
DBLookupComboBox1: TDBLookupComboBox;
DBLookupComboBox2: TDBLookupComboBox;
DBLookupComboBox3: TDBLookupComboBox;
DBLookupComboBox4: TDBLookupComboBox;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
Memo1: TMemo;
Memo2: TMemo;
Label9: TLabel;
Label10: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
StatusBar1: TStatusBar;
Query1: TQuery;
procedure Label1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure DBLookupComboBox1Click(Sender: TObject);
procedure DBLookupComboBox2Click(Sender: TObject);
procedure DBLookupComboBox3Click(Sender: TObject);
procedure DBLookupComboBox4Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

uses Unit2;

{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
var
i:integer;
begin
memo1.Text:='';
memo2.Text:='';
for i:=0 to query1.FieldCount-1 do
combobox1.Items.Add(query1.Fields[i].FieldName);
end;



procedure TForm3.Label1Click(Sender: TObject);
begin
form2.show;form3.Hide;
end;

procedure TForm3.BitBtn1Click(Sender: TObject);

var
sum1:real;
s,s1,s2,s3:string;
bookmark1:tbookmark;
begin
if memo1.Text='' then
begin
Application.MessageBox('请输入查询条件!','提醒',Mb_Ok+Mb_iconwarning);
end
else
begin
sum1:=0;
s1:=combobox1.Text;
s2:=combobox2.Text;
s3:=dblookupcombobox1.Text+dblookupcombobox2.Text+dblookupcombobox3.Text+dblookupcombobox4.Text;
bookmark1:=query1.GetBookmark;
query1.close;
query1.SQL.Add(' where '+memo1.Text);
query1.Open;
if query1.RecordCount=0 then
begin
Application.MessageBox('没有符合条件的记录!','信息',Mb_Ok+Mb_IconInformation);
end
else
begin
query1.DisableControls;
query1.First;
while not query1.Eof do
begin
sum1:=sum1+query1.FieldValues['应缴'];
query1.Next;
end;
query1.GotoBookmark(bookmark1);
query1.FreeBookmark(bookmark1);
end;
str(sum1:8:2,s);
memo2.Text:='符合条件的学生共缴费'+s+'元';
end;
end;






procedure TForm3.ComboBox1Change(Sender: TObject);
begin
memo1.Text:=memo1.Text+combobox1.Text;
end;

procedure TForm3.ComboBox2Change(Sender: TObject);
begin
memo1.Text:=memo1.Text+' '+combobox2.Text+' ';
end;

procedure TForm3.DBLookupComboBox1Click(Sender: TObject);
begin
memo1.Text:=memo1.Text+''''+dblookupcombobox1.Text+'''';
end;

procedure TForm3.DBLookupComboBox2Click(Sender: TObject);
begin
memo1.Text:=memo1.Text+''''+dblookupcombobox2.Text+'''';
end;

procedure TForm3.DBLookupComboBox3Click(Sender: TObject);
begin
memo1.Text:=memo1.Text+''''+dblookupcombobox3.Text+'''';
end;

procedure TForm3.DBLookupComboBox4Click(Sender: TObject);
begin
memo1.Text:=memo1.Text+''''+dblookupcombobox4.Text+'''';
end;
procedure TForm3.BitBtn2Click(Sender: TObject);
begin
memo1.Text:='';
memo2.Text:='';
combobox1.Text:='';
combobox2.Text:='';
end;

end.

...全文
14 15 点赞 打赏 收藏 举报
写回复
15 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cow8063 2003-06-27
逻辑符加个LIKE,edit 中由它输入_ OR % +值
  • 打赏
  • 举报
回复
yzykjh 2003-06-27
query1.close;
query1.SQL.Add(' where '+memo1.Text); //不错才怪
query1.Open;
  • 打赏
  • 举报
回复
ququ621 2003-06-27
源码如下unit Unit5;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, Buttons, Grids, DBGrids, DB, ADODB, ComCtrls,
ExtCtrls, DBTables;

type
TForm5 = class(TForm)
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Label2: TLabel;
Label4: TLabel;
Edit1: TEdit;
SpeedButton1: TSpeedButton;
Label1: TLabel;
StatusBar1: TStatusBar;
Label3: TLabel;
Image3: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
BitBtn9: TBitBtn;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Label5: TLabel;
Edit2: TEdit;
Query1: TQuery;

procedure SpeedButton1Click(Sender: TObject);
procedure Label3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);


private
{ Private declarations }
public
{ Public declarations }
end;

var
Form5: TForm5;

implementation

uses Unit2;

{$R *.dfm}





procedure TForm5.SpeedButton1Click(Sender: TObject);
var

s,s1,s2,s3:string;
begin
s1:=combobox1.Text;
s2:=combobox2.Text;
s3:=edit1.Text;
edit2.Text:=s1+s2+s3;
if s1='' then
begin
showmessage('请选择查询方式!');
end
else
begin
if s2='' then
begin
showmessage('请选择运算符!');
end
else
begin
if s3='' then
begin
showmessage('请输入查询值!');
end
else
begin
s:='select * from TABLE1 where '+s1+s2+''''+s3+'''';
query1.Close;
query1.SQL.Clear;
query1.SQL.Add(s);
query1.Open;
if query1.RecordCount=0 then
showmessage('没有符合条件的记录!');
end;
end;
end;
end;

procedure TForm5.Label3Click(Sender: TObject);
begin
form2.show;form5.hide;
end;

procedure TForm5.FormCreate(Sender: TObject);
begin

end;

end.

procedure TForm5.Label3Click(Sender: TObject);
begin
form2.show;form5.hide;
end;

procedure TForm5.BitBtn1Click(Sender: TObject);
begin
ADOTABLE1.First;
end;

procedure TForm5.BitBtn2Click(Sender: TObject);
begin
ADOTABLE1.Next;
end;

procedure TForm5.BitBtn4Click(Sender: TObject);
begin
ADOTABLE1.Last;
end;

procedure TForm5.BitBtn3Click(Sender: TObject);
begin
ADOTABLE1.Prior;
end;

procedure TForm5.BitBtn5Click(Sender: TObject);
begin
Adotable1.Insert;
end;

procedure TForm5.BitBtn6Click(Sender: TObject);
begin
Adotable1.Cancel;
end;

procedure TForm5.BitBtn7Click(Sender: TObject);
begin
Adotable1.Post;
end;

procedure TForm5.BitBtn8Click(Sender: TObject);
begin
adotable1.Delete;
end;

procedure TForm5.BitBtn9Click(Sender: TObject);
begin
adotable1.Edit;
end;

end.
  • 打赏
  • 举报
回复
ququ621 2003-06-27
我还有一个问题:就是我还有一个页面做查询的用到一个QUERY 和 DBGUID用了2个COMBOBOX,一个用来选查找方式。一个用来选逻辑符。两个EDIT,1个用来输入查询值,另一个用来显示选好的组合如名字=某某
我已经做好了
如果想增加一个模糊查询的功能要怎么设计
  • 打赏
  • 举报
回复
ququ621 2003-06-27
对了对了
多谢大家
我真的急死了
想明白了其实是该这样的
我爱你们
  • 打赏
  • 举报
回复
yujiabian 2003-06-27
解决了就好……呵呵
  • 打赏
  • 举报
回复
mrfanghansheng 2003-06-27
解决了就好……呵呵
  • 打赏
  • 举报
回复
ququ621 2003-06-27
我爱你!
  • 打赏
  • 举报
回复
cow8063 2003-06-27
clear,
select...........
memo1.text看看对不对
  • 打赏
  • 举报
回复
ququ621 2003-06-27
木鱼:真的可以了诶
  • 打赏
  • 举报
回复
ququ621 2003-06-27
SELECT 什么呢
  • 打赏
  • 举报
回复
mrfanghansheng 2003-06-27
感觉是下面这个出了问题

query1.close;
query1.SQL.Add(' where '+memo1.Text);
query1.Open;
if query1.RecordCount=0 then
……

估计你有一部份sql语句是写在query中,而使用动态赋where子句
这样造成你第二次打开query时语法错误!

解决方式:建议将整个sql语句都动态赋值
如:query1.close;
query1.clear;
query1.SQL.Add('select ...... where '+memo1.Text);
query1.Open;
if query1.RecordCount=0 then

  • 打赏
  • 举报
回复
sz1008 2003-06-27
query1.close;
query1.SQL.Add(' where '+memo1.Text);
query1.Open;

Query1.SQL先清空再赋值
  • 打赏
  • 举报
回复
ququ621 2003-06-27
加哪里?
要实现统计功能啊
  • 打赏
  • 举报
回复
lovelymelon 2003-06-27
procedure TForm3.BitBtn1Click(Sender: TObject);

var
sum1:real;
s,s1,s2,s3:string;
bookmark1:tbookmark;
begin
if memo1.Text='' then
begin
Application.MessageBox('请输入查询条件!','提醒',Mb_Ok+Mb_iconwarning);
end
else
begin
sum1:=0;
s1:=combobox1.Text;
s2:=combobox2.Text;
s3:=dblookupcombobox1.Text+dblookupcombobox2.Text+dblookupcombobox3.Text+dblookupcombobox4.Text;
bookmark1:=query1.GetBookmark;
query1.close;
query1.SQL.Add(' where '+memo1.Text);———————————————这样就可以了吗?是不是前面应该加点query1.SQL.Add('select * from tablename')
query1.Open;
if query1.RecordCount=0 then
begin
Application.MessageBox('没有符合条件的记录!','信息',Mb_Ok+Mb_IconInformation);
end
else
begin
query1.DisableControls;
query1.First;
while not query1.Eof do
begin
sum1:=sum1+query1.FieldValues['应缴'];
query1.Next;
end;
query1.GotoBookmark(bookmark1);
query1.FreeBookmark(bookmark1);
end;
str(sum1:8:2,s);
memo2.Text:='符合条件的学生共缴费'+s+'元';
end;
end;
  • 打赏
  • 举报
回复
相关推荐
发帖
数据库相关
创建于2007-08-02

2456

社区成员

Delphi 数据库相关
申请成为版主
帖子事件
创建了帖子
2003-06-27 05:54
社区公告
暂无公告