You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB
C++

#include "StdAfx.h"
#include "WorkRecord.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "AuthorityMgr.h"
#include "WorkTime.h"
#include "FileMgr.h"
#include "LogMgr.h"
CWorkRecordMgr *gWorkRecordMgr = new CWorkRecordMgr;
CWorkRecordMgr::CWorkRecordMgr(void)
{
}
CWorkRecordMgr::~CWorkRecordMgr(void)
{
}
CMFCPropertyGridProperty *CWorkRecordMgr::CreatGridProperty()
{
CString PropertyName;//属性名称
CString Description;//描述
CString Path = _T("WorkRecordMgr");//存储路径
CString Name;
//-------------------------------------------------------------------------------//
PropertyName = _T("加工记录");
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
//-------------------------------------------------------------------------------//
if(gAuthorityMgr->CheckAuthority(_FACTORY))
{
{
//添加属性变量映射
Name = _T("m_RecordFilePath");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_RecordFilePath);
pPropertie->SetType(_PROP_TYPE_STRING);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("存储路径");
Description = _T("记录文件的保存路径");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_RecordFilePath, Description);
pGroup->AddSubItem(p);
gDevicePropertieMgr.Insert(p, pPropertie);
}
}
//-------------------------------------------------------------------------------//
return pGroup;
}
//加工记录写入文件
void CWorkRecordMgr::WriteRecordToFile()
{
CFileMgr FileMgr;
//检查日志目录是否存在
if(!FileMgr.IsDirectoryExists(m_RecordFilePath))
{
gLogMgr->WriteDebugLog("Error---->日志目录不存在");
return;
}
//检查当天的文件是否存在
CString CurFilePath = m_RecordFilePath+"\\"+gWorkTime.GetCurDate("_")+".rcd";
if(!FileMgr.IsFileExist(CurFilePath))
{
//创建新的文件
ofstream File;
File.open(CurFilePath);
File.close();
}
ofstream File(CurFilePath,ios::app);
File<<GetRecordStr()<<endl;
File.close();
gLogMgr->WriteDebugLog("func:WriteRecordToFile--->OK");
}
CString CWorkRecordMgr::GetRecordStr()
{
CString str;
str += "[用户] "+ gAuthorityMgr->GetCurUserName();
str += " [产品型号] "+ m_ProductType;
str += " [开始时间] "+ gWorkTime.GetCurDate("/")+ " "+m_StartWorkTime;
str += " [结束时间] "+ gWorkTime.GetCurDate("/")+ " "+m_EndWorkTime;
str += " [加工时间] "+ m_WorkTime;
return str;
}