?? studentinfoform.~pas
字號:
unit StudentInfoForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ParentForm, ADODB, DB, ImgList, Grids, DBGrids, ComCtrls,
ToolWin, StdCtrls, Buttons, ExtCtrls, DBCtrls, Mask;
type
TStudentInfo = class(TParent)
Label9: TLabel;
Label8: TLabel;
Label7: TLabel;
Label6: TLabel;
Label15: TLabel;
Label14: TLabel;
Label13: TLabel;
Label12: TLabel;
Label11: TLabel;
Label10: TLabel;
DBEdit4: TDBEdit;
DBEdit2: TDBEdit;
DBEdit1: TDBEdit;
DBComboBox1: TDBComboBox;
DBEdit3: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
DBEdit7: TDBEdit;
DBEdit8: TDBEdit;
DBEdit9: TDBEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
procedure DataSource1DataChange(Sender: TObject; Field: TField);
procedure FormShow(Sender: TObject);
procedure ComboBox1Select(Sender: TObject);
procedure ComboBox2Select(Sender: TObject);
procedure ComboBox3Select(Sender: TObject);
procedure ComboBox4Select(Sender: TObject);
procedure ComboBox5Select(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure setlist(fieldname,tablename:string;combo:Tcombobox);
end;
var
StudentInfo: TStudentInfo;
implementation
{$R *.dfm}
//-------------根據學生信息表中的編號,顯示編號所對應的信息 -------------
procedure TStudentInfo.DataSource1DataChange(Sender: TObject;
Field: TField);
begin
inherited;
//根據數據表中的班級編號,顯示班級名稱
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 班級名稱 from 班級信息 where 班級編號='''+dbedit5.Text+'''');
adoquery1.Open;
combobox1.Text:=trim(adoquery1.fieldbyname('班級名稱').AsString);
//根顯示政治面貌
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 政治面貌 from 政治面貌代碼表 where 政治面貌編號='''+dbedit6.Text+'''');
adoquery1.Open;
combobox2.Text:=trim(adoquery1.fieldbyname('政治面貌').AsString);
//顯示民族
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 民族 from 民族代碼表 where 民族編號='''+dbedit7.Text+'''');
adoquery1.Open;
combobox3.Text:=trim(adoquery1.fieldbyname('民族').AsString);
//顯示籍貫
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 籍貫 from 籍貫代碼表 where 籍貫編號='''+dbedit8.Text+'''');
adoquery1.Open;
combobox4.Text:=trim(adoquery1.fieldbyname('籍貫').AsString);
//顯示學籍
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 學籍名稱 from 學籍代碼表 where 學籍編號='''+dbedit9.Text+'''');
adoquery1.Open;
combobox5.Text:=trim(adoquery1.fieldbyname('學籍名稱').AsString);
end;
//--------------根據輸入查詢字段,并設置制定下拉列表框的下拉選項-------------------
procedure TStudentInfo.setlist(fieldname,tablename: string; combo: Tcombobox);
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select distinct '+fieldname+' from '+tablename);
adoquery1.Open;
combo.Items.Clear;
while not adoquery1.Eof do
begin
combo.Items.Add(trim(adoquery1.fieldbyname(fieldname).AsString));
adoquery1.Next;
end;
end;
//-----窗體顯示時,設置各個下拉列表的下拉詞典----------
procedure TStudentInfo.FormShow(Sender: TObject);
begin
inherited;
setlist('班級名稱','班級信息',combobox1);
setlist('政治面貌','政治面貌代碼表',combobox2);
setlist('民族','民族代碼表',combobox3);
setlist('籍貫','籍貫代碼表',combobox4);
setlist('學籍名稱','學籍代碼表',combobox5);
end;
//---------以下5個函數都是根據選擇的字段名稱修改數據表中的對應編號-----------
procedure TStudentInfo.ComboBox1Select(Sender: TObject);
begin
inherited;
//根據選擇的班級名稱,修改班級編號
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 班級編號 from 班級信息 where 班級名稱='''+combobox1.Text+'''');
adoquery1.Open;
dbedit5.Text:=trim(adoquery1.fieldbyname('班級編號').AsString);
end;
procedure TStudentInfo.ComboBox2Select(Sender: TObject);
begin
inherited;
//根據選擇的政治面貌名稱,修改政治面貌名稱
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 政治面貌編號 from 政治面貌代碼表 where 政治面貌='''+combobox2.Text+'''');
adoquery1.Open;
dbedit6.Text:=trim(adoquery1.fieldbyname('政治面貌編號').AsString);
end;
procedure TStudentInfo.ComboBox3Select(Sender: TObject);
begin
inherited;
//根據選擇的民族名稱,修改民族編號
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 民族編號 from 民族代碼表 where 民族='''+combobox3.Text+'''');
adoquery1.Open;
dbedit7.Text:=trim(adoquery1.fieldbyname('民族編號').AsString);
end;
procedure TStudentInfo.ComboBox4Select(Sender: TObject);
begin
inherited;
//根據選擇的籍貫名稱,修改籍貫編號
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 籍貫編號 from 籍貫代碼表 where 籍貫='''+combobox4.Text+'''');
adoquery1.Open;
dbedit8.Text:=trim(adoquery1.fieldbyname('籍貫編號').AsString);
end;
procedure TStudentInfo.ComboBox5Select(Sender: TObject);
begin
inherited;
//根據選擇的學籍名稱,修改學籍編號
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 學籍編號 from 學籍代碼表 where 學籍名稱='''+combobox5.Text+'''');
adoquery1.Open;
dbedit9.Text:=trim(adoquery1.fieldbyname('學籍編號').AsString);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -