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.

282 lines
10 KiB

#include <epm\epm.h>
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")rename("BOF","adoBOF")
#include <atlstr.h>
#include "epm_handler_common.h"
#include <ae/ae.h>
#include <tccore\item.h>
#include <stdio.h>
#include <tc\emh.h>
#include <tc\preferences.h>
#include <epm\epm_toolkit_tc_utils.h>
#include <tccore\item.h>
#include <tccore\grm.h>
#include <tccore\imantype.h>
#include <tccore\iman_grmtype.h>
#include <tccore\aom.h>
#include <property\prop_errors.h>
#include <qry\qry.h>
#include <epm\cr.h>
#include <bom/bom.h>
#include <stdio.h>
#include <string>
#include <iterator>
#include<iostream>
#include <vector>
#include<Windows.h>
#include "ocilib.h"
#include<ics\ics.h>
#include<ics\ics2.h>
#pragma warning(disable : 4996)
#include <tccore\aom_prop.h>
#define DOFREE(obj) \
{ \
if(obj) \
{ \
MEM_free(obj); \
obj = NULL; \
} \
}
using namespace std;
//#include "E:/20200520/DM_ITK/jf_itk/jf_itk/jf_itk/ocilib.cxx"
int jl_dmu_auto(EPM_action_message_t msg) {
::CoInitialize(NULL); //初始化OLE/COM库环境
HRESULT hr = NULL;
_ConnectionPtr m_pConnection; // 数据库
_RecordsetPtr m_pRecordset; // 命令
_CommandPtr m_pCommand; // 记录
int ifail = ITK_ok, count = 0, arg_cnt = 0, item_mast_rev_count = 0,valueNum=0;
int outputColumn = 0, outputValueCount = 0;
tag_t root_task = NULL_TAG;
tag_t* attachments = NULL, * item_mast_rev = NULLTAG;
//char arg1value[1024] = "";
//char* arg = NULL, * argflag = NULL, * argvalue = NULL;
char* item_id = NULL, *type_class=NULL,*part_type = NULL;
char* object_type = NULL;
//char* control_name = "btnDmu"; //DMU验证通过按钮的name
char* puid = NULL;
//char*** outputValue = (char***)calloc(1024, sizeof(char**));
char* describeSelect = (char*)calloc(1024, sizeof(char));
char* describeUpdate = (char*)calloc(1024, sizeof(char));
//label_45,label_46
char* label45 = (char*)calloc(1024, sizeof(char));
char* label46 = (char*)calloc(1024, sizeof(char));
char* button = (char*)calloc(1024, sizeof(char));
char* describeSelect2 = (char*)calloc(1024, sizeof(char));
char* describeUpdate2 = (char*)calloc(1024, sizeof(char));
char* label25 = (char*)calloc(1024, sizeof(char));
char* button10 = (char*)calloc(1024, sizeof(char));
char* server_address;
PREF_ask_char_value("TC11_SqlServer_Link_ITK", valueNum, &server_address);
//获取流程任务
EPM_ask_root_task(msg.task, &root_task);
//获取流程任务目标文件夹中的当前对象
EPM_ask_attachments(root_task, EPM_target_attachment, &count, &attachments);//count 为流程中目标文件夹中的对象数量 attachments 为当前对象数据集
//获取参数个数
//arg_cnt = TC_number_of_arguments(msg.arguments);
for (int i = 0; i < count; i++)
{
ifail = AOM_ask_value_string(attachments[i], "object_type", &type_class);
printf("%s\n", type_class);
//过滤掉非版本对象
if ((strstr(type_class, "Revision") == NULL) || (strstr(type_class, "Master") != NULL)
|| (strstr(type_class, "master") != NULL) || (strstr(type_class, "BOM") != NULL) || (strstr(type_class, "bom") != NULL) || (strstr(type_class, "Bom") != NULL))
{
continue;
}
ifail = AOM_ask_value_string(attachments[i], "item_id", &item_id); //得到itemRev的id
printf("%s\n", item_id);
AOM_ask_value_tags(attachments[i], "IMAN_master_form_rev", &item_mast_rev_count, &item_mast_rev);
printf("获取订单类型\n");
//PROPDESC_ask_lov
//AOM_UIF_ask_value(item_mast_rev[0], "gd6_ddlx", &part_type);
AOM_UIF_ask_value(item_mast_rev[0], "gd6_ddlx", &part_type);//订单类型的值
printf("%s\n", part_type);
//ifail = ITEM_find_item(item_id, &item_tag);
//cout << item_tag << endl;
ITK__convert_tag_to_uid(attachments[i], &puid);
printf("%s\n", puid);
//printf("puid为:%s\n", puid);
hr = m_pConnection.CreateInstance(_uuidof(Connection));//创建连接对象实例
if (SUCCEEDED(hr))
{
/*
Provider=SQLOLEDB.1 ------打开数据库用oledb的方式连接bai
Persist Security Info ----是否保存安全信息du
User ID-------------------用户名
PassWord------------------密码zhi
Initial Catalog-----------数据库的名称或者数据库ip或者目dao录
Data Source---------------数据源
*/
m_pConnection->ConnectionString = (server_address);
printf("\n==========================================================\n");
hr = m_pConnection->Open("", "", "", adConnectUnspecified);//打开数据库
if (FAILED(hr))
{
printf("Open Failed!");
return 1;
}
else
{
printf("开始修改控件\n");
printf("%s\n", puid);
CString strSql;
CString updateSql;
// strSql.Format(_T("INSERT INTO [生产科数据库].[dbo].[tb_Process_Bom]([LinesNo],[ItemCode],[ItemName],[DrawingNo],[ProcessName],[EquiNo],[EquiName],[Designer],[ItemType],[CustomerDrawingNo],[MBomCode],[Material],[ProcessOwner],[RevNo],[OBID],[SysNo],[State]) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s')"), LineID, ItemCode, ItemName, DrawingNo, ProcessName, EquiNo, EquiNames, Designer, Classify, CustomerDrawing, MBOMCode, MaterialNam, ProcessOwner, RevNo, OBID, SysNo, "UnCheck");
//strSql.Format(_T("SELECT ENABLED FROM GD_CONTROLSTYPE_TABLE WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = '%s'"), uid, control_name);
//char* describeSelect = (char*)calloc(1024, sizeof(char));
//char* describeUpdate = (char*)calloc(1024, sizeof(char));
////label_45,label_46
//char* label45 = (char*)calloc(1024, sizeof(char));
//char* label46 = (char*)calloc(1024, sizeof(char));
//char* button = (char*)calloc(1024, sizeof(char));
//updateSql.Format(_T("UPDATE GD_CONTROLSTYPE_TABLE SET ENABLED ='%s' WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = '%s'"), style, uid, control_name);
sprintf(describeSelect, "SELECT ENABLED FROM GD_CONTROLSTYPE_TABLE WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = 'btnDmu'", puid);
sprintf(describeUpdate, "UPDATE GD_CONTROLSTYPE_TABLE SET ENABLED ='false',BACKGROUND = 'GREEN' WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = 'btnDmu'", puid);
sprintf(label45, "UPDATE GD_CONTROLSTYPE_TABLE SET BACKGROUND = 'GREEN' WHERE CONTROL_NAME = 'label_45' AND ORDER_TAGU = '%s'", puid);
sprintf(label46, "UPDATE GD_CONTROLSTYPE_TABLE SET BACKGROUND = 'GREEN' WHERE CONTROL_NAME = 'label_46' AND ORDER_TAGU = '%s'", puid);
sprintf(button, "UPDATE GD_CONTROLSTYPE_TABLE SET ENABLED ='true' WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = 'button_3'", puid);
//sprintf();
/*char* describeSelect2 = (char*)calloc(1024, sizeof(char));
char* describeUpdate2 = (char*)calloc(1024, sizeof(char));
char* label25 = (char*)calloc(1024, sizeof(char));
char* button10 = (char*)calloc(1024, sizeof(char));*/
sprintf(describeSelect2, "SELECT ENABLED FROM GD_CONTROLSTYPE_TABLE WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = 'part_9'", puid);
sprintf(describeUpdate2, "UPDATE GD_CONTROLSTYPE_TABLE SET ENABLED ='false',BACKGROUND = 'GREEN' WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = 'part_9'", puid);
sprintf(label25, "UPDATE GD_CONTROLSTYPE_TABLE SET BACKGROUND = 'GREEN' WHERE CONTROL_NAME = 'label25' AND ORDER_TAGU = '%s'", puid);
sprintf(button10, "UPDATE GD_CONTROLSTYPE_TABLE SET ENABLED ='true' WHERE ORDER_TAGU = '%s' AND CONTROL_NAME = 'part_10'", puid);
cout << describeSelect << endl;
cout << describeUpdate << endl;
cout << label45 << endl;
cout << label46 << endl;
cout << button << endl;
//printf(describeSelect);
//printf(describeUpdate);
//printf(label45);
//printf(label46);
try
{
printf("查询开始\n");
//QuerySQLNoInputParam(describeSelect, &outputColumn, &outputValueCount, &outputValue);
//printf("状态为: %s", **outputValue);
m_pRecordset.CreateInstance(__uuidof(Recordset));
if (strcmp(part_type, "车身") == 0) {
printf("查询车身订单");
m_pRecordset->Open(describeSelect, m_pConnection.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText);
}
else {
m_pRecordset->Open(describeSelect2, m_pConnection.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText);
}
while (!m_pRecordset->adoEOF)
{
printf("查询出dmu按钮得状态");
//查询出dmu按钮得状态
_variant_t taskStyle = NULL;
taskStyle = m_pRecordset->GetCollect("ENABLED");
const char* str;
_bstr_t bst_t = taskStyle;
str = (const char*)bst_t;
printf("按钮状态=======================%s\n", str);
if (strcmp(str,"true") == 0) {
if (strcmp(part_type,"车身") == 0) {
m_pConnection->Execute(_bstr_t(describeUpdate), 0, adCmdText);
m_pConnection->Execute(_bstr_t(label45), 0, adCmdText);
m_pConnection->Execute(_bstr_t(label46), 0, adCmdText);
m_pConnection->Execute(_bstr_t(button), 0, adCmdText);
printf("更新结束\n");
}
else if (strcmp(part_type, "配件") == 0 ){
m_pConnection->Execute(_bstr_t(describeUpdate2), 0, adCmdText);
m_pConnection->Execute(_bstr_t(label25), 0, adCmdText);
m_pConnection->Execute(_bstr_t(button10), 0, adCmdText);
printf("更新结束\n");
}
else {
printf("没有对应的类型");
break;
}
}
else {
break;
}
m_pRecordset->MoveNext();///移到下一条记录
}
printf("执行结束\n");
//if (strcmp(outputValue[0][0], "false") == 0) {
// printf("更新开始%s\n", outputValue[0][0]);
//m_pConnection->Execute(_bstr_t(describeUpdate), 0, adCmdText);
//m_pConnection->Execute(_bstr_t(label45), 0, adCmdText);
//m_pConnection->Execute(_bstr_t(label46), 0, adCmdText);
//m_pConnection->Execute(_bstr_t(updateDescribe), 0, adCmdText);
//printf("更新结束\n");
// return ifail;
//};
}
catch (_com_error e)
{
printf(e.Description());
return 1;
}
//strSql = NULL;
//describe = NULL;
}
}
else
{
printf("Create instance of connection failed!");
return 1;
}
}
DOFREE(attachments);
DOFREE(item_mast_rev);
DOFREE(item_id);
DOFREE(type_class);
DOFREE(part_type);
DOFREE(object_type);
DOFREE(puid);
describeSelect = NULL;
describeUpdate = NULL;
describeUpdate2 = NULL;
describeSelect2 = NULL;
label45 = NULL;
label46 = NULL;
label25 = NULL;
button = NULL;
button10 = NULL;
return ifail;
}