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

📄 3321batchprocessdlg.cpp

📁 美国TSI公司3321仪器数据文件批处理
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	   if(ifover<setnumber)
	   { 		   		   
		   goto begin;
	   }  
	   tf.Close();//关闭导入文件 
	   AfxMessageBox("搞定");
}

void CMy3321batchprocessDlg::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(true);
}

void CMy3321batchprocessDlg::Onbatchtotalconcentration() 
{
	// TODO: Add your control notification handler code here
	
	int fileline=0;/////////文件的行数
	CString filecontent,filesavepath("",MAX_PATH);	
	CString pathname("",MAX_PATH);	//路径字串
  
	CStdioFile filesavename,fileopenname;///////CFECFileDialog能够处理无限组,而这里CFileDialog只能处理最多10组
	CFileDialog fd(TRUE,
		NULL,
		NULL, 
		OFN_ALLOWMULTISELECT | OFN_NODEREFERENCELINKS | OFN_EXPLORER);	
		filesavename.Open("e:\\tatalconcentration.txt",CFile::modeCreate|CFile::modeWrite,NULL);
     	if (fd.DoModal() == IDOK)
		{		 
	       	  POSITION pos = fd.GetStartPosition();////得到你选定文件的第一个文件的路径
		     while (pos)
			 {
		          pathname = fd.GetNextPathName(pos);////下移一个
				  fileopenname.Open(pathname,CFile::modeRead|CFile::typeText,NULL);
	     	      if(!fileopenname)
				  {
	             	  AfxEndThread(0);
		              AfxMessageBox("Failed to open file,Exit!!");
				  }
				  while(fileopenname.ReadString(filecontent))
				  {

					  if(fileline==6)
					  {
						  filecontent+="\n";
		        	     filesavename.WriteString(filecontent);
					  }
					  fileline+=1;
					 //m_printfscreen.Format("%d",fileline);
					 // UpdateData(false);
				  }
		         fileline=0; 
	    	        		
			 }
			 filesavename.Close();		
		}

	

}

