📄 unit4.pas
字号:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB,unit1;
type
TForm4 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
ADOQuery1: TADOQuery;
Label3: TLabel;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
procedure ComboboxList;
implementation
uses Unit2;
{$R *.dfm}
procedure ComboboxList;
begin
form4.adoquery1.Close;
form4.adoquery1.SQL.Clear;
form4.adoquery1.SQL.Add('select distinct 系部编号,系部名称 from 系部班级');
form4.adoquery1.Open;
form4.ComboBox1.Items.Clear;
form4.adoquery1.First;
while not form4.adoquery1.Eof do
begin
//将系部编号和系部名称添加到组合框中
form4.ComboBox1.Items.Add(form4.adoquery1.Fieldbyname('系部编号').value
+'/'+form4.adoquery1.Fieldbyname('系部名称').value);
form4.adoquery1.Next;
end;
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
form4.Close ;
end;
procedure TForm4.FormActivate(Sender: TObject);
begin
ComboboxList;
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
combobox1.Text:='';
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm4.Button3Click(Sender: TObject);
begin
if (combobox1.Text='')or(edit1.Text='')or(edit2.Text='') then
begin
application.MessageBox('信息不完整!','提示',mb_ok);
exit;
end
else
adoquery1.close;
adoquery1.sql.clear;
try
Adoquery1.sql.add('insert into 班级表 (班级编号,系部编号,班级名称)'
+'values (:bjbh,:xbbh,:bjmc)');
Adoquery1.Parameters.ParamByName('bjbh').Value:=''+edit1.text+'';
Adoquery1.Parameters.ParamByName('xbbh').Value:=''+copy(combobox1.text,0,2)+'';
Adoquery1.Parameters.ParamByName('bjmc').Value:=''+edit2.Text+'';
Adoquery1.ExecSQL;
TreeViewShow;
application.MessageBox('数据已录入!','提示',mb_ok);
except
on E: Exception do
messagedlg(E.Message,mterror,[mbok],0);
end;
edit1.Text:='';
edit2.Text:='';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -