CSDN博客

img pas

仅供自己使用的javascipt辅助开发工具

发表于2004/6/24 22:20:00  941人阅读


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>2003-11-12数据库设计</TITLE>
<META NAME="Generator" CONTENT="Microsoft FrontPage 5.0">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="Version=2003-10-24">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<!--
作者:苏翔,suxiang@126.com
http://www.baron.com.cn/javascript/zh/zh17.htm
-->
<BODY title="为了使以后程序好维护" style="font-size:16;"><PRE>2003-10-27说明:介面不友好,功能可自己用之;
有bug:不能放在有空格的路径下(如My Document(我的文档))
主要目的是为了方便写文档:没有文档的程序没有价值!可以自动写一些程序,这样程序更规范,省时间!任何人可以修改和使用
2003-11-6还要有删除功能,还要添加注释,写成面向对象!可以想想保生成XML,合.Net!可加多文档(自由加载文档)
生成前可有操作就保存
2003-11-12 要添加上下移动的功能;file类型?;要把只以更新的东西写出来,特值写出来.(如时间怎样做缺省?)
2003-11-30 ME_ALL
</PRE>
<div id=div_edit title="主要目的是为了方便写文档:没有文档的程序没有价值
可以自动写一些程序,这样程序更规范,省时间
任何人可以修改和使用">
<br>
<style>