void CMy3321batchprocessDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	/*CString str;
	CStdioFile file;
	
	CFileDialog fd(TRUE,
		NULL,
		NULL, 
		OFN_ALLOWMULTISELECT | OFN_NODEREFERENCELINKS | OFN_EXPLORER);
    	file.Open("out.txt",CFile::modeCreate|CFile::modeWrite,NULL);
    if (fd.DoModal() == IDOK)
    {	
	 
		POSITION pos = fd.GetStartPosition();
		while (pos)
		{
			str = fd.GetNextPathName(pos);
			str+="\n";
			file.WriteString(str);
			
		}
		file.Close();
    }
	AfxMessageBox("OK!");*/
	//FILE *file_savepath;
	//int fileline=0;
	int datafileline=0;///////////分别代表临时文件的行数(也就是temptfilename.txt的行数)、3321文件的行数(为88行)
	CString file_tmpcontent;////临时文件的内容
	CString file_3321filepath;///////////3321文件的路径,用于写入到临时文件中	    
	CString read_filedata;///读取3321文件
	TCHAR tab=9;////tab键的ASII码	
	CStdioFile file_createtemptname;////创建临时文件
	CStdioFile file_opentmp;///////再次打开临时文件的路径
	CStdioFile file_savename;//////创建输出文件(out.txt)
    CStdioFile file_read;	//////读取3321文件
	

	CFECFileDialog fd(TRUE,
		NULL,
		NULL, 
		OFN_ALLOWMULTISELECT | OFN_NODEREFERENCELINKS | OFN_EXPLORER);	
		file_createtemptname.Open("e:\\temptfilename.txt",CFile::modeCreate|CFile::modeWrite,NULL);
		if (fd.DoModal() == IDOK)
		{	 
		   POSITION pos = fd.GetStartPosition();///d得到起始文件的路径
		    while (pos)
			{
			     file_3321filepath=fd.GetNextPathName(pos);//顺延,得到下一个文件的路径
			     file_3321filepath+="\n";
			     file_createtemptname.WriteString(file_3321filepath);///写到临时文件中
			
			}
		file_createtemptname.Close();///关闭临时文件
		} 
		else
		{
			//AfxMessageBox("您没有打开文件很遗憾,程序将要关闭!给您带来损失,请于微软联系");
			return;
			//exit(1);
		}




		///再次打开临时文件	
	   file_opentmp.Open("e:\\temptfilename.txt",CFile::modeRead|CFile::typeText,NULL);///再次打开临时文件		
	     if(!file_opentmp)
		 {
	          
		      AfxMessageBox("Failed to open file,Exit!!");
		 }
		 ///创建并打开输出文件out.txt
		 file_savename.Open("e:\\out.txt",CFile::modeCreate|CFile::modeWrite,NULL);
		 while(file_opentmp.ReadString(file_tmpcontent))///读出临时文件中的内容
		 {
             file_tmpcontent=file_tmpcontent.Left(file_tmpcontent.GetLength()-4);///去掉文件名的后缀
			 file_tmpcontent+=".dat";///加上后缀,得到3321文件路径
						  
					  //if(tmpfileline==0)
					  //{					  					  
						  file_read.Open(file_tmpcontent,CFile::modeRead|CFile::typeText,NULL);///依据上面所得到的路径,打开3321文件						  
						  while(file_read.ReadString(read_filedata))/////读取3321文件内容
						  {
							  if(datafileline==6)
							  {
							      // AfxMessageBox(read_filedata);
								  read_filedata=read_filedata.Right(read_filedata.GetLength()-read_filedata.Find(tab)-1);
								   read_filedata+="\n";
								   file_savename.WriteString(read_filedata);
							  }
							  datafileline+=1;///3321文件的行数
						  }						  
						  file_read.Close();////关闭3321文件的行数
						  datafileline=0;
						  /*if((file_read=fopen(file_tmpcontent,"r")) != NULL)
						  {
							  MessageBox("wenjian kai");
						  
						  }
						  fclose(file_read);*/
					  //}
					 // tmpfileline+=1;
					 	 
		 }		 
		file_opentmp.Close();///关闭临时文件
		file_savename.Close();////关闭保存文件		
		file_opentmp.Remove("e:\\temptfilename.txt");///删除临时文件

	   /* file_opentmp.Open("..\\temptfilename.txt",CFile::modeRead|CFile::typeText,NULL);
		
	     if(!file_opentmp)
		{
	          
		      AfxMessageBox("Failed to open file,Exit!!");
	 }
		 while(file_opentmp.ReadString(file_tmpcontent))
		 {

					  if(fileline==1)
					  {
						  filesavepath=file_tmpcontent.Left(file_tmpcontent.Find('\n'));
						  AfxMessageBox(filesavepath);
						  //filesavepath=filesavepath.Left(filesavepath.Getlength-1);
		        	    // filesavename.WriteString(file_tmpcontent);
						 if( (file_savepath=fopen(filesavepath,"w"))==NULL)
						 {
							 MessageBox("不能打开");
						 }
					  }
					  fileline+=1;
					  fclose(file_savepath);	 
		 }
		file_opentmp.Close();*/
     /*	if (fd.DoModal() == IDOK)
		{		 
	       	  POSITION pos = fd.GetStartPosition();
		     while (pos)
			 {
		          pathname = fd.GetNextPathName(pos);
				 // fileopenname.Open(pathname,CFile::modeRead|CFile::typeText,NULL);
	     	      if(!fileopenname)
				  {
	             	  AfxEndThread(0);
		              AfxMessageBox("Failed to open file,Exit!!");
				  }
				  while(fileopenname.ReadString(filecontent))
				  {

					  if(fileline==6)
					  {
						  filecontent+="\n";
		        	     filesavename.WriteString(filecontent);
					  }
					  fileline+=1;
					  m_printfscreen.Format("%d",fileline);
					  UpdateData(false);
				  }
		         fileline=0; 
	    	        		
			 }
			 filesavename.Close();		
		}*/

	

}

void CMy3321batchprocessDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	FILE *file_savepath;
	
	CStdioFile file_opentmp,file_read,file_savename;
	CString file_tmpcontent;
	CString filesavepath;
	CString read_filedata;
	TCHAR huiche=13;

	int tmpfileline=0,datafileline=0;

	 file_opentmp.Open("e:\\temptfilename.txt",CFile::modeRead|CFile::typeText,NULL);
		
	     if(!file_opentmp)
		 {
	          
		      AfxMessageBox("Failed to open file,Exit!!");
		 }
		 file_savename.Open("e:\\out.txt",CFile::modeCreate|CFile::modeWrite,NULL);
		 while(file_opentmp.ReadString(file_tmpcontent))
		 {
                          file_tmpcontent=file_tmpcontent.Left(file_tmpcontent.GetLength()-4);
						  file_tmpcontent+=".dat";
						  
					  //if(tmpfileline==0)
					  //{					  					  
						  file_read.Open(file_tmpcontent,CFile::modeRead|CFile::typeText,NULL);
						  
						  while(file_read.ReadString(read_filedata))
						  {
							  if(datafileline==6)
							  {
							      // AfxMessageBox(read_filedata);
								   read_filedata+="\n";
								   file_savename.WriteString(read_filedata);
							  }
							  datafileline+=1;
						  }						  
						  file_read.Close();
						  datafileline=0;
						  /*if((file_read=fopen(file_tmpcontent,"r")) != NULL)
						  {
							  MessageBox("wenjian kai");
						  
						  }
						  fclose(file_read);*/
					  //}
					 // tmpfileline+=1;
					 	 
		 }		 
		file_opentmp.Close();
		file_savename.Close();
		tmpfileline=0;
}

⌨️ 快捷键说明

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