ConfigurationInfo

ConfigurationInfo.h

 

#ifndef CONFIGURATION_H
#define CONFIGURATION_H

#pragma once
//配置文件路径
#define  CONFIG_FILE_PATH  "conf\\jdbc.properties";

//定义一个用于匹配配置文件的数据类型
typedef struct _conf_info
{
 UINT    port;//数据库端口
 char host[20];//数据库名 
 char dbname[50];//使用的数据库名
 char userName[50];//用户名
 char userPassword[50];//用户密码

}ConfInfo;


//typedef struct _conf_info
//{
// UINT    port;//数据库端口
// CString host;//数据库名
// CString dbname;//使用的数据库名
// CString userName;//用户名
// CString userPassword;//用户密码
//}ConfInfo;

class CConfigurationInfo
{
public:
 CConfigurationInfo(void);
 ~CConfigurationInfo(void);

public:
 //获得文件处理路径
 CString GetExeFilePath();

 //获取系统配置文件信息
 void GetSystemConfInfo(ConfInfo *info);

 /* 将路径中的\转换为\\ */
 void TransformPath(CString &strFilePath);
private:
 //读取配置为文件信息
 CString CConfigurationInfo::GetConfigFileInfo(const CString &confFilePath,//配置文件路径
  const CString &confSectionName,//单元
  const CString &confKeyValue,//键值
  const CString &confDefault);//默认值)

};
#endif

 

 

 

 

 

//ConfigurationInfo.cpp

 


#include "StdAfx.h"
#include "ConfigurationInfo.h"


CConfigurationInfo::CConfigurationInfo(void)
{

}


CConfigurationInfo::~CConfigurationInfo(void)
{
}


CString CConfigurationInfo::GetExeFilePath()
{
 char chConfPath[MAX_PATH] = {0};

 //获取程序运行路径
 GetModuleFileName(NULL, chConfPath, MAX_PATH);
 CString strPath =chConfPath;
 strPath.MakeReverse();
 strPath = strPath.Mid(strPath.Find(TEXT("\\")));
 return strPath.MakeReverse() + CONFIG_FILE_PATH;
}


CString CConfigurationInfo::GetConfigFileInfo(const CString &confFilePath,//配置文件路径
             const CString &confSectionName,//单元
             const CString &confKeyValue,//键值
             const CString &confDefault)//默认值
{
 char chTemp[MAX_PATH] = {0};
 CString strTemp;
 int rtncode;
 rtncode = GetPrivateProfileString(confSectionName, confKeyValue, confDefault, chTemp, MAX_PATH, confFilePath);
 strTemp = chTemp;
 if (rtncode <= 0)
 {
  strTemp = "";
 }

 return strTemp;
}


void CConfigurationInfo::GetSystemConfInfo(ConfInfo *info)
{
 CString strResult;
 CString strPath = GetExeFilePath();
 TransformPath(strPath);

 //MYSQL值
 strResult = GetConfigFileInfo(strPath, TEXT("MYSQL"), TEXT("SERVER"), TEXT("localhost"));
 //info->host = strResult;
 strcpy(info->host,strResult);

 //PORT值
 strResult = GetConfigFileInfo(strPath, TEXT("MYSQL"), TEXT("PORT"), TEXT("3306"));
 info->port = atoi(strResult);

 //用户名值
 strResult = GetConfigFileInfo(strPath, TEXT("MYSQL"), TEXT("USER"), TEXT("root"));
 //info->userName = strResult;
 strcpy(info->userName,strResult);

 //用户密码值
 strResult = GetConfigFileInfo(strPath, TEXT("MYSQL"), TEXT("Password"), TEXT("123456"));
 //info->userPassword = strResult;
 strcpy(info->userPassword,strResult);
 //数据库名
 strResult = GetConfigFileInfo(strPath, TEXT("MYSQL"), TEXT("Database"), TEXT("lda"));
 strcpy(info->dbname,strResult);
 //info->dbname = strResult;
}


void CConfigurationInfo::TransformPath(CString &strFilePath)
{
 int i,iLen;
 iLen = strFilePath.GetLength();
 CString csRetFileName;
 char ch;

 csRetFileName = "";
 for (i=0;i<iLen;i++)
 {
  ch = strFilePath.GetAt(i);

  if (i == 636)
  {
   int a = 0;
  }
  if ( '\\' == ch)
  {
   csRetFileName += '\\';
   i++;
   if(strFilePath.GetAt(i) == '\\')
   {
    csRetFileName += '\\';
   }
   else
   {
    csRetFileName += '\\';
    csRetFileName += strFilePath.GetAt(i);
   }
  }
  else
  {
   csRetFileName += ch;
  }
 }

 strFilePath = csRetFileName;
}

