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

📄 interfacedlg.cpp

📁 程序通过OO4O库实现了VC6.0下oracle10g数据库的访问
💻 CPP
字号:
// InterfaceDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Interface.h"
#include "InterfaceDlg.h"

#include<math.h>//
#include<stdlib.h>//
//#include "Shlwapi.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern ODatabase Database;
/////////////////////////////////////////////////////////////////////////////
// CInterfaceDlg dialog


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


void CInterfaceDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInterfaceDlg)
	DDX_Control(pDX, IDC_INTER_NAME, m_cbName);
	DDX_Control(pDX, IDC_INTER_FILE, m_File);
	DDX_GridControl(pDX, IDC_GRID, m_Grid);
	DDX_Control(pDX, IDC_NTGRAPH, m_Graph);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInterfaceDlg, CDialog)
	//{{AFX_MSG_MAP(CInterfaceDlg)
	ON_BN_CLICKED(IDC_INTER_SHOW, OnInterShow)
	ON_BN_CLICKED(IDC_INTER_POSI, OnPosi)
	ON_BN_CLICKED(IDC_INTRER_DISPLAY, OnDisplay)
	ON_BN_CLICKED(IDC_INTER_OUTPUT, OnOutput)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInterfaceDlg message handlers

BOOL CInterfaceDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here	
	m_Graph.SetFrameStyle(1); // (1) - Flat
		// (2) - Scope (raised frame and sunken plot area borders)
		// (3) - 3DFrame (a bitmap frame picture)
		
	m_Graph.SetGridColor(RGB(192,192,192));
	m_Graph.SetShowGrid (TRUE);
	
	m_Graph.SetCursorColor (RGB(255,0,0));
	m_Graph.SetTrackMode (1);	

	m_Graph.SetXLabel ("X-波长(nm)");
	m_Graph.SetYLabel("Y-反射率(%)");
	m_Graph.SetRange(300.,2600.,0.,100.);


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CInterfaceDlg::OnInterShow() 
{
	// TODO: Add your control notification handler code here
    CString strTemp;
	m_cbName.GetWindowText(strTemp);
	int Type=atoi(strTemp.Left(1));
	CString strCode;
	int n;
	n=strTemp.Find(" ");
	strCode=strTemp.Mid(n+1,strTemp.GetLength()-1-n);
	CString TableName[]={"ObjectTab","SoilTab","VegeTab","WaterTab","RockTab"};
	int ColCount=7;
	long RowCount;
	int i,j;
	CString sql;
	OValue oField;
	ODynaset rs;
	CString strField;
	sql.Format("select RecNo from %s where Code like '%s",TableName[Type-1],strCode);
	sql+="%'";
	rs.Open(Database,sql);
	rs.MoveFirst();
	n=rs.GetRecordCount();
	strCode="";
	for(i=0;i<n;i++)
	{
		rs.GetFieldValue(0,&oField);
		strTemp=oField;
		if(i==n-1)
			strCode+=strTemp;
		else				
			strCode=strCode+strTemp+",";
		rs.MoveNext();
	}
	rs.Close();
	sql.Format("select RecNo,MeasKind,MeasDate,ApparatusType,Longitude,Latitude from "
		"FieldEnvironTab where RecNo in(%s) and ApparatusType=17 and MeasKind='%d' and MeasDate between "
		"TO_DATE('%s', 'yyyy-mm-dd hh24:mi:ss')and TO_DATE('%s', 'yyyy-mm-dd hh24:mi:ss')"
		" and Latitude between '%f' and '%f' and Longitude between '%f' and '%f' order by RecNo",		
		strCode,Type,m_StartTime,m_EndTime,m_Lat-m_ErrorLat,m_Lat+m_ErrorLat,m_Long-m_ErrorLong,m_Long+m_ErrorLong);
	rs.Open(Database,sql);
	RowCount = rs.GetRecordCount()+1;			
	//设定行列数 	
	m_Grid.SetRowCount(RowCount);
	m_Grid.SetColumnCount(ColCount);
	m_Grid.SetFixedRowCount(1);
	m_Grid.SetFixedColumnCount(1);
	//设置标题背景颜色
	m_Grid.SetItemBkColour(0,0,RGB(255,221,255));
	//不显标题提示
	m_Grid.EnableTitleTips(false);
	m_Grid.SetBkColor(RGB(159,184,242));
	GV_ITEM Item;
	Item.mask = GVIF_TEXT|GVIF_FORMAT;
	Item.row = 0;
	Item.col = 0;
	Item.nFormat = DT_LEFT|DT_WORDBREAK|DT_BOTTOM;
	
	//在表格第一列显示行数
	for(i = 0;i <= RowCount;i++)
	{
		j = 0;
		Item.row = i;
		Item.col = j;
		Item.szText.Format(_T("%d"),i);
		m_Grid.SetItem(&Item);
	}
	//设定第一列的宽度
	m_Grid.SetColumnWidth(0,50);	
	CString fieldname[6]={"记录编号","地物类型","测量时间","仪器编号","经度","纬度"};
	Item.row=0;
	for(i=0; i<6; i++)
	{		
		Item.col=i+1;
		Item.szText=fieldname[i];
		m_Grid.SetItem(&Item);				
	}
	//显示表中数据         
	CString FieldName[6]={"RecNo","MeasKind","MeasDate","ApparatusType","Longitude","Latitude"};
	rs.MoveFirst();
	for(i=1;i<RowCount;i++)
	{			
		for(j=1;j<7;j++)
		{
			rs.GetFieldValue(FieldName[j-1],&oField);
			strField=oField;
			if(!strField.IsEmpty())
				m_Grid.SetItemText(i,j,strField);
		}
		rs.MoveNext();
	}
	rs.Close();
}

void CInterfaceDlg::OnPosi() 
{
	// TODO: Add your control notification handler code here
	CString strPosi;//文件位置
	CString strTemp;
	CString strKindName;//地物类型和名称
	CString strDouble;//经纬度
	int nPos;	
	CFileDialog dlg(TRUE,"txt","*.txt",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
		"TXT文件(*.txt)|*.txt|DAT文件(*.dat)|*.dat|所有文件(*.*)|*.*||",NULL);
	if(dlg.DoModal() == IDOK)
	{
		strPosi=dlg.GetPathName();
		m_File.SetWindowText(strPosi);
		Invalidate();
	}
	CStdioFile FilePara(strPosi,CFile::shareDenyNone|CFile::modeRead);
	FilePara.SeekToBegin();
	FilePara.ReadString(strTemp);//地物种类和名称
	/**/
	while (strTemp.FindOneOf(",") != -1) 
	{
		nPos=strTemp.FindOneOf(",");
		strKindName=strTemp.Mid(0,nPos);
		strTemp.Delete(0,nPos+1);
		m_KindName.Add(strKindName);			
	}
	m_KindName.Add(strTemp);
	strKindName=m_KindName.GetAt(1);
	FilePara.ReadString(strTemp);//经度
	/**/
	nPos=strTemp.FindOneOf(".");//度
	strDouble=strTemp.Mid(0,nPos);
	strTemp.Delete(0,nPos+1);
	m_Long=atof(strDouble);
	nPos=strTemp.FindOneOf(".");//分
	if(nPos == -1)
		m_Long+=atof(strTemp)/60;
	else
	{
		strDouble=strTemp.Mid(0,nPos);
		strTemp.Delete(0,nPos+1);
		m_Long+=atof(strDouble)/60;
		m_Long+=atof(strTemp)/3600;
	}
	
	FilePara.ReadString(strTemp);//纬度
	/**/
	nPos=strTemp.FindOneOf(".");
	strDouble=strTemp.Mid(0,nPos);
	strTemp.Delete(0,nPos+1);
	m_Lat=atof(strDouble);
	nPos=strTemp.FindOneOf(".");//分
	if(nPos == -1)
		m_Lat+=atof(strTemp)/60;
	else
	{
		strDouble=strTemp.Mid(0,nPos);
		strTemp.Delete(0,nPos+1);
		m_Lat+=atof(strDouble)/60;
		m_Lat+=atof(strTemp)/3600;
	}	
	FilePara.ReadString(strTemp);//水平半径
	m_ErrorLong=((360*atof(strTemp))/(6400*cos(m_Lat*3.14/180)*3.14*2));
	FilePara.ReadString(strTemp);//垂直半径
	m_ErrorLat=atof(strTemp)/111.64;
	FilePara.ReadString(m_StartTime);//开始时间
	FilePara.ReadString(m_EndTime);//结束时间
	FilePara.Close();
	int Size=m_KindName.GetSize();
	int i,j;
	CString TableName[]={"ObjectCodeTab","SoilCodeTab","VegeCodeTab","WaterCodeTab","RockCodeTab"};
	CString sql;
	ODynaset rs;
	OValue oField;
	for(i=0;i<Size;i++)
	{
		strTemp=m_KindName.GetAt(i);
		j=atoi(strTemp.Left(1));
		CString strName=strTemp.Mid(1,strTemp.GetLength()-1);
		sql.Format("select Code from %s where Name='%s'",TableName[j-1],strName);
		rs.Open(Database,sql);
		if(rs.GetRecordCount() == 1)
		{
			rs.GetFieldValue(0,&oField);
			CString strCode=oField;
			strTemp=strTemp+" "+strCode;
			m_cbName.AddString(strTemp);			
		}
		else
		{
			MessageBox("目标名称有误!");
			return;
		}
		rs.Close();
	}
}

void CInterfaceDlg::OnDisplay() 
{
	// TODO: Add your control notification handler code here
    CCellID seleCell;
	seleCell=m_Grid.GetFocusCell();
	if(!seleCell.IsValid())
	{
		MessageBox("请选择一条记录!","数据库系统提示",MB_OK+MB_ICONINFORMATION);
		return;
	}
	CString strRecNo;
	strRecNo=m_Grid.GetItemText(seleCell.row,1);
	int Type=atoi(m_Grid.GetItemText(seleCell.row,2));
	CString TableName[]={"ObjectTab","SoilTab","VegeTab","WaterTab","RockTab"};
	m_sql.Format("select * from %s where RecNo='%s'",TableName[Type-1],strRecNo);
	m_rs.Open(Database,m_sql);

	CString strPath=GetCurPath()+"spect.txt";
 	BlobtoFile("SpectralCurve",strPath);
	m_rs.Close();
	m_Graph.ClearGraph();
//	m_Graph.SetElementLineColor(RGB(255,0,0));	
	CStdioFile file(strPath,CFile::shareDenyNone|CFile::modeRead);
	file.SeekToBegin();
	CString strTemp;
	file.ReadString(strTemp);
	double x,y;	
	while(file.ReadString(strTemp))//如果读取到尾部则readstring返回NUll
	{
		x=atof(strTemp.Left(7));
		y=atof(strTemp.Right(5));
		m_Graph.PlotXY(x,y,0);		
	}

 	DeleteFile(strPath);
}

int CInterfaceDlg::BlobtoFile(CString FieldName, CString FileName)
{
	OBlob oblob;	
	unsigned char *buffer = 0;
	m_rs.GetFieldValue(FieldName, &oblob);
	if(!(oblob.IsNull()))
	{  
		CFile outFile(FileName,CFile::modeCreate|CFile::modeWrite);
		try
		{
			unsigned long size = oblob.GetSize();
			// calculate an optimum buffersize of approximately 32k bytes
			unsigned long optchunk = oblob.GetOptimumChunkSize();
			unsigned int bufsize = ((int)(32768/optchunk)) *optchunk;
			if (bufsize > size)
				bufsize = size;
			buffer = (unsigned char *)malloc(bufsize);
			//By taking advantage of streaming we get the best performance
			//and do not need to allocate a large buffer
			oblob.EnableStreaming(size);
			short status= OLOB_NEED_DATA;
			unsigned long amtread=0;
			while(status == OLOB_NEED_DATA)
			{
				amtread = oblob.Read(&status, buffer, bufsize);
				outFile.WriteHuge(buffer,amtread);
			}
			oblob.DisableStreaming();
			outFile.Close();
		}
		catch(OException E)
		{
			return 0;
		}
		if (buffer)			
			free(buffer);		
		return 1;
	}
	else 
		return 2;
}

