Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Delete not working
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00791389
Message ID:
00791776
Views:
14
Here is the code that occurs first dealing with SPT Cursor:
** Method Access_delete
WITH thisform
LOCAL hld_ssn,hld_eh,a,g,x,lcUpdFields,lcUpdNames,defdrive,rec,lc_stat,lc_ssno,lc_found

&& put dashes in ssno for access program
	hld_ssn = ALLTRIM(.pf1.p1.txtssn.value)
	hld_ssn = STUFF(hld_ssn,4,0,'-')
	hld_ssn = STUFF(hld_ssn,7,0,'-')

	INSERT INTO lv_x_emp_itc (ssno,upd_status,w_datetime,from_screen) ;
				 VALUES (hld_ssn, ;
						 "D", ;
						 DATETIME(), ;
						 "frm_viewrec.access_delete")
	
	updateval = TABLEUPDATE(.t.,.t.,'lv_x_emp_itc')

*Initailize variables
	lc_stat = "D"  && this is an add record
	lc_found = .f.
	lc_ssno = ALLTRIM(hld_ssn)
	q = 0
	A1 = lc_ssno
	A2 = .pf1.p1.txtfname.value
	A3 = .pf1.p1.txtmi.value
	A4 = .pf1.p1.txtlname.value
	A5 = .pf1.p4.txtstrprobdte.value
	A6 = .hld_div
	A7 = .hld_unit
	A8 = .hld_class
	A9 = .pf1.p1.txtdob.value
	A10 = .pf1.p6.txteye.value
	A11 = .pf1.p6.txthgt.value
	A12 = .pf1.p6.txtwgt.value
	A13 = 'PROBATION'
	A14 = DATETIME()
	A15 = hld_eh
	A16 = .pf1.p6.txtpmt.value
	A17 = ''
	A18 = "A"
	A19 = DATETIME()
	A20 = .methodname

*start connections to remote data
	IF ISNULL(thisform.oCon)
		thisform.oCon = NEWOBJECT('ConMgr','conmgr.prg')
	ENDIF
	defdrive = SYS(5)
	DO CASE
		CASE defdrive = 'H:'
			thisform.nCon = thisform.oCon.OpenConn('itc_H_drive')

		CASE defdrive = 'C:'
			thisform.nCon = thisform.oCon.OpenConn('itc_C_drive')

		CASE defdrive = 'L:'
			thisform.nCon = thisform.oCon.OpenConn('itc_L_drive')

	ENDCASE
	IF thisform.nCon < 1
		MESSAGEBOX('connection failed, aborting cursor update,16, major waaaaaahhhhh!!!')
		RETURN .f.
	ENDIF
	lnRes = SQLSETPROP(thisform.nCon,"Asynchronous",.f.)
	lnRes = SQLSETPROP( thisform.nCon, "DispWarnings", .F. )

	lcSql = " Select *" ;
		+ "  FROM UDFields" ;

	UDFCursor = SYS(2015) && UDFields Cursor
	IF USED(UDFCursor)
		TABLEREVERT(.t.,UDFCursor)
	ENDIF
	lnRes = SQLEXEC( thisform.nCon, lcSql, "UDFCursor" )
	IF lnRes > 0
		q = RECCOUNT()
		IF q > 0 && record available
			SELECT UDFCursor
			LOCATE FOR ssno == lc_ssno
			IF FOUND()
				lc_found = .t.  &&this social does exist
			ELSE
				lc_found = .f.  &&this social doesn't exist
			ENDIF
	
			DO CASE
			
				CASE lc_stat == 'D' AND lc_found = .t.	&& delete			
					SELECT UDFCursor
					AFIELDS(fieldinfo)
					****Define fields to be updated
					lcUpdFields = ''
					lcUpdNames = ''
					FOR i = 1 TO ALEN(fieldinfo,1)
						IF i < ALEN(fieldinfo,1)
							lcUpdFields = lcUpdFields + fieldinfo(i,1) + ","
							lcUpdNames = lcUpdNames + fieldinfo(i,1)+ " " + "UDFields." + fieldinfo(i,1) + ","
						ELSE
							lcUpdFields = lcUpdFields + fieldinfo(i,1)
							lcUpdNames = lcUpdNames + fieldinfo(i,1)+ " " + "UDFields." + fieldinfo(i,1)
						ENDIF
					ENDFOR
					RELEASE fieldinfo
		
					*** Set Tables property (Table for INSERT, UPDATE or DELETE)
					lnRes = CURSORSETPROP( "TABLES", "UDFields", "UDFCursor" )
					*** Key Field(Key field for WHERE clause)
					lnRes = CURSORSETPROP( "KEYFIELDLIST", "idnumber", "UDFCursor" )
					*** Updateable Field List (Fields which are updatable)
					lnRes = CURSORSETPROP( "UPDATABLEFIELDLIST", lcUpdFields, "UDFCursor" )
					*** UpdateNameList (Back-end table name for each cursor field )
					lnRes = CURSORSETPROP( "UPDATENAMELIST", lcUpdNames ,"UDFCursor" )
					*** Set Where Type and Send update flag
					lnRes = CURSORSETPROP( "WHERETYPE", 1, "UDFCursor" )
					lnRes = CURSORSETPROP( "SENDUPDATES", .T., "UDFCursor" )
					*** Also set the Buffer/Locking Mode to Table/Optimistic
					lnRes = CURSORSETPROP( "Buffering", 5, "UDFCursor" )
	
					DELETE from UDFCursor WHERE UDFCursor.ssno = lc_ssno
					lnRes = TABLEUPDATE(.t.,.t.,'UDFCursor')
	
					IF lnRes = .F. && update failed above try again directly on server table
						lcSql = "DELETE from UDFields WHERE UDFields.ssno = ?lc_ssno" 
						lnRes = SQLEXEC(THISFORM.nCon,lcSql)
					ENDIF 
		
		
				CASE lc_stat == 'D' AND lc_found = .f.	&& delete			
					INSERT into lv_hld_from_arc_access ( h_ssno, h_upd_status, h_other_id, h_datetime, ;
						h_from_screen) VALUES (lc_ssno,lc_stat,0,DATETIME(), ;
						"MDBCONVERT.convert (lc_stat == 'D' AND lc_found = .f.) while deleting record: it could not delete because ssno")
						t14 = TABLEUPDATE(.t.,.t.,'lv_hld_from_arc_access')
			ENDCASE 
		
		ENDIF
	ENDIF
	lnRes = thisform.oCon.CloseConn(thisform.nCon)	
	