DealData.h

 

#ifndef DEALDATA_H
#define DEALDATA_H
#pragma once
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include "MySqlHelper.h"
#include "ConfigurationInfo.h"
//结构体,用于保存maxbatch中的相关信息
typedef struct maxbatchinfo
{
 UINT directoryType;
 CString directoryPath;
}MaxBatchInfo;

//定义最大批次的文件路径容器
typedef vector<CString> VecMaxPath;

//定义一个MAP类型用来声明MapRunPath类型变量,存放表run_path中的数据对<Test_Project_Id,runPath>
//typedef map<CString, CString> MapRunPath;

//定义一个MapOfDirAndProjectId类型,用来声明MapOfDirAndProjectId的变量,
//存放表test_project表中的<Test_Project_Id,Project_src_Dir>
//typedef multimap<CString, UINT> MapOfDirAndProjectId;
typedef multimap<CString, MaxBatchInfo> MapOfDirAndProjectId;
class DealData
{
public:
 DealData(void);
 ~DealData(void);
public:
 //获取test_project最大批次数据
 void GetMaxBatch();

 //获取run_path所有数据
 //void GetRunPathData();

 //判断传入路径是否在run_path中已经存在
 //bool IsExistInRunPath(const CString strPath);
 bool IsExistInRunPath(const CString projectPath,const CString strPath);
 //获取对应路径的ProjectId
 UINT GetIDThroughPath(CString strPath);
 UINT  GetbatchThroughPath(CString strPath);
 //获得最大批次的文件路径缓存
 VecMaxPath*  ReturnMaxBatchPath(void);

 //返回runpath所有文件目录
 //MapRunPath* ReturnRunpath(void);

 //入库
 void ControlDataInsertOrRead(const CString strSQL);

 //判断最大批次文件路径中是否已经存在该记录
 bool IsExistMaxPathPath(const CString &strPath);

public:
 //数据库操作类
 MySqlHelper DBHelper;

 //存放最大批次的文件路径
 VecMaxPath m_vecMaxPath;

 //存放最大批次的文件路径对应的ProjectId
 MapOfDirAndProjectId m_mapMaxProjectId;

 //存放run_path数据表中所有数据
 //初始化时从数据库中读取数据,之后每次向数据库中插入数据的同时向MAP中插入
 //MapRunPath m_mapRunPath;

};
#endif

 

 

DealData.cpp


#include "StdAfx.h"
#include "DealData.h"
#include "LogFile.h"

DealData::DealData()
{
 ConfInfo *m_info;
 m_info = new ConfInfo;
 CConfigurationInfo conInfo;
 memset(m_info,0,sizeof(ConfInfo));
 conInfo.GetSystemConfInfo(m_info); 
 //连接数据库
 int iResult = DBHelper.FunConnectData(m_info->host, m_info->userName, m_info->userPassword,
  m_info->dbname, m_info->port, CLIENT_MULTI_STATEMENTS);
 if (iResult == -1)
 {
  return ;//数据库连接失败,此处应失败的原因告知用户,否则不方便调试,找不到扫描没执行的原因
 }
}


DealData::~DealData()
{
 m_vecMaxPath.clear();
 m_mapMaxProjectId.clear();
 //m_mapRunPath.clear(); 
 DBHelper.CloseDataConnect();
}


bool DealData::IsExistMaxPathPath(const CString &strPath)
{
 vector<CString>::iterator itercsVec = m_vecMaxPath.begin();
 while (itercsVec != m_vecMaxPath.end())
 {
  if (strPath == *itercsVec)
  {
   return true;
  }

  itercsVec++;
 }
 return false;
}


