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

📄 tgdata.cpp

📁 这是本人两年前兼职为某个公司做的石油钻进设计软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// TGData.cpp: implementation of the CTGData class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "cvenus.h"
#include "TGData.h"
#include	"MainFrm.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void DaoErrorMsg(CDaoException* e)
{
    char errorMsg[301];
   	wsprintf(errorMsg, "DAO error %d, SOURCE = %s, DESCR = %s",
        e->m_pErrorInfo->m_lErrorCode,
        (const char*) e->m_pErrorInfo->m_strSource,
        (const char*) e->m_pErrorInfo->m_strDescription);
   	AfxMessageBox(errorMsg);
}

CTGData::CTGData()
{
	m_bModify = false;
}

CTGData::~CTGData()
{
	
}

void	CTGData::Empty()
{
	int i,j;
	for(i=0; i<11; i++)
		m_strEdit[i].Empty();
	
	m_strCombo1.Empty();
//	m_strCombo2.Empty();
//	m_strCombo3.Empty();
	m_strCombo3 = m_strCombo2 =_T("0");
	
	
	for(i = 0; i<13; i++)
		for(j = 0; j<7; j++)
			m_grid1[i][j].Empty();
		
	m_strFileName.Empty();
	m_bModify = false;
			
}

bool CTGData::OpenProject()
{
	if(!IsSaveData())
		return false;
    CString		strFileName;
	HANDLE      hSearch; 
	WIN32_FIND_DATA FileData; 

	if(((CMainFrame*)AfxGetMainWnd())->m_TGProjectType==1)
	
	{
		CFileDialog fileDialog(
		TRUE,"TGS",NULL,
		OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
		"TGS文件(*.TGS)|*.TGS|All files(*.*)|*.*|",
		NULL);
	    if(fileDialog.DoModal () == IDCANCEL)
		  return FALSE;
	    strFileName = fileDialog.GetPathName ();
	}
	else
	{
		CFileDialog fileDialog1(
		TRUE,"TGY",NULL,
		OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
		"TGY文件(*.TGY)|*.TGY|All files(*.*)|*.*|",
		NULL);
	    if(fileDialog1.DoModal () == IDCANCEL)
		  return FALSE;
	    strFileName = fileDialog1.GetPathName ();
	}
	
	hSearch = FindFirstFile(strFileName, &FileData); 
	if (hSearch == INVALID_HANDLE_VALUE) 
	{ 
		AfxMessageBox(_T("文件不存在!"), MB_ICONERROR);
		return false;
	}
	
	CStdioFile   file;
	CString		cstrTemp,strTemp;
	int i,j,k;

	if(!file.Open(strFileName, CFile::modeRead) )
	{ 
		cstrTemp = "文件 " + strFileName + " 打开失败!";
		AfxMessageBox(cstrTemp,MB_ICONERROR);
	}
	if(((CMainFrame*)AfxGetMainWnd())->m_TGProjectType==1)
	{	
		CStringArray		saFileData;
		while(TRUE)
		{
			try
			{
				if( file.ReadString(strTemp) )
				{
					saFileData.Add(strTemp);
				}
				else
				{// 到文件尾
					break;
				}
			}
			catch (CFileException exception1)
			{
				Beep(650, 50);
				AfxMessageBox("读文件出错!", MB_ICONERROR);
				return false;
			}
		}
		file.Close ();
		if((saFileData.GetSize() != 71) || (saFileData[0].Compare(_T("[TGF]")) != 0))
		{
			cstrTemp = "文件 " + strFileName + " 格式错误!";
			AfxMessageBox(cstrTemp,MB_ICONERROR);
			return FALSE;
		}
		k = 1;
		for(i=0; i<11; i++)
			m_strEdit[i] = saFileData[k++];
		m_strCombo1 = saFileData[k++];
		m_strCombo2 = saFileData[k++];
		m_strCombo3 = saFileData[k++];
		for(i = 0; i<8; i++)
			for(j = 0; j<7; j++)
				m_grid1[i][j] = saFileData[k++];
	}
    else
	{
		for(i = 0; i<=12; i++)
		{
			for(j = 0; j<=5; j++)
			{
				try
				{
					file.ReadString(strTemp);
					m_grid1[i][j]=strTemp;
				}
				catch (CFileException exception1)
				{
					Beep(650, 50);
					AfxMessageBox("读文件出错!", MB_ICONERROR);
					return false;
				}
			}
		}
	}

	m_strFileName = strFileName;
	m_bModify = false;
		
	OnProjectChanged();
	CMainFrame*	pMainWnd	= (CMainFrame*)AfxGetMainWnd();
	pMainWnd->PostMessage(WM_COMMAND,IDM_TG_BAS,NULL);
			
	return TRUE;
			
}

