Ruey
 
 
  µù¥U®É¶¡: 2003-03-12 ¤å³¹: 1698 ¨Ó¦Û: tunglo
  ²Ä 1 ¼Ó
  | 
		
			
				 µoªí©ó: ¬P´Á¤T ¤K¤ë 13, 2003 11:26 am    ¤å³¹¥DÃD: ¥Ü½dado | 
				     | 
			 
			
				
  | 
			 
			
				*-- ½Ð×§ïµ{¦¡¤¤ªºorecordset.OPEN("select * from authors","Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=RMH;Connect Timeout=15",adopendynamic, adlockoptimistic) 
 
*-- ùرªº User ID=sa¡A(¥Î¤á¦W) 
 
*-- Data Source=RMH   (§Aªº SQL Server ¦øªA¾¹¦W) 
 
*-- Password=   (§Aªº¤f¥O) 
 
 
oFORM = CreateObject("FORM1") 
 
 
If vartype(oFORM) = "O" 
 
  oFORM.Show(1) 
 
Endif 
 
  
 
************************************************** 
 
*-- FORM:         FORM1 (f:\ado\adofirst.scx) 
 
*-- ParentClass:  FORM 
 
*-- BaseClass:    FORM 
 
*-- ®É¶¡ÂW:   03/13/02 07:27:02 PM 
 
* 
 
DEFINE CLASS FORM1 AS FORM 
 
 
 
Top = 6 
 
Left = 28 
 
Height = 263 
 
Width = 644 
 
DoCreate = .T. 
 
Caption = "ADO C/S ¸ê®Æµn¿ýªí³æ" 
 
WindowState = 0 
 
Name = "FORM1" 
 
 
 
ADD OBJECT label1 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "§@®a¼ÐÃÑ", ; 
 
Height = 16, ; 
 
Left = 12, ; 
 
Top = 68, ; 
 
Width = 50, ; 
 
TabIndex = 18, ; 
 
Name = "Label1" 
 
 
 
ADD OBJECT label2 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "©m", ; 
 
Height = 16, ; 
 
Left = 48, ; 
 
Top = 104, ; 
 
Width = 14, ; 
 
TabIndex = 19, ; 
 
Name = "Label2" 
 
 
 
ADD OBJECT label3 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "¦W", ; 
 
Height = 16, ; 
 
Left = 48, ; 
 
Top = 140, ; 
 
Width = 14, ; 
 
TabIndex = 20, ; 
 
Name = "Label3" 
 
 
 
ADD OBJECT label4 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "¹q¸Ü", ; 
 
Height = 16, ; 
 
Left = 36, ; 
 
Top = 176, ; 
 
Width = 26, ; 
 
TabIndex = 21, ; 
 
Name = "Label4" 
 
 
 
ADD OBJECT label5 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "¦a§}", ; 
 
Height = 16, ; 
 
Left = 335, ; 
 
Top = 69, ; 
 
Width = 26, ; 
 
TabIndex = 22, ; 
 
Name = "Label5" 
 
 
 
ADD OBJECT label6 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "«°¥«", ; 
 
Height = 16, ; 
 
Left = 335, ; 
 
Top = 96, ; 
 
Width = 26, ; 
 
TabIndex = 23, ; 
 
Name = "Label6" 
 
 
 
ADD OBJECT label7 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "¬Ù", ; 
 
Height = 16, ; 
 
Left = 347, ; 
 
Top = 123, ; 
 
Width = 14, ; 
 
TabIndex = 24, ; 
 
Name = "Label7" 
 
 
 
ADD OBJECT label8 AS label WITH ; 
 
AutoSize = .T., ; 
 
Caption = "¶l½s", ; 
 
Height = 16, ; 
 
Left = 335, ; 
 
Top = 150, ; 
 
Width = 26, ; 
 
TabIndex = 25, ; 
 
Name = "Label8" 
 
 
 
ADD OBJECT cmdfirst AS commandbutton WITH ; 
 
Top = 10, ; 
 
Left = 70, ; 
 
Height = 25, ; 
 
Width = 26, ; 
 
Caption = "<<", ; 
 
TabIndex = 14, ; 
 
Name = "cmdFirst" 
 
 
 
ADD OBJECT cmdprev AS commandbutton WITH ; 
 
Top = 10, ; 
 
Left = 96, ; 
 
Height = 25, ; 
 
Width = 26, ; 
 
Caption = "<", ; 
 
TabIndex = 15, ; 
 
Name = "cmdPrev" 
 
 
 
ADD OBJECT cmdnext AS commandbutton WITH ; 
 
Top = 10, ; 
 
Left = 122, ; 
 
Height = 25, ; 
 
Width = 26, ; 
 
Caption = ">", ; 
 
TabIndex = 16, ; 
 
Name = "cmdNext" 
 
 
 
ADD OBJECT cmdlast AS commandbutton WITH ; 
 
Top = 10, ; 
 
Left = 148, ; 
 
Height = 25, ; 
 
Width = 26, ; 
 
Caption = ">>", ; 
 
TabIndex = 17, ; 
 
Name = "cmdLast" 
 
 
 
ADD OBJECT cmdsave AS commandbutton WITH ; 
 
Top = 229, ; 
 
Left = 231, ; 
 
Height = 25, ; 
 
Width = 60, ; 
 
Caption = "«O¦s", ; 
 
TabIndex = 10, ; 
 
Name = "cmdSave" 
 
 
 
ADD OBJECT cmdcancel AS commandbutton WITH ; 
 
Top = 229, ; 
 
Left = 353, ; 
 
Height = 25, ; 
 
Width = 60, ; 
 
Caption = "ºM®ø", ; 
 
TabIndex = 11, ; 
 
Name = "cmdCancel" 
 
 
 
ADD OBJECT cmdclose AS commandbutton WITH ; 
 
Top = 229, ; 
 
Left = 414, ; 
 
Height = 25, ; 
 
Width = 60, ; 
 
Caption = "Ãö³¬", ; 
 
TabIndex = 13, ; 
 
Name = "cmdClose" 
 
 
 
ADD OBJECT cmdnew AS commandbutton WITH ; 
 
Top = 229, ; 
 
Left = 170, ; 
 
Height = 25, ; 
 
Width = 60, ; 
 
Caption = "·s«Ø", ; 
 
TabIndex = 12, ; 
 
Name = "cmdNew" 
 
 
 
ADD OBJECT txtau_id AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "999-99-9999", ; 
 
Left = 69, ; 
 
MaxLength = 11, ; 
 
TabIndex = 1, ; 
 
Top = 64, ; 
 
Width = 75, ; 
 
Name = "txtAu_id" 
 
 
 
ADD OBJECT txtau_lname AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ; 
 
Left = 69, ; 
 
MaxLength = 40, ; 
 
TabIndex = 2, ; 
 
Top = 100, ; 
 
Width = 248, ; 
 
Name = "txtAu_lname" 
 
 
 
ADD OBJECT txtau_fname AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "AAAAAAAAAAAAAAAAAAAA", ; 
 
Left = 69, ; 
 
MaxLength = 20, ; 
 
TabIndex = 3, ; 
 
Top = 136, ; 
 
Width = 128, ; 
 
Name = "txtAu_fname" 
 
 
 
ADD OBJECT txtphone AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "999999999999", ; 
 
Left = 69, ; 
 
MaxLength = 12, ; 
 
TabIndex = 4, ; 
 
Top = 172, ; 
 
Width = 81, ; 
 
Name = "txtPhone" 
 
 
 
ADD OBJECT txtaddress AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", ; 
 
Left = 368, ; 
 
MaxLength = 40, ; 
 
TabIndex = 5, ; 
 
Top = 65, ; 
 
Width = 248, ; 
 
Name = "txtAddress" 
 
 
 
ADD OBJECT txtcity AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "AAAAAAAAAAAAAAAAAAAA", ; 
 
Left = 368, ; 
 
MaxLength = 20, ; 
 
TabIndex = 6, ; 
 
Top = 92, ; 
 
Width = 128, ; 
 
Name = "txtCity" 
 
 
 
ADD OBJECT txtstate AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "AA", ; 
 
Left = 368, ; 
 
MaxLength = 2, ; 
 
TabIndex = 7, ; 
 
Top = 119, ; 
 
Width = 26, ; 
 
Name = "txtState" 
 
 
 
ADD OBJECT txtzip AS textbox WITH ; 
 
FORMat = "K", ; 
 
Height = 20, ; 
 
InputMask = "99999", ; 
 
Left = 368, ; 
 
MaxLength = 5, ; 
 
TabIndex = 8, ; 
 
Top = 146, ; 
 
Width = 40, ; 
 
Name = "txtZip" 
 
 
 
ADD OBJECT chkcontract AS checkbox WITH ; 
 
Top = 173, ; 
 
Left = 368, ; 
 
Height = 16, ; 
 
Width = 69, ; 
 
Caption = "Ápô", ; 
 
TabIndex = 9, ; 
 
Name = "chkContract" 
 
 
 
ADD OBJECT cmddelete AS commandbutton WITH ; 
 
Top = 229, ; 
 
Left = 292, ; 
 
Height = 25, ; 
 
Width = 60, ; 
 
Caption = "§R°£", ; 
 
Name = "cmdDelete" 
 
 
 
ADD OBJECT shape1 AS shape WITH ; 
 
Top = 45, ; 
 
Left = 16, ; 
 
Height = 2, ; 
 
Width = 600, ; 
 
SpecialEffect = 0, ; 
 
Name = "Shape1" 
 
 
 
ADD OBJECT shape2 AS shape WITH ; 
 
Top = 215, ; 
 
Left = 16, ; 
 
Height = 2, ; 
 
Width = 600, ; 
 
SpecialEffect = 0, ; 
 
Name = "Shape2" 
 
 
 
PROCEDURE assign_value 
 
ThisFORM.txtAu_id.value = orecordset.FIELDS("au_id").value 
 
ThisFORM.txtAu_lname.value = orecordset.FIELDS("au_lname").value 
 
ThisFORM.txtAu_fname.value = orecordset.FIELDS("au_fname").value 
 
ThisFORM.txtPhone.value = orecordset.FIELDS("phone").value 
 
ThisFORM.txtAddress.value = orecordset.FIELDS("address").value 
 
ThisFORM.txtCity.value = orecordset.FIELDS("city").value 
 
ThisFORM.txtState.value = orecordset.FIELDS("state").value 
 
ThisFORM.txtZip.value = orecordset.FIELDS("zip").value 
 
ThisFORM.chkContract.value = orecordset.FIELDS("contract").value 
 
THISFORM.REFRESH 
 
ENDPROC 
 
 
 
PROCEDURE Init 
 
on error glerr = .t. 
 
thisFORM.Assign_value 
 
ENDPROC 
 
 
 
PROCEDURE Load 
 
* ºt¥Ü ADO AddNew, Update, Find, 
 
* Filter ©M Delete ¥\¯à. 
 
Public orecordset,addflag 
 
 
addflag = .f. 
 
 
#Define adopendynamic 2 
 
#Define adlockoptimistic 3 
 
 
orecordset = CREATEOBJECT("ADODB.Recordset") 
 
 
* SQL Server ÅX°Êµ{¦¡Àq»{ªº¦øªA¾¹ºÝ´å¼Ð, 
 
* ³o»Ýn¨Ï¥Î adOpenDynamic. 
 
 
orecordset.OPEN("select * from authors","Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=RMH;Connect Timeout=15",adopendynamic, adlockoptimistic) 
 
 
orecordset.movefirst() 
 
ENDPROC 
 
 
 
PROCEDURE Release 
 
on error 
 
orecordset = null 
 
release orecordset,addflag 
 
ENDPROC 
 
 
 
PROCEDURE cmdfirst.Click 
 
orecordset.movefirst() 
 
thisFORM.Assign_value 
 
ENDPROC 
 
 
 
PROCEDURE cmdprev.Click 
 
if not orecordset.bof 
 
 
*-- ¦V«e²¾°Ê°O¿ý«ü¼Ð 
 
orecordset.moveprevious() 
 
 
*-- ¬O§_¤w¸g¹J¨ì BOF? 
 
if not orecordset.bof 
 
thisFORM.assign_value 
 
else 
 
orecordset.movenext 
 
wait window "¤w¬O°O¿ý¶°²Ä¤@±ø°O¿ý" 
 
endif 
 
 
else 
 
wait window "¤w¬O°O¿ý¶°²Ä¤@±ø°O¿ý" 
 
endif 
 
ENDPROC 
 
 
 
PROCEDURE cmdnext.Click 
 
if not orecordset.eof 
 
 
*-- ¦V«á²¾°Ê°O¿ý«ü¼Ð 
 
orecordset.movenext 
 
 
*-- ¬O§_¤w¸g¹J¨ì EOF? 
 
if not orecordset.eof 
 
thisFORM.assign_value 
 
else 
 
orecordset.moveprevious 
 
wait window "¤w¬O°O¿ý¶°³Ì«á¤@±ø°O¿ý" 
 
endif 
 
 
else 
 
wait window "¤w¬O°O¿ý¶°³Ì«á¤@±ø°O¿ý" 
 
endif 
 
thisFORM.refresh 
 
ENDPROC 
 
 
 
PROCEDURE cmdlast.Click 
 
orecordset.movelast 
 
thisFORM.assign_value 
 
ENDPROC 
 
 
 
PROCEDURE cmdsave.Click 
 
if empty(thisFORM.txtau_id.value) or empty(thisFORM.txtZip.value) 
 
wait window "§@®a¼ÐÃÑ©M¶l½s¤£¯à爲ªÅ" 
 
return 
 
else 
 
m.auid = trim(thisFORM.txtau_id.value) 
 
endif 
 
 
if addflag 
 
orecordset.addnew 
 
endif 
 
 
glerr = .f. 
 
 
orecordset.fields("au_id") = m.auid 
 
orecordset.fields("au_lname") = trim(thisFORM.txtau_lname.value) 
 
orecordset.fields("au_fname") = trim(thisFORM.txtau_fname.value) 
 
orecordset.fields("phone") = trim(thisFORM.txtphone.value) 
 
orecordset.fields("address") = trim(thisFORM.txtaddress.value) 
 
orecordset.fields("city") = trim(thisFORM.txtcity.value) 
 
orecordset.fields("state") = left(alltrim(thisFORM.txtstate.value),2) 
 
orecordset.fields("zip") = trim(thisFORM.txtzip.value) 
 
orecordset.fields("contract") = thisFORM.chkcontract.value 
 
orecordset.update 
 
 
addflag = .f. 
 
 
if !glerr 
 
=messagebox("°O¿ý¤w«O¦s") 
 
else 
 
 
errmsg = '¿ù»~¸¹: ' + ltrim(str(error())) + chr(13) +chr(13) +chr(13) +; 
 
'¿ù»~¸ê°T: ' + message() + chr(13) +chr(13) +chr(13) +; 
 
'µo¥Í¿ù»~ªº¥N½X: ' + message(1) + chr(13) +chr(13) +chr(13) +; 
 
'µo¥Í¿ù»~ªº¦æ: ' + ltrim(str(lineno())) + chr(13) +chr(13) +chr(13) +; 
 
'µo¥Í¿ù»~ªºµ{¦¡: ' + program() 
 
 
messagebox(errmsg,0,"µo¥Í¿ù»~") 
 
 
endif 
 
ENDPROC 
 
 
 
PROCEDURE cmdcancel.Click 
 
thisFORM.assign_value 
 
addflag = .f. 
 
ENDPROC 
 
 
 
PROCEDURE cmdclose.Click 
 
orecordset = .NULL. 
 
RELEASE orecordset,addflag 
 
thisFORM.release 
 
ENDPROC 
 
 
 
PROCEDURE cmdnew.Click 
 
addflag = .t. 
 
ThisFORM.txtAu_id.value =  '   -  -    ' 
 
ThisFORM.txtAu_lname.value = space(40) 
 
ThisFORM.txtAu_fname.value = space(20) 
 
ThisFORM.txtPhone.value = space(12) 
 
ThisFORM.txtAddress.value = space(40) 
 
ThisFORM.txtCity.value = space(20) 
 
ThisFORM.txtState.value = space(2) 
 
ThisFORM.txtZip.value = space(5) 
 
ThisFORM.chkContract.value = .f. 
 
THISFORM.txtAu_id.SETFOCUS 
 
thisFORM.refresh 
 
ENDPROC 
 
 
 
PROCEDURE cmddelete.Click 
 
glerr = .f. 
 
 
If NOT orecordset.EOF 
 
 
  orecordset.DELETE 
 
 
  If !glerr 
 
     =messagebox("°O¿ý¤w§R°£") 
 
     ThisFORM.cmdnext.Click 
 
  Else 
 
 
     errmsg = '¿ù»~¸¹: ' + ltrim(str(error())) + chr(13) +chr(13) +chr(13) +; 
 
        '¿ù»~¸ê°T: ' + message() + chr(13) +chr(13) +chr(13) +; 
 
        'µo¥Í¿ù»~ªº¥N½X: ' + message(1) + chr(13) +chr(13) +chr(13) +; 
 
        'µo¥Í¿ù»~ªº¦æ: ' + ltrim(str(lineno())) + chr(13) +chr(13) +chr(13) +; 
 
        'µo¥Í¿ù»~ªºµ{¦¡: ' + program() 
 
 
     Messagebox(errmsg,0,"µo¥Í¿ù»~") 
 
 
  Endif 
 
 
Endif 
 
 
glerr = .f. 
 
ENDPROC 
 
 
 
ENDDEFINE 
 
* 
 
*-- EndDefine: FORM1 
 
************************************************** _________________ #############################
 
§Ö¼Ö¶ý«}¨t¦C©¯ºÖ¦v°t,³Ü¤Q¥þÂû´ö~ì¨Ó©¯ºÖ¨º»ò²³æ!!
 
 
¾Ç·|VFP¨Ï¥ÎªÌªÀ°Ïªº·j´M,Code¤~·|§ó¦³½ì~
 
############################# | 
			 
		  |