⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadrecord.cpp

📁 一个给铁路机车系统采集排气
💻 CPP
字号:
// LoadRecord.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "LoadRecord.h"
#include "RecordFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoadRecord dialog


CLoadRecord::CLoadRecord(CWnd* pParent /*=NULL*/)
	: CDialog(CLoadRecord::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoadRecord)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CLoadRecord::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoadRecord)
	DDX_Control(pDX, IDC_LIST1, m_LoadList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoadRecord, CDialog)
	//{{AFX_MSG_MAP(CLoadRecord)
	ON_BN_CLICKED(IDC_BUTTON1, OnExit)
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON2, OnOpenFile)
	ON_BN_CLICKED(IDC_BUTTON_CHANG, OnButtonChang)
	ON_BN_CLICKED(IDC_BUTTON_CHANG2, OnButtonChang2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoadRecord message handlers

void CLoadRecord::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void CLoadRecord::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CLoadRecord::OnInitDialog() 
{
	CDialog::OnInitDialog();
	DWORD styles;
	CRect rect;
	// TODO: Add extra initialization here
    styles=m_LoadList.GetExtendedStyle();
	m_LoadList.SetExtendedStyle(styles|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|
		LVS_EX_UNDERLINEHOT);

    m_LoadList.SetBkColor(RGB(140, 180, 220));
	m_LoadList.SetTextBkColor(RGB(140, 180, 220));

    m_LoadList.InsertColumn(0,"序号");
    m_LoadList.InsertColumn(1,"排风时间 (S)");
    m_LoadList.InsertColumn(2,"排风口压力 (KPa)");
	m_LoadList.InsertColumn(3,"制动机处管压 (KPa)");
	m_LoadList.InsertColumn(4,"连接处压力 (KPa)");
	m_LoadList.InsertColumn(5,"充气时间 (S)");
	m_LoadList.InsertColumn(6,"标志位");

	m_LoadList.GetClientRect(&rect); 
	m_LoadList.SetColumnWidth(0,rect.Width()/16);
	m_LoadList.SetColumnWidth(1,rect.Width()*2/16);
    m_LoadList.SetColumnWidth(2,rect.Width()*3/16);
    m_LoadList.SetColumnWidth(3,rect.Width()*3/16);
    m_LoadList.SetColumnWidth(4,rect.Width()*3/16);
	m_LoadList.SetColumnWidth(5,rect.Width()*2/16);
    m_LoadList.SetColumnWidth(6,rect.Width()*2/16);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLoadRecord::OnExit() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

void CLoadRecord::OnButtonDel() 
{
	// TODO: Add your control notification handler code here
	//删除//请
	    CRecordFile ReFile;	
	
			if(strFileName=="")
			{
			  MessageBox("未选择要删除的记录,请选择!!","提示");
			  return;
			}
		if(MessageBox("删除记录具有不可恢复性,\n删除点击确定,放弃点击取消。","提示",MB_OKCANCEL)==IDOK)
		{
			CFile::Remove(strFilePath);
			m_LoadList.DeleteAllItems();
			CStatic *sta=(CStatic *)GetDlgItem(IDC_FILENAME);
		    sta->SetWindowText("文件名:"); 
		}
}

void CLoadRecord::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CFont font;
   font.CreateFont(28, 0, 0, 0, 
   								FW_BOLD, FALSE, FALSE, 0, 
   								ANSI_CHARSET,
                   	OUT_DEFAULT_PRECIS,
                   	CLIP_DEFAULT_PRECIS,
                   	DEFAULT_QUALITY,
                   	VARIABLE_PITCH | 0x04 | FF_DONTCARE,
                   	_T("Arial"));
   
   GetDlgItem(IDC_TITLE)->SetFont(&font);	
	// Do not call CDialog::OnPaint() for painting messages
}

HBRUSH CLoadRecord::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if((pWnd->GetDlgCtrlID()==IDC_TITLE))
	{
	   pDC->SetTextColor(RGB ( 0x44,0x44,0xbb));
	}
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CLoadRecord::OnOpenFile() 
{
	// TODO: Add your control notification handler code here
	CString temstr;
		CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"TXT(*.TXT*)|*.TXT*|AllFile(*.*)|*.*||",NULL);//.LWH
    if(dlg.DoModal()==IDOK)
	{	
		strFilePath=dlg.GetPathName();
		strFileName=dlg.GetFileName();
		temstr="文件名:"+strFileName;
		CStatic *sta=(CStatic *)GetDlgItem(IDC_FILENAME);
		sta->ShowWindow(SW_NORMAL);
		sta->SetWindowText(temstr); 
		fnReadfileAndShowRecord(strFilePath);
		//this->GetDlgItem(IDC_BUTTON18)->EnableWindow(true);	
		//m_PCurvePic->TopPointForMoveing=0;
		//m_PCurvePic->expNum=0;
	}//end if
	UpdateData(false);
}

