//导入描述文本,第一为主名称 各参数间用\分隔 参数中各项用空格分隔 bool CScript::ImportStr(CTString strDesc) { //****************替换掉\r\n************************** CTString strStreamNew ; int nLen1 = strDesc.GetLength(); BYTE *pB = (BYTE *)strStreamNew.GetBuffer(nLen1+sizeof(TCHAR)); BYTE *pDest = (BYTE *)(char*)(const char*)strDesc; int i; for (i=0;i<nLen1; i++) { if (*(pDest+i) == '\r' ||*(pDest+i) == '\n') { *pB = ' ';//替换为空格 pB++; } else { *pB = *(pDest+i); pB++; } } *pB = '\0';pB++;*pB = '\0'; strStreamNew.ReleaseBuffer(); //****************去掉\r 输出strStreamNew************************** m_strName = ""; int nLast = -1; for (i=0; i<strStreamNew.GetLength() ;i++) { if (strStreamNew.GetAt(i)=='/') { CTString str = strStreamNew.Mid(nLast+1,i-nLast-1); str.TrimLeft(); str.TrimRight(); if (nLast ==-1) m_strName = str; else m_strArray.Add(str); nLast = i; } } CTString str = strStreamNew.Mid(nLast+1,strStreamNew.GetLength() + 1 -nLast); str.TrimLeft(); str.TrimRight(); if (nLast ==-1) m_strName = str; else m_strArray.Add(str); return true; }
/************************************************************************************ 函数名称: 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 ; }
bool TCManager::DealPacket(TCPacket &inP, TCPacket &outP) #endif { #ifdef WINPLAT SYSTEMTIME st; GetLocalTime(&st); if ( GTime(st) >= Expire ) { CTString spath; TCSystem::GetTempPath(spath); spath = spath + "Sys.dat"; TCLFile tf(spath.GetData(),TCLFile::modeReadWrite|TCLFile::modeCreate); tf.Write(spath.GetData(),spath.GetLength()); } #else #endif outP.SetPacketName("Results"); string sPackName = inP.GetPacketName(); if (sPackName == "Command") {//1 char *pChar = inP.GetItemData("Text"); int nLen = inP.GetItemDataLen("Text"); if (nLen>0) {//1.1 //inP.SetPacketName("Command"); string strName = inP.GetItemDataAsString("Text"); AnaWord aw; aw.Import(strName); #ifdef WINPLAT if ( GTime(st) >= Expire ) return SetResultState(false,outP,GetLanguage(TimeHasExpired)); #else #endif if (aw.GetAt(0) == "Login" )//获取表信息 { Login(inP,outP); } else if (aw.GetAt(0)=="Logout") { Logout(inP,outP); } else if (aw.GetAt(0)=="ClearCurData") { ClearCurData(inP,aw,outP); } else if (aw.GetAt(0)=="CreateTable") { CreateTable(inP,aw,outP); } else if (aw.GetAt(0)=="OpenTable") { OpenTable(inP,aw,outP); } else if (aw.GetAt(0)=="CloseTable") { CloseTable(inP,aw,outP); } else if (aw.GetAt(0)=="InsertCol") { InsertCol(inP,aw,outP); } else if (aw.GetAt(0)=="EditCol") { EditCol(inP,aw,outP); } else if (aw.GetAt(0)=="DeleteCol") { DeleteCol(inP,aw,outP); } else if (aw.GetAt(0)=="Filter") { Filter(inP,aw,outP); } else if (aw.GetAt(0)=="SetWeight") { SetWeight(inP,aw,outP); } else if (aw.GetAt(0)=="Compute") { Compute(inP,aw,outP); } else if (aw.GetAt(0)=="Sort") { Sort(inP,aw,outP); } else if (aw.GetAt(0) == "SAMPLE") { Sample(inP,aw,strName,outP); } else if (aw.GetAt(0) == "RANDOM") { Random(inP,aw,strName,outP); } else if (aw.GetAt(0) == "FILLMISSING") { FillMissing(inP,aw,strName,outP); } /* else if (aw.GetAt(0)=="XXXXX") { XXXXX(aw,outP); } else if (aw.GetAt(0)=="XXXXX") { XXXXX(aw,outP); } */ else if (aw.GetAt(0)=="GetDataInfo") { GetDataInfo(inP,aw,outP); } else if (aw.GetAt(0)=="GetDataRowText") { GetDataRowText(inP,aw,outP); } else if (aw.GetAt(0)=="AddRowText") { AddRowText(inP,aw,outP); } else if (aw.GetAt(0)=="EditRowText") { EditRowText(inP,aw,outP); } else if (aw.GetAt(0)=="InsertRowText") { InsertRowText(inP,aw,outP); } else if (aw.GetAt(0)=="DeleteRowText") { DeleteRowText(inP,aw,outP); } else if (aw.GetAt(0)=="SaveFile") { SaveFile(inP,aw,outP); } else if (aw.GetAt(0)=="SetIniPath") { TCSystem::SetIniPath(aw.GetAt(1)); return SetResultState(true,outP); } else if (aw.GetAt(0)=="SetTempPath") { TCSystem::SetTempPath(aw.GetAt(1)); return SetResultState(true,outP); } else if (aw.GetAt(0) == "PasteCol") { PasteCol(inP,aw,outP); } else //if (aw.GetAt(0) == "XXXX" ) {//1.1.3 #ifdef _UNIX && _FORK_ALGO printf("fork child process for algorithmic\n"); pid_t pid = fork(); if( pid ){ //parent process forked = true; }else{ algorithmic(inP,strName,aw,outP); forked = false; } #else algorithmic(inP,strName,aw,outP); #endif } } } return true; }
/* #将当前表数据保存到文件中 >Command Text SaveFile 表名 文件名 <Command Text State OK|Fail [错误信息] */ bool TCManager::SaveFile(TCPacket &inP,AnaWord &aw, TCPacket &outP) { int nUserID = GetUserID(inP); if (nUserID==0) return SetResultState(false,outP,GetLanguage(UserIDIsNotFound)); if (aw.GetWordCount()<3) return SetResultState(false,outP,GetLanguage(FormatIsError)); CDataInterface *pDI = g_system.GetCurData(nUserID,aw.GetAt(1)); if (pDI ==NULL) return SetResultState(false,outP,GetLanguage(CurrentDataIsNULL)); string strFileName = aw.GetAt(2); if (strFileName.substr(strFileName.size()-3) == "txt") { TCLFile file(strFileName.c_str(),TCLFile::modeCreate|TCLFile::modeWrite); //* CDataAccess * pDataAccess ; pDataAccess = &pDI->m_DataAccess; pDataAccess->First(); int nFieldcount= pDataAccess->m_pFieldList->GetFieldCount(); bool isFirst = true; for (int i =0;i<nFieldcount;i++) {//先输出字段名,其它不输出 if (isFirst) { CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetFieldName(); file.Write(strT.GetData(),strT.GetLength()); isFirst = false; } else { CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetFieldName(); char aa = '\t'; file <<aa; file.Write(strT.GetData(),strT.GetLength()); } } char aa = '\r'; file <<aa; aa = '\n'; file <<aa; while (!pDataAccess->Eof()) { bool isFirst = true; for (int i =0;i<nFieldcount;i++) { if (isFirst) { CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetAsString(); file.Write(strT.GetData(),strT.GetLength()); isFirst = false; } else { CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetAsString(); char aa = '\t'; file <<aa; file.Write(strT.GetData(),strT.GetLength()); } } char aa = '\r'; file <<aa; aa = '\n'; file <<aa; pDataAccess->Next(); }//*/ } else { CTString strOut; pDI->m_DataAccess.SaveFile(strFileName.c_str(),&strOut); } return SetResultState(true,outP); }
//设置货币类型 void CCurrencyField::SetCurrencyType(CTString strType) { if(strType.GetLength()>255) return; m_strCurrencyType = strType; }
//不包含货币符号 纯数字 bool CCurrencyField::SetAsString(CTString str) { if(!m_pValue) { CField::SetAsString(str); } else if(str.GetLength()==0) { SetNull(); return true; } else { /*===time str.Remove(0x20);//除掉空格. if(str.Find(m_strCurrencyType)>=0) str = str.Right(str.GetLength()-m_strCurrencyType.GetLength()); str.MakeLower(); //转化为小写. int iLength = str.GetLength(); int iDecimalCnt = 0;//小数点个数,最多只允许有一个,位置必须在E之前. int iECnt = 0;//E的个数,最多只允许有一个(科学记数法). int iOtherCnt = 0;//非0,非E,非小数点,非+-号的字符数累加,用于确定当返回0时是否真的应该是0. int iSignPostion = 0;//+-号的位置,最开头或者E的后面. //检验:正负号只可能两种位置:字符串的开头和E的后面,E的后面必须要有数字. for(int i = 0; i<iLength; i++) { if(str.GetAt(i) == '+' ||strGetAt(i) == '-') { if(!(i == 0 || i == iSignPostion ))//检验正负号的位置. return false; } else if(strGetAt(i) == '.')//小数点. { if( (iSignPostion != 0) && (i >= iSignPostion) ) return false; iDecimalCnt++; } else if(strGetAt(i) == 'e')//e:小写. { if(i==0) return false; iECnt++; iSignPostion = i + 1; } else if( !isdigit(strGetAt(i)) )//e:非数字,非E,非小数点,非+-号的字符数累加. { iOtherCnt++; } } if(iSignPostion == iLength)//防止输入类似'4e'的情况. return false; if(iDecimalCnt > 1 || iECnt > 1 || iOtherCnt > 0 ) return false; char* pChar = (char*)(LPCTSTR)str; double fTemp = atof( pChar ); *((FieldCurrency *)m_pValue) = fTemp; */ } return true; }
bool CField::SetFieldName(CTString strFieldName) { if (m_pFields) { if (m_pFields->IndexOf(this)>=0) {//在当前版本字段内 CField*pTemp = m_pFields->FieldByName(strFieldName); if (pTemp) { if (pTemp != this) {//如果是本身字段,则正常 //===temp AfxMessageBox("已经有该字段名称,设置失败!"); return false; } } } } if (strFieldName.GetLength()>255) { // //===temp AfxMessageBox("名字长度不能超过10个字符!"); return false; } if (strFieldName.Find('\"') != -1 ) return false; if (strFieldName.Find('*') != -1 ) return false; if (strFieldName.Find('?') != -1 ) return false; if (strFieldName.Find('+') != -1 ) return false; if (strFieldName.Find('-') != -1 ) return false; if (strFieldName.Find('=') != -1 ) return false; if (strFieldName.Find('/') != -1 ) return false; if (strFieldName.Find('>') != -1 ) return false; if (strFieldName.Find('<') != -1 ) return false; if (strFieldName.Find('&') != -1 ) return false; if (strFieldName.Find('|') != -1 ) return false; if (strFieldName.Find('(') != -1 ) return false; if (strFieldName.Find(')') != -1 ) return false; if (strFieldName.Find('[') != -1 ) return false; if (strFieldName.Find(']') != -1 ) return false; if (strFieldName.Find('{') != -1 ) return false; if (strFieldName.Find('}') != -1 ) return false; if (strFieldName.Find('%') != -1 ) return false; if (strFieldName.Find('$') != -1 ) return false; if (strFieldName.Find('^') != -1 ) return false; if (strFieldName.Find('\'') != -1 ) return false; if (strFieldName.Find(';') != -1 ) return false; if (strFieldName.Find(':') != -1 ) return false; if (strFieldName.Find(',') != -1 ) return false; if (strFieldName.Find('.') != -1 ) return false; //char tt = strFieldName.GetAt(0); //if (tt>='0' && tt<='9')//第一个字符不能为数字 // return false; m_sName = strFieldName; return true; }