You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
7.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "epm_handler_common.h"
#include <tc\preferences.h>
#include <tc\tc_macros.h>
#include <fclasses/tc_date.h>
#include <epm\epm.h>
#include <epm/signoff.h>
#include <epm/epm_task_template_itk.h>
#include "ae/dataset.h"
#include <tccore\aom.h>
#include <ict/ict_userservice.h>
#include <tc\emh.h>
#include <ae/ae.h>
#include <tccore\aom_prop.h>
#include <tccore\item.h>
#include <tccore\imantype.h>
#include <tccore\iman_grmtype.h>
#include <tccore//grm.h>
#include <tccore/grmtype.h>
#include <string>
#include <sa/user.h>
#include "libxl.h"
#include <ctime>
#include <locale>
#include <codecvt>
#include "sstream"
#include <map>
#include <vector>
#include<iostream>
extern "C" int POM_AM__set_application_bypass(logical bypass);
using namespace libxl;
using namespace std;
#define DOFREE(obj) \
{ \
if(obj) \
{ \
MEM_free(obj); \
obj = NULL; \
} \
}
TCHAR* charToTchar(char * szWord){
//TCHAR tszWord[1024] = {0};
//#ifdef UNICODE
//MultiByteToWideChar(CP_ACP, 0, szWord, -1, tszWord, 1024);
//#else
//strcpy(tszWord, szWord);
//#endif
//return tszWord;
//char *CStr = "string to convert";
size_t len = strlen(szWord) + 1;
size_t converted = 0;
wchar_t *WStr;
WStr=(wchar_t*)malloc(len*sizeof(wchar_t));
mbstowcs_s(&converted, WStr, len, szWord, _TRUNCATE);
return WStr;
}
string ws2s(const std::wstring& wstr)
{
if (wstr.empty() || wstr.length() == 0) return std::string();
int size_needed = WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
int JL_Target_Moveto_Annex(EPM_action_message_t msg){
int ifail = ITK_ok,count = 0,valueNum = 0;
tag_t root_task=NULLTAG,model_path = NULLTAG,ref_obj=NULLTAG;
tag_t *attachments=NULLTAG;
Book* book = nullptr;
time_t t = time(0);
tm* local = localtime(&t);
wstringstream excel_path;
char ** values = NULL;
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ITKCALL(EPM_ask_root_task(msg.task,&root_task));
char * rootname=NULL,excelName[26]= "";
EPM_ask_name2(root_task,&rootname); //ԭ<><D4AD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cout<<rootname<<endl;
if(strstr(rootname,"<EFBFBD><EFBFBD>ƷҪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")!=NULL||strstr(rootname,"<EFBFBD>㲿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")!=NULL){
//excelName = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥";
strcat(excelName,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥.xlsx");
cout<<excelName<<endl;
}
else{
//excelName = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>嵥";
strcat(excelName,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>嵥.xlsx");
cout<<excelName<<endl;
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>еİ汾
ITKCALL(EPM_ask_attachments(root_task,EPM_target_attachment,&count,&attachments));
//xls<6C>ļ<EFBFBD><C4BC><EFBFBD>xlCreateBook() <20><><EFBFBD><EFBFBD><EFBFBD>򿪣<EFBFBD>xlsx<73>ļ<EFBFBD><C4BC><EFBFBD>xml<6D><EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>xlCreateXMLBook() <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򿪡<EFBFBD>
book = xlCreateXMLBook();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸ÿ⣬<C3BF><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>key<65><79><EFBFBD><EFBFBD>û<EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
book->setKey(L"Halil Kural", L"windows-2723210a07c4e90162b26966a8jcdboe");
//<2F><>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
//AE_find_dataset2("model.xlsx",&model_path);
//<2F><>ȡ<EFBFBD><C8A1>ѡ<EFBFBD><D1A1>
PREF_ask_char_values("JL_Target_Moveto_Annex", &valueNum, &values);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
ITK__convert_uid_to_tag(values[0],&model_path);
AE_reference_type_t ae_ref;
ITKCALL(AE_ask_dataset_named_ref2(model_path, "excel", &ae_ref, &ref_obj));
excel_path << getenv("temp");
excel_path << "\\excel";//·<><C2B7>
excel_path << local->tm_year;
excel_path << local->tm_yday;
excel_path << local->tm_hour;
excel_path << local->tm_min;
excel_path << local->tm_sec;
excel_path << ".xlsx";
cout<< ws2s(excel_path.str()).c_str()<<endl;
IMF_export_file(ref_obj, ws2s(excel_path.str()).c_str());//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
//cout<< model_path <<endl;
//ITKCALL(IMF_ask_file_pathname(model_path, SS_WNT_MACHINE, pathname));
//cout<<pathname<<endl;
if(book){
//if(book->load(L"F:/Siemens/Teamcenter11/portal/model.xlsx")){
if(book->load(excel_path.str().c_str())){
for(int i=0;i<count;i++){
char *itemType=NULL,*itemID=NULL,*name=NULL,*type;
AOM_ask_value_string(attachments[i],"object_type",&itemType);
//<2F><><EFBFBD>˵<EFBFBD><CBB5>ǰ汾<C7B0>Ķ<EFBFBD><C4B6><EFBFBD>
if((strstr(itemType,"Gd6_PartsRevision") == NULL) || (strstr(itemType,"Master") != NULL)
|| (strstr(itemType,"master") != NULL) || (strstr(itemType,"BOM") != NULL) || (strstr(itemType,"bom") != NULL) || (strstr(itemType,"Bom") != NULL))
{
continue;
}
AOM_ask_value_string(attachments[i],"item_id",&itemID);
AOM_ask_value_string(attachments[i],"object_name",&name);
AOM_ask_value_string(attachments[i],"gd6_wlfl",&type);
cout<<itemType<<endl;
cout<<itemID<<endl;
cout<<name<<endl;
cout<<type<<endl;
wstring result;
string s="4s";
Sheet *sheet = book->getSheet(0);
sheet->writeStr(i+1, 0, charToTchar(itemID));
sheet->writeStr(i+1, 1, charToTchar(name));
sheet->writeStr(i+1, 2, charToTchar(type));
sheet->writeStr(i+1, 3, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
//sheet->writeStr(i+1, 3, itemID);
//cout<<ws2s(sheet->readStr(i, 0))<<endl;
//cout<<ws2s(sheet->readStr(i, 1))<<endl;
//cout<<ws2s(sheet->readStr(i, 2))<<endl;
//cout<<ws2s(sheet->readStr(i, 3))<<endl;
DOFREE(itemType);
DOFREE(itemID);
DOFREE(name);
DOFREE(type);
}
}
}
char *temp = getenv("temp");
char out_path[SS_MAXPATHLEN] = "";
strcpy(out_path, temp);
strcat(out_path, "\\");
strcat(out_path, "ά<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD>.xlsx");
cout<<out_path<<endl;
book->save(charToTchar(out_path));
book->release();//<2F>ͷŶ<CDB7><C5B6>󣡣<EFBFBD><F3A3A1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
POM_AM__set_application_bypass(true);
//<2F>½<EFBFBD>excel<65><6C><EFBFBD>ݼ<EFBFBD>
const char name[AE_datasettype_name_size_c + 1] = "MSExcelX";
//cout << name << endl;
tag_t datasetType = NULLTAG, tool = NULLTAG;
tag_t newDatasetTag = NULLTAG; //<2F><><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>tag
tag_t relation = NULLTAG;
//cout<<"111"<<endl;
AE_find_datasettype(name, &datasetType);
//cout<<"222"<<endl;
AE_ask_datasettype_def_tool(datasetType, &tool);
//cout<<"333"<<endl;
AE_create_dataset(datasetType, excelName, "", &newDatasetTag);
//cout<<"444"<<endl;
AOM_lock(newDatasetTag);
AE_set_dataset_tool(newDatasetTag, tool);
//cout<<newDatasetTag<<endl;
//cout<<"555"<<endl;
AE_set_dataset_format2(newDatasetTag, name);
AOM_save(newDatasetTag);
AOM_unlock(newDatasetTag);
AOM_refresh(newDatasetTag,TRUE);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
//cout<<"666"<<endl;
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, "excel", "excel", 0);
IMF_import_file(out_path, new_ds_name,SS_BINARY, &new_file_tag, &file_descriptor);
cout<<new_file_tag<<endl;
AOM_lock(new_file_tag);
//cout<<"777"<<endl;
IMF_set_original_file_name(new_file_tag, excelName);
//cout<<"111111"<<endl;
IMF_close_file(file_descriptor);
//cout<<out_path<<endl;
//cout<<new_file_tag<<endl;
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_refresh(new_file_tag,TRUE);
AOM_lock(newDatasetTag);
//AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
//cout<<"888"<<endl;
AE_add_dataset_named_ref(newDatasetTag, "excel", AE_PART_OF, new_file_tag);
AOM_save(newDatasetTag);
AOM_unlock(newDatasetTag);
AOM_refresh(newDatasetTag,TRUE);
int attachment_types = EPM_reference_attachment;
//AOM_unlock(rootTask_tag);
AOM_refresh(root_task, TRUE);
//cout<<"999"<<endl;
EPM_add_attachments(root_task, 1, &(newDatasetTag), &attachment_types);
AOM_save(root_task);
POM_AM__set_application_bypass(false);
DOFREE(attachments);
DOFREE(rootname);
//DOFREE(excelName);
//DOFREE(temp);
//DOFREE(new_file_name);
return ifail;
}