Re: Euphoria vs. C and OOP

new topic     » goto parent     » topic index » view thread      » older message » newer message

This is exactly the way we use EU except that all the table column names are
unique. Here's a sample table.

1st 2 letters - system. AR here
2nd 2 lettere - table name 
3rd ? letters - column name

--------------------------------------------------------------------------------
-- include arCustomer.e			         created 03/15/02
-- dbNames= {"ar", "arCustomer"}
-- arcu
-- Key Length: 8
--
--		AR Customer
--
global constant					-- dec(x,y) defined as tot digits,decimal places
    arcuLength	    	= 039,
    arcuCoNbr           = 001, --K1  dec(2,0)      Company Number
    arcuCustNbr         = 002, --K2  dec(6,0)      Customer Number
    arcuCustNm          = 003, --    char(40)      Customer Name
    arcuAddr1           = 004, --    char(25)      Address Line 1
    arcuAddr2           = 005, --    char(25)      Address Line 2
    arcuCity            = 006, --    char(20)      City
    arcuSt              = 007, --    char(2)       State
    arcuZip             = 008, --    char(10)      Zip Code - 9 digit zip code
                               --                  formatted as 99999-9999
arcuPhone           = 009, --    char(17)      Phone - formatted as
    999-999-9999
--                  XXXX where XXXX is an
                               extension.
    arcuContact1Nm      = 010, --    char(30)      Contact 1 Name
    arcuContact2Nm      = 011, --    char(30)      Contact 2 Name
    arcuSlsmnNbr        = 012, --    char(3)       Salesman Number - default
--                  salesman number for the
                               salesman
--                  to receive credit/commission
                               for
                               --                  a sale to the customer.
arcuBillCustNbr     = 013, --    dec(6)        Bill to Customer Number -
    this is
--                  the number of the customer
                               which
--                  will be billed for a sale to
                               the
                               --                  customer.
arcuCustCl          = 014, --    dec(1)       Customer Class - the price
    level
--                  at which to charge the
                               customer.
--                  Values 1 - 6 are for the
                               price
--                  levels in the Order
                               Processing
                               --                  sub-system. Value 6 indicates
                               --                  that the customer should be
                               --                  charged at cost.
    arcuLstInvDt        = 015, --    date          Last Invoice Date
    arcuLstInvAmt       = 016, --    dec(9,2)      Last Invoice Amount
    arcuLstPayDt        = 017, --    date          Last Pay Date
    arcuLstPayAmt       = 018, --    dec(9,2)      Last Pay Amount
    arcuYtdSales        = 019, --    dec(9,2)      Year-to-Date Sales
arcuInvPdCt         = 020, --    dec(6,0)      Invoice Paid Count - the
    number
                               --                  of invoices the customer has
                               --                  paid.
arcuAvgPayDays      = 021, --    dec(4,0)      Average Days to Pay - the
    average
                               --                  number of days it takes the
                               --                  customer to pay an invoice.
    arcuCurrBal         = 022, --    dec(9,2)      Current Balance
arcuStmtFl          = 023, --    char(1)       Statements Flag - indicates
    if
                               --                  the customer is to receive
                               --                  statements. Y = yes, N = no
arcuTaxAuthCd       = 024, --    char(5)       Tax Authority Code - valid
    codes
                               --                  are in the arCode and opCode
                               --                  tables.
arcuFinanceChg      = 025, --    char(1)       Finance Charge Flag -
    indicates
--                  if the customer should be
                               charged
--                  a finance charge for an over
                               due
                               --                  balance. Y = yes, N = no
arcuCustCatCd       = 026, --    char(2)       Customer Category Code - a
    user
                               --                  assigned value to indicate
                               --                  location, zone, etc.
arcuCrLimit         = 027, --    dec(9,2)      Credit Limit - the maximum
    amount
                               --                  of a sale allowed for the
                               --                  customer.
    arcuLstYrSales      = 028, --    dec(9,2)      Last Year's Sales - the total
                               --                  amount of sales made to the
                               --                  customer last year.
arcuTermsCd  	    = 029, --    char(5)       Payment Terms Code - valid
    values
                               --                  are in the opCode table.