TABLE{border-width:0;margin:0;padding:0;border-color:BLACK;background-color:#666699;font-size:12;cursor:hand;}
TH{background-color:#C0C0C0;text-align:left}
.SX{background-color:#F2F2F2}
#tblMain{border-width:0;;margin:0;padding:0;background-color:#6699CC;font-size:12;cursor:hand;}
input{baobao: expression(textstyle(this))}
</style>

<TABLE width=100% id=tblMain ><TR ><TD>

<TABLE width=100% title="元数据,请修改" id=meta_data >
<TR>
 <TH width=10%>保存为</TH>
 <TH width=10%>打开</TH>
 <TH width=10%>表名称</TH>
 <TH width=1%>文件夹</TH>
 <TH width=10%>作者</TH>
 <TH>功能备注</TH>
</TR>
<TR class=SX>
 <TD onclick="editCell(this);">文件名</TD>
 <TD onclick="openFile(this);">已存的文件</TD>
 <TD onclick="editCell(this);">TableName</TD>
 <TD onclick="editCell(this);">FolderName</TD>
 <TD onclick="editCell(this);">苏翔</TD>
 <TD onclick="editCell(this,60);"></TD>
</TR>
</TABLE>
<TABLE id=tedit class=tb border=0 width=100%  >
<TR>
 <TH title=" " width=8%>字段名称</TH>
 <TH title=" " width=8%>中文说明</TH>
 <TH title=" " width=5%>数据类型</TH>
 <TH title=" " width=5%>长度</TH>
 <TH title=" " width=5%>!null</TH>
 <TH title=" " width=5%>其他属性</TH>
 <TH title=" " width=5%>默认</TH>
 <TH title=" " width=5%>显示</TH>
 <TH title="录入数据时作验证" width=5%>验证</TH>
 <TH title=" " >备注</TH>
 <TH title=" " width=5%>插入</TH>
 <TH title=" " width=5%>删除</TH>
</TR>
<TR >
 <TD title="字段名称" onclick="editCell(this);">id</TD>
 <TD title="中文说明" onclick="editCell(this);">ID</TD>
 <TD title="数据类型" onclick="selectDataType(this);">bigint</TD>
 <TD title="长度"  onclick="editCell(this);">       </TD>
 <TD title="是否为NULL"  onclick="setNull(this);">!null</TD>
 <TD title="其他属性:PK表主键"  onclick="editCell(this);">pk,i++</TD>
 <TD title="默认值"  onclick="editCell(this);">       </TD>
 <TD title="显示:Text"  onclick="selectFormElementType(this);">hidden</TD>
 <TD title="验证:如NotEmpty,Email,IsNumber"  onclick="selectValidate(this);">       </TD>
 <TD title="字段名称" onclick="editCell(this,30);"></TD>
 <TD onclick=insert_row(this.parentNode)>插入</TD>
 <TD onclick=delete_row(this.parentNode)>删除</TD>
</TR>

</TABLE>

</TD></TR></TABLE>
</div>
<SCRIPT LANGUAGE="JavaScript">
<!--
/******************* 表格编辑类 开始 *********************************************/
var ForReading = 1, ForWriting = 2;
var Meta_FileName=0,Meta_TableName=2,Meta_FolderName=3;
var Attr_Field=0,Attr_Description=1,Attr_DataType=2;
var Attr_Length=3,Attr_NotNull=4,Attr_Attrs=5;
var Attr_Default=6,Attr_Html=7,Attr_Validate=8;

function getTime(){
 var d, s = "作者:苏翔 suxiang@126.com 日期: ";
 d = new Date();
 s += d.getYear()+"年"
 s += (d.getMonth() + 1) + "月";
 s += d.getDate() + "日";
   return(s);                                // 返回日期。
}


Hhtml='<HTML><BODY><div id=div_edit>/n';

String.prototype.Trim  =  function()  //by function check()

return  this.replace(/(^/s*)  |(/s*$)/g,  ""); 


function editCell (cell,size) {
 mySize=10
 if(!!size&&size>10)mySize=size;
 input='<INPUT ID="editCell" ONCLICK="event.cancelBubble = true;"';
 input+='ONBLUR="setCell(this.parentElement, this.value)" ';
 input+='VALUE="' + cell.innerText + '" SIZE="' + mySize + '">';
 cell.innerHTML =  input;
 document.all.editCell.focus();
 document.all.editCell.select();
}

function selectDataType(cell){
 strSelect='<SELECT id=editDateType ONCLICK="event.cancelBubble = true;"';
 strSelect+='onChange="setCell(this.parentElement, this.value)"';
 strSelect+='ONBLUR="setCell(this.parentElement, this.value)"';

 strSelect+='<OPTION value=varchar>VARCHAR ';
 strSelect+='<OPTION value=tinyint>TINYINT ';
 strSelect+='<OPTION value=int selected>INT  ';
 strSelect+='<OPTION value=bigint >BIGINT  ';
 strSelect+='<OPTION value=real >REAL  ';

 strSelect+='<OPTION value=date  >DATE   ';
 strSelect+='<OPTION value=datetime  >DATETIME   ';

 strSelect+='<OPTION value=varchar>VARCHAR ';
 strSelect+='<OPTION value=longtext>LONGTEXT ';
 strSelect+='<OPTION value=char>CHAR ';
 strSelect+='</SELECT> ';
 cell.innerHTML=strSelect;
 document.all.editDateType.focus();
}

//窗体,显示,html
function selectFormElementType(cell )
{
 strSelect='<SELECT id=editXType ONCLICK="event.cancelBubble = true;"';
 strSelect+='onChange="setCell(this.parentElement, this.value)"';
 strSelect+='ONBLUR="setCell(this.parentElement, this.value)"';
 strSelect+='<OPTION value= >无 ';
 strSelect+='<OPTION value=text >文本 ';
 strSelect+='<OPTION value=textarea >多文本 ';
 strSelect+='<OPTION value=hidden >隐藏文本 ';
 strSelect+='<OPTION value=password>密码 ';
 strSelect+='<OPTION value=select >下拉 ';
 strSelect+='<OPTION value=checkbox >多选 ';
 strSelect+='<OPTION value=radio >单选 ';
 strSelect+='<OPTION value="" selected>无 ';
 strSelect+='</SELECT> ';
 cell.innerHTML=strSelect;
 document.all.editXType.focus();
}

function show(obj){//by function selectValidate(cell )
 var str=''
 for (var i=0;i<obj.length;i++)
 {
  if (obj[i].selected)str+=str.length>0?','+obj[i].value:obj[i].value;
 }
 if (str.indexOf('none')>=0)str="";
 return str;
}
function selectValidate(cell )
{
 //设置验证属性
 strSelect='<SELECT MULTIPLE id=editValidate ONCLICK="event.cancelBubble = true;"';
 strSelect+='onChange="show(this);setCell(this.parentElement, show(this))"';
 strSelect+='onBlur="show(this);setCell(this.parentElement, show(this))"';
 strSelect+='<OPTION value="" >无 ';
 strSelect+='<OPTION value=optional  selected>非空 ';
 strSelect+='<OPTION value=numeric>数字';
 strSelect+='<OPTION value=email >Email ';
 strSelect+='<OPTION value=optional_x>非空没空格 ';
 strSelect+='<OPTION value=numeric_x>可空数字';
 strSelect+='<OPTION value=email_x >可空Email ';
 strSelect+='<OPTION value="" >无 ';
 strSelect+='</SELECT> ';
 cell.innerHTML=strSelect;
 document.all.editValidate.focus();
}
function setCell (cell, value) {cell.innerText = value}
function setNull(cell){cell.innerText=cell.innerText=='null'?'!null':'null';}

function insert_row(row)
{
 if(!check())return;
 newRow=row.cloneNode(true);
 row.parentNode.insertBefore(newRow,row);
 //设计缺省属性
 row.childNodes[Attr_Field].innerText='';
 row.childNodes[Attr_Description].innerText='';
 row.childNodes[Attr_DataType].innerText='varchar';
 row.childNodes[Attr_Attrs].innerText='';
 row.childNodes[Attr_Length].innerText='50';
 row.childNodes[Attr_NotNull].innerText='null';
 row.childNodes[Attr_Html].innerText='text';
 SetBackColor();

}
function delete_row(row){
 if(!prompt('你真要删除吗?'))return;
 if(row.parentNode.childNodes.length>2)row.parentNode.removeChild(row);
 SetBackColor()
}

/******************* 表格编辑类 结束 *********************************************/


/******************* 文件操作类 开始 *********************************************/
function getFolderPath(){//得到父路径
 var path=location.pathname
 if(path.indexOf('/')==0)path=path.substring(1,path.length)
 return path.substring(0,path.lastIndexOf('//'))
}

function setFileName(val){document.all.meta_data.childNodes[0].childNodes[1].childNodes[0].innerText=val;}
function setOpenHidden(){document.all.meta_data.childNodes[0].childNodes[1].childNodes[1].innerText='';}
function save_to_file()
{

 fso = new ActiveXObject("Scripting.FileSystemObject");
 strFileName=accMetaData(Meta_FileName);
 if(!strFileName){alert('请在元数据表中输入文件名!');return;}
 var path=getFolderPath()
 tf = fso.CreateTextFile(path+"//"+strFileName+".doc.html", true);
 tf.Write (Hhtml+document.all.div_edit.innerHTML);
 tf.Close();
}

function load_data(val)
{
 if(!val)return;
 fso = new ActiveXObject("Scripting.FileSystemObject");
 var path=getFolderPath()
 ts = fso.OpenTextFile(path+'//'+val+".doc.html", ForReading);

 str=ts.ReadAll()

 ts.Close()

 str=str.substring("<HTML><BODY><div id=div_edit>".length,str.length)+"<div>"
 document.all.div_edit.innerHTML=str;

 //accFileName(M);
 //setOpenHidden();
}
function getOpenFile(){
 var path=getFolderPath()
 path=path.replace(/[%20]/g,' ');
 fso = new ActiveXObject("Scripting.FileSystemObject");

 f = fso.GetFolder(path);
  fc = new Enumerator(f.files);
  s = "<option value=>";
  s += "<option value=>请选择";
  for (; !fc.atEnd(); fc.moveNext())
  {
  xxxm=""+fc.item()
  if(xxxm.lastIndexOf('.doc.html')==(xxxm.length-'.doc.html'.length)){//if(~):~去掉了.bak
   xname=xxxm.substring(xxxm.lastIndexOf("//")+1,xxxm.length-9)
   s+="<option value="+xname+">"+xname;
  }
 }
 return s;
}
function openFile(cell){
 strSelect='<SELECT id=openFile ONCLICK="event.cancelBubble = true;"';
 strSelect+='onChange="load_data(this.value)"';
 strSelect+='onBlur="setCell(this.parentElement,/'/')"';

 //strSelect+='ONBLUR="load_data(this.value)"';

 strSelect+=getOpenFile();
 strSelect+="</SELECT>";
 cell.innerHTML=strSelect;
 document.all.openFile.focus();
}
/******************* 文件操作类 结束 *********************************************/
/******************* 检查完整类 开始 *********************************************/

function check(){
try{
 msg="";
 var table=document.all.tedit;
 var objRows=table.childNodes[0].childNodes;
 iRows=objRows.length;
 row=objRows[iRows-1];
 for(var i=0;i<row.childNodes.length;i++)
 {
  row.childNodes[i].innerText=row.childNodes[i].innerText.Trim()
 }
 if(!row.childNodes[Attr_Field].innerText){msg+='未行第一列"字段名"不可为空!/n';}
 if(!row.childNodes[Attr_Description].innerText){msg+='未行第二列"中文说明"不可为空!/n';}
 if(!row.childNodes[Attr_DataType].innerText){msg+='未行第三列"数据类型"不可为空!/n';}
 if(!(row.childNodes[Attr_DataType].innerText.indexOf("har")==-1)&&!
  /^[1-9][0-9]*[0-9]$/.test(row.childNodes[Attr_Length].innerText))
  {msg+='未行第四列"数据类型长度"不可为空并且只能是数字!/n';}
 if(!!msg)msg+="请删除或修改未行";
 if(!!msg){alert(msg);return false;}
 return true;
}catch(e){alert("function check"+'/n/r错误'+e)}
}

/******************* 检查完整类 结束 *********************************************/
/******************* 生成结果类 开始 *********************************************/
function create_form()
{
 if(!check())return;
 strScript='';
 var strForm='METHOD=POST ACTION=<?=$ME_ALL?> >/n<INPUT TYPE="hidden"name="cmd"value=<?pv($cmd)?>>/n<TABLE>/n';
 var table=document.all.tedit;
 var objRows=table.childNodes[0].childNodes;
 var strOnSubmit='';
 iRows=objRows.length;
 iCols=objRows[0].childNodes.length;
 for (var i=1;i<iRows;i++){
  Row=objRows[i]; 
  Cells=Row.childNodes;
  if(!Cells[Attr_Html].innerText)continue;
  if(Cells[Attr_Html].innerText=='hidden')strIsDisplay=' style="display:none;"';
  else strIsDisplay='';
  strForm+='/t<TR '+strIsDisplay+'>/n/t/t<TD>'+Cells[Attr_Description].innerText+'</TD>/n/t/t<TD>/n/t/t';
  strValue=" VALUE=/'<?pv($frm['"+Cells[Attr_Field].innerText+"'])?>/'";
  strValuex="<?pv($frm['"+Cells[Attr_Field].innerText+"'])?>";
  switch(Cells[Attr_Html].innerText)
  {
   case 'text':
   case 'textarea':
    temp=parseInt(Cells[Attr_Length].innerText)
    maxlength=temp>0? " maxLength="+temp :" ";
    if(temp>50||Cells[Attr_Html].innerText=='textarea')
    {
     strForm+='/t<TEXTAREA ROWS="3" COLS="60" '+ maxlength+" ";
     strForm+='NAME= '+Cells[Attr_Field].innerText+'>'+strValuex+'</TEXTAREA>/n/t/t</TD>/n/t</TR>/n'; 
    }else
    strForm+='/t<INPUT TYPE=text  NAME='+Cells[Attr_Field].innerText+maxlength +strValue+">/n/t/t</TD>/n/t</TR>/n";

    break;
   case 'password':
    strForm+='/t<INPUT TYPE="password" NAME='+Cells[Attr_Field].innerText+maxlength+ strValue+">/n/t/t</TD>/n/t</TR>/n";
    break;
   case 'checkbox':
    strForm+='/t<INPUT TYPE=checkbox NAME='+Cells[Attr_Field].innerText+">/n/t/t</TD>/n/t</TR>/n";
    break;
   case 'radio':
    strForm+='/t<INPUT TYPE=radio NAME='+Cells[Attr_Field].innerText+">/n/t/t</TD>/n/t</TR>/n";
    break;
   case 'hidden':
    strForm+='/t<INPUT TYPE="hidden" NAME='+Cells[Attr_Field].innerText+strValue+">/n/t/t</TD>/n/t</TR>/n";
    break;
   case 'select':
    strForm+='/t<SELECT NAME='+Cells[Attr_Field].innerText;
    strForm+="><OPTION VALUE=''>请选择</SELECT>/n/t/t</TD>/n/t</TR>/n";
    break;
  }
  switch(Cells[Attr_Validate].innerText)
  {
   case '':
   case null:
    break;
   case 'optional':
    strOnSubmit+="/nthis."+Cells[Attr_Field].innerText+".description='"+Cells[Attr_Description].innerText+"';";
    strOnSubmit+="/nthis."+Cells[Attr_Field].innerText+".optional=true";
    break;
   case 'numeric':
    strOnSubmit+="/nthis."+Cells[Attr_Field].innerText+".description='"+Cells[Attr_Description].innerText+"';";
    strOnSubmit+="/nthis."+Cells[Attr_Field].innerText+".numeric=true";
    break;
   case 'email':
    strOnSubmit+="/nthis."+Cells[Attr_Field].innerText+".description='"+Cells[Attr_Description].innerText+"';";
    strOnSubmit+="/nthis."+Cells[Attr_Field].innerText+".email=true";
    break;
  }
 
 }
strOnSubmit="";
 if(strOnSubmit)strOnSubmit='<FORM onSubmit="'+strOnSubmit+"/nreturn verify(this)/"/n";
 else strOnSubmit+='<FORM ';
 strForm+='<TR><TD><INPUT TYPE="submit"VALUE="提交">/n</TD><TD><INPUT TYPE="reset"VALUE="重置"></TD><TR>';
 strForm+="/n</TABLE>/n</FORM>";
 strForm=strScript+strOnSubmit+strForm
 return strForm;
}
function CreateValidate()
{
 if(!check())return;
 var strValidate='function validate_form(&$frm) {/n/t$strMsg="";/n/t';
 var table=document.all.tedit;
 var objRows=table.childNodes[0].childNodes;
 iRows=objRows.length;
 iCols=objRows[0].childNodes.length;

 for (var i=1;i<iRows;i++){
  Row=objRows[i]; 
  Cells=Row.childNodes;
  //if(!Cells[Attr_Field].innerText.toUpperCase=='ID')continue;
  if(!Cells[Attr_Validate].innerText)continue;
  _Field=Cells[Attr_Field].innerText
  _Name=Cells[Attr_Description].innerText
  switch(Cells[Attr_Validate].innerText)
  {
   case '':
   case null:
    break;
   case 'optional':
    strValidate+="if(empty($frm['"+_Field+"'])){/n/t/t$strMsg.='<LI>"+_Name+"不可为空,请您检查';/n/t}/n/t"
    break;
   case 'numeric':
    strValidate+="if(!is_numeric($frm['"+_Field+"'])){/n/t/t$strMsg.='<LI>"+_Name+"应为数字,请您检查';/n/t}/n/t"
    break;
   case 'email':
    strValidate+="if(!IsEmail($frm['"+_Field+"'])){/n/t/t$strMsg.='<LI>"+_Name+"邮件格式不对,请您检查';/n/t}/n/t"
    break;
  }
 }
 strValidate+="if(!empty($strMsg))return $strMsg;else return 0; /n}/n"
 return strValidate;
}
function accMetaData(i,val)// by function create_DDL()

 var e=document.all.meta_data.childNodes[0].childNodes[1].childNodes[i];
 if(!val)return e.innerText;
 else e.innerText=val;return i;
}

function trim_comma(val)
{
 return val.substring(0,val.lastIndexOf(','))
}

function create_DDL(type)
{
 var strCreateTableName=accMetaData(Meta_TableName);
 var strCreateTable="Drop  TABLE "+strCreateTableName+"/n/n"
 strCreateTable+="CREATE  TABLE "+strCreateTableName+"(/n";
 var strUpdate="UPDATE "+strCreateTableName+" SET/n";
 var strInsertBefore="INSERT INTO "+strCreateTableName+"(/n";
 var strInsertAfter="/n)VALUES(/n";
 var strWhere="/nWHERE id=$id";
 if(!check())return;
 if(!strCreateTableName){alert('请在第一个表元数据中输入表名');return}
 var table=document.all.tedit;
 var objRows=table.childNodes[0].childNodes;
 iRows=objRows.length;
 iCols=objRows[0].childNodes.length;

 for (var i=1;i<iRows;i++){
  Row=objRows[i];
  _FiledName=Row.childNodes[Attr_Field].innerText//取得字段名称
  _DataType=Row.childNodes[Attr_DataType].innerText//取得数据类型
  _DataLength=Row.childNodes[Attr_Length].innerText//取得数据长度
  _NotNull=Row.childNodes[Attr_NotNull].innerText//取得
  _Attrs=Row.childNodes[Attr_Attrs].innerText
  _IsClient=!!(Row.childNodes[Attr_Html].innerText)
  _DefaultText=Row.childNodes[Attr_Default].innerText;//缺省值(写入缺省和数据缺省)
  _DefaultVale=((_DefaultText.length>0) &&(!_IsClient))?_DefaultText:"";//客户端没有显示,且是是缺省值
  _Default=_DefaultText.length>0?" DEFAULT "+_DefaultText+" ":"";
  //alert(_Default+"|"+_DefaultText)
  if((_FiledName!='id')&&(_IsClient))
  {
   //得到Update Sql 语句
   if((_DataType.indexOf('char')>=0)||(_DataType.indexOf('text')>=0)||
   (_DataType.indexOf('area')>=0)||(_DataType.indexOf('date')>=0))
    strUpdate+="/t"+_FiledName+"='$frm["+_FiledName+"]',/n";
   else strUpdate+="/t"+_FiledName+"=$frm["+_FiledName+"],/n";
  }  
  if(_FiledName!='id'){////得到 Insert Sql 语句
   strInsertBefore+="/t"+_FiledName+",/n";
   if((_DataType.indexOf('char')>=0)||(_DataType.indexOf('text')>=0)
    ||(_DataType.indexOf('area')>=0))//||(_DataType.indexOf('date')>=0)
    strInsertAfter+=_DefaultVale?"/t/'"+_DefaultVale+"',/n":"/t/'$frm["+_FiledName+"]',/n";
   else strInsertAfter+=_DefaultVale?"/t"+_DefaultVale+",/n":"/t$frm["+_FiledName+"],/n";
  }
  switch(_DataType)
  {
   case 'char':
   case 'varchar':
    strCreateTable+="/t"+_FiledName+' '+_DataType+"("+_DataLength+")"+_Default;
    strCreateTable+=_NotNull.indexOf('null')>0?" not null ,/n":",/n"
    continue;
   default:
    strCreateTable+="/t"+_FiledName+' '+_DataType+_Default;
    if(_Attrs.indexOf('pk')>=0){strCreateTable+=" PRIMARY KEY ";}
    if(_Attrs.indexOf('++')>=0)strCreateTable+=" AUTO_INCREMENT ";
    strCreateTable+=_NotNull.indexOf('null')>0?" not null ,/n":",/n"
    continue;
  }
  
 }
 strCreateTable = trim_comma(strCreateTable);
 strUpdate = trim_comma(strUpdate);
 strInsertBefore = trim_comma(strInsertBefore);
 strInsertAfter = trim_comma(strInsertAfter);
 strUpdate+=strWhere;
 strInsert=strInsertBefore+strInsertAfter+")";
 
 strCreateTable+="/n)"
 strDDL=strCreateTable+"/n/n"+strUpdate+"/n/n"+strInsert

 if(!type)return strDDL;
 if(type.indexOf('sert')>0)return strInsert;
 if(type.indexOf('pdat')>0)return strUpdate;
}
function getVadateFunction(){return CreateValidate();}
function gerInsertFunction()
{
 sql=create_DDL('Insert');
 sql=sql.replace(//n/g,'/n/t');
 str="function Insert($frm)/n{/n";
 str+="/t$sql=/""+sql+"/";/n"
 str+="/tdb_query($sql);/n}/n/n"
 return str;
}
function getSqlUpdate()
{
 sql=create_DDL('Update');
 sql=sql.replace(//n/g,'/n/t')
 return sql;
}

function CreateAddFile()
{
 var strScriptName=accMetaData(Meta_TableName);
 var strAddHeader="<?php/n/**/nMAIN  "+getTime()+"/n**//n/n";
 var strAddIsPostBack="include(/"../application.php/");/n/nrequire_login();/n/n";
 strAddIsPostBack+="if (match_referer() && isset($HTTP_POST_VARS)) {/n/t";
 strAddIsPostBack+="$frm = $HTTP_POST_VARS;/n/n/t";
 strAddIsPostBack+="$errValidate = validate_form($frm);/n/t";
 strAddIsPostBack+="if (empty($errValidate)) {;/n/t/t";
 strAddIsPostBack+="Insert($frm);/n/t/t";
 strAddIsPostBack+="$NoticeMsg = '添加成功';/n/t/t//Redirect($url, $message=/"/", $delay=0) {/n/t/t";
 //strAddIsPostBack+="//include(/"$CFG->phpdir/header.php/");/n/t";
 //strAddIsPostBack+="//include(/"templates/"+strScriptName+"_form.php/");/n/t";
 //strAddIsPostBack+="//include(/"$CFG->templatedir/footer.php/");/n/t";
 strAddIsPostBack+="die;/n/t}/n}/n/n"
 var strAddNoPostBack=''//"//include(/"$CFG->templatedir/header.php/");/n";
 //strAddNoPostBack+="//include(/"$CFG->templatedir/form_header.php/");/n";
 strAddNoPostBack+="include(/"$CFG->tmpdir/form_header.php/");/n";
 strAddNoPostBack+="include(/"templates/"+strScriptName+"_form.php/");/n";
 //strAddNoPostBack+="//include(/"$CFG->templatedir/footer.php/");/n";
 var strFunction="/**/nFUNCTION/n**//n/n"
 var strValidateFunction=getVadateFunction()
 var strInsertFunction=gerInsertFunction()
 strFunction+=strValidateFunction+strInsertFunction
 var strMain=strAddHeader+strAddIsPostBack+strAddNoPostBack
 var strAdd=strMain+strFunction+"/n?>";
 return strAdd;

}

function CreateUpdateFile()
{
 var strScriptName=accMetaData(Meta_TableName);
 var strUpdateMain="<?php/n/**/nMAIN  "+getTime()+"/n**//n/ninclude_once(/"/././web.conf.php/");/nrequire_login();/n/n";
 strUpdateMain+="if (match_referer() && isset($HTTP_POST_VARS)) {/n/t";
 strUpdateMain+="$frm = $HTTP_POST_VARS;/n/n/t";
 strUpdateMain+="$errValidate = validate_form($frm);/n/t";
 strUpdateMain+="if (empty($errValidate)) {/n/t/t";
 strUpdateMain+="Update($frm);/n/t/t";
 strUpdateMain+="$NoticeMsg = '修改成功';/n/t/t//goback/n/t/t";
 strUpdateMain+="die;/n/t}/n}/n/n/t/nelse $frm=LoadData();/n/n";
 strUpdateMain+="include(/"$CFG->tmpdir/form_header.php/");/n";
 strUpdateMain+="include(/"templates/"+strScriptName+"_form.php/");/n";
 var strLoadDataFun="function LoadData(){/n/t";
 strLoadDataFun+="global $SESSION;/n/t";
 strLoadDataFun+="$id=$SESSION['user']['id'];/n/t"
 strLoadDataFun+='$sql="select * from '+strScriptName+' where id=$id";/n/t';
 strLoadDataFun+="$qid= db_query($sql);/n/t";
 strLoadDataFun+="return DbFetchArray($qid);/n}/n/n";

 var strUpdateFun="function Update($frm){/n/t";
 strUpdateFun+="global $SESSION;/n/t";
 strUpdateFun+="$id=$SESSION['user']['id'];/n/t";
 strUpdateFun+="$sql=/""+getSqlUpdate()+"/";/n/t";
 strUpdateFun+="return db_query($sql);/n}/n/n";

 var strValidateFun=getVadateFunction()
 var strUpdateFunction="/**/nFUNCTION/n**//n/n"
 strUpdateFunction+=strValidateFun+strLoadDataFun+strUpdateFun
 var strUpdate=strUpdateMain+strUpdateFunction +"?>"
 return strUpdate;
}

function create_Doc(val)
{
 FolderName="templates"
 val=accMetaData(Meta_TableName)
 if(!val)return;
 var CurFolderPath=getFolderPath()

 fso = new ActiveXObject("Scripting.FileSystemObject");
 FolderPath=CurFolderPath+"//"+FolderName+'//';
 var blnExists=fso.FolderExists(FolderPath)
 if(!blnExists)fso.CreateFolder(FolderPath);
 
 tf = fso.CreateTextFile(FolderPath+val+"_form.php", true);
 tf.Write (create_form());
 tf.Close();

 tf = fso.CreateTextFile(FolderPath+val+".sql", true);
 tf.Write (create_DDL());
 tf.Close();

 tf = fso.CreateTextFile(CurFolderPath+"//"+val+"_add.php", true);
 tf.Write (CreateAddFile());
 tf.Close();

 tf = fso.CreateTextFile(CurFolderPath+"//"+val+"_update.php", true);
 tf.Write (CreateUpdateFile());
 tf.Close();

}
/******************* 生成结果类 结束 *********************************************/

//-->
</SCRIPT>
<INPUT TYPE="button"value="保存"onclick=save_to_file()>

<INPUT TYPE="button"value="生成"onclick=create_Doc()>

<SCRIPT LANGUAGE="JavaScript">
function create_new()
{
 var doc_main=document.all.tblMain
 var tempDoc=doc_main.childNodes[0]
 var newDoc=tempDoc.cloneNode(true);
 doc_main.insertBefore(newDoc,tempDoc);
}

function textstyle(obj) {
 if(obj.type=="button"||obj.type=="submit"||obj.type=="reset"){
  obj.style.fontWeight="bold";
  obj.style.backgroundColor="#6699CC";
  obj.style.borderTopColor="#66CCCC";
  obj.style.borderBottomColor="#66FFCC";
  obj.style.borderLeftColor="#66CCCC";
  obj.style.borderRightColor="#66FFCC";
 }
}

</SCRIPT>
<div id=div_save></div>
<SCRIPT LANGUAGE="JavaScript" defer=true>
function SetBackColor(){
 var table=document.all.tedit;
 var objRows=table.childNodes[0].childNodes;
 var tag=0;
 for (var i=0;i<objRows.length;i++){
  e=objRows[i]
  if(tag==0){
   e.style.backgroundColor='#FFFFF7';
   tag=1;
  }else {
   tag=0;
   e.style.backgroundColor='#FEFDE0';
  }
 }
}
SetBackColor();
</SCRIPT>

0 0

相关博文

我的热门文章

img
取 消
img