分享C++寫後臺程式碼

weixin_34107955發表於2017-08-17

/*************************************************
Copyright: Baosight Software LTD.co Copyright (c) 2010
Author: sky_yang
Version: 1.0
Date: 2017-8-08
Description: 生產單元產量完成情況查詢(按生產廠)
**************************************************/

/***** C++ 的標準標頭檔案部分 *****/

include "stdafx.h"

/***** C++ 的業務標頭檔案部分 *****/
/<remark>=========================================================
///<summary>
///<para> </para>
///<para></para>
///</summary>
///<returns></returns>
===========================================================</remark>
/
// service入口
BM2F_ENTERACE(oimmhp05f2_inq)

int f_oimmhp05f2_inq(EIClass * bcls_rec, EIClass * bcls_ret, CDbConnection * conn)
{

CTracer log(__FUNCTION__);  //系統日誌類定義

/* 程式內部變數 */
int doFlag = 0;

/* 資料庫SQL操作字串 */
CString sqlstr;

CDbCommand cmd_inq(conn);
try
{
    //獲取傳入引數
    


    switch (conn->DatabaseKind)
    {
    case DB_KIND_DB2:               // DB2 資料庫(未開Oracle相容)
    case DB_KIND_DB2_ORACLE:        // DB2 資料庫(開Oracle相容)
    case DB_KIND_MSSQL:             // MS SQL Server資料庫
    case DB_KIND_ORACLE:            // Oracle 資料庫
    default:
        sqlstr = "SELECT  CFGP01_VDESC AS CFGP01_VD,SUM(STOCK_END_WT) AS STOCK_END_WT FROM TOIMM02 WHERE CFGP01_NAME = 'PROD_CODE' GROUP BY  CFGP01_VDESC";

    }
    Log::Trace(" ", __FUNCTION__, "sqlstr =[{0}]", sqlstr);
    cmd_inq.SetCommandText(sqlstr);
    cmd_inq.ExecuteQuery(bcls_ret->Tables[0]);
    cmd_inq.Close();

    bcls_ret->Tables.Add();
    bcls_ret->Tables[1].Rows.Add();

    switch (conn->DatabaseKind)
    {
    case DB_KIND_DB2:               // DB2 資料庫(未開Oracle相容)
    case DB_KIND_DB2_ORACLE:        // DB2 資料庫(開Oracle相容)
    case DB_KIND_MSSQL:             // MS SQL Server資料庫
    case DB_KIND_ORACLE:            // Oracle 資料庫
    default:
        sqlstr = "select CFGP01_VDESC AS CFGP01_VE,SUM(STOCK_END_WT) AS STOCK_E_WT from TOIMM02 WHERE CFGP01_NAME = 'STOCK_AGE' GROUP BY  CFGP01_VDESC ";

    }
    Log::Trace(" ", __FUNCTION__, "sqlstr =[{0}]", sqlstr);
    cmd_inq.SetCommandText(sqlstr);
    cmd_inq.ExecuteQuery(bcls_ret->Tables[1]);
    cmd_inq.Close();

    bcls_ret->Tables.Add();
    bcls_ret->Tables[2].Rows.Add();

    switch (conn->DatabaseKind)
    {
    case DB_KIND_DB2:               // DB2 資料庫(未開Oracle相容)
    case DB_KIND_DB2_ORACLE:        // DB2 資料庫(開Oracle相容)
    case DB_KIND_MSSQL:             // MS SQL Server資料庫
    case DB_KIND_ORACLE:            // Oracle 資料庫
    default:
        sqlstr = "select CFGP01_VDESC AS CFGP01_VS,SUM(STOCK_END_WT) AS STOCK_N_WT from TOIMM02 WHERE CFGP01_NAME = 'STOCK_STURCT' AND CFGP02_VALUE = 'SM' group by CFGP01_VDESC";

    }
    Log::Trace(" ", __FUNCTION__, "sqlstr =[{0}]", sqlstr);
    cmd_inq.SetCommandText(sqlstr);
    cmd_inq.ExecuteQuery(bcls_ret->Tables[2]);
    cmd_inq.Close();

    bcls_ret->Tables.Add();
    bcls_ret->Tables[3].Rows.Add();
    switch (conn->DatabaseKind)
    {
    case DB_KIND_DB2:               // DB2 資料庫(未開Oracle相容)
    case DB_KIND_DB2_ORACLE:        // DB2 資料庫(開Oracle相容)
    case DB_KIND_MSSQL:             // MS SQL Server資料庫
    case DB_KIND_ORACLE:            // Oracle 資料庫
    default:
        sqlstr = " SELECT CFGP01_VDESC AS CFGP01_VC,SUM(STOCK_END_WT) AS STOCK_D_WT FROM TOIMM02 WHERE CFGP01_NAME = 'STOCK_STURCT' AND CFGP02_VALUE = 'PR' GROUP BY CFGP01_VDESC ";

    }
    Log::Trace(" ", __FUNCTION__, "sqlstr =[{0}]", sqlstr);
    cmd_inq.SetCommandText(sqlstr);
    cmd_inq.ExecuteQuery(bcls_ret->Tables[3]);
    cmd_inq.Close();

}
catch (CDbException& ex)  //捕獲資料庫操作異常
{
    CFormattable arguments[] = { ex.GetCode() };
    CMessageFormat::Format(s.msg, _RES("GCRSS0000006")/*資料庫處理出錯,sqlcode=[{0}]。請聯絡系統維護人員。*/, arguments, 1);
    CString str = sqlstr + "\r\n" + ex.GetMsg();
    strncpy(s.sysmsg, (const char*)str, sizeof(s.sysmsg) - 1);
    s.flag = -1;
    doFlag = -1;      //資料庫異常時返回-1,事務將被回滾
}
catch (CApplicationException& ex)  //捕獲應用錯誤
{
    s.flag = ex.GetCode();
    doFlag = -1;
}
catch (CException& ex)
{
    strncpy(s.msg, (const char*)ex.GetMsg(), sizeof(s.msg) - 1);
    s.flag = ex.GetCode();
    doFlag = -1;
}

return doFlag;

}

相關文章