📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, frxClass, frxDBSet, DB, DBTables, AppEvnts, Grids,StrUtils,
DBGrids, Buttons, ADODB;
type
TForm1 = class(TForm)
Database1: TDatabase;
ApplicationEvents1: TApplicationEvents;
DataSource1: TDataSource;
Query1: TQuery;
Query2: TQuery;
Query3: TQuery;
Query4: TQuery;
frxDBDataset1: TfrxDBDataset;
Query5: TQuery;
frxDBDataset2: TfrxDBDataset;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
DBGrid1: TDBGrid;
frxReport1: TfrxReport;
frxReport2: TfrxReport;
ComboBox4: TComboBox;
Label4: TLabel;
CheckBox1: TCheckBox;
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox3Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure DBGrid1ColExit(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure FormCreate(Sender: TObject);
procedure frxReport1GetValue(const VarName: String;
var Value: Variant);
procedure frxReport2GetValue(const VarName: String;
var Value: Variant);
procedure ComboBox4Change(Sender: TObject);
private
{ Private declarations }
public
testno:string;
subject:string;
zonghe:integer;//用于记录是否为综合科,若为综合科,其值为1
classname:string;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//form1.Top :=0;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
var
//subject:string; 已经被定义为全局变量
i,testcount:integer;
begin
if directoryexists('d:\besteasy\data') then
begin
//ShowMessage('该文件夹存在!');
database1.Close;
database1.Params.Values['value']:='d:\besteasy\data';
database1.Open;
end
else
begin
if directoryexists('d:\data') then
begin
//ShowMessage('该文件夹存在!');
database1.Close;
database1.Params.Values['value']:='d:\data';
database1.Open;
end
else
begin
application.MessageBox('您要访问的数据不存在!','系统提示',mb_OK+mb_iconinformation);
exit;
end;
end;
query4.Close;
label4.Visible:=false; //先隐藏综合科的分科列表
combobox4.Visible:=false;
if combobox1.Text<>'科目列表' then
combobox2.Text:='考试列表';
combobox3.Text:='班级列表';
combobox4.Text:='分科列表';
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select subno from tb_subject_info where subname='''+combobox1.Text+'''');
query1.Open;
if query1.Fields[0].Value<10 then //表示不是文综10或理综11
begin
zonghe:=0;
subject:=midstr(query1.Fields[0].Value,2,1);//MidStr所属单元在StrUtils中,因此我们将StrUtils添加Uses中即可
end
else
begin
subject:=query1.Fields[0].Value; //也代表用户名
zonghe:=1; //表示所选的为综合科目
end;
query2.Close;
query2.SQL.Clear; //取得该科的所有考试名称
query2.SQL.Add('select testname from tb_test_info where userno='''+subject+'''');
query2.Open;
testcount:=query2.RecordCount;
query2.First;
combobox2.Items.Clear;
combobox3.Items.Clear;
for i:=1 to testcount do //添加考试名称下拉列表
begin
combobox2.Items.Add(query2.Fields[0].value);
query2.Next;
end;
combobox4.Text:='分科列表';
if combobox1.Text='文综' then
begin
label4.Visible:=true;
combobox4.Visible:=true;
combobox4.Items.Clear;
combobox4.Items.Add('政治');
combobox4.Items.Add('历史');
combobox4.Items.Add('地理');
end;
if combobox1.Text='理综' then
begin
label4.Visible:=true;
combobox4.Visible:=true;
combobox4.Items.Clear;
combobox4.Items.Add('物理');
combobox4.Items.Add('化学');
combobox4.Items.Add('生物');
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
var
//testno:string; 已经被定义为全局变量
i,classcount:integer;
begin
if (combobox2.Text<>'考试列表') then
begin
combobox3.Text:='班级列表';
combobox4.Text:='分科列表';
query2.Close;
query2.SQL.Clear;
query2.SQL.Add('select testno from tb_test_info where testname='''+combobox2.Text+''' and userno='''+subject+'''');
query2.Open;
testno:=query2.Fields[0].Value;
query2.Close;
query2.SQL.Clear;
query2.SQL.Add('select classno from tb_test_class where testno='''+testno+'''');
query2.Open;
classcount:=query2.RecordCount;
query2.First;
combobox3.Items.Clear;
for i:=1 to classcount do
begin
query3.Close;
query3.SQL.Clear;
query3.SQL.Add('select classname from tb_class_info where classno='''+query2.Fields[0].Value+'''');
query3.Open;
combobox3.Items.Add(query3.Fields[0].value);
query2.Next;
end;
end;
end;
procedure TForm1.ComboBox3Change(Sender: TObject);
begin
if combobox3.Text<>'班级列表' then
begin
combobox4.Text:='总分';
query4.Close;
query4.SQL.Clear;
query4.SQL.Add('select classname as 班别,studentno as 考号,studentname as 姓名,sum_value0 as 分数 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' order by studentno');
query4.Open;
query5.Close;
query5.SQL.Clear;
query5.SQL.Add('select avg(sum_value0) as 平均分 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' and sum_value0<>0');
query5.Open;
end;
end;
procedure TForm1.ComboBox4Change(Sender: TObject);
begin
if (combobox4.Text='政治') or (combobox4.Text='物理') then // sum_value3为政治或物理
begin
query4.Close;
query4.SQL.Clear;
query4.SQL.Add('select classname as 班别,studentno as 考号,studentname as 姓名,sum_value3 as 分数 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' order by studentno');
query4.Open;
query5.Close;
query5.SQL.Clear;
query5.SQL.Add('select avg(sum_value3) as 平均分 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' and sum_value3<>0');
query5.Open;
end;
if (combobox4.Text='历史') or (combobox4.Text='化学') then
begin
query4.Close;
query4.SQL.Clear;
query4.SQL.Add('select classname as 班别,studentno as 考号,studentname as 姓名,sum_value2 as 分数 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' order by studentno');
query4.Open;
query5.Close;
query5.SQL.Clear;
query5.SQL.Add('select avg(sum_value2) as 平均分 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' and sum_value2<>0');
query5.Open;
end;
if (combobox4.Text='地理') or (combobox4.Text='生物') then
begin
query4.Close;
query4.SQL.Clear;
query4.SQL.Add('select classname as 班别,studentno as 考号,studentname as 姓名,sum_value1 as 分数 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' order by studentno');
query4.Open;
query5.Close;
query5.SQL.Clear;
query5.SQL.Add('select avg(sum_value1) as 平均分 from tb_test_stu_detail where testno='''+testno+''' and classname='''+combobox3.text+''' and sum_value1<>0');
query5.Open;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -