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

📄 tgdata_backup.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<8; 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;
	CFileDialog fileDialog(
		TRUE,"TGF",NULL,
		OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
		"TGF文件(*.TGF)|*.TGF|All files(*.*)|*.*|",
		NULL);
	//	fileDialog.m_ofn.lpstrInitialDir = "";
	if(fileDialog.DoModal () == IDCANCEL)
		return FALSE;
	
//	CloseView();

	CString		strFileName = fileDialog.GetPathName ();
	
	HANDLE      hSearch; 
	WIN32_FIND_DATA FileData; 
	
	hSearch = FindFirstFile(strFileName, &FileData); 
	if (hSearch == INVALID_HANDLE_VALUE) 
	{ 
		AfxMessageBox(_T("文件不存在!"), MB_ICONERROR);
		return false;
	}
	
	CStdioFile   file;
	CString		cstrTemp;
	
	if(!file.Open(strFileName, CFile::modeRead) )
	{ 
		cstrTemp = "文件 " + strFileName + " 打开失败!";
		AfxMessageBox(cstrTemp,MB_ICONERROR);
	}
	
	CStringArray		saFileData;
	CString			strTemp;
	
	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;
		
	}
	
	int i,j,k;
	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++];
		

	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();
	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()
{
	CFileDialog fileDialog(
		FALSE,"TGF",m_strProjectTitle,
		OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
		"TGF文件(*.TGF)|*.TGF|All files(*.*)|*.*|",
		NULL);
	//	fileDialog.m_ofn.lpstrInitialDir = "";	
	
	if(fileDialog.DoModal ()==IDCANCEL)
		return false;
	Save(fileDialog.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;
	}
	
	try
	{
		file.WriteString(_T("[TGF]\n"));
		int i,j;
		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;
	}
	
	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(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();
	AfxGetMainWnd()->PostMessage(WM_COMMAND,IDM_TG_SECURITY,NULL);
}



void CTGData::AddCal()
{
	CDaoDatabase Database;
	CDaoRecordset* pRecordset;
	CString		strQuery;
	CString		strError;
    COleVariant var;
    try {
      // nonexclusive, read-only
      Database.Open(m_strDatabase, FALSE, TRUE);
    }
    catch (CDaoException* e) {
      ::DaoErrorMsg(e);
      e->Delete();
      return;
    }
	pRecordset = new CDaoRecordset(&Database);

	double	 H, rc, rz, rt, psg, pph, rs, dyw, rhk, Hf, dyn, dtw;	\
	bool	fgq, zc;						\
	H = atof(m_strEdit[0]);   /*套管下深*/	\
	rc = atof(m_strEdit[1]);         /*产层压力梯度*/	\
	rz = atof(m_strEdit[2]);         /*钻井液压力梯度*/	\
	rt = atof(m_strEdit[3]);         /*天然气相对密度*/	\
	psg = atof(m_strEdit[4]);       /*增产措施施工压力*/	\
	pph = atof(m_strEdit[5]);      /*施工平衡压力*/	\
	rs = atof(m_strEdit[6]);       /*酸液压力梯度*/	\
	dyw = atof(m_strEdit[7]);      /*油管外径*/	\
	rhk = atof(m_strEdit[8]);      /*环空液柱压力梯度*/	\
	Hf = atof(m_strEdit[9]);      /*封隔器下深*/	\
	dyn = atof(m_strEdit[10]);     /*油管内径*/	\
	dtw = atof(m_strCombo1);   /*套管外径*/	\
	if(m_strCombo2.Compare(_T("0")) == 0)	\
		fgq = true;							\
	if(m_strCombo2.Compare(_T("1")) == 0)	\
		fgq = false; /*封隔器有无*/			\
	if(m_strCombo3.Compare(_T("0")) == 0)	\
		zc = true;							\
	if(m_strCombo3.Compare(_T("1")) == 0)	\
		zc = false; /*有无增产措施*/	\
	double	d[8], l[8][2];				\
	CString	x[8];						\
	for(int	i = 0; i<8; i++)			\
	{									\
		l[i][0] = atof(m_grid1[i][0]);	\
		l[i][1] = atof(m_grid1[i][1]);	\
		d[i] = atof(m_grid1[i][2]);		\
		x[i] = m_grid1[i][3];			\
	}									\

	double q[100], QQ[100], qdanzhong, b, c, dd, e, f, g, k, Pcmax, Pcc,  pi, Qe[100], Sii, Stt, Scc, Tb, Ai, Ao, Ap, pii, F1, F2, pia, poa, T;
	CString sj[100], sk[100], nn[100], ll[100][100], mm[100][100];
	int z, n;
	z = 8;
	Pcmax = H * rhk;
	f = H * (1 - rhk / 0.0785);
	QQ[0] = 0;
	Qe[0] = 0;
	for(n = 0; n<z; n++)
	{
		if(l[n][0] == 0)
			break;
		q[n] = 0;
			/*     Set mydb1 = OpenDatabase("D:\套管程序设计\数据.mdb")
			Set mytable1 = mydb1.OpenRecordset("套管强度", dbOpenTable)
			Do While Not mytable1.EOF
			If mytable1!外径 = dtw And mytable1!壁厚 = d(n) Then
			qdanzhong = mytable1!公称重量
			End If
			mytable1.MoveNext
			Loop
			mytable1.Close
			mydb1.Close
		*/
		strQuery.Format("select [公称重量] from [套管强度] where [外径] = %10.2f and [壁厚] = %10.2f",
			dtw, d[n]);
		TRACE(strQuery);
		try 
		{	
			pRecordset->Open(dbOpenDynaset, strQuery, dbReadOnly);
		}
		catch (CDaoException* e) {
			::DaoErrorMsg(e);
			e->Delete();
			return;
		}
		if(pRecordset->GetRecordCount() == 0)
		{
			strError.Format(_T("  输入参数错误:数据库中没有该种外径或者\n套管强度(第%d项)!"),n+1);
			AfxMessageBox(strError, MB_ICONERROR);
			return;
		}
		
		pRecordset->MoveLast();
		var = pRecordset->GetFieldValue(0);
		TRACE("\n%ld\n",pRecordset->GetRecordCount());
		switch (var.vt) {
		case VT_R4:
			qdanzhong = var.fltVal;
			break;
		case VT_R8:
			qdanzhong = var.dblVal;
			break;
		}
		pRecordset->Close();

		if(l[n][0] != 0 && l[n][0] <= f)
			QQ[n+1] = QQ[n] + 0.00981 * (l[n][0] - l[n][1]) * q[n];
		else if(l[n][1] <= f && f <= l[n][0])
			QQ[n+1] = QQ[n] + 0.00981 * (f - l[n][1]) * qdanzhong;
		else	
			QQ[n+1] = 0;
		TRACE("%f\n", QQ[n+1]);
//          Call 抗挤安全系数计算

⌨️ 快捷键说明

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