arcuTaxableFl       = 030, --    char(1)       Taxable Flag - indicates if
    the
                               --                  customer is subject to tax
                               --                  charges. Y = yes, N = no
    arcuPriceAdjCd      = 031, --    char(2)       Price Adjustment Code - if
--                  numeric, it is a partial key?
                               to
--                  the ic_prod_line table?; if
                               it is
--                  alphabetic, it is a key to
                               the
                               --                  op_ptab? table.
arcuFaxPhone        = 032, --    char(17)      Phone - formatted as
    999-999-9999
--                  XXXX where XXXX is an
                               extension.
    arcuFedId           = 033, --    char(16)      Federal Id - the customer's
                               --                  federal indentifier.
    arcuCreatedDt       = 034, --    date          Date Created - the date the
                               --                  customer was added to the A/R
                               --                  sub-system.
    arcuMaxBal          = 035, --    dec(9,2)     ?Maximum Balance - the highest
--                  balance the customer has had
                               to
                               --                  date.
arcuShipViaCd       = 036, --    char(5)       Ship Via Code - the default
    ship
--                  via code for the customer.
                               Valid
                               --                  values can be found in the
                               --                  ar_code tables.
    arcuFobCd           = 037, --    char(5)       Freight on Board Code - the
--                  default freight on board code
                               for
--                  the customer. Valid values
                               can be
                               --                  found in the arCode table.
	arcuEmail			= 038, --	 Char(50)	   Customer's email address or blank.

	arcuElecInv			= 039  --	 Char(1)	   Does customer allow email invoice
							   --				   faxed invoiced E = email, F = fax
							   --				   N = neither.
--- Initialize ---
global sequence arcuInit
    arcuInit= repeat("",arcuLength)
    arcuInit[arcuCoNbr]           = 1
    arcuInit[arcuCustNbr]         = 0
    arcuInit[arcuSlsmnNbr]		  = "999"
    arcuInit[arcuLstInvDt]        = {0,0,0}
    arcuInit[arcuLstInvAmt]       = 0
    arcuInit[arcuLstPayDt]        = {0,0,0}
    arcuInit[arcuLstPayAmt]       = 0
    arcuInit[arcuYtdSales]        = 0
    arcuInit[arcuInvPdCt]         = 0
    arcuInit[arcuAvgPayDays]      = 0
    arcuInit[arcuCurrBal]         = 0
    arcuInit[arcuCrLimit]         = 0
    arcuInit[arcuLstYrSales]      = 0
    arcuInit[arcuCreatedDt]       = {0,0,0}
    arcuInit[arcuMaxBal]          = 0
	arcuInit[arcuBillCustNbr]	  = 0
	arcuInit[arcuCustCl]		  = 1
	arcuInit[arcuFinanceChg]	  = "N"
	arcuInit[arcuTaxableFl]		  = "N"
	arcuInit[arcuElecInv]		  = "N"
	arcuInit[arcuStmtFl]		  = "Y"
-- end include     arcustomer.e
--------------------------------------------------------------------------------
Bill Reed wrote:
> 
> 
>   People have been saying that Euphoria should be more "C" like, or
>   more "OOP" like.  Euphoria has unique features that set it apart from
>   C or OOP, and make it flexible, but in different ways.
> 
>   Instead of trying to make Euphoria fit into a C mold or OOP mold,
>   take advantage of the unique features of Euphoria.
> 
>   sequences are structures, but not like C.  They are just as flexible,
>   perhaps even more so, since it is easier to add to or change what
>   a sequence is.
> 
>   A sequence can be just a string, "ABC", or a structure:
> }}}
<eucode>
>   a = {
>        "ABC",            -- string
>        123,              -- integer or atom
>        {"XYZ", 456}      -- another sequence
>       }
> 

