#include "epm_handler_common.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tc/envelope.h" #include #include "ae/dataset.h" #include #include #include #include #include #include #include #include "ce/ce.h" #include #include #include #include #include #include "string" #include "sstream" #include #include #include #include "ctime" #include "tchar.h" #using "C:/Users/lyf/source/repos/Testdll/bin/Debug/declib.dll" using namespace std; using namespace Testdll; using namespace System; extern "C" int POM_AM__set_application_bypass(logical bypass); string ConvertToString(System::String^ str) { char* p = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str); return p; } System::String ^ convert_to_cstring(const char *p) { return System::Runtime::InteropServices::Marshal::PtrToStringAnsi((System::IntPtr)(char *)p); } 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 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)); } } int bs_sap_material(EPM_action_message_t msg) { printf("start sap material\n"); int ifail = ITK_ok, att_count; tag_t rootTask, *attachments, relation_type; char *obj_type; int pref_cnt; char **pref_vals; EPM_ask_root_task(msg.task, &rootTask); EPM_ask_attachments(rootTask, EPM_target_attachment, &att_count, &attachments); TC_argument_list_t * arguments = msg.arguments; int arg_cnt = TC_number_of_arguments(arguments), status = 0; POM_AM__set_application_bypass(true); map paras,rel_map; vector rel_vec; for (auto i = 0; i < arg_cnt; i++) { char *temp_key, *temp_val; ITK_ask_argument_named_value(TC_next_argument(arguments), &temp_key, &temp_val); paras[temp_key] = temp_val; } PREF_ask_char_values("connor_sap", &pref_cnt, &pref_vals); split(pref_vals[4], ",", &rel_vec); for(int i=0;i temp_vec; split(rel_vec[i], "=", &temp_vec); if(temp_vec.size()==2) { rel_map[temp_vec[0]] = temp_vec[1]; } } GRM_find_relation_type("IMAN_master_form", &relation_type); printf("create class\n"); Testclass ^test = gcnew Testclass(); printf("create success\n"); String^ url = convert_to_cstring(pref_vals[0]); String^ user = convert_to_cstring(pref_vals[2]); String^ password = convert_to_cstring(pref_vals[3]); map map; map["MTART"] = "jd2_wllx"; map["MATNR"] = "item_id"; map["MAKTX"] = "jd2_wlms"; map["MEINS"] = "jd2_jldw"; map["MATKL"] = "jd2_wlz"; map["PRDHA"] = "jd2_cppc"; map["EXTWG"] = "jd2_wbwlz"; map["MSTAE"] = "release_status_list"; map["VOLUM"] = "jd2_tj"; map["VOLEH"] = "jd2_tjdw"; map["BISMT"] = "jd2_jwlh"; map["ZEINR"] = "jd2_th"; map["BRGEW"] = "jd2_mz"; map["NTGEW"] = "jd2_jz"; map["GEWEI"] = "jd2_zldw"; map["CLASS"] = "jd2_wllx"; vector vec{ "jd2_wllx","item_id","jd2_wlms","jd2_jldw","jd2_wlz","jd2_cppc","jd2_wbwlz","release_status_list","jd2_tj","jd2_tjdw","jd2_jwlh","jd2_th","jd2_mz","jd2_jz","jd2_zldw" }; printf("start111\n"); for (int i = 0; i < att_count; i++) { if (isTypeOf(attachments[i], "ItemRevision")) { int rel_cnt; tag_t *rels; GRM_list_secondary_objects_only(attachments[i], relation_type, &rel_cnt, &rels); System::Collections::Generic::Dictionary ^dic = gcnew System::Collections::Generic::Dictionary(); for (auto j = map.begin(); j != map.end(); j++) { char *val=""; string temp_val; if (j->second == "item_id") { AOM_UIF_ask_value(attachments[i], j->second.c_str(), &val); temp_val = val; } else if (j->second == "release_status_list") { int status_cnt; tag_t *rel_status; AOM_ask_value_tags(attachments[i], j->second.c_str(), &status_cnt, &rel_status); if (status_cnt) AOM_UIF_ask_value(rel_status[status_cnt - 1], "object_string", &val); temp_val = rel_map[val]; } else { AOM_UIF_ask_value(rels[0], j->second.c_str(), &val); temp_val = val; } dic[convert_to_cstring(j->first.c_str())] = convert_to_cstring(temp_val.c_str()); } dic["MBRSH"] = "M"; dic["SPART"] = "00"; dic["KLART"] = "001"; string result = ConvertToString(test->send_material(url, user, password, dic)); printf("result:%s\n", result.c_str()); } } POM_AM__set_application_bypass(false); return 0; } void get_bom(System::Collections::Generic::List^> ^a_list,tag_t line,char *werks,char *stlan) { int line_cnt; tag_t *lines; BOM_line_ask_child_lines(line, &line_cnt, &lines); char *id; AOM_UIF_ask_value(line, "bl_item_item_id", &id); for (int j = 0; j < line_cnt; j++) { System::Collections::Generic::Dictionary ^dic = gcnew System::Collections::Generic::Dictionary(); dic["MATNR"] = convert_to_cstring(id); dic["WERKS"] = convert_to_cstring(werks); dic["STLAN"] = convert_to_cstring(stlan); dic["BMENG"] = "1"; dic["STLST"] = "1"; dic["POSTP"] = "L"; char *val; AOM_UIF_ask_value(lines[j], "bl_sequence_no", &val); dic["POSNR"] = convert_to_cstring(val); AOM_UIF_ask_value(lines[j], "bl_child_id", &val); dic["IDNRK"] = convert_to_cstring(val); AOM_UIF_ask_value(lines[j], "bl_quantity", &val); dic["MENGE"] = convert_to_cstring(val); AOM_UIF_ask_value(lines[j], "bl_uom", &val); dic["MEINS"] = convert_to_cstring(val); a_list->Add(dic); get_bom(a_list, lines[j], werks, stlan); } } int bs_sap_bom(EPM_action_message_t msg) { printf("start sap bom\n"); int ifail = ITK_ok, att_count; tag_t rootTask, *attachments, relation_type, win; char *obj_type; int pref_cnt; char **pref_vals; EPM_ask_root_task(msg.task, &rootTask); EPM_ask_attachments(rootTask, EPM_target_attachment, &att_count, &attachments); TC_argument_list_t * arguments = msg.arguments; int arg_cnt = TC_number_of_arguments(arguments), status = 0; POM_AM__set_application_bypass(true); map paras; for (auto i = 0; i < arg_cnt; i++) { char *temp_key, *temp_val; ITK_ask_argument_named_value(TC_next_argument(arguments), &temp_key, &temp_val); paras[temp_key] = temp_val; } PREF_ask_char_values("connor_sap", &pref_cnt, &pref_vals); GRM_find_relation_type("IMAN_master_form", &relation_type); Testclass ^test = gcnew Testclass(); String^ url = convert_to_cstring(pref_vals[1]); String^ user = convert_to_cstring(pref_vals[2]); String^ password = convert_to_cstring(pref_vals[3]); BOM_create_window(&win); for (int i = 0; i < att_count; i++) { if (isTypeOf(attachments[i], "PSBOMViewRevision")) { printf("execute\n"); int rel_cnt, line_cnt; System::Collections::Generic::List^> ^a_list = gcnew System::Collections::Generic::List^>(); tag_t top_line, *lines, rev, *rels; char *id, *werks, *stlan; BOM_set_window_top_line_bvr(win, attachments[i], &top_line); AOM_ask_value_tag(top_line, "bl_line_object", &rev); GRM_list_secondary_objects_only(rev, relation_type, &rel_cnt, &rels); AOM_ask_value_string(rev, "item_id", &id); AOM_ask_value_string(rels[0], "jd2_gc", &werks); AOM_ask_value_string(rels[0], "jd2_BOMyt", &stlan); if (tc_strlen(werks)==0||tc_strlen(stlan)==0) continue; get_bom(a_list, top_line, werks, stlan); string result = ConvertToString(test->send_bom(url, user, password, a_list)); printf("result:%s\n", result.c_str()); } } BOM_close_window(win); POM_AM__set_application_bypass(false); return 0; }