void DealData::GetMaxBatch()
{
 m_vecMaxPath.clear();
 m_mapMaxProjectId.clear();
 CString strSQL;
 //获取最大批次的数据库语句
 //strSQL.Format(TEXT("SELECT Project_Src_Dir,Test_Project_Id from test_project where batch = (select max(batch) from test_project)"));
 strSQL.Format(TEXT("select directory,type from MonitorDirectory"));
 //typedef pair <UINT, CString> Int_Pair;
 //typedef pair <CString, UINT> Int_PairOne;
 typedef pair <CString, MaxBatchInfo> Int_PairOne;
 MYSQL_RES *SQL_RES  = DBHelper.QuerySQL(strSQL);
 MYSQL_ROW Row;
 CString strRes;
 UINT directoryType = 0;
 MaxBatchInfo tmpMaxBatchInfo;
 while((Row = DBHelper.fetch_QuerySQL(SQL_RES)) !=NULL)
 {
  strRes = Row[0];//路径
  CConfigurationInfo tmp;
  tmp.TransformPath(strRes);
  if (strRes != "")
  {
   if (!IsExistMaxPathPath(strRes))
   {
    //目录类型
    directoryType = atoi(Row[1]);
    tmpMaxBatchInfo.directoryPath=strRes;
    tmpMaxBatchInfo.directoryType=directoryType;

    //保存最大年批次文件路径
    m_vecMaxPath.push_back(strRes);

    //将所有对应文件路径及工程ID存入m_mapProjectId
    //m_mapMaxProjectId.insert(Int_PairOne(strRes, iProjectId));
    m_mapMaxProjectId.insert(Int_PairOne(strRes, tmpMaxBatchInfo));
   }
  }
 }
 DBHelper.ReleaseAfterQuerySQL(SQL_RES);
}


bool DealData::IsExistInRunPath(const CString projectPath,const CString strPath)
{
 CString strTmp=strPath;
 CConfigurationInfo tmp;
 tmp.TransformPath(strTmp);
  CString strTempProjectPath=projectPath;
  int tmpProjectId=GetIDThroughPath(strTempProjectPath);
  CString strSQL;
  strSQL.Format(TEXT("SELECT runPath from run_path where runPath=\'%s\' and Test_Project_Id=%d"),strTmp,tmpProjectId);
  MYSQL_RES *SQL_RES  = DBHelper.QuerySQL(strSQL);
  MYSQL_ROW Row;
  if((Row = DBHelper.fetch_QuerySQL(SQL_RES)) !=NULL)
  {
   return true;
  }
  DBHelper.ReleaseAfterQuerySQL(SQL_RES); 
 return false;
}

 

 

UINT DealData::GetIDThroughPath(CString strPath)
{
 //GetMaxBatch();
 //multimap<CString, UINT>::iterator iterId = m_mapMaxProjectId.find(strPath);

 //if (iterId != m_mapMaxProjectId.end())
 //{
 // return iterId->second;
 //}
 //return -1;
 //if(m_mapMaxProjectId.empty())
 //{
 // GetMaxBatch();
 //}
 //MaxBatchInfo tmpMaxBatchInfo;
 //multimap<CString, MaxBatchInfo>::iterator iterId = m_mapMaxProjectId.find(strPath);

 //if (iterId != m_mapMaxProjectId.end())
 //{
 // tmpMaxBatchInfo = iterId->second;
 // return tmpMaxBatchInfo.Test_Project_Id;
 //}
 return -1;
}


UINT DealData::GetbatchThroughPath(CString strPath)
{
 //MaxBatchInfo tmpMaxBatchInfo;
 //multimap<CString, MaxBatchInfo>::iterator iterId = m_mapMaxProjectId.find(strPath);

 //if (iterId != m_mapMaxProjectId.end())
 //{
 // tmpMaxBatchInfo = iterId->second;
 // return tmpMaxBatchInfo.batch;
 //}
 return -1;
}


VecMaxPath*  DealData::ReturnMaxBatchPath(void)
{
 return &m_vecMaxPath;
}


void DealData::ControlDataInsertOrRead(const CString strSQL)
{
 try
 {
  //UINT iProjectId = GetIDThroughPath(strSou);
  //UINT ibatch=GetbatchThroughPath(strSou);
  //CString str = strData;
  //CConfigurationInfo tmp;
  //tmp.TransformPath(str);
  //CString strSQL;
  //strSQL.Format(TEXT("insert into run_path(Test_Project_Id,runPath,isDone,batch)"\
  // "values(%d,\'%s\',%d,%d);"), iProjectId, str, 0,ibatch); 
  DBHelper.Start_Transaction();//开始事务
  DBHelper.MultiInsert(strSQL);
  DBHelper.Commit();   //提交事务
 }
 catch (...)
 {
  CTime m_currentTime=CTime::GetCurrentTime();
  CString currentTimeStr;
  currentTimeStr.Format(_T("%04d%02d%02d %02d:%02d:%02d"),
   m_currentTime.GetYear(),
   m_currentTime.GetMonth(),
   m_currentTime.GetDay(),
   m_currentTime.GetHour(),
   m_currentTime.GetMinute(),
   m_currentTime.GetSecond());
  WRITELOG("ERR:"+currentTimeStr+"insert into mysql failed!");
 }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值