>    Referencing these members can be done with constants, like
> 
> }}}
<eucode>
>    constant NAME  = 1, AMT  = 2, DESC = 3,
>             DNAME = 1, DAMT = 2
> 
>    a[NAME]           ("ABC")
> 
>    or
>    a[DESC]           (  {"XYZ", 456}  )
>    a[DESC][DNAME]    ("XYZ")
>    a[DESC][DAMT]     (456)
> </eucode>
{{{

> 
>    C has Public and Private functions.  Euphoria can have them too,
>    but in different ways.
> 
>    See the following include and program to see what I mean.  I hope
>    this can stimulate some discussion as to using Euphoria in a more
>    structured way.
> 
> 
>   ====================================================================
>   ==  Member banking.e                                              ==
>   ====================================================================
> }}}
<eucode>
> 
>   --*----------------------------------------------------------------*
>   --*  banking.e             bank account program                    *
>   --*                                                                *
>   --*    Public                                                      *
>   --*      function  BankProgram                                     *
>   --*                                                                *
>   --*    Private (or member functions)                               *
>   --*      function  CreateAcct                                      *
>   --*      function  Withdrawal                                      *
>   --*      function  Deposit                                         *
>   --*      procedure Balance                                         *
>   --*                                                                *
>   --*  example of account:                                           *
>   --*                                                                *
>   --*  a = {015505, "John Smith", 12000.15}                          *
>   --*  a[1] = acctno                                                 *
>   --*  a[2] = acctname                                               *
>   --*  a[3] = balance                                                *
>   --*----------------------------------------------------------------*
> 
> global constant
>     acctno   = 1,
>     acctname = 2,
>     balance  = 3,
>     blank_acct = {0, "", 0}
> 
> function CreateAcct()               -- Private function returns account
>   sequence User_account
> 
>   User_account           = blank_acct
>   User_account[acctno]   = 111000              -- assign next account #
>   User_account[acctname] = prompt_string("Enter name : ")
> 
>   return User_account
> 
> end function
> 
> function Withdrawal(sequence account, atom amount)  -- Private function
>   account[balance] -= amount
> 
>   return account
> 
> end function
> 
> function Deposit(sequence account, atom amount)    -- Private function
>   account[balance] += amount
> 
>   return account
> 
> end function
> 
> procedure Balance(sequence account)                -- Private procedure
>   printf(1, "account : %d  %s  Balance : %.2f\n", {account[acctno],
>                                                    account[acctname],
>                                                    account[balance]})
> 
> end procedure
> 
> global function BankProgram(sequence parms)
>   --*----------------------------------------------------------------*
>   --*  Public because it is global                                   *
>   --*----------------------------------------------------------------*
> 
>   sequence command, User_account, ret_account
>   atom amount
> 
>   --*----------------------------------------------------------------*
>   --*  parms[1] = command                                            *
>   --*  parms[2] = account (optional when creating new account)       *
>   --*  parms[3] = optional amount                                    *
>   --*  parms[4]... optional and expandable                           *
>   --*----------------------------------------------------------------*
> 
>   command  = parms[1]
> 
>   if    equal(command, "new") then
>     ret_account  = CreateAcct()
>   elsif equal(command, "Balance") then
>     User_account = parms[2]
>     Balance(User_account)
>     ret_account  = {}
>   elsif equal(command, "Deposit") then
>     User_account = parms[2]
>     amount       = parms[3]
>     ret_account  = Deposit(User_account, amount)
>   elsif equal(command, "Withdrawal") then
>     User_account = parms[2]
>     amount       = parms[3]
>     ret_account  = Withdrawal(User_account, amount)
>   else
>     puts(1, "Unknown command\n")
>     return {}
>   end if
> 
>   return ret_account
> 
> end function
> </eucode>
{{{

> 
>   ====================================================================
>   ==  end of Member banking.e                                       ==
>   ====================================================================
> 
> 
>   ====================================================================
>   ==                main program:                                   ==
>   ====================================================================
> }}}
<eucode>
> 
>   include get.e
>   include graphics.e
>   include banking.e
> 
>   sequence myAccount, null_status
> 
>   text_color(WHITE) bk_color(BLUE)
>   clear_screen()
> 
>   myAccount   = BankProgram({"new"})
>   myAccount   = BankProgram({"Deposit",    myAccount, 12000.00})
>   myAccount   = BankProgram({"Withdrawal", myAccount, 150.00})
>   null_status = BankProgram({"Balance",    myAccount})
> 
> </eucode>
{{{

> 
>   Other functions and features can be added from this basic
>   framework.  Features such as checking for overdraft status, adding
>   extra fees, crediting or debiting accounts, etc.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu