Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple business object utility or class?
Message
 
To
24/09/2008 14:05:21
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01350261
Message ID:
01350277
Views:
24
>Is there a builder for a simple Business Object in VFP?
>
>For instance, I want to pass a lookup value, and then I would have an object that has a property for every field in the matching record.
>
>(pseudo code):
>
>oJob=CreateObject('JobObject')
>oJob.GetInfo('4033')
>
>
>Now, I should be able to look at the oJob object and see a property for each field in the table:
>
>oJob.CustNo=
>oJob.Po_No=
>oJob.ShipDate=
>oJob.QuotedBy=
>etc.
>
>I want it to figure out the fields from the table structure and create a property for each field.
>
>I am not worried about the full compliment of the usual Business Object features at this point, mostly just a lookup object.
>
>I have hacked out this code, but it it very rough and very hard-coded:
>
>
>LPARAMETERS cJob_num
>
> cAlias=alias()
>
> if not used('Job_Info')
>  Do Open_Job_Info
> else
>  select Job_Info
> endif
>
> *-- Seek the entered text as a job number ---------------
> seek alltrim(cJob_Num)
>
>
> if found()
>  this.ipkey=ipkey
>  this.job_num=alltrim(job_num)
>  this.status=status
>  this.job_start=job_start
>  this.invoiced=invoiced
>  this.po_num=Alltrim(p_o_num)
>  this.ship_date=ship_date
>  this.quote_no=quote_no
>  this.cust_num=alltrim(cust_num)
>  this.company=alltrim(Customer.Company)
>  this.phone=Alltrim(Customer.phone)
>  this.found=1
>  this.value=alltrim(job_num)
>  select (cAlias)
>  return .t.
> else
>   this.ClearProperties()
>   if this.complain=.t.
>    =MessageBox("Job Number " + alltrim(cJob_Num)+ " not found!", 0, 'Notice')
>   endif
>   If !Empty(cAlias)
>    select (cAlias)
>   endif
>   return .F.
> endif
>
>
>Anyoneone ever built something like this?
SET ASSERTS ON

lcTable = GETFILE()
ASSERT .f. 
oJob = CREATEOBJECT([TableInfo])
oJob.TableName = JUSTSTEM(lcTable)
oJob.GetInfo([SomeValue],[TheOrder])


DEFINE CLASS TableInfo AS Session
   Fields        = NULL
   TableName = []
   
   FUNCTION GetInfo(leSeekExpression, lcOrderName)
            SELECT (this.TableName)
            SEEK  leSeekExpression IN (this.TableName) ORDER &lcOrderName
            IF FOUND(this.TableName)
               SCATTER NAME this.Fields
            ELSE 
               this.Fields = NULL
            ENDIF
   ENDFUNC                          
  
   FUNCTION TableName_Assign(leNewValue)
           IF NOT USED(leNewValue)
               USE (leNewValue) IN 0
           ENDIF
           this.TableName = m.leNewValue
  ENDFUNC
ENDDEFINE
Sure that is a VERY rough class but that is just an idea you should put Error handling, check for reliable parameters etc.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform