首页 > 代码库 > 代码编写
代码编写
1 图像处理后在图片上显示信息如下:
2 得到显示数据的代码如下:
dist_OK1 =DistanceMin1>0.5;
dist_OK2=DistanceMin2>3;
mes_disp.Reset();
mes_disp.Append("距¨¤溢°?胶o标à¨o准á?线?距¨¤离¤?"+DistanceMin1);
mes_disp.Append("距¨¤漏?胶o标à¨o准á?线?距¨¤离¤?"+DistanceMin2);
mes_disp.Append("胶o长?è"+Length1);
mes_disp.Append("胶o宽¨a"+Length2);
if(0!=(dist_OK1*dist_OK2))
{
disp_message(m_showStatic.GetHalconWindow(),mes_disp,"window",40,10,"green","false");
disp_message(m_showStatic.GetHalconWindow(),"OK","window",10,10,"green","false");
}
else
{
disp_message(m_showStatic.GetHalconWindow(),mes_disp,"window",40,10,"red","false");
disp_message(m_showStatic.GetHalconWindow(),"NotOK","window",10,10,"red","false");
}
3 界面上有一个按钮:
4 点击后弹出:
5 把数据在对话框中显示出来。点胶合格和断胶用是否表示。这一步怎么做?帮忙写一下代码。
6 框架里有类似的实现,没大看懂,如下两个类DlgWarningList.cpp和DlgWarningInfo.cpp
(1)
// DlgWarningInfo.cpp : 实o|ì现?文?件t
//
#include "stdafx.h"
#include "AutoFrame.h"
#include "DlgWarningInfo.h"
#include "ConfigMgr.h"
#include "System.h"
// CDlgWarningInfo 对?话??框¨°
IMPLEMENT_DYNAMIC(CDlgWarningInfo,CDialog)
CDlgWarningInfo::CDlgWarningInfo(CWnd*pParent/*=NULL*/)
:CDialog(CDlgWarningInfo::IDD,pParent)
,m_showInfoType(SHOW_ALL)
{
}
CDlgWarningInfo::~CDlgWarningInfo()
{
}
void CDlgWarningInfo::DoDataExchange(CDataExchange*pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDlgWarningInfo,CDialog)
ON_WM_SIZE()
END_MESSAGE_MAP()
// CDlgWarningInfo 消?息?é处?|理¤¨a程¨?序¨°
BOOL CDlgWarningInfo::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在¨2此??添?¨a加¨?额?外aa的ì?初?始o?化?¥
this->SetWindowText(_T("错?¨a误¨?信?息?é查¨|看??"));
CRectrcShow;
GetClientRect(rcShow);
m_warnList.Create(IDD_DIALOG_WARNING_LIST,this);
m_warnList.MoveWindow(rcShow);
m_warnList.ShowWindow(SW_SHOW);
m_warnList.ClearItem();
m_warnList.AddItem(_T("序¨°号?"),50);
m_warnList.AddItem(_T("日¨?期¨2"),100);
m_warnList.AddItem(_T("时o?à间?"),100);
m_warnList.AddItem(_T("报à?§警?¥信?息?é"),385);
m_warnList.InitGrid();
CStringstrTmp;
map<int,vector<CString>>info=CWarningMgr::_Instance()->GetErrorMap();
map<int,vector<CString>>::reverse_iteratorit=info.rbegin();
if (it!=info.rend())
{
intline =1;
for(;it!=info.rend();++it,++line)
{
inti =0;
strTmp.Format(_T("%d"),line);
m_warnList.m_gridCtl.SetItemText(line,i,strTmp);
for(i=1;i<4;++i)
{
m_warnList.m_gridCtl.SetItemText(line,i,(it->second).at(i-1));
}
}
}
returnTRUE; // return TRUEunless you set the focus to a control
// 异°¨?常?ê: OCX属o?性?页°3应?|返¤|ì回? FALSE
}
void CDlgWarningInfo::OnSize(UINTnType,intcx,intcy)
{
CDialog::OnSize(nType,cx,cy);
// TODO: 在¨2此??处?|添?¨a加¨?消?息?é处?|理¤¨a程¨?序¨°代?¨2码?
if (m_warnList.GetSafeHwnd())
{
CRectrcShow;
GetClientRect(rcShow);
m_warnList.MoveWindow(rcShow);
m_warnList.m_gridCtl.ExpandLastColumn();
m_warnList.m_gridCtl.Refresh();
}
}
(2)
// DlgWarningList.cpp : 实o|ì现?文?件t
//
#include "stdafx.h"
#include "AutoFrame.h"
#include "DlgWarningList.h"
// CDlgWarningList 对?话??框¨°
IMPLEMENT_DYNAMIC(CDlgWarningList,CDialog)
//************************************
// Method: 构1造¨?函?¥数oy
// FullName: CDlgWarningList::CDlgWarningList
// Access: public
// Returns:
// Qualifier: : CDialog(IDD, pParent), m_nColumn(0)
// Parameter: CWnd * pParent
//************************************
CDlgWarningList::CDlgWarningList(CWnd*pParent/*=NULL*/)
:CDialog(CDlgWarningList::IDD,pParent)
,m_nColumn(0)
{
}
//************************************
// Method: 析?构1函?¥数oy
// FullName: CDlgWarningList::~CDlgWarningList
// Access: virtual public
// Returns:
// Qualifier:
//************************************
CDlgWarningList::~CDlgWarningList()
{
}
void CDlgWarningList::DoDataExchange(CDataExchange*pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX,IDC_CUSTOM_LIST,m_gridCtl);
}
BEGIN_MESSAGE_MAP(CDlgWarningList,CDialog)
ON_WM_SIZE()
END_MESSAGE_MAP()
// CDlgWarningList 消?息?é处?|理¤¨a程¨?序¨°
//************************************
// Method: 初?始o?化?¥对?话??框¨°
// FullName: CDlgWarningList::OnInitDialog
// Access: public
// Returns: BOOL
//************************************
BOOL CDlgWarningList::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在¨2此??添?¨a加¨?额?外aa的ì?初?始o?化?¥
DefaultGrid();
returnTRUE; // return TRUEunless you set the focus to a control
// 异°¨?常?ê: OCX属o?性?页°3应?|返¤|ì回? FALSE
}
//************************************
// Method: 捕?获?对?话??框¨°消?息?é
// FullName: CDlgWarningList::PreTranslateMessage
// Access: public
// Returns: BOOL
//************************************
BOOL CDlgWarningList::PreTranslateMessage(MSG*pMsg)
{
// TODO: 在¨2此??添?¨a加¨?专á?§用??代?¨2码?和¨a/或¨°调ì??用??基¨′类¤¨¤
if (pMsg->message==WM_KEYDOWN)
{
switch(pMsg->wParam)
{
caseVK_ESCAPE: //屏¨¢蔽à?键¨1盘¨?esc
returnTRUE;
default:
break;
}
}
returnCDialog::PreTranslateMessage(pMsg);
}
//************************************
// Method: 对?话??框¨°对?话??框¨°大?¨?小?改?变à?消?息?é响¨?应?|
// FullName: CDlgWarningList::OnSize
// Access: public
// Returns: void
//************************************
void CDlgWarningList::OnSize(UINTnType,intcx,intcy)
{
CDialog::OnSize(nType,cx,cy);
// TODO: 在¨2此??处?|添?¨a加¨?消?息?é处?|理¤¨a程¨?序¨°代?¨2码?
if (m_gridCtl.GetSafeHwnd())
{
CRectrcShow;
GetClientRect(rcShow);
m_gridCtl.MoveWindow(rcShow);
m_gridCtl.ExpandLastColumn();
m_gridCtl.Refresh();
}
}
//************************************
// Method: 初?始o?化?¥默?认¨?列¢D表à¨a样¨′式o?
// FullName: CDlgWarningList::DefaultGrid
// Access: public
// Returns: void
//************************************
void CDlgWarningList::DefaultGrid()
{
GridTypegridType;
gridType.nWidth=40;
gridType.itemName="序¨°号?";
m_gridType.push_back(gridType);
gridType.nWidth=80;
gridType.itemName="日¨?期¨2";
m_gridType.push_back(gridType);
gridType.nWidth=90;
gridType.itemName="时o?à间?";
m_gridType.push_back(gridType);
gridType.nWidth=80;
gridType.itemName="优??先¨¨级?";
m_gridType.push_back(gridType);
gridType.nWidth=70;
gridType.itemName="线?程¨?";
m_gridType.push_back(gridType);
if (CSystem::_Instance()->DisplayModeMax()==2)
{
gridType.nWidth=635;
gridType.itemName="信?息?é";
m_gridType.push_back(gridType);
InitGrid(m_gridType,FALSE,39);
}
else
{
gridType.nWidth=385;
gridType.itemName="信?息?é";
m_gridType.push_back(gridType);
InitGrid(m_gridType,FALSE,27);
}
//m_gridCtl.ExpandLastColumn();
}
//************************************
// Method: 初?始o?化?¥列¢D表à¨a样¨′式o?
// FullName: CDlgWarningList::InitGrid
// Access: public
// Returns: void
//************************************
void CDlgWarningList::InitGrid(vector<GridType>vGridType,BOOLbEdit,intnRowInit)
{
m_nColumn=vGridType.size();
if (m_nColumn<=0)
{
return;
}
m_gridCtl.DeleteAllItems();
m_gridCtl.SetRowCount(nRowInit);
m_gridCtl.SetColumnCount(m_nColumn);
m_gridCtl.SetRowHeight(0,30);
int i =0;
for (vector<GridType>::iteratorit=vGridType.begin();it!=vGridType.end();++it,++i)
{
if(it->nWidth>0)
{
m_gridCtl.SetColumnWidth(i,it->nWidth);
}
m_gridCtl.SetItemText(0,i,it->itemName);
}
m_gridCtl.SetEditable(bEdit);
m_gridCtl.SetRowResize();
m_gridCtl.SetHeaderSort(FALSE);
m_gridCtl.SetFixedRowCount(1);
m_gridCtl.SetFixedColumnCount(0);
}
//************************************
// Method: 初?始o?化?¥列¢D表à¨a样¨′式o?
// FullName: CDlgWarningList::InitGrid
// Access: public
// Returns: void
//************************************
void CDlgWarningList::InitGrid(BOOLbEdit,intnRowInit)
{
m_nColumn=m_gridType.size();
if (m_nColumn<=0)
{
return;
}
m_gridCtl.DeleteAllItems();
m_gridCtl.SetRowCount(nRowInit);
m_gridCtl.SetColumnCount(m_nColumn);
m_gridCtl.SetRowHeight(0,30);
int i =0;
for (vector<GridType>::iteratorit=m_gridType.begin();it!=m_gridType.end();++it,++i)
{
if(it->nWidth>0)
{
m_gridCtl.SetColumnWidth(i,it->nWidth);
}
m_gridCtl.SetItemText(0,i,it->itemName);
}
m_gridCtl.SetEditable(bEdit);
m_gridCtl.SetHeaderSort(FALSE);
m_gridCtl.SetFixedRowCount(1);
m_gridCtl.SetFixedColumnCount(0);
m_gridCtl.Refresh();
}
//************************************
// Method: 清?除y列¢D表à¨a样¨′式o?
// FullName: CDlgWarningList::InitGrid
// Access: public
// Returns: void
//************************************
void CDlgWarningList::ClearItem()
{
m_gridType.clear();
}
//************************************
// Method: 列¢D表à¨a添?¨a加¨?一°?列¢D
// FullName: CDlgWarningList::InitGrid
// Access: public
// Returns: void
//************************************
void CDlgWarningList::AddItem(CStringitemName,intwidth)
{
//定?§义°?一°?个?结¨¢构1体??
GridTypegridType;
gridType.nWidth=width;
gridType.itemName=itemName;
//放¤?到ì?结¨¢构1体??里¤?
m_gridType.push_back(gridType);
}
//************************************
// Method: 查¨|找¨°列¢D表à¨a位?置?
// FullName: CDlgWarningList::InitGrid
// Access: public
// Returns: void
//************************************
int CDlgWarningList::FindItem(LPCTSTRitemName)
{
int i =0,index=-1;
for (vector<GridType>::iteratorit=m_gridType.begin();it!=m_gridType.end();++it,++i)
{
if(it->itemName.Compare(itemName)==0)
{
index=i;
break;
}
}
returnindex;
}
7 需仿照上面两个类在(1)DlgAoiData.cpp和(2)system.cpp中实现
(1)
// DlgAoiData.cpp : 实o|ì现?文?件t
//
#include "stdafx.h"
#include "AutoFrame.h"
#include "DlgAoiData.h"
#include "afxdialogex.h"
// CDlgAoiData 对?话??框¨°
IMPLEMENT_DYNAMIC(CDlgAoiData,CDialogEx)
CDlgAoiData::CDlgAoiData(CWnd*pParent/*=NULL*/)
:CDialogEx(CDlgAoiData::IDD,pParent)
{
}
CDlgAoiData::~CDlgAoiData()
{
}
void CDlgAoiData::DoDataExchange(CDataExchange*pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX,IDC_CUSTOM_AOI_DATA,m_gridAoiData);
}
BEGIN_MESSAGE_MAP(CDlgAoiData,CDialogEx)
ON_BN_CLICKED(IDC_OK,&CDlgAoiData::OnBnClickedOk)
END_MESSAGE_MAP()
// CDlgAoiData 消?息?é处?|理¤¨a程¨?序¨°
BOOL CDlgAoiData::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在¨2此??添?¨a加¨?额?外aa的ì?初?始o?化?¥
SetGridDefault();
OnProductionRecordUpdate(0,0);
returnTRUE; // return TRUEunless you set the focus to a control
// 异°¨?常?ê: OCX属o?性?页°3应?|返¤|ì回? FALSE
}
//************************************
// Method: 设|¨¨置?表à¨a格?在¨2本à?工?è程¨?的ì?默?认¨?格?式o?
// FullName: CDlgAoiData::SetGridDefault
// Access: public
// Returns: void
//************************************
void CDlgAoiData::SetGridDefault()
{
constchar*strTitle[]=
{
//框¨°架¨1要°a求¨?添?¨a加¨?具?体??用??到ì?的ì?表à¨a格?样¨′式o?
"序¨°号?",
"产¨2品?¤条??码?",
"点ì?胶o合?格?",
"胶o长?è",
"胶o宽¨a",
"上|?溢°?胶o",
"下?溢°?胶o",
"断?胶o",
};
CGridCtrl*pGrid=&m_gridAoiData;
pGrid->SetEditable(FALSE);
int nRowTotal =1001;
pGrid->SetRowCount(nRowTotal);
int nColTotal =sizeof(strTitle)/sizeof(char*);
pGrid->SetColumnCount(nColTotal);
pGrid->SetHeaderSort(TRUE);
pGrid->SetFixedRowCount(1);
CRectrc;
GetDlgItem(IDC_CUSTOM_AOI_DATA)->GetWindowRect(&rc);
this->ScreenToClient(&rc);
pGrid->SetColumnWidth(0,40);
pGrid->SetColumnWidth(1,200);
for(inti=2;i<nColTotal;++i)
{
pGrid->SetColumnWidth(i,(rc.Width()-20-240)/(nColTotal-2));
}
for(inti=0;i<nColTotal;++i)
{
pGrid->SetItemText(0,i,*(strTitle+i));
}
CStringstr;
for (inti=1;i<nRowTotal;i++)
{
//pGrid->SetRowHeight(i, 20);
str.Format("%d",i);
pGrid->SetItemText(i,0,str);
}
pGrid->Refresh();
}
LRESULT CDlgAoiData::OnProductionRecordUpdate(WPARAMwParam,LPARAMlParam)
{
//
// intnRecordPackTrayCount =CSystem::_Instance()->GetParamInt("RecordPackTrayCount");
// intnCurPackTrayCount =CSystem::_Instance()->GetParamInt("CurPackTrayCount");
// intnCurReceiveTrayCount =CSystem::_Instance()->GetParamInt("CurReceiveTrayCount");
// intnBarcodeTrayNo =CSystem::_Instance()->GetParamInt("BarcodeTrayNo");
//
// SetDlgItemInt(IDC_EDIT_BARCODE_PACK_COUNT,nRecordPackTrayCount);
// SetDlgItemInt(IDC_EDIT_CUR_NUM,nCurPackTrayCount);
// SetDlgItemInt(IDC_EDIT_BARCODE_RECEIVE_COUNT,nCurReceiveTrayCount);
// SetDlgItemInt(IDC_EDIT_BARCODE_TRAY_NO,nBarcodeTrayNo);
if (2==wParam)
{
return0;
}
CGridCtrl*pGrid=&m_gridAoiData;
int nTrayRowTotal =m_gridAoiData.GetRowCount();//CSystem::_Instance()->GetParamInt("TrayRowTotal");
int nTrayColTotal =m_gridAoiData.GetColumnCount();//CSystem::_Instance()->GetParamInt("TrayColTotal");
// intnCurTrayPackNo = CSystem::_Instance()->GetBarcodePackNo();
map<u32,vector<string>>*pMap=CSystem::_Instance()->GetProductionAOIMap();
//*pMap.insert(map<string,int>::value_type("b",2));
if (NULL==pMap)
{
return-1;
}
if (pMap->size())
{
CStringstr;
inti =0, nIndex=0;
for(map<u32,vector<string>>::iteratorit=pMap->begin();it!=pMap->end();it++,i++)
{
for(intj=0;j<nTrayColTotal;++j)
{
str.Format("%s",it->second.at(j).c_str());
//pGrid->SetItemText(i, j, str);
pGrid->SetItemText(i,j,"str");
pGrid->EnsureVisible(i,j);
}
}
}
pGrid->Refresh();
return0;
}
void CDlgAoiData::OnBnClickedOk()
{
// TODO: 在¨2此??添?¨a加¨?控?件t通a?§知a处?|理¤¨a程¨?序¨°代?¨2码?
CStringstrPath;
CFileDialogfileDlg(true,NULL,NULL,OFN_FILEMUSTEXIST|OFN_READONLY|OFN_PATHMUSTEXIST,TEXT("条??码?文?件t (*.csv)|*.csv|所¨′有?D文?件t(*.*)|*.*|"),NULL);
stringstrDir =CSystem::_Instance()->GetParamStr(PRODUCTION_RECORD_FILE_PATH);
fileDlg.m_ofn.lpstrInitialDir=strDir.c_str();
if (fileDlg.DoModal()==IDOK)
{
strPath=fileDlg.GetPathName();
CSystem::_Instance()->LoadProductionAOIData(strPath);
}
OnProductionRecordUpdate(0,0);
}
(2)
//获?取¨?AOI信?息?é寄?存??器??
map<u32,vector<string>>*CSystem::GetProductionAOIMap()
{
if(m_mapProductionAOI.empty())
returnNULL;
//m_mapProductionAOI.insert(map<string,int>::value_type("b",2));
return(&m_mapProductionAOI);
}
//向¨°AOI信?息?é寄?存??器??增?加¨?产¨2品?¤AOI信?息?é
bool CSystem::AddProductionAOIStr(vector<string>&strData)
{
int nCurProductionNo =m_mapProductionAOI.size();
pair<map<u32,vector<string>>::iterator,bool>Insert_Pair;
Insert_Pair=m_mapProductionAOI.insert(make_pair(++nCurProductionNo,strData));
if(Insert_Pair.second==false)
{
AfxMessageBox("产¨2品?¤条??码?键¨1值|ì有?D问¨o题?a!ê?");
returnfalse;
}
m_nRecordProductionCnt++;
m_nCurProductionCnt++;
SaveProductionRecordCount();
if (nCurProductionNo>=1000) //每?生|¨2产¨21000个?产¨2品?¤保à?ê存??一°?个?产¨2品?¤生|¨2产¨2记?录?文?件t
{
SaveProductionAOIData();
}
returntrue;
}
//获?取¨?当ì?à前??产¨2品?¤生|¨2产¨2记?数oy
int CSystem::GetCurProductionCount()
{
returnm_nCurProductionCnt;
}
//设|¨¨置?产¨2品?¤AOI信?息?é
bool CSystem::WriteProductionAOIStr(intnIndex,vector<string>&strData)
{
int nSize =m_mapProductionAOI.size();
if (nIndex>=0&&nIndex<nSize)
{
map<u32,vector<string>>::iteratorit=m_mapProductionAOI.find(nIndex);
it->second=strData;
returntrue;
}
returnfalse;
}
//设|¨¨置?产¨2品?¤AOI信?息?é
bool CSystem::WriteProductionAOIStr(CString&strBarcode,vector<string>&strData)
{
int nSize =m_mapProductionAOI.size();
if (nSize>0)
{
for(map<u32,vector<string>>::iteratorit=m_mapProductionAOI.begin();it!=m_mapProductionAOI.end();it++)
{
if(strBarcode.Compare(it->second.at(0).c_str()))
{
it->second=strData;
returntrue;
}
}
}
returnfalse;
}
//获?取¨?产¨2品?¤AOI信?息?é
bool CSystem::GetProductionAOIStr(intnIndex,vector<string>&strData)
{
int nSize =m_mapProductionAOI.size();
if (nIndex>=0&&nIndex<nSize)
{
map<u32,vector<string>>::iteratorit=m_mapProductionAOI.find(nIndex);
strData=http://www.mamicode.com/it->second;
returntrue;
}
returnfalse;
}
//获?取¨?产¨2品?¤AOI信?息?é
bool CSystem::GetProductionAOIStr(CString&strBarcode,vector<string>&strData)
{
int nSize =m_mapProductionAOI.size();
if (nSize>0)
{
for(map<u32,vector<string>>::iteratorit=m_mapProductionAOI.begin();it!=m_mapProductionAOI.end();it++)
{
if(strBarcode.Compare(it->second.at(0).c_str()))
{
strData=http://www.mamicode.com/it->second;
returntrue;
}
}
}
returnfalse;
}
//获?取¨?当ì?à前??产¨2品?¤AOI信?息?é
bool CSystem::GetLastProductionAOI(vector<string>&strData)
{
int nSize =m_mapProductionAOI.size();
if (nSize>0)
{
map<u32,vector<string>>::iteratorit=m_mapProductionAOI.find(nSize);
strData=http://www.mamicode.com/it->second;
returntrue;
}
returnfalse;
}
bool CSystem::RemoveProductionAOI(intnIndex)
{
int nSize =m_mapProductionAOI.size();
if (nIndex>=0&&nIndex<nSize)
{
m_mapProductionAOI.erase(nIndex);
returntrue;
}
}
//移°?除y产¨2品?¤AOI信?息?é
bool CSystem::RemoveProductionAOI(CString&strBarcode)
{
int nSize =m_mapProductionAOI.size();
if (nSize>0)
{
for(map<u32,vector<string>>::iteratorit=m_mapProductionAOI.begin();it!=m_mapProductionAOI.end();it++)
{
if(strBarcode.Compare(it->second.at(0).c_str()))
{
m_mapProductionAOI.erase(it);
returntrue;
}
}
returntrue;
}
}
//清?除yAOI信?息?é寄?存??器??信?
bool CSystem::ClearProductionAOIData()
{
int nSize =m_mapProductionAOI.size();
if (nSize>0)
{
for(map<u32,vector<string>>::iteratorit=m_mapProductionAOI.begin();it!=m_mapProductionAOI.end();it++)
{
it->second.clear();
}
m_mapProductionAOI.clear();
returntrue;
}
returnfalse;
}
//载?入¨?指?定?§文?件t的ì?产¨2品?¤AOI信?息?é
bool CSystem::LoadProductionAOIData(constchar*szFileName)
{
charstrPath[1024];
memset(strPath,0,1024);
if (NULL==szFileName)
{
sprintf(strPath,"%s%s",CSystem::_Instance()->GetParamStr(PRODUCTION_RECORD_FILE_PATH),CSystem::_Instance()->GetParamStr(PRODUCTION_RECORD_FILE_NAME));
}
else
{
sprintf(strPath,"%s",szFileName);
}
CCsvFileCsvBarcode;
boolbOpen =CsvBarcode.LoadCSV(strPath);
if (!bOpen)
returnfalse;
if (m_mapProductionAOI.size())
{
for(map<u32,vector<string>>::iteratorit=m_mapProductionAOI.begin();it!=m_mapProductionAOI.end();it++)
{
it->second.clear();
}
m_mapProductionAOI.clear();
}
AnalysisAOIData(&CsvBarcode,m_mapProductionAOI);
returntrue;
}
//以°?CVS格?式o?保à?ê存??产¨2品?¤AOI信?息?é,ê?按???天?¨?保à?ê存??
bool CSystem::SaveProductionAOIData()
{
charstrPath[1024];
memset(strPath,0,1024);
sprintf(strPath,"%s\\BarcodeCsv",CSystem::_Instance()->GetParamStr(PRODUCTION_RECORD_FILE_PATH));
SYSTEMTIMEsys;
GetLocalTime(&sys);
charFileName[1024];
memset(FileName,0,1024);
sprintf(FileName,"%s\\ProductionRecord%d_%4d-%02d-%02d-%02d-%02d.csv",strPath,m_nRecordProductionCnt,sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute);
std::stringstrFileName=FileName;
// pair<map<u32,string >::iterator, bool> Insert_Pair;
// Insert_Pair= m_mapBarcodePackFileName.insert(make_pair(m_nCurTrayPackNo, strFileName));
// if(Insert_Pair.second== false)
// {
// AfxMessageBox("条??码?打?¨°包?¨1编ਤ号?出?错?¨a!ê?");
// returnfalse;
// }
std::stringstrProductionRecordFileName=strFileName.substr(strFileName.rfind("\\")+1);
CSystem::_Instance()->SetParamStr(PRODUCTION_RECORD_FILE_NAME,strProductionRecordFileName.c_str());
// if(FALSE== ::PathFileExists(FileName))
// {
// CreateDirectory(strPath,NULL);
// CStringstrSrc = http://www.mamicode.com/CConfigMgr::_Instance()->m_strDir +"Data" +"ProductionRecord.csv";
// ::CopyFile(strSrc,FileName, FALSE);
// }
FILE*pfile=fopen(strFileName.c_str(),"w");
if (NULL==pfile)
{
returnfalse;
}
chartmp[1024];
memset(tmp,0,1024);
stringstrData;
CStringstr;
int i =0;
for (map<u32,vector<string>>::iteratorit=m_mapProductionAOI.begin();it!=m_mapProductionAOI.end();it++,i++)
{
intnVecSize =it->second.size();
for(intj=0;j<nVecSize;j++)
{
strData=http://www.mamicode.com/it->second.at(j);
memset(tmp,0,1024);
sprintf(tmp,"%d,",it->first);
fwrite(tmp,1,strlen(tmp),pfile);
fwrite(strData.c_str(),1,strData.size(),pfile);
charDelim =‘\n‘;
fwrite(&Delim,1,1,pfile);
}
}
fclose(pfile);
ClearProductionAOIData();
returntrue;
}
重点:
这只是我的思路,框架太大还不熟悉,重新写不会写,应该是想复杂了。领导只说了用容器,不好写代码就把思路和关键的知识点和技巧写在下面:
代码编写