//网络回来数据,要入缓存并刷新对象 BOOL CMSurveyList::DoPutItem(TiXmlElement* pItem, sqlite3* db, TSurveyListItem& item) { memset(&item,0,sizeof(TSurveyListItem)); const char* pstr = pItem->Attribute("id"); if(pstr) utf8ncpy(item.sID, pstr, 99); pstr = pItem->Attribute("title"); if(pstr) utf8ncpy(item.sTitle, pstr, 99); pItem->Attribute("invitecount", &item.nInvitecount); pItem->Attribute("completecount", &item.nCompletecount); pstr = pItem->Attribute("desc"); if(pstr) utf8ncpy(item.sDesc, pstr, 599); pstr = pItem->Attribute("expiredate"); if(pstr) utf8ncpy(item.sExpiredate, pstr, 99); return TRUE; }
const char* CMGeneral::FormatUrlBySID(const char* sOrgUrl) { if(!sOrgUrl) return NULL; if(m_pNewUrl) { delete[] m_pNewUrl; m_pNewUrl = NULL; } int size = strlen(sOrgUrl) + 100; //足够放下sid m_pNewUrl = new char[size]; if (strstr(sOrgUrl, "sid=") == NULL) { CMString sID; if (CMGlobal::TheOne().GetSessionID(sID)) { if (strstr(sOrgUrl, "?") == NULL) snprintf(m_pNewUrl, size, "%s?sid=%s", sOrgUrl, (const char*)sID); else snprintf(m_pNewUrl, size, "%s&sid=%s", sOrgUrl, (const char*)sID); return m_pNewUrl; } } utf8ncpy(m_pNewUrl, sOrgUrl, size-1); return m_pNewUrl; }
BOOL CMLogin::DoGetCacheItems(sqlite3* db) { if(m_lstItem) m_lstItem->clear(); BOOL ret = FALSE; sqlite3_stmt *stmt; CHAR sql[1024]; sql[0] = '\0'; snprintf(sql,1024,"SELECT id,title,slogan from %s order by _id ASC", m_tablename); if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { while(sqlite3_step(stmt) == SQLITE_ROW) { CMEnterpriseInfo item; utf8ncpy(item.sID, (const char*) sqlite3_column_text(stmt, 0), 19); utf8ncpy(item.sTitle, (const char*) sqlite3_column_text(stmt, 1), 49); utf8ncpy(item.sSlogan, (const char*) sqlite3_column_text(stmt, 2),99); m_mutex.Lock(); if(!m_lstItem) m_lstItem = new CMList<CMEnterpriseInfo>; m_lstItem->push_back(item); m_mutex.UnLock(); } ret=TRUE; } else ret = FALSE; sqlite3_finalize(stmt); ret = DoGetCacheImages(db); return ret; }
CMLogin::CMLogin(IMLoginListener* pListener) { m_pListener = pListener; m_bLogin = FALSE; m_pSession = NULL; #if defined(PLAT_IOS) //copy raw file CMString sFileName = CMPath(CMPath::SYS_CONF_PATH).String() + L"mlplayer.cfg"; if(!CMFile::FileExist(sFileName)) { CMString sSrc = CMPath(CMPath::APP_PATH).String() + L"mlplayer.cfg"; CMFile::CopyFile(sSrc, sFileName); } SETTING.Load(); sFileName = CMPath(CMPath::DATA_PATH).String() + L"defaulticon.png"; if(!CMFile::FileExist(sFileName)) { CMString sSrc = CMPath(CMPath::APP_PATH).String() + L"defaulticon.png"; CMFile::CopyFile(sSrc, sFileName); } #endif //初始化一下SystemInfo CMGlobal::TheOne().SystemInfo(); //数据库初始化 utf8ncpy(m_tablename,"enterpriseInfo", 63); utf8ncpy(m_sADImagesTableName,"adimagesurl", 63); m_lisOption = new CMList<TADImages>; sqlite3* db = NULL; db = CheckRootTable(); if(db) { DoCreate(db); } DoGetCacheItems(db); }
void CMSession::LogIn(const char* sEid, const char* sName, const char* sPass,const char* sUid,BOOL isReLogin,int nLoginType) { m_bRun = TRUE; utf8ncpy(sCustomer, sEid, 99); utf8ncpy(sUsername, sName, 99); utf8ncpy(sPassword, sPass, 99); utf8ncpy(sUserid, sUid, 99); if (!isReLogin) { m_nCurCmd = SERVICE_LOGIN; } LogIn(nLoginType); }
CMBrowser& CMBrowser::operator=(const CMBrowser& right) { utf8ncpy(sCategoryID, right.sCategoryID,63); sCategoryID[63] = '\0'; CMContenthandler::operator=(right); return *this; }
BOOL CMQuestionDetail::LikeAnswer(const char* sQuestionID, const char* sAnswerID) { SetPaging(FALSE); char param[640]; snprintf(param,sizeof(param),"&questionid=%s&answerid=%s", sQuestionID, sAnswerID); utf8ncpy(sTAID, sAnswerID, 63); sprintf(m_tablename, ""); //不缓存 return Request(SERVICE_LIKEANSWER, param); }
void CMQACategory::CycParser(TiXmlElement *pItem,CMQACategoryItem* pfather) { if(!pItem) return; pItem = pItem->FirstChildElement("item"); CMQACategoryItem *pchild = NULL; const CHAR *pStr = NULL; while(pItem) { pchild = new CMQACategoryItem; if(!pchild) break; //id pStr = pItem->Attribute("id"); if(pStr) utf8ncpy(pchild->sID, pStr, 63); else pchild->sID[0] = '\0'; //title pStr = pItem->Attribute("title"); if(pStr) utf8ncpy(pchild->sCategoryTitle, pStr, 99); else pchild->sID[0] = '\0'; //questioncount pItem->QueryIntAttribute("questioncount", &pchild->nQuestioncount); if(!pfather) m_lstCategoryItem->push_back(pchild); else { if(!pfather->m_lstCategoryItem) pfather->m_lstCategoryItem = new CMList<CMQACategoryItem*>; pfather->m_lstCategoryItem->push_back(pchild); } if(!pItem->NoChildren()) CycParser(pItem,pchild); pItem = pItem->NextSiblingElement("item"); } }
BOOL CMBrowser::RequestTrain(const char* sFlag, const char* sTrainID) { if(IsRunning()) return FALSE; utf8ncpy(sCategoryID,sTrainID,63); char sParam[200]; snprintf(sParam,200,"flag=%s&id=%s",sFlag,sTrainID); snprintf(m_tablename,64,"browserall_%s",sFlag); SetPaging(TRUE); return CMContenthandler::Request(SERVICE_GETMYTRAINCOURSELIST,sParam); }
BOOL CMBrowser::Request(const char* sFlag, const char* sID) { if(IsRunning()) return FALSE; utf8ncpy(sCategoryID, sID, 63); // CM_ERRP("CMBrowser::Request flag %s id %s", sFlag, sID); char sParam[200]; snprintf(sParam,200,"flag=%s&categoryid=%s",sFlag,sID); snprintf(m_tablename,64,"browserall_%s",sFlag); SetPaging(TRUE); return CMContenthandler::Request(SERVICE_GETCONTENTLIST,sParam); }
BOOL CMBrowser::RequestPisitionCourse() { if(IsRunning()) return FALSE; memset(sCategoryID, 0, 64); utf8ncpy(sCategoryID, "99", 63); char sParam[10]; sParam[0]='\0'; snprintf(m_tablename,64,"browserall_position"); SetPaging(TRUE); return CMContenthandler::Request(SERVICE_GETPOSITIONCOURSE,sParam); }
BOOL CMQuestionDetail::GetDetail(const char* qID) { SetPaging(TRUE); char param[150]; memset(sQuestionID, 0, 64); utf8ncpy(sQuestionID, qID, 63); snprintf(param,sizeof(param),"&questionid=%s", qID); snprintf(m_tablename,sizeof(m_tablename),"AnswerList"); SetPaging(TRUE); // if (!CMGlobal::TheOne().IsOffline()) // Clear(); return Request(SERVICE_GETQADETAIL, param); }
static jboolean TRepalymentItem_SetFullName(JNIEnv* env, jobject thiz, jstring sFullName) { TRepalymentItem* pObj = (TRepalymentItem*)env->GetIntField(thiz, gTRepalymentItemFieldID.nativeJavaObj); if (pObj == 0) return false; const jchar* jChar = env->GetStringChars(sFullName, NULL); jsize size = env->GetStringLength(sFullName); char* data = UTF16toUTF8((jchar*)jChar, (size_t*)&size); utf8ncpy(pObj->sFullName, (const char*)data, 31); pObj->sFullName[31] = '\0'; env->ReleaseStringChars(sFullName, jChar); free(data); return true; }
static jboolean CMCategoryItem_SetImage(JNIEnv* env, jobject thiz, jstring sImage) { CMCategoryItem* pObj = (CMCategoryItem*)env->GetIntField(thiz, gCMCategoryItemFieldID.nativeJavaObj); if (pObj == 0) return false; const jchar* jChar = env->GetStringChars(sImage, NULL); jsize size = env->GetStringLength(sImage); char* data = UTF16toUTF8((jchar*)jChar, (size_t*)&size); utf8ncpy(pObj->sImage, (const char*)data, 299); pObj->sImage[299] = '\0'; env->ReleaseStringChars(sImage, jChar); free(data); return true; }
BOOL CMWebImage::GetFromUrl(int nID, const char* sUrl) { CMString url = sUrl; INT32 pos = 0; PicUrl * pPicUrl = NULL; if(!sUrl || strlen(sUrl) <= 0) goto ret; pos = url.ReverseFind(L"/"); if(pos < 0) goto ret; if(GetFilePath(sUrl)) return TRUE;//CMFile::DeleteFile(sFilePath); if(m_lstPicUrl) { for(int i=0; i<m_lstPicUrl->size();i++) { pPicUrl = (PicUrl *)m_lstPicUrl->at(i); if(strcmp(pPicUrl->url, sUrl) == 0) goto ret; } } //加入下载列表 pPicUrl = new PicUrl; pPicUrl->id = nID; utf8ncpy(pPicUrl->url, sUrl, 299); if(!m_lstPicUrl) m_lstPicUrl = new CMList<PicUrl*>; m_lstPicUrl->push_back(pPicUrl); DownloadNext(); return FALSE; ret: if(m_pListener) m_pListener->OnFinish(m_UserData,TResult::EUnknownError,nID); return FALSE; }
BOOL CMLogin::DoGetCacheImages(sqlite3* db) { if(m_lisOption) m_lisOption->clear(); BOOL ret = FALSE; sqlite3_stmt *stmt; CHAR sql[1024]; sql[0] = '\0'; snprintf(sql,1024,"SELECT imageurl from %s order by _id ASC", m_sADImagesTableName); if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { while(sqlite3_step(stmt) == SQLITE_ROW) { TADImages item; utf8ncpy(item.sImage, (const char*) sqlite3_column_text(stmt, 0), 199); m_mutex.Lock(); if(!m_lisOption) m_lisOption = new CMList<TADImages>; m_lisOption->push_back(item); m_mutex.UnLock(); } ret=TRUE; } else ret = FALSE; sqlite3_finalize(stmt); return ret; }
static void update_hist_button() { int i; for(i=0;i<gcb_history_n;i++) { char tstr[16]; if (!hist_strArr[i]) continue; utf8ncpy(tstr, sizeof(tstr), hist_strArr[i]); del_nl(tstr); gtk_button_set_label(GTK_BUTTON(hist_buttonArr[i]),tstr); #if 0 #if GTK_CHECK_VERSION(2,12,0) gtk_widget_set_tooltip_text (hist_buttonArr[i], hist_strArr[i]); #else gtk_tooltips_set_tip (GTK_TOOLTIPS (button_bar_tips),hist_buttonArr[i], hist_strArr[i],NULL); #endif #endif } }
BOOL CMQuestionDetail::DoRefresh(TAnswerItem& obj) { BOOL ret = FALSE; m_mutex.Lock(); for (int i = 0; i < m_lstItem->size(); i++) { TAnswerItem& item = m_lstItem->at(i); if (strcmp(item.sID.c_str(), obj.sID.c_str()) == 0) { obj=item; ret = TRUE; break; } } m_mutex.UnLock(); if (strcmp(m_tablename, "") == 0) return FALSE; //根据obj的sID属性更新 sqlite3_stmt *stmt; CHAR sql[1024]; sql[0] = '\0'; sqlite3*db = CheckTable(m_tablename); if (db == NULL) return FALSE; snprintf(sql,sizeof(sql),"SELECT * FROM %s WHERE id = ? ", m_tablename); if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { BindParam(stmt, 1, obj.sID.c_str()); if (sqlite3_step(stmt) == SQLITE_ROW) { TAnswerItem item; item.sID = (const char*) sqlite3_column_text(stmt, 1); item.sAnswer = (const char*) sqlite3_column_text(stmt, 2); item.sAnswerer_username =(const char*) sqlite3_column_text(stmt, 3); item.sAnswerer_fullname =(const char*) sqlite3_column_text(stmt, 4); item.sAnswerer_icon = (const char*) sqlite3_column_text(stmt, 5); item.sPubdate = (const char*) sqlite3_column_text(stmt, 6); item.nAnswerflag = sqlite3_column_int(stmt, 7); item.nPV = sqlite3_column_int(stmt, 8); //strcpy(sQuestionID, (const char*)sqlite3_column_text(stmt, 9)); utf8ncpy(sQuestionID, (const char*) sqlite3_column_text(stmt, 9), 63); item.nIsliked = sqlite3_column_int(stmt, 10); item.sPic_url = (const char*) sqlite3_column_text(stmt, 11); item.sThumburl =(const char*) sqlite3_column_text(stmt, 12); } else { CM_ERRP("sqlite3_prepare_v2 %s failed.error:%s", sql, sqlite3_errmsg(db)); } sqlite3_finalize(stmt); } else { CM_ERRP("sqlite3_step %s failed.error:%s", sql, sqlite3_errmsg(db)); } return ret; }
/* Signal handler called when the selections owner returns the data */ void disp_gcb_selection(const gchar *text) { // dbg("selection_received '%s'\n", text); char *tmpstr; GtkWidget *button = snoop_button; int i; int textlen; static char bombom[]="\xef\xbb\xbf\xef\xbb\xbf"; if (!text || !text[0]) return; textlen=strlen(text); if (textlen==1 && text[0] <= ' ') return; // google chrome if (!strcmp(text,bombom)) return; #if 0 dbg("textlen %d\n", textlen); for(i=0; i < textlen;i++) dbg("%x ", (unsigned char)text[i]); dbg("\n"); #endif if (!buttonArr) return; for(i=0;i<gcb_button_n;i++) { if (buttonStr[i] && !strcmp(buttonStr[i],text)) return; } tmpstr=(char *)g_malloc(maxButtonStrlen); utf8ncpy(tmpstr, maxButtonStrlen, (char *)text); del_nl(tmpstr); for(i=0;i<gcb_button_n;i++) { if (buttonArr[i]==button) { if (buttonStr[i]) g_free(buttonStr[i]); buttonStr[i]=g_strdup(text); } } gtk_button_set_label(GTK_BUTTON(button),tmpstr); set_win_title(text); #if GTK_CHECK_VERSION(2,12,0) gtk_widget_set_tooltip_text (button, text); #else gtk_tooltips_set_tip (GTK_TOOLTIPS (button_bar_tips), button, text,NULL); #endif g_free(tmpstr); gtk_window_resize(GTK_WINDOW(mainwin), 100, 24); // remove the duplicate item if any for(i=0;i< gcb_history_n; i++) { if (!hist_strArr[i]) continue; int len = strlen(hist_strArr[i]); if (strncmp(hist_strArr[i], text, len)) continue; g_free(hist_strArr[i]); memmove(&hist_strArr[i],&hist_strArr[i+1], sizeof(hist_strArr[0])*(gcb_history_n - i - 1)); hist_strArr[gcb_history_n-1]=NULL; break; } g_free(hist_strArr[gcb_history_n-1]); memmove(&hist_strArr[1],&hist_strArr[0], sizeof(hist_strArr[0])*(gcb_history_n-1)); hist_strArr[0]=g_strdup(text); update_hist_button(); }
void set_win_title(const gchar *text) { char titlestr[34]; utf8ncpy(titlestr, sizeof(titlestr), (char *)text); gtk_window_set_title (GTK_WINDOW (mainwin),titlestr); }
BOOL CMSpecialTopic::DoGetCacheItems(sqlite3* db) { BOOL ret = FALSE; sqlite3_stmt *stmt; CHAR sql[1024]; sql[0] = '\0'; snprintf(sql,sizeof(sql),"SELECT main.*, sub.stitle , sub.simage , sub.parentspecid FROM %s AS sub LEFT JOIN %s AS main ON sub.id = main.id WHERE sub.parentspecid = ? ",m_tablename,m_tablename ); if (m_bPaging) { snprintf(sql,sizeof(sql),"%s LIMIT %d OFFSET %d", sql, m_nPageSize, (m_nPageNo - 1)*m_nPageSize); } // printf("error:%d \n",sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) ); if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { BindParam(stmt, 1, sParentSpecId); if ( m_nPageNo == 1) { m_mutex.Lock(); m_lstItem->clear(); m_mutex.UnLock(); m_mutex.Lock(); m_lstHeadItem->clear(); m_mutex.UnLock(); } while(sqlite3_step(stmt)==SQLITE_ROW) { TClassItem* item= new TClassItem(); item->fetchItem(stmt); // utf8ncpy(item.sID, (const char*)sqlite3_column_text(stmt, 1), 63); // // utf8ncpy(item.sFlag, (const char*)sqlite3_column_text(stmt, 2), 15); // // utf8ncpy(item.sTitle, (const char*)sqlite3_column_text(stmt, 3), 99); // // utf8ncpy(item.sBrief, (const char*)sqlite3_column_text(stmt, 4), 99); // // // utf8ncpy(item.sLargeimage, (const char*)sqlite3_column_text(stmt, 5) ,299); // // utf8ncpy(item.sImage, (const char*)sqlite3_column_text(stmt, 6) ,299); // // utf8ncpy(item.sThumbs, (const char*)sqlite3_column_text(stmt, 7) ,299); // // utf8ncpy(item.sType , (const char*)sqlite3_column_text(stmt, 8) ,63); // // item.nCoursewarecount = sqlite3_column_int(stmt, 9); // // utf8ncpy(item.sUrl, (const char*)sqlite3_column_text(stmt, 10) ,299); // // utf8ncpy(item.sPubdate, (const char*)sqlite3_column_text(stmt, 11) ,19); // // item.nVC = sqlite3_column_int(stmt, 12); // // item.nPV = sqlite3_column_int(stmt, 13); // // item.nCommentcount = sqlite3_column_int(stmt, 14); // // item.bEnablecomment = sqlite3_column_int(stmt, 15); // // item.bEnabledownload = sqlite3_column_int(stmt, 16); // // item.bEnablerating = sqlite3_column_int(stmt, 17); // // utf8ncpy(item.sDescription, (const char*)sqlite3_column_text(stmt, 18) , 449); // // // utf8ncpy(item.sTag, (const char*)sqlite3_column_text(stmt, 19) , 63); // // utf8ncpy(item.sSpecialtopic, (const char*)sqlite3_column_text(stmt, 20) , 63); // // utf8ncpy(item.sCredit, (const char*)sqlite3_column_text(stmt, 21) , 31); // // item.nStudyduration = sqlite3_column_int(stmt, 22); // // item.nStudyprogress = sqlite3_column_int(stmt, 23); // // utf8ncpy(item.sLaststudydate, (const char*)sqlite3_column_text(stmt, 24) , 31); // // // utf8ncpy(item.sFavoritedate, (const char*)sqlite3_column_text(stmt, 25) , 19); // // item.bMyCompany = sqlite3_column_int(stmt, 26); // // item.bIsRated = sqlite3_column_int(stmt, 27); utf8ncpy(m_sTitle, (const char*)sqlite3_column_text(stmt, 28) , 99); utf8ncpy(m_sImage, (const char*)sqlite3_column_text(stmt, 29) , 299); utf8ncpy(sParentSpecId, (const char*)sqlite3_column_text(stmt, 30) , 63); m_mutex.Lock(); if(m_lstItem) m_lstItem->push_back(item); m_mutex.UnLock(); } ret=TRUE; if (ret) { //计算总数 m_nTotalCount = 0; snprintf(sql,sizeof(sql),"SELECT COUNT(*) FROM %s WHERE parentspecid = ? ", m_tablename); if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { BindParam(stmt, 1, sParentSpecId); if (sqlite3_step(stmt) == SQLITE_ROW) { m_nTotalCount = sqlite3_column_int(stmt, 0); } sqlite3_finalize(stmt); } } sqlite3_finalize(stmt); ret = TRUE; } return ret; }
void CMGetNewContent::DoItem(TiXmlElement* pItem, TNewContentItem* newContentItem){ if(!pItem) return; const char* pstr = NULL; pstr = pItem->Attribute("tx_type"); if (pstr) { utf8ncpy(newContentItem->sType, pstr, 20); } pstr = pItem->Attribute("tx_title"); if (pstr) { utf8ncpy(newContentItem->sTitle, pstr, 100); } pstr = pItem->Attribute("tx_desc"); if (pstr) { utf8ncpy(newContentItem->sDescription, pstr, 250); } int value = 0; pItem->QueryIntAttribute("model", &value); newContentItem->nModel = value; if (strcmp(newContentItem->sType, "course") == 0) { if (newContentItem->nModel != 1) { TClassItem* bItem = new TClassItem; *bItem = pItem; newContentItem->item = bItem; } else { TCoursewareItem* bItem = new TCoursewareItem; *bItem = pItem; newContentItem->item = bItem; } } else if (strcmp(newContentItem->sType, "news") == 0) { TBrowserItem* bItem = new TBrowserItem; *bItem = pItem; newContentItem->item = bItem; } else if (strcmp(newContentItem->sType, "exam") == 0) { TExamListItem* examItem = new TExamListItem; pstr = pItem->Attribute("id"); if(!pstr) { return; } examItem->sID = pstr; pstr = pItem->Attribute("title"); if(pstr) { examItem->sTitle = pstr; } int val = 0; pItem->QueryIntAttribute("iscomplete", &val); examItem->bIsComplete = val; val = 0; pItem->QueryIntAttribute("viewanswer", &val); examItem->bViewAnswer = val; pItem->QueryIntAttribute("requirecount", &examItem->nRequirecount); pItem->QueryIntAttribute("uncompletecount", &examItem->nUncompletecount); pstr = pItem->Attribute("testscores"); if(pstr) examItem->nTestscores = pstr; pItem->QueryIntAttribute("ranking", &examItem->nRanking); pstr = pItem->Attribute("desc"); if(pstr) examItem->sDesc = pstr; pstr = pItem->Attribute("category"); if(pstr) examItem->sCategory = pstr; pItem->QueryIntAttribute("usercompletecount", &examItem->nUsercompletecount); pstr = pItem->Attribute("pubdate"); if(pstr) examItem->sPubdate = pstr; pItem->QueryIntAttribute("questioncount", &examItem->nQuestioncount); pItem->QueryIntAttribute("duration", &examItem->nDuration); examItem->nCurrIndex = 0; examItem->nRemainTime = examItem->nDuration*60; pItem->QueryIntAttribute("passmark", &examItem->nPassmark); pItem->QueryIntAttribute("fullmark", &examItem->nFullmark); pstr = pItem->Attribute("rankurl"); if(pstr) examItem->sRankurl = pstr; pstr = pItem->Attribute("completetime"); if(pstr) examItem->sCompletetime = pstr; newContentItem->item = examItem; } else if (strcmp(newContentItem->sType, "exercise") == 0) { TExerciseListItem* exerciseItem = new TExerciseListItem; pstr = pItem->Attribute("id"); if (!pstr) { return; } exerciseItem->sID = pstr; pstr = pItem->Attribute("title"); if (pstr) { exerciseItem->sTitle = pstr; } pItem->QueryIntAttribute("questioncount", &exerciseItem->nQuestioncount); pItem->QueryIntAttribute("uncompletecount", &exerciseItem->nUncompletecount); pstr = pItem->Attribute("desc"); if(pstr) exerciseItem->sDesc = pstr; pstr = pItem->Attribute("category"); if(pstr) exerciseItem->sCategory = pstr; pItem->QueryIntAttribute("usercompletecount", &exerciseItem->nUsercompletecount); pstr = pItem->Attribute("pubdate"); if(pstr) exerciseItem->sPubdate = pstr; newContentItem->item = exerciseItem; } else if (strcmp(newContentItem->sType, "survey") == 0) { TSurveyListItem* surveyItem = new TSurveyListItem; memset(surveyItem, 0, sizeof(TSurveyListItem)); pstr = pItem->Attribute("id"); if (!pstr) { return; } utf8ncpy(surveyItem->sID, pstr, 99); pstr = pItem->Attribute("title"); if (pstr) { utf8ncpy(surveyItem->sTitle, pstr, 99); } pItem->QueryIntAttribute("invitecount", &surveyItem->nInvitecount); pItem->QueryIntAttribute("completecount", &surveyItem->nCompletecount); pstr = pItem->Attribute("desc"); if(pstr) utf8ncpy(surveyItem->sDesc,pstr, 599); pstr = pItem->Attribute("expiredate"); if(pstr) utf8ncpy(surveyItem->sExpiredate,pstr, 99); newContentItem->item = surveyItem; } else if (strcmp(newContentItem->sType, "qa") == 0) { TQAItem* qaItem=new TQAItem; pstr = pItem->Attribute("id"); if (!pstr) { return; } qaItem->sID = pstr; pstr=pItem->Attribute("question"); if(pstr) qaItem->sQuestion=pstr; pstr=pItem->Attribute("categorytitle"); if(pstr) qaItem->sQcategorytitle=pstr; pstr=pItem->Attribute("questioner_username"); if(pstr) qaItem->sQuestioner_username=pstr; pstr=pItem->Attribute("questioner_fullname"); if(pstr) qaItem->sQuestioner_fullname=pstr; pstr=pItem->Attribute("question_icon"); if(pstr) qaItem->sQuestioner_icon=pstr; pstr=pItem->Attribute("pubdate"); if(pstr) qaItem->sPubdate=pstr; pItem->QueryIntAttribute("vc",&qaItem->nVC); pItem->QueryIntAttribute("pv", &qaItem->nPV); pItem->QueryIntAttribute("answercount", &qaItem->nAnswercount); pItem->QueryIntAttribute("value", &qaItem->nValue); pstr=pItem->Attribute("url"); if(pstr) qaItem->sPic_url=pstr; pstr=pItem->Attribute("Thumurl"); if(pstr) qaItem->sThumburl=pstr; newContentItem->item=qaItem; } else if(strcmp(newContentItem->sType, "apply") == 0)//报名 { TTrainApplyItem* bItem = new TTrainApplyItem; *bItem = pItem; newContentItem->item = bItem; } else if(strcmp(newContentItem->sType, "signin") == 0)//报名 { TTrainSignInItem* bItem = new TTrainSignInItem(); *bItem = pItem; newContentItem->item = bItem; } else if(strcmp(newContentItem->sType, "trainclass") == 0)//报名 { TMyTrainItem* bItem = new TMyTrainItem(); *bItem = pItem; newContentItem->item = bItem; } }
String String::InternalTrim(bool bLeft, bool bRight, s_char c) const { // Copy ourselves into a new buffer #ifdef SCRATCH_NO_UTF8 size_t bytes = strlen(this->str_szBuffer); #else size_t bytes = utf8size(this->str_szBuffer) - 1; #endif char* szBuffer = new char[bytes + 1]; #ifdef SCRATCH_NO_UTF8 #if WINDOWS strcpy_s(szBuffer, bytes + 1, this->str_szBuffer); #else strcpy(szBuffer, this->str_szBuffer); #endif #else utf8ncpy(szBuffer, this->str_szBuffer, bytes); #endif // Keep a pointer to the current offset char* szOffset = szBuffer; if (bLeft) { #ifdef SCRATCH_NO_UTF8 // While there's a space, keep incrementing the offset char lc = *szOffset; while (lc == c && lc != '\0') { // This way, we'll trim all the spaces on the left lc = *(++szOffset); } #else // Find the space int codepoint; void* v = utf8codepoint(szOffset, &codepoint); while (codepoint == c && codepoint != '\0') { szOffset = (char*)v; v = utf8codepoint(szOffset, &codepoint); } #endif } if (bRight) { // Loop from right to left in the string #ifdef SCRATCH_NO_UTF8 for (int i = strlen(szOffset) - 1; i >= 0; i--) { // When we find a space if (szOffset[i] == c) { // Put the null terminator here to trim the right part szOffset[i] = '\0'; } else { // Something other than a space, we can stop now break; } } #else int codepoint; char* lastValid = szOffset; for (void* v = utf8codepoint(szOffset, &codepoint); ; v = utf8codepoint(v, &codepoint)) { if (codepoint == '\0') { break; } if (codepoint != c) { lastValid = (char*)v; } } *(char*)lastValid = '\0'; #endif } // Return String ret(szOffset); delete[] szBuffer; return ret; }
BOOL CMLogin::DoPutItem(TiXmlElement* pItem, sqlite3* db, CMEnterpriseInfo& item) { BOOL ret = FALSE; if(!pItem || !db) return FALSE; if(strlen(m_tablename)==0) return FALSE; const CHAR* pStr= NULL; pStr = pItem->Attribute("id"); if(pStr) utf8ncpy(item.sID,pStr, 19); pStr = pItem->Attribute("title"); if(pStr) utf8ncpy(item.sTitle,pStr, 49); pStr = pItem->Attribute("slogan"); if(pStr) utf8ncpy(item.sSlogan,pStr, 99); TiXmlElement* pOptionItem = pItem->FirstChildElement(); while (pOptionItem) { TADImages imageitem; pStr = pOptionItem->Attribute("url"); if (pStr) { utf8ncpy(imageitem.sImage, pStr, 199); } m_lisOption->push_back(imageitem); DoSaveADImages(db, imageitem, item.sID); pOptionItem = pOptionItem->NextSiblingElement("images"); } CHAR sql[1024]; sqlite3_stmt *stmt; snprintf(sql, 1024,"REPLACE INTO %s(id,title,slogan) VALUES (?,?,?)", m_tablename); if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) { CMHandler<CMEnterpriseInfo>::BindParam(stmt, 1, item.sID); CMHandler<CMEnterpriseInfo>::BindParam(stmt, 2, item.sTitle); CMHandler<CMEnterpriseInfo>::BindParam(stmt, 3, item.sSlogan); if(sqlite3_step(stmt) == SQLITE_DONE) { ret = TRUE; } else { ret = FALSE; CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db)); } } if(ret) DoGetCacheItems(db); return TRUE; }
void CMWetools::OnSessionCmd(unsigned int nCmdID, unsigned int nCode, TiXmlDocument* pDoc) { // INT32 result = TResult::EUnknownError; if (nCode == MER_OK&&pDoc) { TiXmlElement *pItem = pDoc->RootElement(); if (pItem) { INT32 nCmdID = 0; pItem->QueryIntAttribute("no", &nCmdID); if (pItem->QueryIntAttribute("count", &m_nCount) != TIXML_SUCCESS) { m_nCount = 0; } INT32 nErr = 0; if (pItem->QueryIntAttribute("errno", &nErr) == TIXML_SUCCESS) { if (nErr == 0) { if (nCmdID == SERVICE_WE) { pItem = pItem->FirstChildElement(); if(!pItem){ goto ERR; } const char *pStr = NULL; pStr = pItem->Attribute("wesize"); if (pStr) utf8ncpy(sWesize, pStr, 15); pStr = pItem->Attribute("weversion"); if (pStr) utf8ncpy(sWeversion, pStr, 15); pStr = pItem->Attribute("weurl"); if (pStr) utf8ncpy(sWeurl, pStr, 599); m_pUpdateDataListener->OnUpdateDataFinish(m_UserData, TResult::ESuccess); return; } } else if (nErr == MERS_NOTRETURN) { goto ERR; } else { m_pUpdateDataListener->OnUpdateDataFinish(m_UserData, TResult::ENothing); return; } } } } else { goto ERR; } ERR: if (nCmdID == SERVICE_WE) m_pUpdateDataListener->OnUpdateDataFinish(m_UserData, TResult::EUnknownError); }