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

📄 shizdlg.cpp

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

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


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


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


BEGIN_MESSAGE_MAP(CShizDlg, CDialog)
	//{{AFX_MSG_MAP(CShizDlg)
	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()

/////////////////////////////////////////////////////////////////////////////
// CShizDlg message handlers

BOOL CShizDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	modiflag = true;
	char ptitle[6][10]=
	{
		_T("序号"),_T("观测时间"),_T("线号"),_T("点名"),_T("边长(m)"),_T("角度值"),
	};
	CString fname;
	char m_Name1[20],m_Name2[20];
	long m_times;
	int m_id=0;
	int j=1;
	double m_length;
	double m_degree;
	fname = directory + "shiz.str" ;
	FILE *fp; 	
	fp=fopen(fname,"r");
	if (fp == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据读入失败!");
		OnCancel();
		return false;
	}
	while(!feof(fp))
	{	
		fscanf(fp,"%d %d %s %s %lf %lf\n",&m_id,&m_times,&m_Name1,&m_Name2,&m_length,&m_degree);
		j=j+1;
	}
	m_nRows = j;
	m_nCols = 6;
	if (m_id == 0)
	{
		m_nRows = 1;
	}
	m_Grid.SetRowCount(m_nRows);
	m_Grid.SetColumnCount(m_nCols);
	for (j=1;j<m_nRows;j++)
		m_Grid.SetRowHeight(j,17);
	m_Grid.SetFixedColumnCount(1); 
	m_Grid.SetFixedRowCount(1);
	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,50);
	m_Grid.SetColumnWidth(3,50);
	m_Grid.SetColumnWidth(4,70);
	m_Grid.SetColumnWidth(5,90);
	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 %d %s %s %lf %lf\n",&m_id,&m_times,&m_Name1,&m_Name2,&m_length,&m_degree);
		item.row=i;
		item.col=0;
		item.szText.Format(_T("%d"),m_id);
		m_Grid.SetItem(&item);
		item.col=1;
		item.szText.Format(_T("%d"),m_times);
		m_Grid.SetItem(&item);
		item.col=2;
		item.szText.Format(_T("%s"),m_Name1);
		m_Grid.SetItem(&item);
		item.col=3;
		item.szText.Format(_T("%s"),m_Name2);
		m_Grid.SetItem(&item);
		item.col=4;
		item.szText.Format(_T("%.4lf"),m_length);
		m_Grid.SetItem(&item);
		item.col=5;
		item.szText.Format(_T("%.4lf"),m_degree);
		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 CShizDlg::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 CShizDlg::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 CShizDlg::OnPrintButton() 
{
	// TODO: Add your control notification handler code here
	m_Grid.Print();
}

void CShizDlg::OnSaveButton() 
{
	// TODO: Add your control notification handler code here
	double fangx =1.414*(atof(m_Fangx));
	CString fname,fnewname,text;
	CString m_Name1,m_Name2;
	int m_id;
	long m_times;
	double m_length;
	double m_degree;
	fname = directory + "shiz.str" ;
	fnewname = directory + "shiz.adj" ; 
	FILE *fp; 
	FILE *fpnew; 
	fp=fopen(fname,"w");
	if (fp == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据写入失败!");
		return;
	}
	fpnew=fopen(fnewname,"w");
	if (fpnew == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据写入失败!");
		return;
	}
	for (int row = 1; row < m_Grid.GetRowCount(); row++)
	{
		text = m_Grid.GetItemText(row,0);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_id = atoi(text);
		text = m_Grid.GetItemText(row,1);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_times = atoi(text);
		text = m_Grid.GetItemText(row,2);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_Name1 = text;
		text = m_Grid.GetItemText(row,3);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_Name2 = text;
		text = m_Grid.GetItemText(row,4);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_length = atof(text);
		text = m_Grid.GetItemText(row,5);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_degree = atof(text);
		fprintf(fp,"%d %d %s %s %.4lf %.4lf\n",m_id,m_times,m_Name1,m_Name2,m_length,m_degree);
		m_degree = (DmsToDegree(m_degree))*3600;
		fprintf(fpnew,"%d %d %s %s %.4lf %.4lf %.4lf\n",m_id,m_times,m_Name1,m_Name2,m_length,m_degree,fangx);
	}
	fclose(fp);
	fclose(fpnew);
	modiflag = true;
}

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

double CShizDlg::DmsToDegree(double x)
{
	int  kf;
	double d,m;
	double xx,s;
	if (x < 0)
	{kf = -1;x = -x;}
	else
		kf = 1;
	d = (double)floor(x);
	m = (double)floor((x - d) * 100 + 0.001);
	s = (x - d - m / 100.0) * 10000.0;
	xx=(d + m / 60.0 + s / 3600.0) * kf;
	return xx;
}

⌨️ 快捷键说明

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