Пример #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);
}