예제 #1
0
/*
	PasteCol 表名 源列名称 目标列名称
 */
bool TCManager::PasteCol(TCPacket &inP,AnaWord &aw, TCPacket &outP)
{
	if (aw.GetWordCount() !=4)
		return SetResultState(false,outP,GetLanguage(FormatIsError)); 

	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
	
	string sTableName = aw.GetAt(1);
	string sSrcName  = aw.GetAt(2);
	string sDstName  = aw.GetAt(3);
	CDataInterface *pDI = g_system.GetCurData(nUserID,aw.GetAt(1));
	if (pDI == NULL)
		return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
	CField *pSrcField = pDI->FieldByName(sSrcName.c_str());
	if (pSrcField == NULL)
		return SetResultState(false,outP,GetLanguage(FieldNameNotFind)); 
	CFieldType ft = pSrcField->GetFieldType();
	CField *pDstField = pDI->FieldByName(sDstName.c_str());
	if (pDstField == NULL)
	{
		pDstField = pDI->m_DataAccess.m_pFieldList->CreateField(ft);
		pDstField->SetFieldName(sDstName);
		pDstField->SetWidth(pSrcField->GetWidth());
		pDI->m_DataAccess.m_pFieldList->Add(pDstField);
	}
	pDI->m_DataAccess.First();
	while (!pDI->m_DataAccess.Eof())
	{
		pDI->m_DataAccess.Edit();
		if (pSrcField->IsNull())
		{
			pDstField->SetNull();
		}
		else
		{
			if (ft == fDouble)
				pDstField->SetAsDouble(pSrcField->GetAsDouble());
			else if (ft == fInt)
				pDstField->SetAsInteger(pSrcField->GetAsInteger());
			else if (ft == fBoolean)
				pDstField->SetAsBool(pSrcField->GetAsBool());
			else if (ft == fString)
				pDstField->SetAsString(pSrcField->GetAsString());
			else
				pDstField->SetAsDateTime(&pSrcField->GetAsDateTime());
		}
		pDI->m_DataAccess.Next();
	}
	return SetResultState(true,outP);
}
예제 #2
0
/*
	EditCol 表名 所在列号 {字段名A 类型 长度}
	列号是从0开始(-1表示从后面追加),类型表示,s 字符串 d 日期类型 n 数字类型
 */
