/************************************************************************************
函数名称:
	CFieldList::Modify
功能说明:
	修改一个字段
详细解释:

出入参数:
	[in,out]nIndex:旧字段的位置
	[in,out]pField :新的字段
返回类型:

制作:
	Eric 2002-9-4
修改:

************************************************************************************/
bool CFieldList::Modify(int nIndex,CFieldType NewFieldType)
{
	CField *pField = this->FieldByIndex(nIndex);
	if (pField ==NULL)
		return false;
	if (pField->GetFieldType() == NewFieldType)
		return true;
	CField* pNewField=CreateField(NewFieldType);
	pNewField->CopyCommonProperty(pField);
	Modify(IndexOf(pField),pNewField);
	return true;
}
Beispiel #2
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);
}
Beispiel #3
0
/*
#获取字段和记录信息 文件名没有,则返回当前表信息
>Command
	Text
		GetDataInfo 表名
<Command
	Text
		ColInfo	列信息
		Fail 错误信息
 */
bool TCManager::GetDataInfo(TCPacket &inP,AnaWord &aw,TCPacket &outP)
{
	if (aw.GetWordCount()!=2)
		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));
	}

	CDataAccess &da = pDI->m_DataAccess;

	
	string strScript ;
	int nCnt = da.GetRecordCount();
	char  buffer[50];
	memset(buffer,0,50);
	sprintf(buffer,"%d",nCnt);
	string sRecordCount = buffer;
	for (int i=0;i<da.GetFieldCount();i++)
	{
		CField *pField = da.FieldByIndex(i);
		string ss = (const char*)pField->GetFieldName();				
		ss = AnaWord::GetUniquely(ss);
		CFieldType ft = pField->GetFieldType();
		if (ft ==fString )
			ss = ss + " s ";
		else if (ft == fDate)
			ss = ss + " d ";
		else if (ft == fInt)
			ss = ss + " n ";
		else if (ft == fDouble)
			ss = ss + " f ";
		else if (ft == fBoolean)
			ss = ss + " b ";
		
		char buf[10];
		sprintf(buf," %d ",pField->GetWidth());
		string sWidth = buf;
		strScript = strScript+ " "+ ss +sWidth;
	}
	sRecordCount = "ColInfo "+sRecordCount + strScript;
	outP.AddItem("Text",sRecordCount);
	return SetResultState(true,outP);
}
Beispiel #4
0
//字段类型修改
void CFields::Modify(int nIndex, CField* pNewField)
{	
	m_FieldVersion.Modify(nIndex,FieldByIndex(nIndex), pNewField);
///////////////////////////////////////////////{{lps added.2003/02/18
	CField* pOldFld = FieldByIndex(nIndex);

	LPBYTE pOldValue = pNewField->m_pValue;

	POSITION posData = pNewField->m_ValueLabel.m_DataList.GetHeadPosition();	
	
	while(posData)
	{
		pNewField->m_pValue = (LPBYTE)pNewField->m_ValueLabel.m_DataList.GetNext( posData );
		pNewField->RealDeleteData();	
	}
	pNewField->m_ValueLabel.m_DataList.RemoveAll();
	pNewField->m_ValueLabel.m_strLabelList.RemoveAll();

	posData = pOldFld->m_ValueLabel.m_DataList.GetHeadPosition();
    int posStr  = pOldFld->m_ValueLabel.m_strLabelList.GetSize();
    int nPos = 0;
	while(posData != NULL && nPos < posStr)
	{

 		LPBYTE pData = (LPBYTE)pOldFld->m_ValueLabel.m_DataList.GetNext( posData );
		CTString strLabel = pOldFld->m_ValueLabel.m_strLabelList.GetAt(nPos);
		pOldFld->m_ValueLabel.m_pField->m_pValue = pData;//~~~~~~~~~~~~~~~~~~~~~~~~~
		pNewField->RealNewData();
		//从日期字段转化到其他类型,或者从其他字段转化到日期字段.
		if((pOldFld->GetFieldType() == fDate)
			||(pNewField->GetFieldType() == fDate))
		{
			FILETIME ftValue = pOldFld->m_ValueLabel.m_pField->GetAsDateTime();
			//填入不成功,则m_pValue无效.
			if(!pNewField->SetAsDateTime(&ftValue))
			{
				pNewField->m_pValue = pOldValue;
				pNewField->RealDeleteData();
				continue;
			}
		}
		else
		{
			CTString strr = pOldFld->m_ValueLabel.m_pField->GetAsString();
			//填入不成功,则m_pValue无效.此时的原则:留下可以转换的,抛弃无法转化的.
			//比如fString型串"2002/01/30"转换为fInt,fDouble等时将为false.
			if(!pNewField->SetAsString(strr))
			{
				pNewField->m_pValue = pOldValue;
				pNewField->RealDeleteData();
				continue;
			}
		}
	
		pNewField->m_ValueLabel.m_DataList.AddTail(pNewField->m_pValue);

        //取得label字符串然后添加在当前对象中相应的链表中
	//	CTString str = pValueLabel->m_strLabelList.GetNext(posStr);
		pNewField->m_ValueLabel.m_strLabelList.Add(strLabel);
		nPos++;
	}
	//assert(posData == NULL && posStr == NULL);
	pNewField->m_pValue = pOldValue;
///////////////////////////////////////////////}}
	SetCurVersion();
}