CString CInterfaceDlg::GetCurPath()
{
	char FullPath[80];
	GetModuleFileName(NULL,FullPath,_MAX_PATH);
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];	
	_splitpath(FullPath, drive, dir, fname, ext);
	char Path[100];
	strcpy(Path,drive);
	strcat(Path,dir);
	CString strPath(Path);
	strPath=strPath.Left(strPath.GetLength()-1);
	int i=strPath.ReverseFind('\\');
	CString CurPath=strPath.Left(i+1);
	return CurPath;
}

void CInterfaceDlg::OnOutput() 
{
	// TODO: Add your control notification handler code here
	CString strPosi;
	CString strTemp;

	m_cbName.GetWindowText(strTemp);
	int Type=atoi(strTemp.Left(1));
	CString strName;
	int i,n;
	n=strTemp.Find(" ");
	strName=strTemp.Mid(1,n-1);
	strTemp=strName+".txt";

	CFileDialog dlg(FALSE,"txt",strTemp,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
		"TXT文件(*.txt)|*.txt|DAT文件(*.dat)|*.dat|所有文件(*.*)|*.*||",NULL);
	if(dlg.DoModal() == IDOK)
	{
		strPosi=dlg.GetPathName();	
		Invalidate();
	}
	
	CString TableName[]={"ObjectTab","SoilTab","VegeTab","WaterTab","RockTab"};
	long RowCount=m_Grid.GetRowCount();
	strTemp.Empty();
	for(i=1;i<RowCount;i++)
	{
		if (i == (RowCount-1))
			strTemp+=m_Grid.GetItemText(i,1);
		else
			strTemp+=m_Grid.GetItemText(i,1)+",";
	}
	m_sql.Format("select * from %s where RecNo in (%s)",TableName[Type-1],strTemp);
	m_rs.Open(Database,m_sql);

	CString strPath;
	strPath=GetCurPath()+"output.txt";

	double * pY=NULL;
	long * pN=NULL;
	pY=new double[2250];
	if(!pY)
		MessageBox("内存分配失败!");
	pN=new long[2250];
	if(!pN)
		MessageBox("内存分配失败!");
	for(n=0;n<2250;n++)
	{
		pY[n]=0;
		pN[n]=0;
	}

	m_rs.MoveFirst();

	for(i=0;i<m_rs.GetRecordCount();i++)
	{
 		BlobtoFile("SpectralCurve",strPath);		
	
		CStdioFile file1(strPath,CFile::shareDenyNone|CFile::modeRead);
		file1.SeekToBegin();
		file1.ReadString(strTemp);
		n=0;
		while(file1.ReadString(strTemp))//如果读取到尾部则readstring返回NUll
		{
			pN[n]=pN[n]+1;
			pY[n]=pY[n]+atof(strTemp.Right(5));
			n++;					
		}
		file1.Close();
		m_rs.MoveNext();
		DeleteFile(strPath);
	}
	m_rs.Close();
	for(n=0;n<2250;n++)
	{
		if(pN[n] != 0)
			pY[n]=pY[n]/pN[n];
		else
			pY[n]=0;
	}
	CStdioFile file2(strPosi,CFile::modeCreate|CFile::modeWrite);

	for(n=0;n<2250;n++)
	{
		long fX=n+350;
		if (pY[n] != 0)
		{
			if(fX<1000.00)
				strTemp.Format("%d  %.2f\n",fX,pY[n]);
			else
				strTemp.Format("%d %.2f\n",fX,pY[n]);
			file2.WriteString(strTemp);
		}
	}
	file2.Close();
	m_Graph.ClearGraph();
	m_Graph.SetElementLineColor(RGB(255,0,0));
	CStdioFile file3(strPosi,CFile::modeRead);
	file3.SeekToBegin();
	file3.ReadString(strTemp);
	double x,y;	
	while(file3.ReadString(strTemp))//如果读取到尾部则readstring返回NUll
	{
		x=atof(strTemp.Left(7));
		y=atof(strTemp.Right(5));
		m_Graph.PlotXY(x,y,0);		
	}
	file3.Close();
	delete []pY;
	delete []pN;
	pY=NULL;
	pN=NULL;

}

⌨️ 快捷键说明

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