




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
浙江大學(xué)遠(yuǎn)程教育學(xué)院
《數(shù)據(jù)庫(kù)應(yīng)用程序設(shè)計(jì)》課程作業(yè)
姓名:學(xué)號(hào):
年級(jí):2016年春學(xué)習(xí)中心:
作業(yè)
第一早
1.5如何保存Delphi的項(xiàng)目?嘗試自己動(dòng)手創(chuàng)建一個(gè)項(xiàng)目,并保存。
答:執(zhí)行File|SaveAll菜單命令或單擊工具欄中的SaveAll按鈕便可保存,在保存時(shí)可以對(duì)
工程文件和單元文件進(jìn)行改名,但后綴名不能改。保存文件之后,單擊工具中的Run按鈕
或按F9鍵,系統(tǒng)將開(kāi)始編譯、連接、運(yùn)行該工程。
3-包含5W中-共享-新猛文件55
*姬
匕收朝名的修改日期大小
*T?1QPrqjectLcfg第16/3/2919而一CFG文件1KB
■直苴LProjectl.dof2016/3/29""DOFXS2KB
工最正訪問(wèn)的位置,Projectl.dpr2016/3/291905DelphiProject1KB
OPrqjectl.res2016/3/2913RESFSe1KB
>testdfm2016/3/2919:04DelphiForm1KB
三層
tftestpas2016/3/2919XMDelphiSourceFile1K8
8陋
?8B片
1.7嘗試設(shè)計(jì)如圖1—10所示的窗體。(圖見(jiàn)教材P15頁(yè)圖1—10)
圖1-10
答:設(shè)計(jì)界面:
運(yùn)行界面:
第二章
2.8設(shè)計(jì)如圖2—5所示的界面。單擊"按鈕1"或"按鈕2"時(shí)在標(biāo)簽上顯示用戶所執(zhí)行的操作。
單擊"開(kāi)啟/停用按鈕"可控制"按鈕r和"按鈕2"是否可用,單擊"退出系統(tǒng)”按鈕時(shí),結(jié)束程
序的運(yùn)行。
運(yùn)行界面:
代碼:
unittest;
interface
uses
Windows,Messages,Syslltils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
showLabel:TLabel;
btnl:TButton;〃按鈕1
btn2:TButton;〃按鈕2
ctlBtn:TButton;〃開(kāi)啟停用按鈕
exitBtn:TButton;〃退出按鈕
procedurebtnlClick(Sender:TObject);
procedurebtn2Click(Sender:TObject);
procedureexitBtnClick(Sender:TObject);
procedurectlBtnClick(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
ctlStatus:integer=0;〃控制按鈕1和2的開(kāi)啟和關(guān)閉,0表示當(dāng)前為開(kāi)啟,1表示關(guān)閉
implementation
{$R*.dfm)
procedureTForml.btnlClick(Sender:TObject);
begin
forml.showLabel.Caption:=,您點(diǎn)擊了按鈕I1;
end;
procedureTForml.btn2Click(Sender:TObject);
begin
forml.showLabel.Caption:='您點(diǎn)擊了按鈕2';
end;
procedureTForml.exitBtnClick(Sender:TObject);
begin
forml.Close;
end;
procedureTForml.ctlBtnClick(Sender:TObject);
begin
ifctlStatus=0then
begin
forml.btnl.Enabled:=false;
forml.btn2.Enabled:=false;
ctlStatus:=1;
end
else
begin
forml.btnl.Enabled:=true;
forml.btn2.Enabled:=true;
ctlStatus:=0;
end;
end;
end.
2.9設(shè)計(jì)如圖2—6所示的界面。當(dāng)單擊按鈕時(shí),可控制文本框中字體的顏色。
答:設(shè)計(jì)界面:
運(yùn)行界面:
代碼:(按鈕快捷鍵的設(shè)置方法為在字母前加&,如&R,&G,&B)
unittest;
interface
uses
Windows,Messages,Syslltils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
Labell:TLabel;
Editl:TEdit;
btnRed:TButton;
btnGreen:TButton;
btnBlue:TButton;
procedurebtnRedClick(Sender:TObject);
procedurebtnGreenClick(Sender:TObject);
procedurebtnBlueClick(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
implementation
{$R*.dfm}
procedureTForml.btnRedClick(Sender:TObject);
begin
forml.Editl.Font.Color:=clred;
end;
procedureTForml.btnGreenClick(Sender:TObject);
begin
forml.Editl.Font.Color:=clgreen;
end;
procedureTForml.btnBlueClick(Sender:TObject);
begin
forml.Editl.Font.Color:=clblue;
end;
end.
第二早
3.8下列實(shí)數(shù)中哪些是合法的,哪些是不合法的?不合法的請(qǐng)說(shuō)明理由。
(A)0.25E+02(B).25+2(C)25E+2
(D)34.5(E).123(F)-3E-4
答:(A)合法,即為25
(B)不合法,小數(shù)點(diǎn)前必須有數(shù)字,如表示為0.25+2
(C)合法,即為2500
(D)合法,即為34.5
(E)不合法,同(2)
(F)合法,即為-0.0003
3.12數(shù)學(xué)式子sin30寫(xiě)成Delphi表達(dá)式是下列哪個(gè)?
(A)Sin30(B)Sin(30)(C)SIN(30)(D)Sin(30*Pi/180)
答:D,需要把角度轉(zhuǎn)化為弧度
第四章
4.7利用3個(gè)數(shù)字編輯框分別輸入小時(shí)、分、秒,換算共有多少秒,然后使用標(biāo)簽輸出。
答:設(shè)計(jì)界面:
運(yùn)行界面:
代碼:
unittest;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls,Spin;
type
TForml=class(TForm)
SpinEditl:TSpinEdit;
Labell:TLabel;
Label2:TLabel;
SpinEdit2:TSpinEdit;
Label3:TLabel;
SpinEdit3:TSpinEdit;
Label4:TLabel;
procedureSpinEditlChange(Sender:TObject);
procedureSpinEdit2Change(Sender:TObject);
procedureSpinEdit3Change(Sender:TObject);
private
{Privatedeclarations}
procedureCalculateTimeToSencond(timeKind:String;timerinteger);
public
{Publicdeclarations}
end;
var
Forml:TForml;
hour:integer=0;
minute:integer=0;
second:integer=0;
tot:integer=0;
implementation
{$R*.dfm}
procedureTForml.CalculateTimeToSencond(timeKind:String;time:integer);
begin
iftimeKind='hh'then
hour:=time
elseiftimeKind='mi'then
minute:=time
elseiftimeKind='ss'then
second:=time;
tot:=hour*60*60+minute*60+second;
forml.Label4.Caption:='總共為'+IntToStr(tot)+,秒';
end;
procedureTForml.SpinEditlChange(Sender:TObject);
begin
Forml.CalculateTimeToSencond('hh',StrTolnt(Forml.SpinEditl.Text));
end;
procedureTForml.SpinEdit2Change(Sender:TObject);
begin
Forml.CalculateTimeToSencondCmi',StrTolnt(Forml.SpinEdit2.Text));
end;
procedureTForml.SpinEdit3Change(Sender:TObject);
begin
ForrnKalculateTimeToSencondCss',StrTolnt(Forml.SpinEdit3.Text));
end;
end.
4.8在編輯框中輸入一個(gè)實(shí)數(shù),利用備注框輸出該實(shí)數(shù)及其平方和平方根。
答:設(shè)計(jì)界面:
代碼:
unitUnitl;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
Editl:TEdit;
Labell:TLabel;
Memol:TMemo;
Label2:TLabel;
procedureEditlChange(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
numl:Real;〃原實(shí)數(shù)
num2:Real;〃實(shí)數(shù)平方
num3:Real;〃實(shí)數(shù)平方根
implementation
{$R*.dfm}
procedureTForml.EditlChange(Sender:TObject);
begin
ifforml.Editl.Text<>*'then
begin
numl:=StrToFloat(forml.Editl.Text);
num2:=Sqr(numl);
num3:=Sqrt(numl);
forml.Memol.Lines.Clear;
forml.Memol.Lines.Add('實(shí)數(shù)為:'+FloatToStr(numl));
formLMemol.Lines.AddC平方為:'+FloatToStr(num2));
forml.Memol.Lines.Add('平方根為:'+FloatToStr(num3));
end;
end;
end.
第五章
5.11任意給定3個(gè)實(shí)數(shù),按照從大到小的順序依次輸出這3個(gè)數(shù)。
答:設(shè)計(jì)界面:
運(yùn)行界面:
代碼:
unitUnitl;
interface
uses
Windows,Messages,Syslltils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
numlEdit:TEdit;
Labell:TLabel;
Label2:TLabel;
resultLabel:TLabel;
num2Edit:TEdit;
num3Edit:TEdit;
procedurenumlEditChange(Sender:TObject);
procedurenum2EditChange(Sender:TObject);
procedurenum3EditChange(Sender:TObject);
private
{Privatedeclarations}
procedureCompareNumber();
public
{Publicdeclarations}
end;
var
Forml:TForml;
numl:Real;〃數(shù)字1
num2:Real;〃數(shù)字2
num3:Real;〃數(shù)字3
compnum:Real;〃比較時(shí)轉(zhuǎn)換2數(shù)
outStr:String;〃輸出結(jié)果;
implementation
{$R*.dfm}
procedureTForml.CompareNumber();
begin
if(trim(forml.numlEdit.Text)<>")And(trim(forml.num2Edit.Text)<>")And
(trim(forml.num3Edit.Text)<>")then
begin
numl:=StrToFloat(forml.numlEdit.Text);
num2:=StrToFloat(forml.num2Edit.Text);
num3:=StrToFloat(forml.num3Edit.Text);
ifnum2>numlthen
begin
compnum:=numl;
numl:=num2;
num2:=compnum;
end;
ifnum3>numlthen
begin
compnum:=numl;
numl:=num3;
num3:=compnum;
end;
ifnum3>num2then
begin
compnum:=num2;
num2:=num3;
num3:=compnum;
end;
outStr:=FloatToStr(numl)+'/+FloatToStr(num2)++FloatToStr(num3);
forml.resultLabel.Caption:=outStr;
end;
end;
procedureTForml.numlEditChange(Sender:TObject);
begin
forml.CompareNumber;
end;
procedureTForml.num2EditChange(Sender:TObject);
begin
forml.CompareNumber;
end;
procedureTForml.num3EditChange(Sender:TObject);
begin
forml.CompareNumber;
end;
end.
5.13假設(shè)工資的增幅標(biāo)準(zhǔn)為:若基本工資大于等于1000元,增加工資20%;若小于1000
元大于等于800元,則增加工資15%;若小于800元,則增加工資10%。請(qǐng)根據(jù)用戶在文本
框中輸入的基本工資,計(jì)算出增加后的工資。
Label2:TLabel;
resultLabel:TLabel;
procedureEditlChange(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
salary:Real;
outSalary:Real;
implementation
{$R*.dfm}
procedureTForml.EditlChange(Sender:TObject);
begin
salary:=StrToFloat(forml.Editl.Text);
if(salary>=1000)then
outSalary:=salary*(1+0.2)
elseif(salary<1000)And(salary>=800)then
outSalary:=salary*(1+0.15)
elseif(salary<800)then
outSalary:=salary*(1+0.1);
forml.resultLabel.Caption:=FloatToStr(outSalary);
end;
end.
第六章
6.5設(shè)s=lX2X3X…Xn,求s不大于20000時(shí)最大的n。
答:設(shè)計(jì)界面:
運(yùn)行界面:
代碼:
unitUnitl;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
Labell:TLabel;
Editl:TEdit;
Label2:TLabel;
resultLabel:TLabel;
procedureFormCreate(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
number;n,tot:Integer;
implementation
{$R*.dfm}
procedureTForml.FormCreate(Sender:TObject);
begin
tot:=1;n:=0;
number:=StrTolnt(forml.Editl.Text);
Whiletot<=numberdo
begin
n:=n+1;
tot:=tot*n;
end;
forml.resultLabel.Caption:=IntToStr(n-l);
end;
end.
6.10在標(biāo)簽上輸出100~200之間的所有的奇數(shù),其中3的倍數(shù)除外。
答:設(shè)計(jì)界面:
運(yùn)行界面:
3r先出令我
101103107109113115119121125127131133137139143451491511551571611631G71691731751791811851871sl133197199
代碼:
unitUnitl;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
resultLabel:TLabel;
procedureFormCreate(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
number;i:Integer;
outStr:String;
implementation
{$R*.dfm}
procedureTForml.FormCreate(Sender:TObject);
begin
fori:=100to200do
begin
ifimod2<>0then
ifimod3<>0then
outStr:=outStr+''+IntToStr(i);
forml.resultLabel.Caption:=outStr;
end;
end;
end.
第七章
7.4求l~200這200個(gè)數(shù)的和,當(dāng)和大于10000時(shí)結(jié)束計(jì)算。(要求使用轉(zhuǎn)向語(yǔ)句)
答:設(shè)計(jì)界面:
運(yùn)行界面:
》計(jì)算1-200W和[p1回
總和為10011
代碼:
unitUnitl;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
Labell:TLabel;
procedureFormCreate(Sender:TObject);
private
{Privatedeclarations}
public
{Publicdeclarations}
end;
var
Forml:TForml;
sum,n:integer;
implementation
{$R*.dfm}
procedureTForml.FormCreate(Sender:TObject);
begin
sum:=0;
n:=0;
repeat
n:=n+1;
sum:=sum+n;
if(sum>10000)thenbreak;
untiln>=200;
forml.Labell.Caption:='總和為,+IntToStr(sum);
end;
end.
第八章
8.8編寫(xiě)函數(shù),輸出100~500之間所有能同時(shí)被3和13整除的數(shù)。
答:設(shè)計(jì)界面:
運(yùn)行界面:
代碼:
unitUnitl;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForml=class(TForm)
Labell:TLabel;
procedureFormCreate(Sender:TObject);
private
{Privatedeclarations}
FunctioncheckNum(num:integer):boolean;
public
{Publicdeclarations}
end;
var
Forml:TForml;
implementation
{$R*.dfm}
FunctionTForml.checkNum(num:integer):boolean;
varn:boolean;
begin
if(nummod3=0)And(nummod13=0)then
n:=true
else
n:=false;
result:=n;
end;
procedureTForml.FormCreate(Sender:TObject);
vari:integer;
varout:string;
begin
fori:=100to500do
begin
ifcheckNum(i)then
out:=out+''+IntToStr(i);
end;
forml.Labell.Caption:=out;
end;
end.
第九章
9.2打開(kāi)對(duì)話框組件和打開(kāi)圖片對(duì)話框組件有什么異同點(diǎn)?
答:兩者都會(huì)打開(kāi)一個(gè)對(duì)話框用于選擇電腦本地上的文件
不同的是前者可以選擇全部類型的文件,而后者只可以選擇圖片類型的文件,并且可以
預(yù)覽圖片
第十章
10.7菜單命令項(xiàng)與工具欄按鈕的單擊事件中的代碼是否可以關(guān)聯(lián)?如何關(guān)聯(lián)?
答:將工具欄按鈕ToolButton的Style屬性設(shè)置為tbsDropDown然后在Menuitem屬性中選
擇對(duì)應(yīng)的菜單項(xiàng)即可
第十一章
11.4調(diào)用子窗體的close方法時(shí)是否可關(guān)閉該子窗體?若不能,需要怎么做?
答:調(diào)用close方法只能最小化窗口,如果要真正關(guān)閉,需要調(diào)用free方法
第十二章
12.3使用紅色的畫(huà)筆在窗體中繪制一個(gè)半徑為5的圓,并且用黃色來(lái)填充圓的內(nèi)部。
procedureTForml.FormPaint(Sender:TObject);
varr,x,y:integer;
begin
r:=5;
Canvas.Pen.Color:=clred;
Canvas.Brush.Color:=clyellow;
Canvas.Ellipse(0,0,r*2zr*2);
end;
end.
第十三章
13.3打開(kāi)一個(gè)文本文件有幾種方法?區(qū)別是什么?
答:有3種打開(kāi)文件的方法:
(1)Reset過(guò)程以只讀方式打開(kāi)一個(gè)文件。
(2)Rewrite過(guò)程創(chuàng)建并打開(kāi)文件,對(duì)于一個(gè)己經(jīng)存在的文件,此操作將使文件被覆蓋。
(3)Append過(guò)程以追加方式打開(kāi)文件,并向已經(jīng)存在的文本文件中追加文本。
第十四章
14.4使用DatabaseDeskTop設(shè)計(jì)如表14一5所示的數(shù)據(jù)表,并創(chuàng)建簡(jiǎn)單的應(yīng)用程序完成數(shù)
據(jù)的瀏覽和編輯功能。
表14—5數(shù)據(jù)表字段設(shè)置說(shuō)明
字段名類型長(zhǎng)度說(shuō)明
Id字符型4產(chǎn)品編號(hào)
Name字符型20產(chǎn)品名稱
Price數(shù)值型產(chǎn)品單價(jià)
Count短整型產(chǎn)品庫(kù)存量
答:設(shè)計(jì)界面:
StrurtureInformationParadox7Table:Product.db
FieHrosterTableccopetlies
FieldNameTypeSizeKey|VMyChecks
1IdI4
2Name20
3Pricer1Re^edField
4Count
r
3Maximunvalue.
1
i
5Pcluje:
Savs乩.|Qone|Help
(數(shù)據(jù)庫(kù)設(shè)計(jì))
(界面設(shè)計(jì))
運(yùn)行界面:
14.6使用數(shù)據(jù)庫(kù)軟件(如SqlServer2000)創(chuàng)建如表14-6所示的數(shù)據(jù)表,并開(kāi)發(fā)一個(gè)學(xué)生
檔案管理系統(tǒng),完成學(xué)生基本信息的添加、刪除、修改等。同時(shí),可以按照學(xué)生的學(xué)號(hào)、姓
名等進(jìn)行數(shù)據(jù)的查詢。最后,將學(xué)生的基本信息以報(bào)表的方式輸出。
表14-6數(shù)據(jù)表字段設(shè)置說(shuō)明
字段名類型長(zhǎng)度說(shuō)明
Id字符型8學(xué)號(hào)
Name字符型8姓名
Sex字:符型2性別
Birthday日期型4出生日期
Address字符型50家庭住址
答:⑴使用的數(shù)據(jù)庫(kù)軟件為SqlServer2008,依據(jù)題目設(shè)計(jì)的數(shù)據(jù)表結(jié)構(gòu)為
列名蟻據(jù)類型允許Nul值
IdncharjB)B
Namenchar?)B
Sexnchar⑵回
>Birthdaydate□
Addressnchar(50)回
國(guó)
表名為Students
(2)本系統(tǒng)包含5個(gè)Form,分別為FormMain主界面,FormTable信息錄入查詢界面,FormReport
學(xué)生信息報(bào)表界面,FormHelp系統(tǒng)幫助界面,FormAbout系統(tǒng)關(guān)于界面
(3)各Form詳細(xì)內(nèi)容:
A:FormMain
設(shè)計(jì)界面:
歡迎使用學(xué)生檔案管理系統(tǒng)
Ver1.0.0
副作:翁惠桃
二MainFocm
□Labell
□Label2
□Label3_
B3IM,ainMenul
E檔案管理模塊{N1}
嗎信息錄入/查詢{N2}
>H信息報(bào)表{N4}
退出{N5}
日投■科助{N6}
A*.使用說(shuō)明{N7)
應(yīng)關(guān)于{N8}
運(yùn)行界面:
procedurecloseApp;
public
{Publicdeclarations}
end;
var
MainForm:TMainForm;
implementation
{$R*.dfm}
procedureTMainForm.N8Click(Sender:TObject);
begin
formAbout.Show;
end;
procedureTMainForm.N5Click(Sender:TObject);
begin
closeApp;
end;
procedureTMainForm.N2Click(Sender:TObject);
varchild:TFormTable;
begin
child:=TFormTable.Create(Application);
child.Show;
end;
procedureTMainForm.closeApp;
begin
ifmessagedig('您確定要退出本系統(tǒng)了嗎?,,mtconfirmation,[mbyes,mbnoLO)=mryes
then
Application.Terminate
end;
procedureTMainForm.FormCloseQuery(Sender:TObject;varCanClose:Boolean);
begin
ifmessagedig('您確定要退出本系統(tǒng)了嗎?',mtconfirmation」mbyes,mbnoLO)=mryes
then
CanClose:=true
else
CanClose:=false;
end;
procedureTMainForm.N4Click(Sender:TObject);
varchild:TFormReport;
begin
child:=TFormReport.Create(Application);
child.Show;
end;
procedureTMainForm.N7Click(Sender:TObject);
begin
formHelp.Show;
end;
end.
B:FormTable
設(shè)計(jì)界面:
運(yùn)行界面:
望學(xué)生信息首理系婉
>??JLM?BS'^S叵
?|,|X|Q|⑶當(dāng)前模式:查詢模式
字號(hào):?姓名:?性刖:網(wǎng)—3
出生曰期:12016/4/43
家庭住址:|
學(xué)學(xué)生信息告理系統(tǒng)一
石8售建模塊(Y)幅助(Z)
程案苦理模塊(Y)制助(Z)
代碼:
unitUnitl;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,Grids,DBGrids,DBZADODB,ComCtrls,StdCtrls,ToolWin,ImgList;
type
TFormTable=class(TForm)
ADOConnectionl:TADOConnection;
DataSourcel:TDataSource;
DBGridl:TDBGrid;
ToolBarl:TToolBar;
TBAdd:TToolButton;
Editname:TEdit;
Labell:TLabel;
Label2:TLabel;
Label3:TLabel;
Editaddress:TEdit;
Label4:TLabel;
Editid:TEdit;
Labels:TLabel;
Label6:TLabel;
ComboBoxsex:TComboBox;
DateBirthday:TDateTimePicker;
TBUpdate:TToolButton;
TBDelete:TToolButton;
TBSelect:TToolButton;
TBCommit:TToolButton;
LabelMode:TLabel;
ToolButton6:TToolButton;
Labels:TLabel;
ADOQueryl:TADOQuery;
DataSource2:TDataSource;
ADOTablel:TADOTable;
ImageListl:TlmageList;
procedureTBAddClick(Sender:TObject);
procedureTBUpdateClick(Sender:TObject);
procedureTBDeleteClick(Sender:TObject);
procedureTBSelectClick(Sender:TObject);
procedureFormPaint(Sender:TObject);
procedureTBCommitClick(Sender:TObject);
procedureDBGridlDblClick(Sender:TObject);
private
public
{Publicdeclarations}
end;
var
FormTable:TFormTable;
TBStatus:integer;〃模式類型,0-查詢,1■新增,2-修改,3刪除
SelMode:integer;〃第一次按查詢按鈕進(jìn)入查詢模式再按一次執(zhí)行查詢-2,其他情
況下為-0
implementation
{$R*.dfm}
procedureTFormTable.TBAddClick(Sender:TObject);
varmaxid:integer;
vardate:string;
begin
TBStatus:=1;
Editid.Enabled:=false;
Editname.Enabled:=true;
Comboboxsex.Enabled:=true;
DateBirthday.Enabled:=true;
Editaddress.Enabled:=true;
Editid.Text:=
Editname.Text:=
SelMode:=0;
LabelMode.Caption:='新增模式';
DBGridl.DataSource:=DataSourcel;
date:=FormatDateTimeCyymm',now);
WithFormTable.ADOQueryldo
begin
ADOQueryl.Close;
ADOQueryl.SQL.CIear;
ADOQueryl.SQL.Add('selectmax(substring(ld,6,3))maxidfromStudentswhere
substring(ld/2,4)='+date);
ADOQueryl.Open;
if(ADOQueryl.RecordCount=0)then
Editid.Text:='S'+date+'001'
else
begin
if(ADOQueryl.FieldByName('maxid').Text=")or
(ADOQueryl.FieldByNameCmaxid'J.Text='NULL')then
Editid.Text:='S'+date+'001'
else
begin
maxid:=StrTolntfADOQueryl.FieldByNameCmaxidyText);
maxid:=maxid+1;
Editid.Text:='S'+date+StringOfCharCO',3-length(lntToStr(maxid)))+
IntlbStr(maxid);
end;
end;
end;
end;
procedureTFormTable.TBUpdateClick(Sender:TObject);
begin
TBStatus:=2;
Editid.Enabled:=false;
Editname.Enabled:=true;
Comboboxsex.Enabled:=true;
DateBirthday.Enabled:=true;
Editaddress.Enabled:=true;
Editid.Text:=
Editname.Text:=
SelMode:=0;
LabelMode.Caption:='修改模式';
DBGridl.DataSource:=DataSourcel;
end;
procedureTFormTable.TBDeleteClick(Sender:TObject);
begin
TBStatus:=3;
Editid.Enabled:=false;
Editname.Enabled:=false;
Comboboxsex.Enabled:=false;
DateBirthday.Enabled:=false;
Editaddress.Enabled:=false;
Editid.Text:=
Editname.Text:=
SelMode:=0;
LabelMode.Caption:='刪除模式';
DBGridl.DataSource:=DataSourcel;
end;
procedureTFormTable.TBSelectClick(Sender:TObject);
varid,ename,address:string;
begin
ifSelMode=0then
begin
TBStatus:=0;
Editid.Enabled:=true;
Editname.Enabled:=true;
Comboboxsex.Enabled:=true;
DateBirthday.Enabled:=true;
Editaddress.Enabled:=true;
Editid.Text:=
Editname.Text:=
SelMode:=1;
LabelMode.Caption:='查詢模式';
DBGridl.DataSource:=DataSource2;
end
elseifSelMode=1then
begin
ifEditid.Text="then
id:='null'
else
id:=""+Editid.Text+"";
ifEditname.Text="then
ename:='null'
else
ename:=,",+Editname.Text+,n,;
ifEditaddress.Text=Hthen
address:='null'
else
address:=""+Editaddress.Text+"";
withADOQueryldo
begin
ADOQueryl.Close;
ADOQueryl.SQL.CIear;
ADOQueryl.SQL.Add('selectId,Name,Sex,Birthday,AddressfromStudents'+
,,
'whereId=isnull(+id+'zld)+
,
'andName=isnull(+ename+'zName)'+
'andSex=,+",,+Comboboxsex.Text+""+
'andBirthday=,+H,,+DateToStr(DateBirthday.Date)+""+
1andAddress=isnullC+address+\Address)');
ADOQueryl.Open;
end;
end;
end;
procedureTFormTable.FormPaint(Sender:TObject);
begin
〃默認(rèn)為查詢模式,此模式下學(xué)號(hào)可以輸入,其他模式下不可以輸入
TBStatus:=0;
Editid.Enabled:=true;
Editid.Text:=
SelMode:=1;
DBGridl.DataSource:=DataSource2;
end;
procedureTFormTable.TBCommitClick(Sender:TObject);
begin
〃新增,修改,刪除操作后,執(zhí)行保存動(dòng)作
ifTBStatus=1then
begin
ifmessagedig('您確定要新增止匕筆資米*嗎?',mtconfirmation,[mbyes,mbno],0)=mryes
then
begin
ifEditname.Text="then
begin
ShowMessage('姓名必須輸入!,);
exit;
end;
WithADOQueryldo
begin
ADOQueryl.Close;
ADOQueryl.SQL.CIear;
ADOQueryl.SQL.Add('insertintoStudents(Id,Name,Sex,Birthday,
Address)'+
?Values
(,+,,''+EditidText+'',,+';+',n+Editname.Text+n',+,,,+
,,>++()
"+ComboBoxsex.Text+"+'/'""DateToStrDateBirthday.Date+""+
,,,),)
*/'+"^+Editaddress.Text+"+';
try
ADOQueryl.ExecSQL;
ifADOQueryl.RowsAffected>0then
begin
ADOTablel.Close;
ADOTablel.Open;
ShowMessage('提交成功');
end
else
ShowMessage('提交出現(xiàn)異?!?;
except
ShowMessage('提交出現(xiàn)異常');
end;
end;
end;
end
elseifTBStatus=2then
begin
ifmessagedlgC您確定要修改此筆資料嗎?:mtconfirmation」mbyes,mbno],0)=mryes
then
begin
ifEditname.Text="then
begin
ShowMessage('姓名必須輸入!');
exit;
end;
withADOQueryldo
begin
ADOQueryl.Close;
ADOQueryl.SQL.CIear;
ADOQueryl.SQLAdd('updateStudentssetName=,+""+Editname.Text+""+
7+
'Sex=
'+'>"+Comboboxsex.Text+""+7+
'Birthday=
'+,,"+DateToStr(DateBirthday.Date)+""+';+
'Address=,+""+Editaddress.Text+""+
'whereId='+""+Editid.Text+"");
try
ADOQueryl.ExecSQL;
ifADOQueryl.RowsAffected>0then
begin
ADOTablel.Close;
ADOTablel.Open;
ShowMessage('修改成功');
end
else
ShowMessage('提交出現(xiàn)異常);
except
ShowMessage('提交出現(xiàn)異常力
end;
end;
end;
end
elseifTBStatus=3then
begin
ifmessagedig('您確定要?jiǎng)h除此筆資料嗎?',mtconfirmation」mbyes,mbnoLO)=mryes
then
begin
withADOQueryldo
begin
ADOQueryl.Close;
ADOQueryl.SQL.CIear;
ADOQueryl.SQL.Add('deletefromStudentswhereId='+""+Editid.Text+"");
try
ADOQueryl.ExecSQL
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 關(guān)于孩子撫養(yǎng)權(quán)的離婚合同書(shū)
- 貨物采購(gòu)合同補(bǔ)充協(xié)議
- 設(shè)備銷(xiāo)售與購(gòu)買(mǎi)合同范文
- 車(chē)險(xiǎn)綜合保險(xiǎn)合同示例
- 服務(wù)合同預(yù)付款借款范本
- 歌手簽約演出服務(wù)合同
- 服裝采購(gòu)代理合同
- 大型建筑機(jī)械租賃合同樣本范本
- 城鄉(xiāng)結(jié)合部三方共建項(xiàng)目合同
- 商鋪?zhàn)赓U合同規(guī)范樣本
- 2025年湖南高速鐵路職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)附答案
- 《高鐵乘務(wù)安全管理與應(yīng)急處置(第3版)》全套教學(xué)課件
- 歷年湖北省公務(wù)員筆試真題2024
- 學(xué)校食品安全長(zhǎng)效管理制度
- 2.2 說(shuō)話要算數(shù) 第二課時(shí) 課件2024-2025學(xué)年四年級(jí)下冊(cè)道德與法治 統(tǒng)編版
- 滋補(bǔ)品項(xiàng)目效益評(píng)估報(bào)告
- 提綱作文(解析版)- 2025年天津高考英語(yǔ)熱點(diǎn)題型專項(xiàng)復(fù)習(xí)
- 2025年南京機(jī)電職業(yè)技術(shù)學(xué)院高職單招數(shù)學(xué)歷年(2016-2024)頻考點(diǎn)試題含答案解析
- 2025年春新人教版歷史七年級(jí)下冊(cè)全冊(cè)課件
- 2025年浙江臺(tái)州機(jī)場(chǎng)管理有限公司招聘筆試參考題庫(kù)含答案解析
- 《工程勘察設(shè)計(jì)收費(fèi)標(biāo)準(zhǔn)》(2002年修訂本)
評(píng)論
0/150
提交評(píng)論