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

📄 gaocdlg.cpp

📁 商业测绘软件
💻 CPP
字号:
// GaocDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DeformAdj.h"
#include "GaocDlg.h"
//#include "global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString directory;
extern CString projname;
/////////////////////////////////////////////////////////////////////////////
// CGaocDlg dialog


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


void CGaocDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGaocDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	DDX_GridControl(pDX,IDC_GAOC_GRID,m_Grid);
}


BEGIN_MESSAGE_MAP(CGaocDlg, CDialog)
	//{{AFX_MSG_MAP(CGaocDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
	ON_BN_CLICKED(IDC_PRINT_BUTTON, OnPrintButton)
	ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGaocDlg message handlers
BOOL CGaocDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	modiflag = true;
	char ptitle[4][15]=
	{
		_T("序号"),_T("点名"),_T("高程(m)"),_T("属性(1/0)"),
	};
	CString fname;
	char m_Name[20];
	int m_id=0;
	int m_io=0;
	int j=1;
	double m_h;
	fname = directory + "gaoc.ela" ;
	FILE *fp; 
	fp=fopen(fname,"r");
	if (fp == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据读入失败!");
		OnCancel();
		return false;
	}
	while(!feof(fp))
	{	
		fscanf(fp,"%d %s %lf %d\n",&m_id,&m_Name,&m_h,&m_io);
		j=j+1;
	}
	m_nRows = j;
	m_nCols = 4;
	if (m_id == 0)
	{
		m_nRows = 1;
	}
	m_Grid.SetRowCount(m_nRows);
	m_Grid.SetColumnCount(m_nCols);
	m_Grid.SetFixedColumnCount(1); 
	m_Grid.SetFixedRowCount(1);
	for (j=1;j<m_nRows;j++)
		m_Grid.SetRowHeight(j,17);
	m_Grid.SetEditable(true);
	m_Grid.SetTextBkColor(RGB(0xFF,0xFF,0xE0));
	m_Grid.SetColumnWidth(0,40);
	m_Grid.SetColumnWidth(1,60);
	m_Grid.SetColumnWidth(2,60);
	m_Grid.SetColumnWidth(3,50);
	for (int col=0;col<m_nCols;col++)
	{
		GV_ITEM item;
		item.mask=GVIF_TEXT|GVIF_FORMAT;
		item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
		item.row=0;
		item.col=col;
		item.szText.Format(_T("%s"),ptitle[col]);
		m_Grid.SetItem(&item);
	}
	fseek(fp,0L,SEEK_SET);
	int i=1;
	while(!feof(fp))
	{
		GV_ITEM item;
		item.mask=GVIF_TEXT|GVIF_FORMAT;
		item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
		fscanf(fp,"%d %s %lf %d\n",&m_id,&m_Name,&m_h,&m_io);
		item.row=i;
		item.col=0;
		item.szText.Format(_T("%d"),m_id);
		m_Grid.SetItem(&item);
		item.col=1;
		item.szText.Format(_T("%s"),m_Name);
		m_Grid.SetItem(&item);
		item.col=2;
		item.szText.Format(_T("%.4lf"),m_h);
		m_Grid.SetItem(&item);
		item.col=3;
		item.szText.Format(_T("%d"),m_io);
		m_Grid.SetItem(&item);
		i=i+1;
	}
	fclose(fp);		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGaocDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	CString heading;
	heading.Format(_T("%d"),m_nRows);
	m_Grid.InsertRow(heading,-1);
	m_Grid.SetRowHeight(m_nRows,17);
	m_Grid.Invalidate();
	m_nRows=m_nRows+1;
	m_Grid.SetFocusCell(m_nRows-1,1);
	m_Grid.SetScrollPos32(1,17*m_nRows);
	m_Grid.Invalidate();
	modiflag = false;
}

void CGaocDlg::OnDeleteButton() 
{
	// TODO: Add your control notification handler code here
	int row = m_Grid.GetFocusCell().row;
	if (row >= 0)
	{
		m_Grid.DeleteRow(row);
		m_nRows = m_nRows - 1;
		for (int i=1;i<m_nRows;i++)
		{
			GV_ITEM item;
			item.mask=GVIF_TEXT|GVIF_FORMAT;
			item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
			item.row = i;
			item.col=0;
			item.szText.Format(_T("%d"),i);
			m_Grid.SetItem(&item);
		}
		m_Grid.Invalidate();
	}
	else
	{
		AfxMessageBox("请选择要删除的行!");
		return;
	}
	modiflag = false;
}

void CGaocDlg::OnPrintButton() 
{
	// TODO: Add your control notification handler code here
	m_Grid.Print();
}

void CGaocDlg::OnSaveButton() 
{
	// TODO: Add your control notification handler code here
	CString fname,text,m_Name;
//	char m_Name[20];
	int m_id;
	double m_h;
	int m_io;
	fname = directory + "gaoc.ela" ;
	FILE *fp; 
	fp=fopen(fname,"w");
	if (fp == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据写入失败!");
		return;
	}
	for (int row = 1; row < m_Grid.GetRowCount(); row++)
	{
		text = m_Grid.GetItemText(row,0);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			return;
		}
		m_id = atoi(text);
		text = m_Grid.GetItemText(row,1);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			return;
		}
		m_Name = text;
		text = m_Grid.GetItemText(row,2);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			return;
		}
		m_h = atof(text);
		text = m_Grid.GetItemText(row,3);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			return;
		}
		m_io = atoi(text);
		fprintf(fp,"%d %s %.4lf %d\n",m_id,m_Name,m_h,m_io);
	}
	fclose(fp);
	modiflag = true;
}

void CGaocDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	if ( modiflag == false )
	{
		int retuvalu = AfxMessageBox("你需要保存数据吗?",MB_OK|MB_OKCANCEL);
		if (retuvalu == IDOK )
		{
			CGaocDlg::OnSaveButton();
		}			
	}
	CDialog::OnCancel();
}



⌨️ 快捷键说明

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