void CTGData::NewProject()
{
	if(!IsSaveData())
		return;
//	CloseView();

	WIN32_FIND_DATA FileData; 
	CString str =((CCVenusApp*)AfxGetApp())->m_strAppPath;
	HANDLE hSearch = FindFirstFile(str + "\\tempfile.txt", &FileData); 
	if (hSearch != INVALID_HANDLE_VALUE) 
	{ 
		DeleteFile(str + "\\tempfile.txt");
	}

	Empty();
	OnProjectChanged();
	CMainFrame*	pMainWnd	= (CMainFrame*)AfxGetMainWnd();
	pMainWnd->PostMessage(WM_COMMAND,IDM_TG_BAS,NULL);
	
}

bool CTGData::SaveProject()
{
	if(m_strFileName.IsEmpty())
		return SaveAsProject();
	else
		Save(m_strFileName);
	return	true;
	
}

void CTGData::OnProjectChanged()
{
	CString		strAppTitle;
	strAppTitle.LoadString(IDR_MAINFRAME);
	
	if(m_strFileName.IsEmpty())
	{
		m_strProjectTitle = _T("新工程");
	}
	else
	{	
		int         iDotPlace, iDirPlace;
		TCHAR        ch;
		bool		bFirst = true;
		iDotPlace = m_strFileName.GetLength();
		for(iDirPlace = iDotPlace - 1; iDirPlace >= 0; iDirPlace--)
		{
			ch = m_strFileName.GetAt(iDirPlace);
			if(ch == _T('.') && bFirst)
			{
				iDotPlace = iDirPlace;
				bFirst = false;
			}
			if(ch == _T('\\'))
				break;
		}
		m_strProjectTitle = m_strFileName.Mid(iDirPlace+1, iDotPlace - iDirPlace - 1);
	}
	AfxGetMainWnd()->SetWindowText(m_strProjectTitle+_T(" - ")+strAppTitle);
	
}

bool CTGData::SaveAsProject()
{
	if(((CMainFrame*)AfxGetMainWnd())->m_TGProjectType==1)
	{
		CFileDialog fileDialog(
			FALSE,"TGS",m_strProjectTitle,
			OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
			"TGS文件(*.TGS)|*.TGS|All files(*.*)|*.*|",
			NULL);
	    if(fileDialog.DoModal ()==IDCANCEL)
			return false;
	    Save(fileDialog.GetPathName());
	}
	else
	{
		CFileDialog fileDialog1(
			FALSE,"TGY",m_strProjectTitle,
			OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
			"TGY文件(*.TGY)|*.TGY|All files(*.*)|*.*|",
			NULL);
	    if(fileDialog1.DoModal ()==IDCANCEL)
			return false;
	    Save(fileDialog1.GetPathName());
	}

	return	true;
}

void CTGData::Save(CString strFileName)
{
	
	CString		cstrTemp;	
	CStdioFile   file;
	
	if( !file.Open(strFileName, CFile::modeWrite | CFile::modeCreate) )
	{
		cstrTemp = "工程文件“" + strFileName + "”保存错误!";
		AfxMessageBox(cstrTemp,MB_ICONERROR);
		return;
	}
	int i,j;
	if(((CMainFrame*)AfxGetMainWnd())->m_TGProjectType==1)
	{	
		try
		{
			file.WriteString(_T("[TGF]\n"));
			for(i=0; i<11; i++)
				file.WriteString(m_strEdit[i]+_T("\n"));
			
			file.WriteString(m_strCombo1+_T("\n"));
			file.WriteString(m_strCombo2+_T("\n"));
			file.WriteString(m_strCombo3+_T("\n"));
			for(i = 0; i<8; i++)
				for(j = 0; j<7; j++)
					file.WriteString(m_grid1[i][j]+_T("\n"));
		}
		catch (CFileException exception1)
		{
			Beep(650, 700);
			AfxMessageBox(_T("写文件出错!"), MB_ICONERROR);
			return;
		}
	}
	else
	{
		for(i = 0; i<=12; i++)
		{
			for(j = 0; j<=5; j++)
			{
				try
				{ 
					file.WriteString(m_grid1[i][j]+_T("\n"));
				}
				catch (CFileException exception1)
				{
					Beep(650, 700);
					AfxMessageBox(_T("写文件出错!"), MB_ICONERROR);
					return;
				}
			}
		}
	}
	file.Close();

	m_strFileName = strFileName;
	m_bModify = false;
		
	OnProjectChanged();
	
	
}

