#include "StdAfx.h"
|
#include "MBFireAppExtParam.h"
|
#include "json.h"
|
|
CMBFireAppExtParam::CMBFireAppExtParam(void)
|
{
|
m_pMasterCls = new CMBFireMasterCls();
|
m_pComposeCls = new CMBFireComposeCls();
|
m_pDataCls = new CMBFireDataCls();
|
m_pGroupSet = new CMBFireGroupSet();
|
m_pQrCodeSet = new CMBFireQrCodeSet();
|
m_pPrintStyle = new CMBFirePrintStyle();
|
m_pOutputSet = new CMBFireOutputSet();
|
}
|
|
|
CMBFireAppExtParam::~CMBFireAppExtParam(void)
|
{
|
MBSAFE_DELETE(m_pMasterCls)
|
MBSAFE_DELETE(m_pComposeCls)
|
MBSAFE_DELETE(m_pDataCls)
|
MBSAFE_DELETE(m_pGroupSet)
|
MBSAFE_DELETE(m_pQrCodeSet)
|
MBSAFE_DELETE(m_pPrintStyle)
|
MBSAFE_DELETE(m_pOutputSet)
|
}
|
|
|
CMBFireMasterCls *CMBFireAppExtParam::GetMasterCls()
|
{
|
return m_pMasterCls;
|
}
|
|
CMBFireComposeCls *CMBFireAppExtParam::GetComposeCls()
|
{
|
return m_pComposeCls;
|
}
|
|
CMBFireDataCls *CMBFireAppExtParam::GetDataCls()
|
{
|
return m_pDataCls;
|
}
|
|
CMBFireGroupSet *CMBFireAppExtParam::GetGroupSet()
|
{
|
return m_pGroupSet;
|
}
|
|
CMBFireQrCodeSet *CMBFireAppExtParam::GetQrCodeSet()
|
{
|
return m_pQrCodeSet;
|
}
|
|
CMBFirePrintStyle *CMBFireAppExtParam::GetPrintStyle()
|
{
|
return m_pPrintStyle;
|
}
|
|
CMBFireOutputSet *CMBFireAppExtParam::GetOutputSet()
|
{
|
return m_pOutputSet;
|
}
|
|
// {"mastercls":{"cls_id":"0031","cls_name":"µç¿Ø×ܳÉ","key_attr":"CODE","key_attrname":"ÎïÁϱàÂë","key_attrsize":"32","attrs":[{"attr":"NAME","name":"Ãû³Æ","size":"128"}]},"composecls":{"cls_id":"0032","cls_name":"Èí¼þ"},"datacls":{"cls_id":"0030","cls_name":"µç¿ØÈí¼þ"},"groupset":{"group":"1","attr":"TYPE","attr_name":"Èí¼þÀàÐÍ"},"qr_code_set":[{"clsid":"0031","attr":"CODE"},{"clsid":"0030","attr":"SOFT_CODE"}]}
|
bool CMBFireAppExtParam::ParseJson( CString strJson,CString &strErrInfo )
|
{
|
if( strJson.IsEmpty() )
|
return false;
|
|
////////³õʼ»¯///////////////////
|
MBSAFE_DELETE(m_pMasterCls)
|
MBSAFE_DELETE(m_pComposeCls)
|
MBSAFE_DELETE(m_pDataCls)
|
MBSAFE_DELETE(m_pGroupSet)
|
MBSAFE_DELETE(m_pQrCodeSet)
|
MBSAFE_DELETE(m_pPrintStyle)
|
MBSAFE_DELETE(m_pOutputSet)
|
|
m_pMasterCls = new CMBFireMasterCls();
|
m_pComposeCls = new CMBFireComposeCls();
|
m_pDataCls = new CMBFireDataCls();
|
m_pGroupSet = new CMBFireGroupSet();
|
m_pQrCodeSet = new CMBFireQrCodeSet();
|
m_pPrintStyle = new CMBFirePrintStyle();
|
m_pOutputSet = new CMBFireOutputSet();
|
//////////////////////////////////////////
|
Json::Reader reader;
|
Json::Value json_object;
|
Json::Value json_orderby;
|
Json::Value json_groupset;
|
Json::Value json_outputset;
|
Json::Value json_masterclsattr;
|
|
CString strDataType,strDesc;
|
string json;
|
string masterCls,composeCls,dataCls,groupSet,qrCodeSet;
|
|
strJson.Replace(_T("'"),_T("\""));
|
|
json = CT2A(strJson);
|
|
if (!reader.parse(json, json_object)){
|
strErrInfo = strJson + _T(" ·Çjson¸ñʽ£¡");
|
return false;
|
}
|
|
m_pMasterCls->m_strClsID = json_object["mastercls"]["cls_id"].asString().c_str();
|
m_pMasterCls->m_strClsName = json_object["mastercls"]["cls_name"].asString().c_str();
|
m_pMasterCls->m_strKeyAttr = json_object["mastercls"]["key_attr"].asString().c_str();
|
m_pMasterCls->m_strKeyAttrName = json_object["mastercls"]["key_attrname"].asString().c_str();
|
m_pMasterCls->m_strKeyAttrSize = json_object["mastercls"]["keyattr_size"].asString().c_str();
|
m_pMasterCls->m_strNameAttr = json_object["mastercls"]["name_attr"].asString().c_str();
|
m_pMasterCls->m_strNameAttrName = json_object["mastercls"]["name_attrname"].asString().c_str();
|
m_pMasterCls->m_strNameAttrSize = json_object["mastercls"]["nameattr_size"].asString().c_str();
|
json_masterclsattr = json_object["mastercls"]["attrs"];
|
if( json_masterclsattr.isArray() )
|
{
|
int nSize = json_masterclsattr.size();
|
for( int i = 0; i< nSize; i++ )
|
{
|
CMBFireMasterClsAttr *pAttr = new CMBFireMasterClsAttr();
|
|
pAttr->m_strAttr = json_masterclsattr[i]["attr"].asString().c_str();
|
pAttr->m_strName = json_masterclsattr[i]["name"].asString().c_str();
|
pAttr->m_strSize = json_masterclsattr[i]["size"].asString().c_str();
|
|
if( !m_pMasterCls->GetAttrMgr()->AddAttr( pAttr ) )
|
{
|
MBSAFE_DELETE(pAttr)
|
}
|
|
}// end for
|
} // end if( json_masterclsattr.isArray() )
|
|
|
m_pComposeCls->m_strClsID = json_object["composecls"]["cls_id"].asString().c_str();
|
m_pComposeCls->m_strClsName = json_object["composecls"]["cls_name"].asString().c_str();
|
|
// orderby
|
json_orderby = json_object["composecls"]["orderby"];
|
if( json_orderby.isArray() )
|
{
|
int nSize = json_orderby.size();
|
for( int i = 0; i< nSize; i++ )
|
{
|
CMBFireOrderBy *pOrderBy = new CMBFireOrderBy();
|
pOrderBy->m_strAttr = json_orderby[i]["attr"].asString().c_str();
|
strDesc = json_orderby[i]["desc"].asString().c_str();
|
if( strDesc == _T("1") )
|
{
|
pOrderBy->m_bDesc = true;
|
}
|
if( !m_pComposeCls->AddOrderBy(pOrderBy) )
|
{
|
MBSAFE_DELETE(pOrderBy)
|
}
|
}
|
}
|
|
|
|
m_pDataCls->m_strClsID = json_object["datacls"]["cls_id"].asString().c_str();
|
m_pDataCls->m_strClsName = json_object["datacls"]["cls_name"].asString().c_str();
|
|
m_pGroupSet->m_strGroup = json_object["groupset"]["group"].asString().c_str();
|
m_pGroupSet->m_strAttr = json_object["groupset"]["attr"].asString().c_str();
|
m_pGroupSet->m_strAttrName = json_object["groupset"]["attr_name"].asString().c_str();
|
|
//// qr_code_set
|
json_groupset = json_object["qr_code_set"] ;
|
if( json_groupset.isArray() )
|
{
|
int nSize = json_groupset.size();
|
for( int i = 0; i< nSize; i++ )
|
{
|
CMBFireQrCodeInfo *pQrCodeInfo = new CMBFireQrCodeInfo();
|
strDataType = json_groupset[i]["datatype"].asString().c_str();
|
pQrCodeInfo->m_nDataType = _ttoi(strDataType);
|
pQrCodeInfo->m_strClsID = json_groupset[i]["clsid"].asString().c_str();
|
pQrCodeInfo->m_strAttr = json_groupset[i]["attr"].asString().c_str();
|
pQrCodeInfo->m_strValue = json_groupset[i]["value"].asString().c_str();
|
|
if( !m_pQrCodeSet->AddQrCode(pQrCodeInfo) )
|
{
|
MBSAFE_DELETE(pQrCodeInfo)
|
}
|
|
}// end for
|
} // end if( json_groupset.isArray() )
|
/// print_style
|
m_pPrintStyle->m_strLayout = json_object["print_style"]["layout"].asString().c_str();
|
m_pPrintStyle->m_strQrPosition = json_object["print_style"]["qr_position"].asString().c_str();
|
//// attr_output_set
|
json_outputset = json_object["attr_output_set"] ;
|
if( json_outputset.isArray() )
|
{
|
int nSize = json_outputset.size();
|
for( int i = 0; i< nSize; i++ )
|
{
|
CMBFireOutputSetInfo *pSetInfo = new CMBFireOutputSetInfo();
|
strDataType = json_outputset[i]["datatype"].asString().c_str();
|
pSetInfo->m_nDataType = _ttoi(strDataType);
|
pSetInfo->m_strClsID = json_outputset[i]["clsid"].asString().c_str();
|
pSetInfo->m_strAttr = json_outputset[i]["attr"].asString().c_str();
|
pSetInfo->m_strValue = json_outputset[i]["value"].asString().c_str();
|
pSetInfo->m_strTitle = json_outputset[i]["title"].asString().c_str();
|
if( !m_pOutputSet->Add(pSetInfo) )
|
{
|
MBSAFE_DELETE(pSetInfo)
|
}
|
|
}// end for
|
} // end if( json_groupset.isArray() )
|
|
return true;
|
}
|
|
// ÊÇ·ñ´ïµ½ÒªÇó
|
bool CMBFireAppExtParam::IsReachRequire(CString &strErrInfo)
|
{
|
if(m_pMasterCls->m_strClsID.IsEmpty())
|
{
|
strErrInfo = _T("master clsidΪ¿Õ£¡");
|
return false;
|
}
|
|
if( m_pComposeCls->m_strClsID.IsEmpty() )
|
{
|
strErrInfo = _T("Compose clsidΪ¿Õ£¡");
|
return false;
|
}
|
|
if( m_pDataCls->m_strClsID.IsEmpty() )
|
{
|
strErrInfo = _T("data clsidΪ¿Õ£¡");
|
return false;
|
}
|
|
|
return true;
|
}
|
|
|
CString CMBFireAppExtParam::GetTN_XXX_XXXTableName()
|
{
|
CString strTableName;
|
|
strTableName.Format(_T("TN_%s_%s"),m_pMasterCls->m_strClsID,m_pDataCls->m_strClsID);
|
|
return strTableName;
|
}
|
|
CString CMBFireAppExtParam::GetTN_XXXTableName()
|
{
|
CString strTableName;
|
|
strTableName.Format(_T("TN_%s"),m_pDataCls->m_strClsID);
|
|
return strTableName;
|
}
|
|
|
CString CMBFireAppExtParam::GetTN_MClsID_DClsIDCreateTableSql()
|
{
|
CString strSql,strTableName,strKeyAttrSize,
|
strNameAttrSize,strAttrSql,strKeyAttr;
|
|
strTableName = GetTN_XXX_XXXTableName();
|
|
// ĬÈÏ
|
strKeyAttrSize = _T("32");
|
strNameAttrSize = _T("64");
|
strKeyAttr = m_pMasterCls->m_strKeyAttr;
|
|
if( !m_pMasterCls->m_strKeyAttrSize.IsEmpty() )
|
{
|
strKeyAttrSize = m_pMasterCls->m_strKeyAttrSize;
|
}
|
|
if( !m_pMasterCls->m_strNameAttrSize.IsEmpty() )
|
{
|
strNameAttrSize = m_pMasterCls->m_strNameAttrSize;
|
}
|
|
strAttrSql = m_pMasterCls->GetAttrMgr()->GetAttrSql();
|
|
strSql.Format(_T("CREATE TABLE %s(G_MASTER_OBJ_ID char(36),G_SLAVE_OBJ_ID char(36),G_SLAVE_OBJ_VID char(36),%s varchar(%s),%s,C_Order int,C_Effect char(10),C_Invalidate char(10),PRIMARY KEY(G_MASTER_OBJ_ID,G_SLAVE_OBJ_ID))"),
|
strTableName,strKeyAttr,strKeyAttrSize,strAttrSql );
|
|
|
return strSql;
|
}
|
|
// Ö÷ÀàÊôÐÔ
|
CString CMBFireAppExtParam::GetMasterClassAttrs()
|
{
|
return m_pMasterCls->GetMasterClassAttrs();
|
}
|