2013年12月11日 星期三

foxpro.gendao

para p_name
store 'VENDOR' TO P_NAME
STORE 'COMPANY_PROFILE'  TO P_NAME
store 'PAYMENT_TERMS' to P_NAME                                  
store 'PAYMENT_METHOD' to P_NAME                                  
STORE 'CUSTOMER'  TO P_NAME
store 'VENDOR' TO P_NAME
store 'RESOURCE' TO P_NAME
store 'ITEM' TO P_NAME
*STORE 'USER'  TO P_NAME
CLOS DATA
set dele on
use result in 0
use gendao in 0
sele gendao
dele for empty(field1)
SET FILTER TO tableNAME=P_NAME OR NAME=P_NAME
SCAN
if (not empty(name)) and empty(tablename)
replace tablename with name
replace name with ''
endif
if not empty(raw)

replace field1 with strt(strt(raw,'  `',''),'` ',' ')
replace field1 with strt(field1,'DEFAULT NULL','')
replace field1 with strt(field1,'NOT NULL','')
replace field1 with strt(field1,'varchar','C ')
replace field1 with strt(field1,'int(11)','I')
replace field1 with strt(field1,'char','c')
replace field1 with strt(field1,'bigint(20)','L')
endif
ENDSCAN
sele gendao
LOCATE FOR ALLT(upper(aarray(field1,1,' ')))=='RECORDID'
IF NOT FOUND()
INSERT INTO GENDAO (tableNAME,FIELD1,ZTYPE) VALUES (P_NAME,'RECORDID','FIELD')
*BROW FIELD ZTYPE
ENDIF

LOCATE FOR ALLT(upper(aarray(field1,1,' ')))=='DOC_NO'
IF NOT FOUND()
INSERT INTO GENDAO (tableNAME,FIELD1,ZTYPE) VALUES (P_NAME,'DOC_NO','FIELD')
ENDIF

LOCATE FOR ALLT(upper(aarray(field1,1,' ')))=='STATUS'
IF NOT FOUND()
INSERT INTO GENDAO (tableNAME,FIELD1,ZTYPE) VALUES (P_NAME,'STATUS','FIELD')
ENDIF

LOCATE FOR ALLT(upper(aarray(field1,1,' ')))=='TIMESTAMP'
IF NOT FOUND()
INSERT INTO GENDAO (tableNAME,FIELD1,ZTYPE) VALUES (P_NAME,'TIMESTAMP','FIELD')
ENDIF

*alter table PAYMENT_TERMS ADD COLUMN STATUS CHAR DEFAULT 'D'

*create table PAYMENT_TERMS ( TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,`DOC_NO` int(10) unsigned NOT NULL AUTO_INCREMENT ,CODE NVARCHAR(10) DEFAULT '',DUE_DATE_CALCULATION NVARCHAR(32) DEFAULT '',DISCOUNT_DATE_CALCULATION NVARCHAR(32) DEFAULT '',DISCOUNT_PERCENT FLOAT DEFAULT 0,DESCRIPTION NVARCHAR(50) DEFAULT '',CALC_PMT_DISC_ON_CR_MEMOS char DEFAULT '',BASE_DATE_CAPTION NVARCHAR(30) DEFAULT '',COD_PAYMENT char DEFAULT '',COD_CASHIERS_CHECK char DEFAULT '',RECORDID bigint(20) NOT NULL DEFAULT '0',
*PRIMARY KEY (`RECORDID`),
*KEY `DOC_NO` (`DOC_NO`) USING BTREE);

sele gendao
scan
replace field1 with strt(field1,' `',' ')
endscan
*strt(strt(raw,'  `',''),'` ',' ')

replace all ftype with 'BIG' FOR 'INT' $ FIELD1
REPLACE ALL FIELD1 WITH ALLT(FIELD1)
REPLACE ALL FIELD1 WITH STRT(FIELD1,'-','_')
REPLACE ALL FIELD1 WITH STRT(FIELD1,'_>_','_TO_')
REPLACE ALL FIELD1 WITH STRTRAN(FIELD1,space(4),'')
replace ALL fieldname with  STRT(SUBS(FIELD1,AT('TABLE',FIELD1)+5),'(','') , ZTYPE WITH 'TABLE' for 'TABLE' $ FIELD1
replace all fieldname with allt(fieldname)
replace all fieldname with strt(allt(fieldname),chr(9),'')
replace ALL classname  with  proper(fieldname) for 'TABLE' $ FIELD1
replace all fieldname with  LEFT(FIELD1,AT(' ',FIELD1)),ZTYPE WITH 'FIELD'  for (not 'TABLE' $ FIELD1) and (not 'ENGINE' $ FIELD1)
replace all ZTYPE WITH 'ENGINE'  for  'ENGINE' $ FIELD1
*replace all zvariable with  lower(fieldname) for ztype='FIELD'
replace all zvariable with  lower(fieldname)
replace all varName with "seqNum" for zvariable='msg_seq_no'
replace all varName with t2v(zvariable) for (not zvariable='msg_seq_no')
replace ALL classname with upper(left(varName,1))+subs(varName,2)  for ztype='FIELD' or ztype='TABLE'
sele gendao
scan
do case
case upper(aarray(field1,1,' '))='RECORDID'
replace fieldtype with "bigint(20) NOT NULL DEFAULT '0'"
replace javatype with "String"
case upper(aarray(field1,1,' '))='DOC_NO'
replace fieldtype with "int(10) NOT NULL DEFAULT '0'"
replace javatype with "int"