void CLoadRecord::fnReadfileAndShowRecord(CString strFilePath)
{
    MSG message;
	CString caseName;
	static unsigned int needdata[7],tempstr,tempstr2,strPA1,mycount[4],strPA2,temtime=0,temsn=0;
	for(int k=0;k<7;k++)
		needdata[k]=0;
	for (k=0;k<4;k++)
	{
		mycount[k]=0;
	}
	//UpdateData(true);
//	CComboBox *box=(CComboBox *)GetDlgItem(IDC_COMBO1);
//	box->GetWindowText(caseName);
	//m_BoxCurInt=box->GetCurSel();

    CWaitCursor waitc;
	CFile file1;
	CFileException e;
	//if(caseName=="") return;
	CRecordFile temfile;
	CStatic *cs=(CStatic*)GetDlgItem(IDC_PAIFENGTIME);
	CStatic *cs2=(CStatic*)GetDlgItem(IDC_JIANYA);
	if(!file1.Open(strFilePath,CFile::modeRead,&e))
	{
		e.ReportError();
		return;
	}
	m_LoadList.DeleteAllItems();
	CArchive ar(&file1,CArchive::load);
	if(ar.IsLoading()&&(file1.GetLength()>0))
	{
		static CString strtemp[7],strtemp1,strtemp2,tmp;
		int Count;
		ar>>Count;
    		
		for(int i=0;i<Count;i++)
		{
			int listcount=m_LoadList.GetItemCount();
			m_LoadList.InsertItem(listcount,strtemp1);
			for(int j=0;j<7;j++)
			{
			  ar>>strtemp[j];
			  needdata[j]=atoi((LPCTSTR)strtemp[j]);	  
			  m_LoadList.SetItemText(listcount,j,strtemp[j]);
			}
			 switch(needdata[4])
			 {
			 case 502:
				  mycount[0]++;
			 case 503:
				  mycount[1]++;
			 case 504:
				  mycount[2]++;
			 case 505:
				  mycount[3]++;
			 }
             int mymax1=max(mycount[0],mycount[1]);       
			 int mymax2=max(mycount[2],mycount[3]);
			 int mymax=max(mymax1,mymax2);
			 for(k=0;k<4;k++)
				 if(mycount[k]==mymax)
				 {
					 if(k==0) strPA1=502;
					 if(k==1) strPA1=503;
					 if(k==2) strPA1=504;
					 if(k==3) strPA1=505;
				 }
	        if ((needdata[2]==0)&&(tempstr>0))
			  {
                 strtemp[1].Format("%d",needdata[0]-temsn+temtime+1); 
				 cs->SetWindowText("排风时间:"+strtemp[1]);
			  }
			if ((strtemp[6]=="aa")&&(tmp=="55"))
			{
                    temtime=needdata[1];
					temsn=needdata[0];
			}
			  if((needdata[1]==0)&&(tempstr2>0))
			  {
				strtemp2.Format("%d",(strPA1-strPA2));
			    cs2->SetWindowText("减压量:"+strtemp2);
			  }
			  tmp=strtemp[6];
			  tempstr=needdata[2];
			  tempstr2=needdata[1];
              strPA2=needdata[4];
			while (::PeekMessage(&message,NULL,0,0,PM_REMOVE))
			{
	          ::TranslateMessage(&message);
	          ::DispatchMessage(&message);
			}
		} 
	}
	//if(!FirstShow)
	//{
	// AviDlg->ShowWindow(SW_HIDE);//SW_HIDE
	
	//}
	ar.Close();
	file1.Close();
	//FirstShow=false;
	//GetDlgItem(IDC_COMBO2)->SetFocus();
	//delete AviDlg;
}