ENDWITH 
The above routine is called in following routine:
** method Moverec
.....
.....
IF proceed = .t.
   	nAnswer = 	MESSAGEBOX('Are you sure you want to Archive The Current Record On Screen ?', 4+32+256, 'Archive Record')
   
   	do case
      	case nAnswer = 6
      		
      		IF nosync = .f.
      			.access_delete && delete this record from camera access program
      		ENDIF 
      	
	      	select * from employee where employee.e_id = .d into array a__gen6
	        If type('a__gen6') # 'U' and type('a__gen6') # 'L' &&if1
				insert into archive (ae_id, ae_ssn, ae_fname, ae_lname, ae_mi, ae_inital, ;
						ae_sex, ae_unit, ae_class, ae_itemno, ae_strcty_dte, ;
						ae_strprob_dte, ae_address, ae_city, ae_state, ae_zip, ae_dob, ae_lic, ;
						ae_lic_class, ae_licexp, ae_milectrt, ae_physdte, ae_emg, ae_phone, ;
						ae_prkper, ae_entryc, ae_empstatus, ae_badgeno, ae_budget, ae_psycdte, ;
						ae_cntysnrdte, ae_relinfo, ae_drugdte, ae_degree, ae_rehiredte, ;
						ae_agdte, ae_termdte, ae_rehire, ae_kcso, ae_dmv, ae_bpd, ae_comments, ;
						ae_phq, ae_employeed, ae_cto, ae_lstrdte, ae_lretdte, ae_sickamt, ;
						ae_lieu, ae_lwop, ae_reason, ae_drstmt, ae_dtestamp, ae_flg1, ae_flg2, ;
						ae_flg3, ae_flg4, ae_flg5, ae_flg6, ae_flg7, ae_flg8, ae_flg9, ae_flg10, ;
						ae_flg11, ae_flg12, ae_flg13, ae_flg14, ae_flg15, ae_flg16, ae_flg17, ;
						ae_flg18, ae_flg19, ae_flg20, ae_flg21, ae_flg22, ae_flg23, ae_flg24, ;
						ae_flg25) ;
				values (a__gen6(1,1), a__gen6(1,2), a__gen6(1,3), a__gen6(1,4), a__gen6(1,5), ;
						a__gen6(1,6), a__gen6(1,7), a__gen6(1,10), ;
						a__gen6(1,11), a__gen6(1,12), a__gen6(1,13), a__gen6(1,14), a__gen6(1,15), ;
						a__gen6(1,16), a__gen6(1,17), a__gen6(1,18), a__gen6(1,19), a__gen6(1,20), ;
						a__gen6(1,21), a__gen6(1,22), a__gen6(1,23), a__gen6(1,24), a__gen6(1,25), ;
						a__gen6(1,26), a__gen6(1,27), a__gen6(1,28), a__gen6(1,29), a__gen6(1,30), ;
						a__gen6(1,31), a__gen6(1,32), a__gen6(1,33), a__gen6(1,34), a__gen6(1,35), ;     	
						a__gen6(1,36), a__gen6(1,37), a__gen6(1,38), a__gen6(1,39), a__gen6(1,40), ;		
						a__gen6(1,41), a__gen6(1,42), a__gen6(1,43), a__gen6(1,44), a__gen6(1,45), ;
						a__gen6(1,46), a__gen6(1,47), a__gen6(1,48), a__gen6(1,49), a__gen6(1,50), ;		
						a__gen6(1,51), a__gen6(1,52), a__gen6(1,53), a__gen6(1,54), a__gen6(1,55), ;
						a__gen6(1,56), a__gen6(1,57), a__gen6(1,58), 1, a__gen6(1,60), ;
						a__gen6(1,61), a__gen6(1,62), a__gen6(1,63), a__gen6(1,64), a__gen6(1,65), ;
						a__gen6(1,66), a__gen6(1,67), a__gen6(1,68), a__gen6(1,69), a__gen6(1,70), ;
						a__gen6(1,71), a__gen6(1,72), a__gen6(1,73), a__gen6(1,74), a__gen6(1,75), ;
						a__gen6(1,76), a__gen6(1,77), a__gen6(1,78), a__gen6(1,79), a__gen6(1,80))
				release a__gen6
				r2 = CURSORSETPROP("Buffering",5)
				delete for lv_employee.e_id = .d
				r3 = tableupdate(.t., .t., 'lv_employee')
		 		MESSAGEBOX('Record has Been Archived', 0, 'Archive Record')
				.release()
			else	
		 		MESSAGEBOX('Record Does not exist in the employee table', 0, 'Archive Record')
		 		.release()
			endif

		case nAnswer = 7
			.refresh()	

	ENDCASE
ENDIF 
endwith 
Thanks
Nick Patel
Previous
Reply
Map
View

Click here to load this message in the networking platform