bool CTGData::IsSaveData()
{
	if(m_bModify)
	{
		int iResults = AfxMessageBox(_T("工程数据已修改,是否保存?"),
			MB_YESNOCANCEL|MB_ICONQUESTION) ;
		if(iResults == IDCANCEL)
			return false;

		if(iResults == IDYES )
		{
			if(!SaveProject())
				return false;
		}
		else
			m_bModify = false;
	}
	return true;


}

void CTGData::CloseView()
{
	CMainFrame*		pMainWnd = (CMainFrame*)AfxGetMainWnd();

	if(pMainWnd->GetActiveFrame() != pMainWnd)
		pMainWnd->GetActiveFrame()->SendMessage(WM_CLOSE, NULL, NULL);

}

void CTGData::Calculate()
{
	if(((CMainFrame*)AfxGetMainWnd())->m_TGProjectType==1)
	{
		if(m_strDatabase.IsEmpty())
		{
			m_strDatabase =	AfxGetApp()->GetProfileString (_T("TG"), _T("DataBase"));
			if(m_strDatabase.IsEmpty())
			{
				m_strDatabase = ((CCVenusApp*)AfxGetApp())->m_strAppPath + _T("\\数据.mdb");
				TRACE(m_strDatabase);
				AfxGetApp()->WriteProfileString (_T("TG"), _T("DataBase") ,m_strDatabase);
			}
		}
		HANDLE      hSearch; 
		WIN32_FIND_DATA FileData; 
		
		hSearch = FindFirstFile(m_strDatabase, &FileData); 
		if (hSearch == INVALID_HANDLE_VALUE) 
		{ 
			AfxMessageBox(_T("请确定数据库的位置!"), MB_ICONEXCLAMATION);
			return;
		}
		CWaitCursor	wait;
		CloseView();

		if(m_strCombo3.Compare(_T("0")) == 0)
			AddCal();
		if(m_strCombo3.Compare(_T("1")) == 0)
			NoAddCal();
	}
	else
	{
        YGCal();
	}
	AfxGetMainWnd()->PostMessage(WM_COMMAND,IDM_TG_SECURITY,NULL);
}