bool TCManager::EditCol(TCPacket &inP,AnaWord &aw, TCPacket &outP)
{
	if (aw.GetWordCount()%3 !=0)//保证是3的整数倍
		return SetResultState(false,outP,GetLanguage(FormatIsError)); 

	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));

	CDataInterface *pDI = g_system.GetCurData(nUserID,aw.GetAt(1));
	if (pDI ==NULL)
		return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
	

	string sColStart = aw.GetAt(2);
	int nColStart = atoi(sColStart.c_str());
	if (nColStart<0 || nColStart+aw.GetWordCount()/3-1 > pDI->GetColCount())
		return SetResultState(false,outP,GetLanguage(ColIndexOutOfRangeFail)); 

	for (int i=1;i<	aw.GetWordCount()/3 ;i++)
	{
		string sName =aw.GetAt(i*3+0);
		string sType =aw.GetAt(i*3+1);
		string sLength =aw.GetAt(i*3+2);
		CFieldType ft = fDouble;
		if (sType == "s" || sType == "S")
			ft = fString;
		else if (sType == "d" || sType == "D")
			ft = fDate;
		else if (sType == "n" || sType == "N")
			ft = fInt;
		else if (sType == "f" || sType == "F")
			ft = fDouble;
		else if (sType == "b" || sType == "B")
			ft = fBoolean;

		CField *pField = pDI->m_DataAccess.m_pFieldList->CreateField(ft);
		pField->SetWidth(atoi(sLength.c_str()));
		//pDI->m_DataAccess.m_pFieldList->Insert(pField,nColStart++);
		pDI->m_DataAccess.m_pFieldList->Modify(nColStart++,pField);
		if (pField->SetFieldName(sName)==false)
			return SetResultState(false,outP,GetLanguage(SetFieldNameFail));
	}


	return SetResultState(true,outP);
}
예제 #3
0
/************************************************************************************
函数名称:
CField* CFields::NewFieldType(CFieldType chType)
功能说明:根据传入的字段类型生成相应的字段类型.

详细解释:1.返回新生成的字段.
          2.如果传入的chType无效,则返回NULL.
    
出入参数:
[in]: 1.chType:传入的字段类型.    
     
[out]:无.

返回类型:CField*

制作:YTLI   2002/07/15

修改: 
***********************************************************************************/
CField* CFields::NewFieldType(CFields* pOwner ,CFieldType chType)
{
	CField* pField = NULL;//如果传入的chType无效,则返回NULL.

	switch(chType)
	{
	case fString :
		pField = new CStringField(this);
		break;
	case fDouble  :
		pField = new CDoubleField(this);
		break;
	case fInt :
		pField = new CIntField(this);
		break;
	case fBoolean :
		pField = new CBooleanField(this);
		break;
	case fDate :
		pField = new CDateField(this);
		break;
	case fCurrency :
		pField = new CCurrencyField(this);
		break;
	}
	
	CTString str;//###_Mod 2002-9-24 zlq  缺省字段名
	int nCount = m_FieldVersion.GetAbsoluteFieldCount();
	do
	{//#_S 2003-5-28 $ 9 zlq 确保生成时,就唯一
		str.Format("%d",nCount+1);
		while (str.GetLength()<4)
		{//#_修改 2002-11-15 $ 9:15:44 zlq
			str = "0"+str;
		}
		str = "变量" +str;
		nCount++;
	}while (FieldByName(str)!=NULL);
	pField->SetFieldName(str);
	pField->m_pFields = pOwner;
	return pField ;
}
예제 #4
0
void CMarkovChain::DrawResult()
{
	if (m_nTotalID > 1000 || m_bSaveData)
	{
		//在主界面输出聚类结果
		int i;
		CDataAccess DataAcc;
		CField *pUserIdNum = DataAcc.m_pFieldList->CreateField(fInt);
		CField *pCluster = DataAcc.m_pFieldList->CreateField(fInt);
		pUserIdNum->SetFieldName("用户序号");
		pCluster->SetFieldName("分类结果");
		DataAcc.m_pFieldList->Add(pUserIdNum);
		DataAcc.m_pFieldList->Add(pCluster);
		for ( i=0; i<m_nTotalID; i++)
		{
			DataAcc.Append();
			pUserIdNum->SetAsInteger(i+1);
			pCluster->SetAsInteger(m_VecClus(i) );
		}
		BOOL bSucSave;//保存文件
		CTString NoUse, FileName;
		if (m_bSaveData)
		{
			bSucSave = DataAcc.SaveFile(m_DataFile, &NoUse);
			FileName = m_DataFile;
		}
		else
		{
			CTString strOutNameTemp = "_马尔可夫链聚类结果";
			CTString strOrgNameTemp = m_pDataInterface->m_DataAccess.GetFileName();
			FileName = CFileReadWrite::GetSaveFileName(strOrgNameTemp, strOutNameTemp);
			bSucSave = DataAcc.SaveFile(FileName, &NoUse);
		}

		CRsltElementText * pWarningTextRslt = new CRsltElementText( "马尔可夫链分类结果" );
		CTString strWarn;
		if (bSucSave)
			strWarn = "模型运行结束,结果已经成功输出到"+FileName+"文件里。";
		else
			strWarn = "模型运行结束,结果已经成功输出到"+NoUse+"文件里。";
		pWarningTextRslt->AddString(strWarn);
		m_pResult->Add( pWarningTextRslt );
		return;
	}
	else
	{
		CTLTable * pTable = new CTLTable;
		CRsltElementTable * pETable = new CRsltElementTable("马尔可夫链分类结果",pTable);//申请一个表对象类的对象
		pTable->CreateTable(2, 2);
		pTable->SetTitle("马尔可夫链分类情况");

		pTable->SetCols(2);
		pTable->SetRows(m_nTotalID+1);
		pTable->InsertColumn(0,"用户序号");
		pTable->InsertColumn(1,"分类结果");
		CTString str;
		for(int i=0;i<m_nTotalID;i++)
		{
			str.Format("%d",i+1);
			pTable->InsertItem(i,str);
			pTable->SetItemText(i, 1, m_VecClus(i) );
		}
		m_pResult->Add(pETable);
		return;
	}
}