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

📄 positiondlg.cpp

📁 VC做的矢量画图程序!
💻 CPP
字号:
// PositionDlg.cpp : implementation file
//

#include "stdafx.h"
#include "draw.h"
#include "PositionDlg.h"
#include "drawDoc.h"
#include "drawView.h"

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

extern CDrawView * p_View;
/////////////////////////////////////////////////////////////////////////////
// CPositionDlg dialog


CPositionDlg::CPositionDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPositionDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPositionDlg)
	m_LINENO = _T("");
	m_ID = _T("");
	m_type=0;
	//}}AFX_DATA_INIT
}


void CPositionDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPositionDlg)
	DDX_Text(pDX, IDC_LINENO, m_LINENO);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPositionDlg, CDialog)
	//{{AFX_MSG_MAP(CPositionDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPositionDlg message handlers

void CPositionDlg::OnOK() 
{
    UpdateData();
	CString & f1=m_ID;
	m_LINENO.TrimLeft();
	m_LINENO.TrimRight();
	bool bTag=true;
	for(int i=0;i<m_LINENO.GetLength();i++)
	{
		char ch=m_LINENO.GetAt(i);
		if(i==0)
		{
			if(m_type==1)
			{
				 if(ch!='1')
				 { 
				   bTag=false;
				   break;
				 }
			}
		    else if(m_type==2)
			{
				if(ch!='2')
				{
					bTag=false;
					break;
				}
			}
			else if(m_type==3)
			{
				if(ch!='3')
				{
					bTag=false;
					break;
				}
			}
		}
		else
		{
		   if(ch<'0' || ch>'9')
		   { 
			bTag=false;
			break;
		   }
		}
	}
	if(!bTag||m_LINENO.GetLength()!=8)
	{
	    if(m_type==1)
		AfxMessageBox("请输入首位为1的8位数字上水管线编号 !");	
		if(m_type==2)
		AfxMessageBox("请输入首位为2的8位数字下水管线编号 !");	
		if(m_type==1)
		AfxMessageBox("请输入首位为3的8位数字上水管线编号 !");	
		GetDlgItem(IDC_LINENO)->SetFocus();
        return ;
	}
	CRecordset * pSet=new CRecordset(&((CDrawApp*) AfxGetApp())->m_pdatabase);
	if(m_type==1)
        pSet->Open(CRecordset::dynaset,_T("select ID from UPWATER where LINE_NO='"+m_LINENO+"'"));
	else if(m_type==2)
        pSet->Open(CRecordset::dynaset,_T("select ID from DOWNWATER where LINE_NO='"+m_LINENO+"'"));
    else if(m_type==3)
        pSet->Open(CRecordset::dynaset,_T("select ID from POWER where LINE_NO='"+m_LINENO+"'"));  
	if(pSet->IsBOF())
	{
		
	     AfxMessageBox("没有这个管线编号!");		
	     GetDlgItem(IDC_LINENO)->SetFocus();
			  return ;
	}
	else
	{
		pSet->MoveFirst();
		pSet->GetFieldValue("ID",f1);
	}
	pSet->Close();
	
	////////////////////////////////////////////////
	float minx,miny,maxx,maxy;
	float width,height;
	CDrawDoc * pDoc=(CDrawDoc *)p_View->GetDocument();
	CString f;
    CString &f2=f;
	int *Lb=new int[2000];
	int *element=new int[2000];
	CDraw * pDraw;
	int nSelect=0;

    pSet->Open(CRecordset::dynaset,_T("select * from LINKINFO where record_id="+m_ID));
	if(!pSet->IsBOF())
	{
		pSet->MoveFirst();
		while(!pSet->IsEOF())
		{			
			pSet->GetFieldValue("element_id",f2);
			element[nSelect]=atoi(f);
			pSet->GetFieldValue("graph_id",f2);
			Lb[nSelect++]=atoi(f);
		
			pSet->MoveNext();
		}
		pSet->Close();
		delete pSet;
	}
	if(nSelect==0)
	{
		AfxMessageBox("没有该记录的管线");
		return;
	}
	pDoc->n_GraphSelect=0;
	for(i=0;i<nSelect;i++)
	{
		for(int j=1;j<=2;j++)	//对2类图形元素循环
		{
			int nn=pDoc->GetGraphUpperBound(j)+1;	//得到图形元素的数目	
			while(nn-->pDoc->GraphNumbStart[j-1])	
			{
				pDraw=pDoc->GetGraph(j,nn);
				if(pDraw&&pDraw->b_Delete==false&&pDraw->m_id_only==element[i]&&pDraw->m_Lb==Lb[i])
				{
					pDoc->AddSelectList(Lb[i],nn,pDraw->m_id_only);
					pDraw->GetRect(&minx,&miny,&maxx,&maxy);
					width=maxx-minx;
					height=maxy-miny;
					if(width>height)
						p_View->blc=width/100;
					else
						p_View->blc=height/100;
					p_View->m_xStart=minx-p_View->blc*(p_View->m_wScreen-width)/2;
					p_View->m_yStart=miny-p_View->blc*(p_View->m_hScreen-height)/2;
				}
			}
		}
	}
	if(pDoc->n_GraphSelect==0)
	{
		AfxMessageBox("没有该记录的管线");
		return;
	}
	p_View->Invalidate();
	//pDoc->UpdateAllViews(p_View);

	/////////////////////
	CDialog::OnOK();
}

BOOL CPositionDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	if(m_type==1)
		this->SetWindowText("上水管线快速定位对话框");
	if(m_type==2)
		this->SetWindowText("下水管线快速定位对话框");
	if(m_type==3)
		this->SetWindowText("电力管线快速定位对话框");
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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