void CLoadRecord::OnButtonChang() 
{
	// TODO: Add your control notification handler code here
	CString temstr;
		CFileDialog dlg(false,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"TXT(*.TXT*)|*.TXT*|AllFile(*.*)|*.*||",NULL);//.LWH
		int listcount=m_LoadList.GetItemCount();
		if(listcount==0)
		{
		  MessageBox("未加载要转换文件!!","提示");
		  return;
		}

    if(dlg.DoModal()==IDOK)
	{	
		temstr=dlg.GetPathName();
		if(temstr=="")
		{
		  MessageBox("未输入文件名!!","提示");
		  return;
		}
		if (temstr.Right(4)==".txt")
		{
		  int leth=temstr.GetLength();
		  //int k=temstr.Find(".");
		  strFilePath=temstr.Left(leth-4)+"排风"+".txt";
		  temstr=temstr.Left(leth-4)+"充风"+".txt";
		}
		else
		{  
		   strFilePath=dlg.GetPathName()+"排风"+".txt";
		   temstr=dlg.GetPathName()+"充风"+".txt";
		}
		//strFileName=dlg.GetFileName()+".txt";
		WriteRecoreFile(strFilePath);  //排风
		WriteRecoreFile2(temstr);  //冲风
		//this->GetDlgItem(IDC_BUTTON18)->EnableWindow(true);	
		//m_PCurvePic->TopPointForMoveing=0;
		//m_PCurvePic->expNum=0;
		MessageBox("记录已经转换成功!!","提示");
	}//end if
	UpdateData(false);	
}

void CLoadRecord::WriteRecoreFile(CString filename)
{
 	//获取当前时间
    unsigned int MyData[2]={1,300};
	CString strtemp[7],temstr;
	bool  startadd=false;
	unsigned char mycount=0;
	//写文件	//保存直接处理。
	/*CRecordFile ReFile;
	CString pathfile=filename;
	CFile file1;
	CFileException e;
	if(!file1.Open(pathfile,CFile::modeCreate|CFile::modeWrite|CFile::modeRead,&e))
	{
	//	e.ReportError();
	//	return;
		CFile file2(pathfile,CFile::modeCreate|CFile::modeWrite);
		file1.m_hFile=file2.m_hFile;
	}
    file1.Write(MyData,sizeof(MyData));
	file1.Close();*/
	int listcount=m_LoadList.GetItemCount();
	FILE   *fp;   
    fp   =   fopen(filename,"w");  
	for(int i=0;i<listcount;i++)
	{	  
	  for(int j=0;j<7;j++)
		strtemp[j]=m_LoadList.GetItemText(i,j);
     
	 MyData[0]=atoi((LPCTSTR)strtemp[1]);
	 MyData[1]=atoi((LPCTSTR)strtemp[4]);
	 if((strtemp[6]=="aa")&&(temstr=="55"))
	 {
		 startadd=true;
	 }
	 if(startadd)
	 {
		 mycount++;
		 MyData[0]=MyData[0]+mycount;
	 }
	 if(strtemp[2]=="00")
	 {
           MyData[0]=0;
		   startadd=false;

	 }
	 if(MyData[0]>0)
	 {
       fprintf(fp,"%f,%d\n",(float)MyData[0]/10,MyData[1]);  
	 }
	 temstr=strtemp[6];
	}
	fclose(fp);
	return ;
}

void CLoadRecord::OnButtonChang2() 
{
	// TODO: Add your control notification handler code here
   	CString temstr;
		CFileDialog dlg(false,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"TXT(*.TXT*)|*.TXT*|AllFile(*.*)|*.*||",NULL);//.LWH
    if(dlg.DoModal()==IDOK)
	{	
		strFilePath=dlg.GetPathName()+".txt";
		strFileName=dlg.GetFileName()+".txt";
		WriteRecoreFile2(strFilePath);
		//this->GetDlgItem(IDC_BUTTON18)->EnableWindow(true);	
		//m_PCurvePic->TopPointForMoveing=0;
		//m_PCurvePic->expNum=0;
	}//end if
	UpdateData(false);	
}

void CLoadRecord::WriteRecoreFile2(CString filename)
{
   unsigned int MyData[2]={1,300};
   float temdata=0.5;
   float temstr=0.3;
	CString strtemp[7];
    bool startflg=false;
	int listcount=m_LoadList.GetItemCount();
	FILE   *fp;   
    fp   =   fopen(filename,"w");  
	for(int i=0;i<listcount;i++)
	{	  
	  for(int j=0;j<7;j++)
		strtemp[j]=m_LoadList.GetItemText(i,j);
     
	 temdata=atof((LPCTSTR)strtemp[5]);
	 MyData[1]=atoi((LPCTSTR)strtemp[4]);

	 if((temdata>0.0)&&(temstr==0.0))
	 {
		 startflg=true;
	 }

	 if((temdata>0)&&(startflg==true))
	 {
       fprintf(fp,"%.1f,%d\n",temdata,MyData[1]);  
	 }
	 
	 temstr=temdata;
	}
	fclose(fp);
	return ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -