#include "util.h" int checkIsTypeOrSubtype(tag_t objtag, char * type_name) { tag_t type = NULLTAG; TCTYPE_ask_object_type(objtag, &type); tag_t item_type = NULLTAG; TCTYPE_find_type(type_name, "", &item_type); int is_type = 0; if (item_type != NULLTAG) { logical isok = FALSE; TCTYPE_is_type_of(type, item_type, &isok); if (isok) { is_type = 1; } } return is_type; } void split(std::string s, const char* delim, std::vector* ret) { size_t last = 0; size_t index = s.find(delim, last); int size=strlen(delim); while (index != std::string::npos) { ret->push_back(s.substr(last, index - last)); last = index + size; index = s.find(delim, last); } if (index - last > 0) { ret->push_back(s.substr(last, index - last)); } } bool isTypeOf(tag_t objtag, const char * type_name) { tag_t type = NULLTAG; TCTYPE_ask_object_type(objtag, &type); tag_t item_type = NULLTAG; TCTYPE_find_type(type_name, "", &item_type); bool is_type = false; if (item_type != NULLTAG) { logical isok = FALSE; TCTYPE_is_type_of(type, item_type, &isok); if (isok) { is_type = true; } } return is_type; } void vecToArray(vector &vec,char ***arr) { (*arr)=(char **)MEM_alloc(vec.size()*sizeof(char *)); for(auto i=0;itm_year + 1900 << '-'; if (local->tm_mon < 9) ss << "0"; ss << local->tm_mon + 1 << '-'; if (local->tm_mday < 9) ss << "0"; ss << local->tm_mday << ' '; if (local->tm_hour < 10) ss << "0"; if (local->tm_min < 10) ss << "0"; ss << local->tm_min; if(local->tm_sec<10) ss<<"0"; ss<tm_sec; return ss.str(); } string getTime() { stringstream ss; time_t t = time(0); tm* local = localtime(&t); ss << local->tm_year + 1900 << '-'; if (local->tm_mon < 9) ss << "0"; ss << local->tm_mon + 1 << '-'; if (local->tm_mday < 9) ss << "0"; ss << local->tm_mday << ' '; if (local->tm_hour < 10) ss << "0"; ss << local->tm_hour << ':'; if (local->tm_min < 10) ss << "0"; ss << local->tm_min<<':'; if(local->tm_sec<10) ss<<"0"; ss<tm_sec; return ss.str(); } string WStringToString(const wstring& ws) { if(ws.empty()|| ws.length()==0) { LINFO<<"该数据为空"; return ""; } string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C"; setlocale(LC_ALL, "chs"); const wchar_t* _Source = ws.c_str(); size_t _Dsize = 2 * ws.size() + 1; char *_Dest = new char[_Dsize]; memset(_Dest,0,_Dsize); wcstombs(_Dest,_Source,_Dsize); string result = _Dest; delete []_Dest; setlocale(LC_ALL, curLocale.c_str()); return result; } wstring StringToWString(const string s) { printf("%s\r\n","StringToWString start"); setlocale(LC_ALL, "chs"); const char* _Source = s.c_str(); size_t _Dsize = s.size() + 1; wchar_t *_Dest = new wchar_t[_Dsize]; wmemset(_Dest, 0, _Dsize); mbstowcs(_Dest,_Source,_Dsize); wstring result = _Dest; delete []_Dest; setlocale(LC_ALL, "C"); printf("StringToWString start end\r\n"); return result; } std::string string_To_UTF8(const std::string str) { int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); wchar_t * pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴 ZeroMemory(pwBuf, nwLen * 2 + 2); ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen); int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); char * pBuf = new char[nLen + 1]; ZeroMemory(pBuf, nLen + 1); ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL); std::string retStr(pBuf); delete []pwBuf; delete []pBuf; pwBuf = NULL; pBuf = NULL; return retStr; } double stringToNum( string str) { istringstream iss(str); double num; iss >> num; return num; } string get_excel_data(libxl::Book *book,libxl::Sheet *sheet,int row,int col) { string result; double temp; try { libxl::CellType cell_type=sheet->cellType(row,col); switch(cell_type) { case libxl::CELLTYPE_STRING: result=WStringToString(sheet->readStr(row,col)); break; case libxl::CELLTYPE_BLANK: result=""; break; case libxl::CELLTYPE_EMPTY: result=""; break; case libxl::CELLTYPE_NUMBER: temp=sheet->readNum(row,col); if(sheet->isDate(row,col)) { int year=0,month=0,day=0,hour=0,min=0,second=0; book->dateUnpack(temp,&year,&month,&day,&hour,&min,&second); date_t d; d.year=year;d.month=month;d.day=day;d.hour=hour;d.minute=min;d.second=second; char *date_str,*date_format; DATE_default_date_format(&date_format); DATE_date_to_string(d,date_format,&date_str); result=date_str; }else { result=temp==(int)temp?to_string((int)temp):to_string(temp); } break; case libxl::CELLTYPE_BOOLEAN: result=to_string(sheet->readBool(row,col)); break; case libxl::CELLTYPE_ERROR: result=""; break; } }catch(exception e) { // LERROR<<"col num"<=0;i--) { AOM_ask_value_tags(tags[i],"release_status_list",&rel_cnt,&rels); if(rel_cnt) { *rev=tags[i]; return; } } *rev=NULLTAG; } //根据itemID查询零件版本 void queryRevByItemID(string item_id, tag_t *rev) { tag_t latest = NULLTAG; tag_t query; QRY_find2("chint_query_item", &query); if (query == NULL){ printf("没有该查询\r\n"); return ; } char **entries, **vals; entries = (char **)MEM_alloc(1 * sizeof(char *)); vals = (char **)MEM_alloc(1 * sizeof(char *)); char *a = "ID"; entries[0] = (char *)MEM_alloc((int)strlen(a) * sizeof(char)); strcpy(entries[0], a); vals[0] = (char *)MEM_alloc((int)strlen(item_id.c_str()) * sizeof(char)); strcpy(vals[0], item_id.c_str()); int count; tag_t *item_revs; //调用查询获得厂家版本 SAFECALL(QRY_execute(query, 1, entries, vals, &count, &item_revs)); if (count>0) { *rev = item_revs[0]; //char *gname; //tag_t vendor; //SAFECALL(ITEM_ask_item_of_rev(item_revs[0], &vendor)); }else { (*rev) = NULLTAG; } }