?? studentinfounit.pas
字號:
unit StudentInfoUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, ExtCtrls, StdCtrls;
type
TStudentInfoForm = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOQuery1: TADOQuery;
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Button2: TButton;
Label2: TLabel;
Edit2: TEdit;
Button3: TButton;
ADOQuery2: TADOQuery;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
StudentInfoForm: TStudentInfoForm;
ssno:string; //全局變量,學號,用于判斷是否重復
implementation
uses Unit1, AddStudentUnit, EditStudentUnit;
{$R *.dfm}
procedure TStudentInfoForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
application.Terminate;
end;
procedure TStudentInfoForm.FormCreate(Sender: TObject);
begin
ADOQuery1.close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select sno,sname,sage,idno,dept from student order by sno');
ADOQuery1.open;
end;
procedure TStudentInfoForm.Button1Click(Sender: TObject);
begin
Application.CreateForm(TAddStudentForm, AddStudentForm);
AddStudentForm.show;
end;
procedure TStudentInfoForm.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then Button2Click(Sender);
end;
procedure TStudentInfoForm.Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then Button3Click(Sender);
end;
procedure TStudentInfoForm.Button3Click(Sender: TObject);
begin
if Edit2.Text='' then messagedlg(#10'請輸入要刪除的課號',mtwarning,[mbOk],0)
else begin
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('select * from student where sno=:Psno') ;
ADOQuery2.Parameters.ParamByName('Psno').value:= Edit2.text;
ADOQuery2.open;
if ADOQuery2.Eof then messagedlg(#10'沒有該學生信息,請確認學號!', mtwarning,[mbOk],0)
else begin
if messagedlg(#10'是否刪除該學生信息?', mtConfirmation,[mbYes,mbNo],0)=mrYes then
begin
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('delete * from student where sno=:Psno') ;
ADOQuery2.Parameters.ParamByName('Psno').value:= Edit2.text;
ADOQuery2.ExecSQL;
FormCreate(Sender);
Edit2.Clear;
end;
end;
end;
end;
procedure TStudentInfoForm.Button2Click(Sender: TObject);
begin
if Edit1.Text='' then messagedlg(#10'請輸入要修改的學生學號',mtwarning,[mbOk],0)
else begin
Application.CreateForm(TEditStudentForm, EditStudentForm);
EditStudentForm.ADOQuery1.Close;
EditStudentForm.ADOQuery1.SQL.Clear;
EditStudentForm.ADOQuery1.SQL.Add('select sno,sname,sage,idno,dept from student where sno=:Psno') ;
EditStudentForm.ADOQuery1.Parameters.ParamByName('Psno').value:= Edit1.text;
ssno:=Edit1.text;
EditStudentForm.ADOQuery1.open;
if EditStudentForm.ADOQuery1.Eof then messagedlg(#10'無該學生信息,請確認學號!', mtwarning,[mbOk],0)
else EditStudentForm.show;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -