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.
WFPLM_ITK/jf_itk/w2_Clear_Form_PropValue.cpp

523 lines
15 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 "w2_Clear_Form_PropValue.h"
#include "error_handling.h"
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <epm/epm.h>
#include <epm/epm_toolkit_tc_utils.h>
#include <ict/ict_userservice.h>
#include <tccore/item.h>
#include <ae/ae.h>
#include <tc/folder.h>
#include <tccore/aom.h>
#include <sa/sa.h>
#include <tccore/aom_prop.h>
#include <property/prop_errors.h>
#include <tccore/workspaceobject.h>
#include <tc/preferences.h>
#include <tccore/imantype.h>
#include <tccore/grm.h>
#include <tccore/grmtype.h>
#include <sa/am.h>
#include <cfm/cfm.h>
#include <bom/bom.h>
#include <tccore/uom.h>
#include <ps/ps.h>
#include <epm/signoff.h>
#include <fclasses/tc_date.h>
#include <ics\ics2.h>
//#include <iostream>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
int delete_msword(tag_t dataset,char *ext)
{
tag_t spec_dataset_rev = NULLTAG , ref_object = NULLTAG;
AE_reference_type_t reference_type;
printf("\n111111111111\n");
AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);
char ref_name[WSO_name_size_c + 1] = "Fnd0word";
//printf("\n22222222222\n");
AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object);
if(reference_type == AE_PART_OF)
{
printf("\n3333333333333\n");
char pathname[SS_MAXPATHLEN] = "";
IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname);
char origin_file_name[IMF_filename_size_c + 1] = "";
IMF_ask_original_file_name(ref_object, origin_file_name);
printf("\n44444444444444\n");
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
char *temp_dir = getenv("temp");
printf("\n555555555555\n");
char temp_file[SS_MAXPATHLEN] = "";
strcpy(temp_file, temp_dir);
strcat(temp_file, "\\");
strcat(temp_file, new_file_name);
IMF_export_file(ref_object, temp_file);
printf("\n66666666666666\n");
int iCnt;
char *user_lib_env,pTempStr[500];
char local_path[MAX_PATH] = "";
char cmd[256] = "";
//user_lib_env = getenv("TC_USER_LIB");
//strcpy(local_path, user_lib_env);
//iCnt = strlen(user_lib_env);
//while( user_lib_env[iCnt] != '\\' )
//{
// iCnt--;
//}
//strcpy(pTempStr,"");
//strcpy(pTempStr,&user_lib_env[iCnt+1]);
//if( strcmp(pTempStr,"SubstMacros-MSWord.wsf") != 0 )
//{
// strcat( user_lib_env, "\\SubstMacros-MSWord.wsf" );
//}
//strcpy( cmd, user_lib_env );
strcpy( cmd, "DeleteMacros-MSWord.wsf" );
strcat( cmd, " \"" );
strcat( cmd, temp_file );
strcat( cmd, "\"" );
printf( "\n%s\n",cmd );
system( cmd );
printf("\n777777777777\n");
//strcpy(user_lib_env, local_path);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor);
IMF_set_original_file_name(new_file_tag, origin_file_name);
IMF_close_file(file_descriptor);
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_lock(spec_dataset_rev);
AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag);
AOM_save(spec_dataset_rev);
AOM_unlock(spec_dataset_rev);
}
return ITK_ok;
}
int delete_msexcel(tag_t dataset, char *ext)
{
tag_t spec_dataset_rev = NULLTAG,
ref_object = NULLTAG;
AE_reference_type_t reference_type;
AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);
char ref_name[WSO_name_size_c + 1] = "excel";
AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object);
if(reference_type == AE_PART_OF)
{
char pathname[SS_MAXPATHLEN] = "";
IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname);
char origin_file_name[IMF_filename_size_c + 1] = "";
IMF_ask_original_file_name(ref_object, origin_file_name);
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
char *temp_dir = getenv("temp");
char temp_file[SS_MAXPATHLEN] = "";
strcpy(temp_file, temp_dir);
strcat(temp_file, "\\");
strcat(temp_file, new_file_name);
IMF_export_file(ref_object, temp_file);
int iCnt;
char *user_lib_env,pTempStr[500];
char local_path[MAX_PATH] = "";
char cmd[256] = "";
/*user_lib_env = getenv("TC_USER_LIB");
strcpy(local_path, user_lib_env);
iCnt = strlen(user_lib_env);
while( user_lib_env[iCnt] != '\\' )
{
iCnt--;
}
strcpy(pTempStr,"");
strcpy(pTempStr,&user_lib_env[iCnt+1]);
if( strcmp(pTempStr,"SubstMacros-MSExcel.wsf") != 0 )
{
strcat( user_lib_env, "\\SubstMacros-MSExcel.wsf" );
}*/
//strcpy( cmd, user_lib_env );
strcpy( cmd, "DeleteMacros-MSExcel.wsf" );
strcat( cmd, " \"" );
strcat( cmd, temp_file );
strcat( cmd, "\"" );
printf( "\n%s\n",cmd );
system( cmd );
//strcpy(user_lib_env, local_path);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor);
IMF_set_original_file_name(new_file_tag, origin_file_name);
IMF_close_file(file_descriptor);
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_lock(spec_dataset_rev);
//CALL(AOM_load (dataset));
//CALL(AOM_load(spec_dataset_rev));
AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag);
AOM_save(spec_dataset_rev);
AOM_unlock(spec_dataset_rev);
}
return ITK_ok;
}
int W2_Revise_clear_form( METHOD_message_t* msg, va_list args )
{
int ifail = ITK_ok, i = 0, j = 0;
char rev_type[ITEM_type_size_c + 1],
*optionname= "W2_Revise_clear_form";\
map<int, string> prop_map;
//int msgid = va_arg(args,int );
tag_t new_rev = va_arg(args,tag_t );
char* operation = va_arg(args,char* );
/*tag_t parent_rev = va_arg(args,tag_t );
int copyCount = va_arg(args,int );
tag_t **obj_tags = va_arg(args,tag_t** );*/
printf("*******************************************************\n");
printf("* W2_Revise_clear_form is comming *\n");
printf("*******************************************************\n");
//printf("msgid==============================%d \n",msgid);
printf("new_rev==============================%d\n",new_rev);
char* id;
AOM_ask_value_string(new_rev,"object_type",&id);
printf("id==============================%s\n",id);
printf("operation==============================%s\n",operation);
//printf("parent_rev==============================%u\n",parent_rev);
//printf("copyCount==============================%d\n",copyCount);
//-------------<2D><>ȡ<EFBFBD><C8A1>ѡ<EFBFBD><D1A1>(origin+rev_type+_str),itemrev<65><76>Form<72><6D>ϵ<EFBFBD><CFB5>Form<72><6D><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int option_value_count;
char **option_values;
char *PREF_W2_Revise_clear_form="WF_Revise_ItemRev";//<2F><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(strcmp(operation,"Revise")!=0 && strcmp(operation,"SaveAs")!=0){
return ifail;
}
ITKCALL(PREF_ask_char_values(PREF_W2_Revise_clear_form,&option_value_count,&option_values));
printf("=====option_value_count======%d\n",option_value_count);
if(option_value_count == 0)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>option<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>%s<><73>\n",PREF_W2_Revise_clear_form);
return ifail;
}
////-----------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-------
//for (j = 1; j <option_value_count; j++)
//{
// prop_map.insert(make_pair(j-1, option_values[j]));
//}
for(int i=0;i<option_value_count;i++){
char charlist[100][100];
int col =0;
char *substr= strtok(option_values[i], ":");
printf("substr :%s\n", substr);
while (substr != NULL) {
strcpy(charlist[col],substr);
col++;
printf("%s\n", substr);
substr = strtok(NULL,":");
}
char *type=new char[32];
ITKCALL(WSOM_ask_object_type(new_rev,type));
printf("type :%s\n", type);
if(strcmp(type,charlist[0])==0){
char charlist2[100][100];
int col2 =0;
char *substr= strtok(charlist[1], ",");
while (substr != NULL) {
strcpy(charlist2[col2],substr);
col2++;
printf("%s\n", substr);
substr = strtok(NULL,",");
}
tag_t* form;
int form_count = 0;
ITKCALL(AOM_ask_value_tags(new_rev,"IMAN_master_form_rev",&form_count,&form));
ITKCALL( AOM_lock( form[0] ) );
for(int m=0;m<col2;m++){
ITKCALL(AOM_set_value_string(form[0],charlist2[m],""));
ITKCALL( AOM_save( form[0] ) );
}
ITKCALL( AOM_unlock( form[0] ) );
ITKCALL( AOM_refresh( form[0],true ) );
}
}
MEM_free(option_values);
/* //-----------<2D><><EFBFBD>ҹ<EFBFBD>ϵ-----------WTB<54><42><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ,<2C><>Ϊmasterform
tag_t relationTag = NULLTAG;
//ITKCALL (GRM_find_relation_type(option_values[0],&relationTag));
ITKCALL (GRM_find_relation_type("IMAN_master_form",&relationTag));
if(relationTag == NULLTAG)
{
printf("=====<3D><EFBFBD><EBBDA8>%s<><73>ϵ<EFBFBD><CFB5><EFBFBD>ͣ<EFBFBD>======\n",option_values[0]);
return ifail;
}
//-----------ͨ<><CDA8><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>Form<72><6D><EFBFBD><EFBFBD>
int rfCount = 0;
tag_t *rfTags = NULL;
char form_object_type[WSO_name_size_c+1];
ITKCALL (GRM_list_secondary_objects_only(new_rev,relationTag,&rfCount,&rfTags));//
printf("=====rfCount======%d\n",rfCount);
for(i = 0; i < rfCount; i++)
{
ITKCALL(WSOM_ask_object_type(rfTags[i],form_object_type));
printf("=====form_object_type======%s\n",form_object_type);
//----------WTBȡ<42><C8A1>item<65><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//if(tc_strcmp(form_object_type,option_values[1]) == 0)
{
ITKCALL( AOM_lock( rfTags[i] ) );
for(j = 1;j < option_value_count; j++)
//---------WTB<54><42>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Ϊ<EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>ֵ<EFBFBD><D6B5>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//for(j = 2;j < option_value_count; j++)
{
ITKCALL(AOM_set_value_string(rfTags[i],option_values[j],""));
ITKCALL( AOM_save( rfTags[i] ) );
}
ITKCALL( AOM_unlock( rfTags[i] ) );
ITKCALL( AOM_refresh( rfTags[i],true ) );
break;
}
}
*/
char rev_id[ITEM_id_size_c+1]="";
char item_id[ITEM_id_size_c+1]="";
tag_t master_form_rel_type = NULLTAG;
tag_t item = NULLTAG;
ITEM_ask_rev_id(new_rev,rev_id);
ITEM_ask_item_of_rev( new_rev, &item);
ITEM_ask_id(item, item_id);
GRM_find_relation_type( TC_master_form_rtype, &master_form_rel_type );
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
tag_t relation_type=NULLTAG;
//tag_t attach_relation_type = NULLTAG;
GRM_find_relation_type(TC_specification_rtype, &relation_type);
tag_t *secondary_objects=NULLTAG;
int ds_count = 0;
char *dataset_type = NULL, *desc_value=NULL,*file_path = NULL,*desc_path;
GRM_list_secondary_objects_only(new_rev, relation_type, &ds_count, &secondary_objects);
for (int j = 0; j < ds_count; j++)
{
AOM_ask_value_string(secondary_objects[j], "object_type", &dataset_type);
//if(strcmp(dataset_type, "JF3_DWG") == 0)
//{
//// ECHO("<22><><EFBFBD><EFBFBD>dwg...\n");
//// POM_AM__set_application_bypass(true);
//// ifail = export_dataset_file(dataset_list[j], "PDF_Reference", "dwg", &filename,&original_name);
// if( data_file != NULL )
// signoff_acad(secondary_objects[j],data_file);
//}
//else
if(strcmp(dataset_type, "MSWord") ==0 )
{
delete_msword(secondary_objects[j],"doc");
}
else if(strcmp(dataset_type, "MSWordX") ==0)
{
delete_msword(secondary_objects[j],"docm");
}
else if(strcmp(dataset_type, "MSExcel") ==0 )
{
delete_msexcel(secondary_objects[j],"xls");
}
else if(strcmp(dataset_type, "MSExcelX") ==0)
{
delete_msexcel(secondary_objects[j],"xlsm");
}
//else if(strcmp(dataset_type, "PDF") ==0){
// signoff_pdf(secondary_objects[j],data_file,"pdf");
//}
MEM_free(dataset_type);
}
DOFREE(secondary_objects);
GRM_find_relation_type(TC_attaches_rtype, &relation_type);
GRM_list_secondary_objects_only(new_rev, relation_type, &ds_count, &secondary_objects);
for (int j = 0; j < ds_count; j++)
{
AOM_ask_value_string(secondary_objects[j], "object_type", &dataset_type);
//if(strcmp(dataset_type, "JF3_DWG") == 0)
//{
//// ECHO("<22><><EFBFBD><EFBFBD>dwg...\n");
//// POM_AM__set_application_bypass(true);
//// ifail = export_dataset_file(dataset_list[j], "PDF_Reference", "dwg", &filename,&original_name);
// if( data_file != NULL )
// signoff_acad(secondary_objects[j],data_file);
//}
//else
if(strcmp(dataset_type, "MSWord") ==0 )
{
delete_msword(secondary_objects[j],"doc");
}
else if(strcmp(dataset_type, "MSWordX") ==0)
{
delete_msword(secondary_objects[j],"docm");
}
else if(strcmp(dataset_type, "MSExcel") ==0 )
{
delete_msexcel(secondary_objects[j],"xls");
}
else if(strcmp(dataset_type, "MSExcelX") ==0)
{
delete_msexcel(secondary_objects[j],"xlsm");
}
//else if(strcmp(dataset_type, "PDF") ==0){
// signoff_pdf(secondary_objects[j],data_file,"pdf");
//}
MEM_free(dataset_type);
}
DOFREE(secondary_objects);
/**/
printf("*******************************************************\n");
printf("* W2_Clear_Form_PropValue is end *\n");
printf("*******************************************************\n");
return ifail;
}
extern int Register_revise_msg( void )
{
int status = ITK_ok;
char *err_string,*err_function;
int err_line = -1;
printf("W2_Revise_clear_form<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
METHOD_id_t mth_tag;
ITKCALL(status = METHOD_find_method("ItemRevision", ITEM_deep_copy_msg ,&mth_tag));
if (mth_tag.id != 0){
ITKCALL( METHOD_add_action(mth_tag, METHOD_post_action_type, W2_Revise_clear_form, NULL));
printf("ע<EFBFBD><EFBFBD>W2_Revise_clear_form<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
}
return status;
}
#define SAFECALL(x) \
{ \
err_function = #x; err_line = __LINE__; \
if((rcode = (x)) != ITK_ok) \
{ \
goto CLEANUP; \
} \
}
void va_copy( va_list *dest , va_list * src ){
*dest = *src ;
}
#ifdef __cplusplus
}
#endif
#include <stdarg.h>
#include <base_utils\Mem.h>
#include <tccore\grm.h>
#include <tccore\grmtype.h>
#include <tc\iman.h>
#include <user_exits\user_exits.h>
#include <tccore\method.h>
#include <property\prop.h>
#include <tccore\aom_prop.h>
#include <property\prop_msg.h>
#include <tccore\imantype.h>
#include <property\prop_errors.h>
#include <tccore\item.h>
#include <lov\lov.h>
#include <sa\sa.h>
#include <tc\emh.h>
#include <res\reservation.h>
#include <tccore\workspaceobject.h>
#include <tc\wsouif_errors.h>
#include <tccore\aom.h>
#include <form\form.h>
#include <bom\bom.h>
#include <epm\cr.h>
#include <epm\releasestatus.h>
/**
* @headerfile standard c & cpp header files
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <iostream>
using namespace std;
/**
* @headerfile user's header files
*/