Click here to load reader

第 12 章 应用开发实例

  • Upload
    tania

  • View
    123

  • Download
    0

Embed Size (px)

DESCRIPTION

第 12 章 应用开发实例. 本章学习目标 l 理解 ADO 对象结构和编程模型,并正确为项目添加 ADO l 通过在 Delphi 中使用数据库对象加深对 SQL Server 数据库的理解 l 完成基于 SQL Server 的数据库系统实例开发. 12.1 ActiveX 数据对象 ——ADO. 12.1.1 ADO 对象结构 1 . ADO 简介 - PowerPoint PPT Presentation

Citation preview

  • 12

  • l ADOADOl DelphiSQL Server lSQL Server

  • 12.1 ActiveXADO 12.1.1 ADO1ADO ADOActive Data ObjectsOLE DBADOADO ADOUDAUniversal Data Access (UDA)APIUDAMicrosoft Data Access ComponentsMDACMDACADOOpen Database Connectivity(ODBC)OLE DBOLE DBCOMADOOLE DBOLE DBODBCMDACODBCOLE DBOLE DBMicrosoft AccessMicrosoft SQLOracleODBCOLE DBADO12-1

  • 12-1 ODBC,OLE DB,ADO

  • 2ADO 12-2ADOADOl Connection l Command l Recordser l Record (semi-structured)l Stream WebHTMLADORecordsetConnectionADO

  • PropertyParameterFieldErrorPropertys, Parameters, FieldsErrors12-2PropertiesProperties12-3 12-2 ADO

  • 12-3 Properties

  • DelphiADOTADOConnection, TADOCommand, TADODataSetDelphiDelphiBDETADOTable, TADOQuery, TADOStoredProcADODelphiDelphiADO

  • 12.1.2 TADOConnection TADOConnectionADOConnectionTADODataSet, TADOCommandADOConnectionADOCommand, ADODataSetConnectionStringADOConnectionDataSet

  • 1TADOConnectionl CommandCount ADOConnectionADOCommandl Commands ADOConnectionADOCommandl Connected Connected l ConnectionString ADO u Provider u File name u Remote Provider uRemote Server

  • DelphiADO12-4FormADOConnection12-5 12-4 ADO

  • 12-5 FormADOConnection

  • 12-6Object InspectorConnectionStringEdit Connection String12-7 12-6 12-7 ConnectionString

  • Build...12-8 12-8

  • 12-912-10 12-9

  • 12-10

  • l ConnectionTimeout 15(Exception)l ConnectOptions l CursorLocation (clUseClientl DataSetCount ADOConnectionDataSetCount lDataSets ADOConnectionDataSets

  • l Errors ErrorsADOMicrosoft Data Store SDKl Properties PropertiesADOPropertiesMicrosoft Data Store SDKl Provider ADO12-6l State ADOConnectionu StClosed ADOConnectionu StOpen u StConnecting u StExecuting u StFetching lVersion ADO

  • 2TADOConnectionl BeginTrans ADOConnectionBeginTransOnBeginTransCompleteInTransactionTruel Cancel CancelOpen lCommitTrans CommitTransOnCommitTransCompleteInTransactionFalse

  • l Execute CommandTextSQLExecuteOptionsExecuteu EoAsyncExecute u EoAsyncFetch u EoAsyncFetchNonBlocking u EoExecuteNoRecords l GetFieldNames l GetTableNames lRollbackTrans RollbackTransOnRollbackTransCompleteInTransactionTrue

  • 3TADOConnectionl OnBeginTransComplete BeginTransTransactionLevell OnCommitTransComplete CommitTransl OnConnectComplete ConnectedTrueOpenl OnDisconnect ConnectedFalseClose lOnExecuteComplete ExecuteConnectionConnectionRecordsAffected

  • l OnWillConnect ConnectedTrueOpen lOnWillExecuteExecute12.1.3 TADOCommand TADOCommandDataSetSQLADOCommandExecuteCommandTextSQLParameters

  • 1TADOCommandl CommandObject ADOCommandTADOCommandCommandADO"Microsoft Data Store SDK"l CommandText TADOCommandSQLl CommandType TADOCommand CommandTextu CmdUnknown u CmdText CommandTextSQLu cmdTable CommandText u cmdStoredProc CommandTextStored Procedure)

  • l Connection ADOConnectionConnectionStringl Parameters ADOCommandCommandTypecmdTextcmdStoredProcSQL lStates ADOCommandstClosed, stOpen, stConnecting, stExecutingstFetching

  • 2TADOCommandl Assign AssignADOCommand ConnectionConnectionStringCommandText, CommandTimeout, CommandTypePreparedParametersl Cancel CancelCommandTimeoutExecuteOptionseoAsyncExecute lExecute CommandTextRecordset,ADODataSetADOQuery1.Recordset=ADOCommand1.ExecuteADODataSet1.Recordset=ADOCommandl.Execute

  • 12.1.4 TADODataSet TADODataSetTADOConnection ADODataSetADOCommandRecordsetADOCommandADODataSetRecordsetRecordsetADODataSet1TADODataSet l RDSConnection RDSConnectionADODataSetRDSRDSADOConnection

  • l CacheSize CacheSizel CursorType u CtUnspecified u CtOpenForwardOnly u CtKeyset u CtDynamic u CtStatic CursorTypeCursorLocation (clUseClient ) CursorTypectStaticCursorType

  • l LockType LockTypeDataSet u 1tUnspecified u 1tReadOnly DataSet u 1tPessimistic u 1tOptimistic u 1tBatchOptimistic CursorTypeLockTypeLockType

  • l MaxRecords ADODataSet0Accessl RecNo l RecordCount TADODataSetTCustomADODataSetRecordSizel Recordset RecordsetADORecordsetl Sort 'ORDERDATE ASC,ORDERNO DESC'ASC, DESCSort lIsUnidirectional DataSet

  • 2 TADODataSetl CancelBatch DataSet AffectRecords u ArCurrent u arf filtered Filter u arAll u arAllChapters ChapterRecordset CursorTypectKeySetctStaticLockTypeItBatchOptimistic

  • l DeleteRecords CancelBatchAffectRecordsDataSetl Supports u CoHoldRecords u CoMovePrevious u CoAddNew u CoDelete u CoUpdate u CoBookmark u CoApproxPosition RecNou CoUpdateBatch u CoResync Resyncu CoNotify u CoFind Locateu CoSeek Seeku CoIndex IndexName

  • Supports If ADOdataSet1.Supports([coMovePervious]) then ShowMessage() l UpdateBatch

  • 3TADODataSetl OnEndOfRecordset RecordsetADORecordsetl OnFetchComplete l OnFetchProgress l OnFieldChangeComplete RecordsetFieldl OnMoveComplete RecordsetRecordsetADODataSet lOnRecordChangeComplete Recordset OnRecordChangeCompleteADODataSet

  • l OnRecordsetCreate Recordsetl OnWillChangeField RecordsetFieldADODataSetl OnWillChangeRecord RecordsetADODataSetl OnWillChangeRecordset RecordsetADODataSetl OnWillMove Recordset ADODataSetBeforeScroll, AfterScroll

  • 12.1.5 TADOTableTADOTableADOTADOConnection1 TADOTablel MasterSource, MasterFields Master/DetailDataSourcel TableDirect FalseADOTableSELECTTrueADOTableTable lTableName ADOTableADOTable CloseActiveFalse

  • 2TADOTablel GetIndexNames TADOConnection GetFieldNames, GetTableNames12.1.6 TADOQuery TADOQuerySQLTADOConnectionTADOTableTADOQueryADOADOBDEDelphi

  • 1 TADOQueryl DataSource Master/Detaill RowsAffected ADOQuery-1 l SQL TADOQuerySQL2 TADOQueryl Close l Create TADOQuery lExecSQL ExecSQLSQLSELECTOpenExecSQLSQLExecSQL

  • 3 TADOQueryTADOQueryTADODataSet12.1.7 ADOADOADODelphiADOBDEADO12-11DBRridDataSourceADOQueryADOConnectionADOConnectionADOQueryConnectionString

  • 12-11 ADO DelphiADOSQL ServerSQL

  • 12.2 SQL ServerDelphiADOSQL Server 200012.2.1 1. 2. 12-12

  • 12-12

  • 3. admin12-13 12-13

  • 12.2.2 XSCJXSCJCHECK1. SQL Server 200012-1412-1512-16

  • 12-14 12-15

  • 12-16

  • 2. 12-1712-18 12-17 12-18

  • 3. 12-1912-2012-21 12-19 12-20

  • 12-21 12-22

  • 4. 12-2212-2312-24

  • 5. CHECK12-2512-2612-27

  • 12-27 CHECK 12-28

  • 6. XSCJ12-28usernameadminuserpswdadminadminuserpswd 7. XSCJ12-2912-30

  • 12-29

  • 12-30

  • 12.2.3 DelphiDelphiProject2.dpr12.2.4 1. Form112-31 12-31

  • 12-1Edit,Combobox

    12-1 Form1 CaptionBorderStylebsSingleEdit1TextEdit2TextSpeedButton1CaptionSpeedButton2CaptionADOTable1 ConnectionConnection1TableNameADOConnection1ConnectionString12.1.2

  • SpeedButton1OnClick procedure Tform1.SpeedButton1Click(Sender: TObject);var results:variant;begin ADOTable1.Close;

  • ADOTable1.Open; ADOTable1.Active; results:=ADOTable1.Lookup('username',edit1.text,'userpswd');{} if edit1.Text='' then application.MessageBox(,,mb_ok) else if edit2.Text='' then application.messagebox(,'',mb_ok) else if varisnull(results) then application.MessageBox(,'',mb_ok) else if trim(results)=trim(edit2.Text) then

  • // begin form2.ShowModal; end else application.MessageBox(,'',mb_ok) ; edit1.Text:=''; edit2.Text:=''; end;end.

  • results:=ADOTable1.Lookup('username',edit1.text,'userpswd')Edit1usernameuserpswdresultsSpeedButton2OnClick procedure Tform1.SpeedButton2Click(Sender: TObject);begin form1.close;end; form1.close Form1

  • 2. Form2Form212-32

  • 12-32

  • StandardMainMenuMainMenu1Win32StatusBarStatusBar1ToolBarToolBar1TreeViewTreeView1AlignalLeftStandardPanelPanel1AlignalClientPanel1Data ControlsDBGridDBGrid1Panel1StandardPanelPanel2AlignalTopCaptionDBGrid1AlignalClient

  • Win32ImageList1Data AccessDataSource1ADO3ADOQueryADOQuery1, ADOQuery2, ADOQuery3Panel2Win32PageControlPanel2PageControl1AlignalClientPageControl1New PageTapSheet13TapSheet2, TapSheet3, TapSheet4Caption

  • TapSheet2, TapSheet3, TapSheet412-3312-3412-3512-36LabelCaption

  • 12-33 TapSheet1

  • 12-34 TapSheet2

  • 12-35 TapSheet3

  • 12-36 TapSheet4

  • ADOQuery1, ADOQuery2, ADOQuery3Connectionform1.ADOConnection1(unit Unit2usesUnit1FormADO),DataSource1DataSetADOQuery3DBGrid1DataSourceDataSource1MainMemu1MainMemu112-37

  • Caption12-38

  • toolbar1New ButtonImageList1ImageList1Form2F12implementation procedure ComboboxList1; procedure TreeViewShow;ComboboxList1Edit25.textComboBox1TreeViewShowTreeView1

  • implementation procedure ComboboxList1;var s1,xbbh:string; i:integer;begin with form2 do begin s1:=trim(edit25.Text); i:=pos('/',s1); if i>0 then xbbh:=copy(s1,1,i-1) else xbbh:='';

  • adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add(select distinct , from '); if xbbh'' then adoquery1.SQL.Add(' where ='+quotedstr(xbbh)); adoquery1.Open; ComboBox1.Items.Clear; adoquery1.First; while not adoquery1.Eof do begin // ComboBox1.Items.Add(adoquery1.Fieldbyname('').value +'/'+adoquery1.Fieldbyname('').value);

  • adoquery1.Next; end; end;end;procedure TreeViewShow;var treenode1,treenode2:ttreenode;//begin form2.adoquery1.Close; form2.adoquery1.SQL.Clear; form2.adoquery1.SQL.Add(select distinct , from '); form2.adoquery1.Open; form2.treeview1.Items.Clear; treenode1:=form2.treeview1.Items.Add(nil,''); // form2.adoquery1.First; while not form2.adoquery1.Eof do

  • begin ///' treenode2:=form2.treeview1.Items.Addchild(treenode1, form2.adoquery1.Fieldbyname('').value +'/'+form2.adoquery1.Fieldbyname('').value); form2.adoquery2.Close; form2.adoquery2.SQL.Clear; form2.adoquery2.SQL.Add(select * from where =:'); form2.adoquery2.Parameters.ParamByName('').Value:=form2.adoquery1.Fields[1].Value; form2.adoquery2.Open;

  • // while not form2.adoquery2.Eof do begin form2.treeview1.Items.AddChild(treenode2,form2.adoquery2.fieldbyname('').Value +'/'+form2.adoquery2.fieldbyname('').Value); form2.adoquery2.Next; end; form2.adoquery1.Next; end;end;

  • ADOQuerySQLSQLSQLForm2OnActive procedure Tform2.FormActivate(Sender: TObject);begin edit21.ReadOnly:=True; edit22.ReadOnly:=True; edit23.ReadOnly:=True; edit24.ReadOnly:=True; edit25.ReadOnly:=True; edit26.ReadOnly:=True; edit27.ReadOnly:=True; edit28.ReadOnly:=True; dbgrid1.ReadOnly:=True; edit3.ReadOnly:=True;

  • edit18.ReadOnly:=True; edit19.ReadOnly:=True; TreeViewShow; comboboxlist1; StatusBar1.Panels[0].Text:=StatusBar1.Panels[0].Text +''+form1.Edit1.Text; if trim(form1.Edit1.Text)='admin' then begin n14.Enabled:=True; n15.Enabled:=False;

  • end else begin n14.Enabled:=False; n15.Enabled:=True; end;end;

  • Form2OnCreate procedure Tform2.FormCreate(Sender: TObject);beginstatusbar1.Panels[0].Width:=400;statusbar1.Panels[1].Width:=130;StatusBar1.Panels[1].Text:=': '+datetostr(date);StatusBar1.Panels[2].Text:=': '+timetostr(time);StatusBar1.Panels[0].Text:='';end;

  • DbGrid1OnCellClick procedure Tform2.DBGrid1CellClick(Column: TColumn);begincase pagecontrol1.TabIndex of1:begin if not ADOQuery3.fieldbyname('').IsNull then edit3.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit3.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then

  • edit4.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit4.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then combobox5.Text:=trim(ADOQuery3.fieldbyname('').Value) else combobox5.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit5.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit5.Text:='';

  • if not ADOQuery3.fieldbyname('').IsNull then edit6.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit6.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit7.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit7.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit8.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit8.Text:='';

  • if not ADOQuery3.fieldbyname('').IsNull then edit9.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit9.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit10.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit10.Text:=''; end;3:begin

  • if not ADOQuery3.fieldbyname('').IsNull then edit18.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit18.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit19.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit19.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit20.Text:=trim(ADOQuery3.fieldbyname('').Value) else

  • edit20.Text:=''; end;end;end;

  • DbGrid1OnKeyUp procedure Tform2.DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin if (key=VK_UP) or (key=VK_DOWN) then begin case pagecontrol1.TabIndex of 1:begin if not ADOQuery3.fieldbyname('').IsNull then edit3.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit3.Text:='';

  • xb:=trim(treeview1.Selected.Parent.Text); edit21.Text:=xb; edit22.Text:=bj; edit23.Text:=xb; edit24.Text:=bj; edit25.Text:=xb; edit26.Text:=bj; edit27.Text:=xb; edit28.Text:=bj; ComboboxList1; for i:=0 to Combobox1.Items.Count do Combobox2.Items.Add(Combobox1.Items.Strings[i]); end;end;

  • if not ADOQuery3.fieldbyname('').IsNull then edit4.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit4.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then combobox5.Text:=trim(ADOQuery3.fieldbyname('').Value) else combobox5.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit5.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit5.Text:='';

  • if not ADOQuery3.fieldbyname('').IsNull then edit6.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit6.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit7.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit7.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit8.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit8.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit9.Text:=trim(ADOQuery3.fieldbyname('').Value) else

  • edit9.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit10.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit10.Text:=''; end; 3:begin if not ADOQuery3.fieldbyname('').IsNull then edit18.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit18.Text:='';

  • if not ADOQuery3.fieldbyname('').IsNull then edit19.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit19.Text:=''; if not ADOQuery3.fieldbyname('').IsNull then edit20.Text:=trim(ADOQuery3.fieldbyname('').Value) else edit20.Text:=''; end; end; end;end;

  • TabSheet1Button1OnClick procedure Tform2.Button1Click(Sender: TObject);begin edit1.Text:=''; edit2.Text:=''; edit21.Text:=''; edit22.Text:='';end;

  • Button2OnClick procedure Tform2.Button2Click(Sender: TObject);var bjbh,xh,xm,s1,s2:string; i:integer;begin s1:=trim(edit22.Text); i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else

  • bjbh:=''; xh:=trim(edit1.Text); xm:=trim(edit2.text); s1:='select * from '; s2:=' order by '; if (bjbh'') and (xh'') and (xm'') then s1:=s1+' where ='+quotedstr(bjbh) +' and ='+quotedstr(xh) +' and ='+quotedstr(xm)+s2 else if (bjbh'') and (xh'') and (xm='') then s1:=s1+' where ='+quotedstr(bjbh) +' and ='+quotedstr(xh)+s2

  • else if (bjbh'') and (xh='') and (xm'') then s1:=s1+' where ='+quotedstr(bjbh) +' and ='+quotedstr(xm)+s2 else if (bjbh'') and (xh='') and (xm='') then s1:=s1+' where ='+quotedstr(bjbh)+s2 else if (bjbh='') and (xh'') and (xm'') then s1:=s1+' where ='+quotedstr(xh) +' and ='+quotedstr(xm)+s2 else if (bjbh='') and (xh'') and (xm='') then s1:=s1+' where ='+quotedstr(xh)+s2 else if (bjbh='') and (xh='') and (xm'') then s1:=s1+' where ='+quotedstr(xm)+s2 else if (bjbh='') and (xh='') and (xm='') then s1:=s1+s2;

  • adoquery3.Close; adoquery3.SQL.Clear; adoquery3.SQL.Add(s1); adoquery3.Open;end; SQLDBGrid1TreeView1OnDblClick

  • procedure Tform2.TreeView1DblClick(Sender: TObject);var xb,bj:string; i:integer;begin if not treeview1.Selected.HasChildren then // begin bj:=trim(treeview1.Selected.Text);

  • xb:=trim(treeview1.Selected.Parent.Text); edit21.Text:=xb; edit22.Text:=bj; edit23.Text:=xb; edit24.Text:=bj; edit25.Text:=xb; edit26.Text:=bj; edit27.Text:=xb; edit28.Text:=bj; ComboboxList1; for i:=0 to Combobox1.Items.Count do Combobox2.Items.Add(Combobox1.Items.Strings[i]); end;end;

  • TabSheet2ComboBox5ItemsButton4OnClick procedure Tform2.Button4Click(Sender: TObject);var bjbh,s1: string; i:integer;begin if (trim(edit3.Text)='') or (trim(edit4.Text)='') then application.MessageBox('','',mb_ok) else begin try s1:=trim(edit24.Text); i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else

  • bjbh:=''; adoquery1.close; adoquery1.sql.clear; s1:=update set ='+quotedstr(trim(edit4.Text)) +',='+quotedstr(trim(combobox5.Text)) +',='+quotedstr(trim(edit5.Text)) // +',='+strtodatetime(Edit6.Text) +',=:' +',='+quotedstr(trim(edit7.Text)) +',='+quotedstr(trim(edit8.Text)) +',='+quotedstr(trim(edit9.Text)) +',='+quotedstr(trim(edit10.Text))

  • +',='+quotedstr(bjbh) +' where ='+quotedstr(trim(edit3.Text)); Adoquery1.sql.add(s1); Adoquery1.parameters.parambyname('').value:=strtodatetime(Edit6.Text); Adoquery1.ExecSQL; adoquery3.Requery(); application.MessageBox(,'',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end; end;end;

  • Button3OnClick procedure Tform2.Button3Click(Sender: TObject);begin if (trim(edit3.Text)='') or (trim(edit4.Text)='') then application.MessageBox(','',mb_ok) else if application.MessageBox(','!',mb_okcancel)=idok then begin adoquery1.close; adoquery1.sql.clear; Adoquery1.sql.add(delete from where ='+quotedstr(trim(edit3.Text)) +' and ='+quotedstr(trim(edit4.Text))); Adoquery1.ExecSQL;

  • adoquery3.Requery(); //15 //adoquery3.Delete; application.MessageBox(','',mb_ok); end;end;

  • TabSheet3Button7OnClick procedure Tform2.Button7Click(Sender: TObject);begin edit13.Text:=''; edit14.Text:='';end;

  • Button6OnClick procedure Tform2.Button6Click(Sender: TObject);var

  • s1:string;begin DBgrid1.Font.Color:=clteal; try // adoquery3.close; adoquery3.sql.clear; s1:='select * from '; if (trim(edit13.Text)'') and (trim(edit14.Text)'') then s1:=s1+' where like '+quotedstr('%'+trim(edit13.Text)+'%') +' or like '+quotedstr('%'+trim(edit14.Text)+'%') else if (trim(edit13.Text)'') and (trim(edit14.Text)='') then s1:=s1+' where like '+quotedstr('%'+trim(edit13.Text)+'%')

  • else if (trim(edit13.Text)='') and (trim(edit14.Text)'') then s1:=s1+' where like '+quotedstr('%'+trim(edit14.Text)+'%'); Adoquery3.sql.add(s1); Adoquery3.Open; except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;

  • Button5OnClick procedure Tform2.Button5Click(Sender: TObject);var s1,bjbh,kcbh:string; i:integer;begin DBgrid1.Font.Color:=clteal; if (trim(edit25.Text)='') or (trim(edit26.Text)='') or (trim(combobox1.Text)='')then application.MessageBox('','',mb_ok) else try //

  • s1:=trim(ComboBox1.Text); i:=pos('/',s1); if i>0 then kcbh:=copy(s1,1,i-1) else kcbh:=''; s1:=trim(edit26.Text); i:=pos('/',s1); if i>0 then

  • bjbh:=copy(s1,1,i-1) else bjbh:=''; adoquery3.close; adoquery3.sql.clear; s1:='select * from ' +' where ='+quotedstr(bjbh) +' and ='+quotedstr(kcbh); if trim(edit13.Text)'' then s1:=s1+' and ='+quotedstr(trim(edit13.Text)); if trim(edit14.Text)'' then s1:=s1+' and ='+quotedstr(trim(edit14.Text)); Adoquery3.sql.add(s1);

  • Adoquery3.Open; except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • TabSheet4Button9OnClick procedure Tform2.Button9Click(Sender: TObject);var xh,xm,kcbh,s1: string; i:integer; cj:variant;begin s1:=trim(combobox2.Text); i:=pos('/',s1); if i>0 then kcbh:=copy(s1,1,i-1) else kcbh:='';

  • xh:=trim(edit18.Text); xm:=trim(edit19.Text); cj:=strtofloat(Edit20.Text); if (xh='') or (xm='') or (kcbh='') then application.MessageBox(','',mb_ok) else begin try adoquery1.close; adoquery1.sql.clear; s1:='update set =:cj'

  • +' where ='+quotedstr(trim(edit18.Text)) +' and ='+quotedstr(kcbh); Adoquery1.sql.add(s1); Adoquery1.parameters.parambyname('cj').value:=cj; Adoquery1.ExecSQL; adoquery3.Requery(); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end; end;end;

  • Button8OnClick procedure Tform2.Button8Click(Sender: TObject);var xh,xm,kcbh,s1: string; i:integer;begin s1:=trim(combobox2.Text); i:=pos('/',s1); if i>0 then kcbh:=copy(s1,1,i-1) else kcbh:=''; xh:=trim(edit18.Text); xm:=trim(edit19.Text); if (xh='') or (xm='') or (kcbh='') then

  • application.MessageBox(','',mb_ok) else if application.MessageBox(','!',mb_okcancel)=idok then begin adoquery1.close; adoquery1.sql.clear; Adoquery1.sql.add('delete from where ='+quotedstr(xh) +' and ='+quotedstr(kcbh)); Adoquery1.ExecSQL; adoquery3.Requery(); //15 //adoquery3.Delete; application.MessageBox('','',mb_ok); end;end;

  • PageControl1OnChange procedure Tform2.PageControl1Change(Sender: TObject);var s1,s2,bjbh,kcbh:string; i:integer;begin case pagecontrol1.TabIndex of 1:begin s1:=trim(edit24.Text); i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else bjbh:=''; s1:='select * from '; s2:=' order by ';

  • if (bjbh'') then s1:=s1+' where ='+quotedstr(bjbh)+s2 else s1:=s1+s2; adoquery3.Close; adoquery3.SQL.Clear; adoquery3.SQL.Add(s1); adoquery3.Open; end; 0,2:begin adoquery3.Close; adoquery3.SQL.Clear; end; 3:begin

  • edit18.Text:=''; edit19.Text:=''; edit20.Text:=''; s1:=trim(edit28.Text); i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else bjbh:=''; s1:=trim(combobox2.Text); i:=pos('/',s1); if i>0 then kcbh:=copy(s1,1,i-1) else

  • kcbh:=''; s1:='select * from '; s2:=' order by '; if (bjbh'') and (kcbh'') then s1:=s1+' where ='+quotedstr(bjbh) +' and ='+quotedstr(kcbh)+s2 else if (bjbh'') and (kcbh='') then s1:=s1+' where ='+quotedstr(bjbh)+s2 else if (bjbh='') and (kcbh'') then s1:=s1+' where ='+quotedstr(kcbh)+s2 else if (bjbh='') and (kcbh'') then s1:=s1+s2; adoquery3.Close; adoquery3.SQL.Clear; adoquery3.SQL.Add(s1);

  • adoquery3.Open; end; end;end; DBGrid1Form2Click

  • 3. Form3Form312-39ADOQuery1

  • 12-39

  • Form3BorderIcons[]BorderStylebsSingleForm2Form3Button3Click procedure TForm3.Button3Click(Sender: TObject);begin if (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 (:xbbh,:xbmc)'); Adoquery1.Parameters.ParamByName('xbbh').Value:=''+edit1.text+''; Adoquery1.Parameters.ParamByName('xbmc').Value:=''+edit2.Text+''; Adoquery1.ExecSQL; application.MessageBox('','',mb_ok); except on E: Exception do application.MessageBox(','',mb_ok); end; edit1.Text:=''; edit2.Text:='';end;

  • Button2Click procedure TForm3.Button2Click(Sender: TObject);begin edit1.text:=''; edit2.Text:='';end;

  • Button1Click procedure TForm3.Button1Click(Sender: TObject);begin form3.Close ;end;

  • 4. Form4Form412-40ADOQuery1

  • 12-40

  • Button3Click 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;

  • Button2Click procedure TForm4.Button2Click(Sender: TObject);begin combobox1.Text:=''; edit1.Text:=''; edit2.Text:='';end;

  • Button1Click procedure TForm4.Button1Click(Sender: TObject);begin form4.Close ;end;

  • 5. Form5Form512-41ADOQuery1ADOQuery2ADOQuery3DataSource13ADOQueryConnectionform1.ADOConnection1DataSource1DataSetADOQuery3DBGrid1DataSourceDataSource1

  • 12-413GroupBox1Form5F12implementation procedure ComboboxList1; procedure ComboboxList2; procedure initialize;

  • 3implementation procedure ComboboxList1;begin form5.adoquery1.Close; form5.adoquery1.SQL.Clear; form5.adoquery1.SQL.Add(select distinct , from '); form5.adoquery1.Open; form5.ComboBox1.Items.Clear; form5.adoquery1.First; while not form5.adoquery1.Eof do begin //

  • form5.ComboBox1.Items.Add(form5.adoquery1.Fieldbyname('').value +'/'+form5.adoquery1.Fieldbyname('').value); form5.adoquery1.Next; end;end;procedure ComboboxList2;var s1,xbbh: string; i: integer;begin s1:=form5.ComboBox1.Text; i:=pos('/',s1);

  • if i>0 then xbbh:=copy(s1,1,i-1) else xbbh:=''; form5.ComboBox2.Text:=''; form5.adoquery2.Close; form5.adoquery2.SQL.Clear; form5.adoquery2.SQL.Add('select , from where =:'); form5.adoquery2.Parameters.ParamByName('').Value:=xbbh; form5.adoquery2.Open;

  • form5.ComboBox2.Items.Clear; form5.adoquery2.First; while not form5.adoquery2.Eof do begin // form5.ComboBox2.Items.Add(form5.adoquery2.Fieldbyname('').value +'/'+form5.adoquery2.Fieldbyname('').value); form5.adoquery2.Next; end;end;procedure initialize;begin

  • form5.edit1.Text:=''; form5.edit2.Text:=''; form5.combobox3.Text:=''; form5.edit3.Text:=''; form5.edit4.Text:=''; form5.edit5.Text:=''; form5.edit6.Text:=''; form5.edit7.Text:=''; form5.edit8.Text:='';end;

  • ComboBox3Form5OnActive procedure TForm5.FormActivate(Sender: TObject);begin comboboxlist1; initialize; dbgrid1.DataSource.AutoEdit:=false;end;procedure TForm5.ComboBox1Change(Sender: TObject);

  • begin comboboxlist2;end;procedure TForm5.ComboBox2Change(Sender: TObject);var s1,bjbh: string; i: integer;begin s1:=combobox2.Text; i:=pos('/',s1); if i>0 then

  • bjbh:=copy(s1,1,i-1) else bjbh:=''; form5.adoquery3.Close; form5.adoquery3.SQL.Clear; form5.adoquery3.SQL.Add(select * from where =:'); form5.adoquery3.Parameters.ParamByName('').Value:=bjbh; form5.adoquery3.Open;end;

  • ComboBox1OnChange procedure TForm5.ComboBox1Change(Sender: TObject);begin comboboxlist2;end;

  • ComboBox2OnChange procedure TForm5.ComboBox2Change(Sender: TObject);var s1,bjbh: string; i: integer;begin s1:=combobox2.Text; i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else bjbh:=''; form5.adoquery3.Close; form5.adoquery3.SQL.Clear;

  • form5.adoquery3.SQL.Add(select * from where =:'); form5.adoquery3.Parameters.ParamByName('').Value:=bjbh; form5.adoquery3.Open;end;

  • Button3OnClick procedure TForm5.Button3Click(Sender: TObject);var s1,bjbh: string; i: integer;begin s1:=combobox2.Text; i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else bjbh:=''; // if (edit1.Text='')or(edit2.Text='')or(edit3.Text='')or(combobox1.Text='') or(combobox2.Text='')or(combobox3.Text='') then begin

  • application.MessageBox('','',mb_ok); // exit; end else begin adoquery1.close; adoquery1.sql.clear; try s1:=insert into (,,,,,'; s1:=s1+,,,,)'; s1:=s1+' values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10)'; Adoquery1.SQL.Add(s1);

  • Adoquery1.parameters.parambyname('1').value:=Edit1.Text; Adoquery1.parameters.parambyname('2').value:=Edit2.Text; Adoquery1.parameters.parambyname('3').value:=combobox3.Text; Adoquery1.parameters.parambyname('4').value:=Edit3.Text; Adoquery1.parameters.parambyname('5').value:=strtodatetime(Edit4.Text); Adoquery1.parameters.parambyname('6').value:=Edit5.Text; Adoquery1.parameters.parambyname('7').value:=Edit7.Text; Adoquery1.parameters.parambyname('8').value:=Edit8.Text; Adoquery1.parameters.parambyname('9').value:=Edit6.Text; Adoquery1.parameters.parambyname('10').value:=bjbh; Adoquery1.execsql;

  • form5.ADOQuery3.Requery(); Application.MessageBox(','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end; end;end;

  • Button2OnClick procedure TForm5.Button2Click(Sender: TObject);begin initialize;end; Button1OnClick procedure TForm5.Button1Click(Sender: TObject);begin form5.Close ;end;

  • 6. Form6Form612-42ADOQuery1ADOQuery2DataSource12ADOQueryConnectionform1.ADOConnection1DataSource1DataSetADOQuery2DBGrid1DataSourceDataSource1

  • 12-423GroupBox1Form6F12implementation procedure initialize; implementation

  • procedure initialize;begin form6.edit1.Text:=''; form6.edit2.Text:=''; form6.edit3.Text:=''; form6.edit4.Text:=''; form6.edit5.Text:=''; form6.edit6.Text:=''; form6.edit7.Text:=''; form6.edit8.Text:='';end;

  • Form6OnActive procedure TForm6.FormActivate(Sender: TObject);begin initialize; dbgrid1.DataSource.AutoEdit:=false; form6.adoquery2.Close; form6.adoquery2.SQL.Clear; form6.adoquery2.SQL.Add('select * from '); form6.adoquery2.Open;end;

  • Button1,OnClick procedure TForm6.Button1Click(Sender: TObject);var s1:string;begin if (edit1.Text='')or(edit2.Text='')or(edit3.Text='')or(edit4.Text='') or(edit4.Text='')or(edit5.Text='') then begin

  • application.MessageBox(''+chr(13)+chr(10) +','',mb_ok); // exit; end else begin adoquery1.close; adoquery1.sql.clear; try s1:=insert into (,,,,,'; s1:=s1+',,)';

  • s1:=s1+' values ('+quotedstr(trim(edit1.Text))+','+quotedstr(trim(edit4.Text)) +','+trim(edit5.Text)+','+trim(edit6.Text)+','+quotedstr(trim(edit7.Text)) +','+quotedstr(trim(edit3.Text))+','+quotedstr(trim(edit2.Text)) +','+quotedstr(trim(edit8.Text))+')'; Adoquery1.SQL.Add(s1); { 102SQL s1:=s1+' values (:1,:2,:3,:4,:5,:6,:7,:8)'; Adoquery1.SQL.Add(s1); Adoquery1.parameters.parambyname('1').value:=Edit1.Text; Adoquery1.parameters.parambyname('2').value:=Edit4.Text;

  • Adoquery1.parameters.parambyname('3').value:=strtofloat(trim(Edit5.Text)); Adoquery1.parameters.parambyname('4').value:=strtofloat(trim(Edit6.Text)); Adoquery1.parameters.parambyname('5').value:=Edit7.Text; Adoquery1.parameters.parambyname('6').value:=edit3.Text; Adoquery1.parameters.parambyname('7').value:=Edit2.Text; Adoquery1.parameters.parambyname('8').value:=Edit8.Text; } Adoquery1.execsql; form6.ADOQuery2.Requery(); Application.MessageBox('','',mb_ok); except on E: Exception do

  • messagedlg(E.Message,mterror,[mbok],0); end; end;end; Button2,OnClick procedure TForm6.Button2Click(Sender: TObject);begin initialize;end;

  • Button3,OnClick procedure TForm6.Button3Click(Sender: TObject);begin form6.Close ;end; 6. Form7Form712-43ADOQuery1ADOQuery2ADOQuery3ADOQuery4DataSource1DataSource24ADOQueryConnectionform1.ADOConnection1DataSource1DataSetADOQuery3DataSource2DataSetADOQuery4DBGrid1DataSourceDataSource1DBGrid2DataSourceDataSource2

  • 12-43

  • 12-433GroupBox1Form7F12implementation5 procedure ComboboxList1; procedure ComboboxList2; procedure listboxlist1; procedure adoquery3_initialize; procedure initialize;

  • implementation5 procedure ComboboxList1;begin form7.adoquery1.Close; form7.adoquery1.SQL.Clear; form7.adoquery1.SQL.Add(select distinct , from '); form7.adoquery1.Open; form7.ComboBox1.Items.Clear; form7.adoquery1.First; while not form7.adoquery1.Eof do begin

  • // form7.ComboBox1.Items.Add(form7.adoquery1.Fieldbyname('').value +'/'+form7.adoquery1.Fieldbyname('').value); form7.adoquery1.Next; end;end;procedure ComboboxList2;var s1,xbbh: string; i: integer;

  • begin s1:=form7.ComboBox1.Text; i:=pos('/',s1); if i>0 then xbbh:=copy(s1,1,i-1) else xbbh:=''; form7.ComboBox2.Text:=''; form7.adoquery2.Close; form7.adoquery2.SQL.Clear; form7.adoquery2.SQL.Add(select , from where =:');

  • form7.adoquery2.Parameters.ParamByName('').Value:=xbbh; form7.adoquery2.Open; form7.ComboBox2.Items.Clear; form7.adoquery2.First; while not form7.adoquery2.Eof do begin // form7.ComboBox2.Items.Add(form7.adoquery2.Fieldbyname('').value +'/'+form7.adoquery2.Fieldbyname('').value); form7.adoquery2.Next; end;end;

  • procedure listboxlist1;var s1,xbbh: string; i: integer;begin s1:=form7.ComboBox1.Text; i:=pos('/',s1); if i>0 then xbbh:=copy(s1,1,i-1) else xbbh:=''; form7.ComboBox2.Text:=''; form7.adoquery2.Close; form7.adoquery2.SQL.Clear;

  • form7.adoquery2.SQL.Add('select , from where =:'); form7.adoquery2.Parameters.ParamByName('').Value:=xbbh; form7.adoquery2.Open; form7.ListBox1.Items.Clear; form7.adoquery2.First; while not form7.adoquery2.Eof do begin //1 form7.listbox1.Items.Add(form7.adoquery2.Fieldbyname('').value

  • form7.adoquery2.Next; end;end;procedure adoquery3_initialize;var s1,xbbh,bjbh,kcbh: string; i: integer;begin s1:=form7.combobox1.Text; i:=pos('/',s1); if i>0 then xbbh:=copy(s1,1,i-1) else xbbh:=''; s1:=form7.combobox2.Text;;

  • i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else bjbh:=''; kcbh:=trim(form7.edit1.Text); form7.adoquery3.Close; form7.adoquery3.SQL.Clear; s1:='select s., s., c.' +' FROM as x INNER JOIN' + as b ON x. = b. INNER JOIN' +' as s ON' +' b. = s. INNER JOIN' +' as k INNER JOIN' +' as c ON k. = c. ON'

  • +' s. = c.' +' WHERE (x. = :xbbh) AND (k. = :kcbh) AND (b. = :bjbh)'; form7.ADOQuery3.SQL.Add(s1); form7.adoquery3.Parameters.ParamByName('xbbh').Value:=xbbh; form7.adoquery3.Parameters.ParamByNam.('kcbh').Value:=kcbh;form7.adoquery3.Parameters.ParamByName('bjbh').Value:=bjbh; form7.adoquery3.Open;

  • end;procedure initialize;begin form7.edit3.Text:=''; form7.edit3.ReadOnly:=True; form7.edit4.Text:=''; form7.edit5.Text:='';end;

  • Form7OnActive procedure TForm7.FormActivate(Sender: TObject);begin comboboxlist1; initialize; dbgrid1.DataSource.AutoEdit:=false;end;

  • ComboBox1OnChange procedure TForm7.ComboBox1Change(Sender: TObject);begin listboxlist1; comboboxlist2; adoquery3_initialize;end;

  • ComboBox2OnChange procedure TForm7.ComboBox2Change(Sender: TObject);var s1,bjbh: string; i: integer;begin s1:=combobox2.Text; i:=pos('/',s1); if i>0 then bjbh:=copy(s1,1,i-1) else

  • ListBox1OnDblClick

  • DBGrid2ReadOnlyTrueOnDblClick

  • DBGrid1ReadOnlyTrueButton1,OnClick procedure TForm7.Button1Click(Sender: TObject);begin if (edit1.Text='')or(edit4.Text='')or(edit5.Text='') then begin application.MessageBox('','',mb_ok); exit; end else if adoquery3.Locate('',edit5.Text,[loCaseInsensitive]) then begin

  • application.MessageBox('','',mb_ok); edit4.Text:=''; exit; end else try adoquery1.close; adoquery1.sql.clear; Adoquery1.sql.add('insert into (,,)' +'values (:xh,:kcbh,:cj)'); Adoquery1.Parameters.ParamByName('xh').Value:=edit5.text; Adoquery1.Parameters.ParamByName('kcbh').Value:=edit1.Text; Adoquery1.Parameters.ParamByName('cj').Value:=strtofloat(trim(Edit4. Text));

  • Adoquery1.ExecSQL; adoquery3.Requery(); //application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • Button2,OnClick procedure TForm7.Button2Click(Sender: TObject);begin initialize;end; Button3,OnClick procedure TForm7.Button3Click(Sender: TObject);begin form7.Close ;end;

  • 7. Form8Form812-44ADOQuery1ADOQuery2DataSource12ADOQueryConnectionform1.ADOConnection1DataSource1DataSetADOQuery1DBGrid1DataSourceDataSource1

  • 12-44

  • Form8OnActivate procedure TForm8.FormActivate(Sender: TObject);begin dbgrid1.DataSource.AutoEdit:=false; adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select * from '); adoquery1.Open; edit1.ReadOnly:=True; edit1.Text:=''; edit2.Text:='';end;

  • DBGrid1OnCellClick procedure TForm8.DBGrid1CellClick(Column: TColumn);begin if not ADOQuery1.fieldbyname('').IsNull then edit1.Text:=trim(ADOQuery1.fieldbyname('').Value) else edit1.Text:=''; if not ADOQuery1.fieldbyname('').IsNull then edit2.Text:=trim(ADOQuery1.fieldbyname('').Value) else edit2.Text:='';end;

  • OnKeyUp procedure TForm8.DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin if (key=VK_UP) or (key=VK_DOWN) then begin if not ADOQuery1.fieldbyname('').IsNull then edit1.Text:=trim(ADOQuery1.fieldbyname('').Value) else edit1.Text:=''; if not ADOQuery1.fieldbyname('').IsNull then edit2.Text:=trim(ADOQuery1.fieldbyname('').Value) else edit2.Text:=''; end;end;

  • Button3,OnClick procedure TForm8.Button3Click(Sender: TObject);var xbbh,xbmc,s1: string;begin if (trim(edit1.Text)='') or (trim(edit2.Text)='') then application.MessageBox('','',mb_ok) else begin xbbh:=trim(ADOQuery1.fieldbyname('').Value); xbmc:=trim(ADOQuery1.fieldbyname('').Value); if (xbbh=trim(edit1.Text)) and (xbmc=trim(edit2.Text)) then application.MessageBox('','',mb_ok) else try

  • adoquery2.close; adoquery2.sql.clear; s1:='update set ='+quotedstr(trim(edit2.Text)) +' where ='+quotedstr(trim(edit1.Text)); Adoquery2.sql.add(s1); Adoquery2.ExecSQL; adoquery1.Requery(); application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end; end;end;

  • Button2,OnClick

  • Button1,OnClick procedure TForm8.Button1Click(Sender: TObject);begin form8.Close ;end; 8. Form9Form912-45ADOQuery1ADOQuery2DataSource12ADOQueryConnectionform1.ADOConnection1DataSource1DataSetADOQuery2DBGrid1DataSourceDataSource1

  • Form9OnActivate

  • ComboBox1OnChange

  • DBGrid1OnCellClick

  • OnKeyUp

  • Button3,OnClick procedure TForm9.Button3Click(Sender: TObject);var xbbh,xbmc,s1: string; i:integer;begin if (trim(edit1.Text)='') or (trim(edit2.Text)='') then application.MessageBox('','',mb_ok) else begin xbbh:=trim(ADOQuery2.fieldbyname('').Value); xbmc:=trim(ADOQuery2.fieldbyname('').Value); if (xbbh=trim(edit1.Text)) and (xbmc=trim(edit2.Text)) then application.MessageBox('','',mb_ok) else try

  • s1:=trim(ComboBox1.Text); i:=pos('/',s1); if i>0 then xbbh:=copy(s1,1,i-1) else xbbh:=''; adoquery1.close; adoquery1.sql.clear; s1:='update set ='+quotedstr(trim(edit2.Text)) +' where ='+quotedstr(xbbh) +' and ='+quotedstr(trim(edit1.Text)); Adoquery1.sql.add(s1); Adoquery1.ExecSQL; adoquery2.Requery(); application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end; end;end;

  • Button2,OnClick

  • xbbh:=''; adoquery1.close; adoquery1.sql.clear; Adoquery1.sql.add('delete from where ='+quotedstr(xbbh) +' and ='+quotedstr(trim(edit1.Text))); Adoquery1.ExecSQL; adoquery2.Requery(); //15 //adoquery2.Delete; application.MessageBox('','',mb_ok); end;end;

  • Button1,OnClick 9. Form10Form1012-46ADOQuery1ADOQuery2DataSource12ADOQueryConnectionform1.ADOConnection1DataSource1DataSetADOQuery2DBGrid1DataSourceDataSource1

  • 12-46

  • Form10F12implementation implementation procedure initialize;begin with form10 do begin edit1.Text:=''; edit2.Text:=''; edit3.Text:=''; edit4.Text:=''; edit5.Text:='';

  • edit6.Text:=''; edit7.Text:=''; edit8.Text:=''; end;end;procedure getonecourse;begin with form10 do begin if not ADOQuery2.fieldbyname('').IsNull then edit1.Text:=trim(ADOQuery2.fieldbyname('').Value) else

  • edit1.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit2.Text:=trim(ADOQuery2.fieldbyname('').Value) else edit2.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit3.Text:=trim(ADOQuery2.fieldbyname('').Value) else edit3.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit4.Text:=trim(ADOQuery2.fieldbyname('').Value) else

  • edit4.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit5.Text:=trim(ADOQuery2.fieldbyname('').Value) else edit5.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit6.Text:=trim(ADOQuery2.fieldbyname('').Value) else edit6.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit7.Text:=trim(ADOQuery2.fieldbyname('').Value) else

  • edit7.Text:=''; if not ADOQuery2.fieldbyname('').IsNull then edit8.Text:=trim(ADOQuery2.fieldbyname('').Value) else edit8.Text:=''; end;end; Form10OnActivate

  • DBGrid1OnCellClick procedure TForm10.DBGrid1CellClick(Column: TColumn);begin getonecourse;end;procedure TForm10.Button3Click(Sender: TObject);var s1: string;begin if (trim(edit1.Text)='') or (trim(edit2.Text)='') then application.MessageBox('','',mb_ok) else try adoquery1.close; adoquery1.sql.clear; s1:='update set ='+quotedstr( trim(edit2.Text))

  • +', ='+quotedstr(trim(edit5.Text)) +', ='+quotedstr(trim(edit6.Text)) +', ='+quotedstr(trim(edit7.Text)) +', ='+quotedstr(trim(edit8.Text)) +' where ='+quotedstr(trim(edit1.Text)); Adoquery1.sql.add(s1); Adoquery1.ExecSQL; adoquery2.Requery(); application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • OnKeyUp

  • begin kcbh:=trim(edit1.Text); adoquery1.close; adoquery1.sql.clear; Adoquery1.sql.add('delete from where ='+quotedstr(kcbh)); Adoquery1.ExecSQL; adoquery2.Requery(); //15 //adoquery2.Delete; application.MessageBox('','',mb_ok); end;end;

  • Button4,OnClick Button3,OnClick procedure TForm10.Button3Click(Sender: TObject);var s1: string;begin if (trim(edit1.Text)='') or (trim(edit2.Text)='') then application.MessageBox('','',mb_ok) else try adoquery1.close; adoquery1.sql.clear;

  • s1:='update set ='+quotedstr(trim(edit2.Text)) +', ='+trim(edit3.text)+', ='+trim(edit4.text) +', ='+quotedstr(trim(edit5.Text)) +', ='+quotedstr(trim(edit6.Text)) +', ='+quotedstr(trim(edit7.Text)) +', ='+quotedstr(trim(edit8.Text)) +' where ='+quotedstr(trim(edit1.Text)); Adoquery1.sql.add(s1); Adoquery1.ExecSQL; adoquery2.Requery(); application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • Button2,OnClick

  • Adoquery1.ExecSQL; adoquery2.Requery(); //15 //adoquery2.Delete; application.MessageBox('','',mb_ok); end;end; Button1,OnClick

  • 10. Form11Form1112-47ADOQuery1ADOQuery22ADOQueryConnectionform1.ADOConnection1PageControl13TabSheet1Edit1Edit2SpeedButton1SpeedButton2TabSheet2Edit3SpeedButton3SpeedButton4TabSheet3ComboBox1SpeedButton5SpeedButton6

  • 12-47

  • Form11F12implementation implementation

  • adoquery2.First; while not adoquery2.Eof do begin // ComboBox1.Items.Add(adoquery2.Fieldbyname('username').value); adoquery2.Next; end; end;end; Form11OnActivate

  • TabSheet1SpeedButton1OnCellClick procedure TForm11.SpeedButton1Click(Sender: TObject);var s1,yhxm,yhkl1,yhkl2:string;begin yhxm:='admin'; yhkl1:=trim(edit1.Text); yhkl2:=trim(edit2.Text); if yhkl1yhkl2 then begin application.MessageBox('','',mb_ok); edit1.Text:=''; edit2.Text:=''; end

  • else if yhkl1='' then application.MessageBox('','',mb_ok) else try adoquery1.close; adoquery1.sql.clear; s1:='update set userpswd='+quotedstr(yhkl1) +' where username='''+yhxm+''''; Adoquery1.sql.add(s1); Adoquery1.ExecSQL; application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • TabSheet1SpeedButton2OnCellClick TabSheet2SpeedButton3OnCellClick procedure TForm11.SpeedButton3Click(Sender: TObject);var s1,yhxm,yhkl:string;begin yhxm:=trim(edit3.Text); yhkl:='1234';

  • if yhxm='' then application.MessageBox('','',mb_ok) else try adoquery1.close; adoquery1.sql.clear; s1:='select * from where username='+quotedstr(yhxm); Adoquery1.sql.add(s1); Adoquery1.Open; if Adoquery1.RecordCount>0 then application.MessageBox('','',mb_ok) else begin adoquery1.close; adoquery1.sql.clear; s1:='insert into (username,userpswd)'; s1:=s1+' values ('+quotedstr(yhxm)+','+quotedstr(yhkl)+')'; Adoquery1.sql.add(s1);

  • Adoquery1.ExecSQL; application.MessageBox('','',mb_ok); end; except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • TabSheet2SpeedButton4OnCellClick TabSheet3SpeedButton5OnCellClick

  • procedure TForm11.SpeedButton5Click(Sender: TObject);var s1,yhxm:string;begin yhxm:=trim(combobox1.Text); if yhxm='' then application.MessageBox('','',mb_ok) else try adoquery1.close; adoquery1.sql.clear; s1:='select * from where username='+quotedstr(yhxm); Adoquery1.sql.add(s1); Adoquery1.Open; if Adoquery1.RecordCount=0 then

  • TabSheet3SpeedButton6OnCellClick 11. Form12Form1212-48ADOQuery1Connectionform1.ADOConnection1Edit1Edit2SpeedButton1SpeedButton2

  • 12-48 Form12OnActivate

  • SpeedButton1OnCellClick

  • if yhkl1='' then application.MessageBox('','',mb_ok) else try adoquery1.close; adoquery1.sql.clear; s1:='update set userpswd='+quotedstr(yhkl1) +' where username='''+yhxm+''''; Adoquery1.sql.add(s1); Adoquery1.ExecSQL; application.MessageBox('','',mb_ok); except on E: Exception do messagedlg(E.Message,mterror,[mbok],0); end;end;

  • SpeedButton2OnCellClick 12. Form13Form1312-49Memo1SpeedButton1Memo1Standard

  • 12-49

  • Form12OnActivate SpeedButton1OnCellClick

  • ADODelphiADOADODelphiADOSQL Server 2000

  • 1 2 XSCJDelphiADOADOStoredProc