<?php
require('../../../Test/Common/Component/ComInitialHead.php');

set_time_limit(120);

class PaDefault extends CustomPage {
	public $sProductData=array();
	
	public function PaDefault(){
		$this->CustomPage();
		$this->sysMetaTitle='生成数据结构描述表文件';
	}
	public function makeDbDescription(){
		$this->sDb=new netsDb('localhost,3306,root,K3FCJKDX9WOEA5HZ,information_schema,gb2312');
		$tmpDbName='nets_installtest';
		$tmpSQL=' SELECT
			A.TABLE_SCHEMA,A.TABLE_NAME
			FROM TABLES AS A
			WHERE A.TABLE_SCHEMA LIKE \''.$tmpDbName.'\'; ';
		$tmpDataCollection0=$this->sDb->Search($tmpSQL);
		$Coun0=0;
		foreach ($tmpDataCollection0 as $Row0){
			$tmpTablename=$Row0['TABLE_NAME'];
			//$tmpTablename=str_replace($this->sysTableHead,'{NetsInstall.Db_Tablehead}',$Row0['TABLE_NAME']);
			$tmpSQL=' SELECT
				A.TABLE_NAME,A.COLUMN_NAME,A.DATA_TYPE
				FROM COLUMNS AS A
				WHERE A.TABLE_NAME LIKE \''.$Row0['TABLE_NAME'].'\' AND TABLE_SCHEMA LIKE \''.$tmpDbName.'\' ; ';
			$tmpDataCollection1=$this->sDb->Search($tmpSQL);
			$tmpSTR='<?php
//-- ------ #'.$tmpTablename.' ------ --
$sysDbDescriptions[\''.$tmpTablename.'\']=array(
	\'TableDescription\'=>array(
';		
			$Coun1=0;
			foreach ($tmpDataCollection1 as $Row1){
				if($Coun1==0){
$tmpSTR.='		\'sttTableName\'=>\''.$tmpTablename.'\',\'sttColumnHead\'=>\''.str_replace('ID','',$Row1['COLUMN_NAME']).'\',\'sttType\'=>\'0\',\'sttIntroduct\'=>\'0\',\'SearchColumn\'=>\'SearchColumn,\',
	),
	\'Columns\'=>array(
';
					$tmpSTR.='//#'.$Row1['COLUMN_NAME'].'
\''.$Row1['COLUMN_NAME'].'\'=>array(\'stcotName\'=>\''.$Row1['COLUMN_NAME'].'\',\'stcoctDbType\'=>\'Int\',\'stcoctDbLen\'=>\'11\',\'stcoctDbIsKey\'=>\'1\',\'stcoctUiType\'=>\'Text\',\'stcoctDefaultValue\'=>\'0\',\'Value\'=>\'0\',),
';
				}else {
					if($Row1['DATA_TYPE']=='varchar' || $Row1['DATA_TYPE']=='text'){
						$tmpSTR.='//#'.$Row1['COLUMN_NAME'].'
\''.$Row1['COLUMN_NAME'].'\'=>array(\'stcotName\'=>\''.$Row1['COLUMN_NAME'].'\',\'stcoctDbType\'=>\'Text\',\'stcoctDbLen\'=>\'180\',\'stcoctDbIsKey\'=>\'0\',\'stcoctUiType\'=>\'Text\',\'stcoctDefaultValue\'=>\'0\',\'Value\'=>\'-\',),
';
					}else if($Row1['DATA_TYPE']=='int' || $Row1['DATA_TYPE']=='int'){
						$tmpSTR.='//#'.$Row1['COLUMN_NAME'].'
\''.$Row1['COLUMN_NAME'].'\'=>array(\'stcotName\'=>\''.$Row1['COLUMN_NAME'].'\',\'stcoctDbType\'=>\'Int\',\'stcoctDbLen\'=>\'11\',\'stcoctDbIsKey\'=>\'0\',\'stcoctUiType\'=>\'Text\',\'stcoctDefaultValue\'=>\'0\',\'Value\'=>\'0\',),
';
					}else if($Row1['DATA_TYPE']=='decimal' || $Row1['DATA_TYPE']=='decimal'){
						$tmpSTR.='//#'.$Row1['COLUMN_NAME'].'
\''.$Row1['COLUMN_NAME'].'\'=>array(\'stcotName\'=>\''.$Row1['COLUMN_NAME'].'\',\'stcoctDbType\'=>\'Decimal\',\'stcoctDbLen\'=>\'11\',\'stcoctDbIsKey\'=>\'0\',\'stcoctUiType\'=>\'Text\',\'stcoctDefaultValue\'=>\'0\',\'Value\'=>\'0\',),
';
					}else if($Row1['DATA_TYPE']=='datetime'){
						$tmpSTR.='//#'.$Row1['COLUMN_NAME'].'
\''.$Row1['COLUMN_NAME'].'\'=>array(\'stcotName\'=>\''.$Row1['COLUMN_NAME'].'\',\'stcoctDbType\'=>\'Datetime\',\'stcoctDbLen\'=>\'0\',\'stcoctDbIsKey\'=>\'0\',\'stcoctUiType\'=>\'Text\',\'stcoctDefaultValue\'=>date(\'Y-m-d H:i:s\'),\'Value\'=>date(\'Y-m-d H:i:s\'),),
';
					}
				}
				$Coun1++;
			}
$tmpSTR.='
)); ?>';
			
			$tmpTablename=str_replace($this->sysTableHead,'',$Row0['TABLE_NAME']);
			$this->writeFile('../../../Cache/DbDescription/'.$tmpTablename.'.php',$tmpSTR);
			$Coun0++;
		}
	}
}
//-- ------ #Instanct ------
$tmpDefault=new PaDefault();
$tmpDefault->sysMetaTitle.=' - '.$tmpDefault->sysFileConfig['sysTitle'];
require('../../../Template/Test/m_default/Component/Head_0.php');
$tmpDefault->makeDbDescription(); ?>
<div class="TestContent0">目的：</div>
<div class="TestContent1">生成数据结构描述表文件。</div>
<div class="TestContent0">结果：</div>
<div class="TestContent1">生成成功。</div>
<?php require('../../../Template/Test/m_default/Component/End_0.php'); ?> 