void CTGData::YGCal()//油管抗拉强度校核计算()
{
	//油管深度                [[[[             ygsd
	//安全系数                [[[[             aqxs
	//屈服极限1               [[[[             qfjx1
	//外径1                   [[[[             waijing1
	//内径1                   [[[[             neijing1
	//抗拉强度1               [[[[             klqd1
	//单位长度重量1           [[[[             dwcdzl1 
	//内径2                   [[[[             neijing2
	//外径2                   [[[[             waijing2
	//屈服极限2               [[[[             qfjx2
	//抗拉强度2               [[[[             klqd2
	//单位长度重量2           [[[[             dwcdzl2
	//J抗拉强度1              [[[[             Jklqd1
	//J抗拉强度2              [[[[             Jklqd2
	//长度1                   [[[[             changdu1
	//长度2                   [[[[             changdu2

       double ygsd,aqxs,qfjx1,waijing1,neijing1,klqd1,dwcdzl1,neijing2,waijing2;
       double qfjx2,klqd2,dwcdzl2,Jklqd1,Jklqd2,changdu1,changdu2,CA,tempdou;
	   ygsd=0;aqxs=0;qfjx1=0;waijing1=0;neijing1=0;klqd1=0;dwcdzl1=0;neijing2=0;
	   waijing2=0;qfjx2=0;klqd2=0;dwcdzl2=0;
	   char Temp[100];
	   CString str,str1;

	   ygsd=atof(m_grid1[1][5]);
	   aqxs=atof(m_grid1[2][5]);
	   qfjx1=atof(m_grid1[3][5]);
	   waijing1=atof(m_grid1[4][5]);
	   neijing1=atof(m_grid1[5][5]);
	   klqd1=atof(m_grid1[6][5]);
	   dwcdzl1=atof(m_grid1[7][5]);
	   neijing2=atof(m_grid1[8][5]);
	   waijing2=atof(m_grid1[9][5]);
	   qfjx2=atof(m_grid1[10][5]);
	   klqd2=atof(m_grid1[11][5]);
	   dwcdzl2=atof(m_grid1[12][5]);

	   CStdioFile f3;
	   CFileException exception3;
	   BOOL status1;	 
	   str = ((CCVenusApp*)AfxGetApp())->m_strAppPath;
	   str  += "\\tempfile.txt";	
	   status1 = f3.Open(str,CFile::modeCreate|CFile::modeWrite);
	   if (!status1)
	   {
		   char s[100];
		   sprintf(s, "Error opening file for reading. Code:%d",
			   exception3.m_cause);
		   AfxMessageBox(s);
		   return;
	   }
	   try
	   {
		   f3.WriteString("\n");
		   str="\t\t井油管抗拉强度校核计算结果$0\n";
		   f3.WriteString(str);
		   f3.WriteString("\n");
	   }
	   catch (CFileException exception3)
	   {
		   AfxMessageBox("Error reading file");
		   return;
	   }

	  Jklqd1 = 3.14159 / 4000 * qfjx1 * (pow(waijing1,2) - pow(neijing1,2));
	  Jklqd2 = 3.14159 / 4000 * qfjx2 * (pow(waijing2,2) - pow(neijing2,2));
	  if( Jklqd1 > 0 && klqd1 == 0)
		  klqd1 = Jklqd1;
	  if( Jklqd2 > 0 && klqd2 == 0)
		  klqd2 = Jklqd2;
	  if( ygsd > 0)
	  {
		if( klqd2 * dwcdzl2 == 0)
		{
		  aqxs = int(100000 * klqd1 / dwcdzl1 / ygsd) / 100.00;
		  changdu2 = 0;
		  changdu1 = ygsd;
		  tempdou=changdu2 + changdu1;
          gcvt(tempdou,20,Temp);
		  str1=Temp;
		  str="";
		  str =str+"\t" + "设计油管下入总深度$16" + "\t" + str1 + "$12" + "\t" + "m" + "$14"+"\n";
		  try
		  {
			   f3.WriteString(str);
		  }
		  catch (CFileException exception3)
		  {
			   AfxMessageBox("Error reading file");
			   return;
		  }
		  gcvt(aqxs,20,Temp);
		  str1=Temp;
		  str="";
		  str =str+ "\t" + "设计安全系数$16" + "\t" + str1 + "$12" + "\t" + "" + "$14"+"\n";
		  try
		  {
			   f3.WriteString(str);
		  }
		  catch (CFileException exception3)
		  {
			   AfxMessageBox("Error reading file");
			   return;
		  }
		}
		else
		{
		  CA = 1000 * klqd1 / dwcdzl1 + 1000 * klqd2 / dwcdzl2;
		  aqxs = (CA + pow((pow(CA,2) - 4 * ygsd * 1000 * klqd2 / dwcdzl1),0.5)) / 2 / ygsd;
		  changdu2 = 1000 * klqd2 / dwcdzl2 / aqxs;
		  changdu1 = 1000 * (klqd1 - klqd2 / aqxs) / dwcdzl1 / aqxs;
		  tempdou=changdu2 + changdu1;
          gcvt(tempdou,20,Temp);
		  str1=Temp;
		  str="";
		  str = str+"\t" + "设计油管下入总深度$16" + "\t" + str1 + "$12" + "\t" + "m" + "$14"+"\n";
		  try
		  {
			   f3.WriteString(str);
		  }
		  catch (CFileException exception3)
		  {
			   AfxMessageBox("Error reading file");
			   return;
		  }
		  if( changdu1 > 0)
		  {
		    gcvt(changdu1,20,Temp);
		    str1=Temp;
			str="";
			str = str+"\t" + "上段油管下入深度$16" + "\t" + str1 + "$12" + "\t" + "m" + "$14"+"\n";
			try
			{
				   f3.WriteString(str);
			}
			catch (CFileException exception3)
			{
				   AfxMessageBox("Error reading file");
				   return;
			}
		  }
		  if( changdu2 > 0)
		  {
		    gcvt(changdu2,20,Temp);
		    str1=Temp;
			str="";
			str =str+ "\t" + "下段油管下入深度$16" + "\t" + str1+ "$12" + "\t" + "m" + "$14"+"\n";
			try
			{
				   f3.WriteString(str);
			}
			catch (CFileException exception3)
			{
				   AfxMessageBox("Error reading file");
				   return;
			}
		  }

⌨️ 快捷键说明

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