#include "stdafx.h"
#include "XQTools.h"
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
map<string,string> XQTools::mapTabDatas = map<string,string>();
string GetLine()
{
char cTmp = 0;
string sRes;
do{
cTmp = getchar();
sRes += cTmp;
}while(cTmp != '
');
return sRes;
}
bool XQTools::MapLineData()
{
char cTmp = 0;
string sRes = "";
string sKey = "";
cin>>sKey;
sRes += sKey;
do{
cTmp = getchar();
sRes += cTmp;
}while(cTmp != '
'&&cTmp!=EOF);
XQTools::mapTabDatas[sKey] = sRes;
return sRes.length()>20;
}
static string sHead = "";
void XQTools::Init()
{
if(freopen("D://Source.tab","r",stdin));
{
sHead += GetLine();
sHead += GetLine();
sHead += GetLine();
}
while(MapLineData());
return ;
}
void XQTools::WriteNewFile(string sFileName, string sMessage )
{
freopen(sFileName.c_str(),"w",stdout);
cout<<sHead;
string sYear = "";
string sMon = "";
int flag = 1;
for(int i = 0 ; i < sMessage.length(); i ++)
{
if(flag == 1)
{
if(sMessage[i]!='
'&&sMessage[i] != ' '&& sMessage[i] !=13 && sMessage[i] != 0)
sYear+= sMessage[i];
}else if(flag == 2)
{
if(sMessage[i] == ' ' || sMessage[i] == '
'||sMessage[i] == 13)
{
if(sMon.length() > 0)
AddLine(sYear,sMon);
sMon = "";
}else
{
sMon += sMessage[i];
}
}
if(sMessage[i]=='
')
{
flag ++;
if(flag == 3)
{
flag = 1;
sYear = "";
}
}
}
cout<<flush;
return ;
}
std::string XQTools::GetFileName()
{
//"D://解密后的图片.jpg";
string sFileName = "D://";
char sTmp[20];
time_t Time = 0;
time(&Time);
struct tm Tm;
localtime_s(&Tm,&Time);
sprintf_s(sTmp,20,"%02d%02d%02d",Tm.tm_hour,Tm.tm_min,Tm.tm_sec);
sFileName += sTmp;
sFileName += ".tab";
return sFileName;
}
void XQTools::AddLine(string sYear,string sMon)
{
string sDate = "";
sDate += sYear + "年";
sDate += sMon + "月";
if(mapTabDatas.find(sDate)==mapTabDatas.end())
{
cout<<sDate<<" No Find"<<endl;
}else
{
string sCout = mapTabDatas[sDate];
cout << sCout;
}
}
void CExcelToolsDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
string sFileName = XQTools::GetFileName();
CString csMessage ;
GetDlgItem(IDC_EDIT1)->GetWindowText(csMessage);
USES_CONVERSION;
string sMessage = W2CA((LPCWSTR)csMessage);
XQTools::WriteNewFile(sFileName,sMessage);
system(sFileName.c_str());
//OnOK();
}