case upper(aarray(field1,1,' '))='STATUS'
replace fieldtype with "CHAR NOT NULL DEFAULT 'D'"
replace javatype with "char"


*alter table PAYMENT_TERMS ADD COLUMN STATUS CHAR DEFAULT 'D'

other
if aarray(field1,2,' ')='C' OR  aarray(field1,2,' ')='S'
replace fieldtype with 'NVARCHAR('+aarray(field1,3,' ')+") DEFAULT ''"
replace  javatype with 'String'
endif
if aarray(field1,2,' ')='D'
replace fieldtype with 'DOUBLE DEFAULT 0'
replace  javatype with 'double'
endif
if aarray(field1,2,' ')='c'
replace fieldtype with "char DEFAULT ''"
replace  javatype with 'char'
endif
if aarray(field1,2,' ')='I'
replace fieldtype with 'INTEGER DEFAULT 0'
replace  javatype with 'int'
endif

if aarray(field1,2,' ')='F'
replace fieldtype with 'FLOAT DEFAULT 0'
replace  javatype with 'float'
endif
if aarray(field1,2,' ')='L'
replace fieldtype with 'LONG'
replace  javatype with 'long'
endif
if upper(aarray(field1,2,' '))='DATE'
replace fieldtype with 'date'
replace javatype with 'Date'
endif
if upper(aarray(field1,2,' '))='C' and allt(upper(aarray(field1,3,' ')))=='1'
replace fieldtype with "char DEFAULT ''"
replace  javatype with 'char'
endif
endcase
Endscan

select result
locate for name=p_name
if not found()
insert into result (name) value (p_name)
endif
store  createtable() to _r
replace in result createtab with _r
store createbean() to _r
replace in result javabean with _r

sele result
brow
sele gendao
set filter to
*brow field field1:30,tablename:30,fieldname:30,classname:30, varname:30,fieldtype:30



function createbean()

select gendao
_delimiter=''
quota='"'
quota2="+"
r0=''
r1=''
r=''
store ''  to mclassname
scan

if ztype='TABLE'
r= r+'import java.util.Date;'+chr(13)

r=r+'public class '+allt(classname)+"  implements java.io.Serializable  {"+chr(13)
store allt(classname) to mclassname
else
r0=r0+" protected " + allt(javatype)+" "+allt(varname)+";"+chr(13)

r1=r1+"public void set"+allt(classname)+"("+allt(javatype)+" newValue){"+allt(varname)+" = newValue;}"+chr(13)
r1=r1+"public "+allt(javatype)+" get"+allt(classname)+"(){return "+allt(varname)+";}"+chr(13)+chr(13)

endif


endscan
r=r+r0+chr(13)
r=r+"public "+mclassname+"(){}"+chr(13)
r=r+r1+chr(13)+"}"
*public employee(){}
return r

*public class employee
*{*
* // select password, email,surname from employee;*
* protected  int theValue;
* protected  String password;
* protected  String email;
*







function createtable()
r= ''
select gendao
_delimiter=''
quota='"'
quota2="+"
scan
if ztype='TABLE'
r=r+quota+"create table "+allt(tablename) +' ( '+quota+quota2+chr(13)
else

do case
case LOWER(ALLT(fieldname))=='timestamp'
s='" '+_delimiter+'TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP "+'+CHR(13)

r=r+allt(s)




case LOWER(ALLT(fieldname))=='doc_no'
s=' `DOC_NO` int(10) unsigned NOT NULL AUTO_INCREMENT "+'+CHR(13)
r=r+'"'+_delimiter+allt(s)
other
s=fieldname
s=strt(s,'))',')')
s=strt(s,'((','(')

s0=fieldtype
s0=strt(s0,'))',')')
s0=strt(s0,'((','(')

r=r +quota+ _delimiter+allt(s)+' '+ALLT(s0)+quota+quota2+chr(13)
endcase


_delimiter=','
endif
endscan
r=r+quota+','+ "PRIMARY KEY (`RECORDID`)"+quota+quota2+chr(13)
r=r+'",KEY `DOC_NO` (`DOC_NO`) USING BTREE"+'+chr(13)
r=r+quota+');'+quota+";"+chr(13)
return r

function t2v()
para p_1
for i=0 to 25
p_1=strt(p_1,'_'+chr(97+i),chr(65+i))
endfor
r=p_1
return r

沒有留言:

張貼留言