📄 browsedlg.cpp
字号:
// BrowseDlg.cpp : implementation file
//
#include "stdafx.h"
#include "draw.h"
#include "BrowseDlg.h"
#include "MaintainDlg.h"
#include "ModifyDlg.h"
#include "ModifyDlg2.h"
#include "ModifyDlg3.h"
#include "QueryDlg.h"
#include "QueryDlg3.h"
#include "DianlanDlg.h"
#include "tree.h"
#include "drawDoc.h"
#include "drawView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CBrowseDlg * pBrowseDlg;
extern CTree * pTree;
extern CDrawView *p_View;
/////////////////////////////////////////////////////////////////////////////
// CBrowseDlg dialog
CBrowseDlg::CBrowseDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBrowseDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBrowseDlg)
m_ID="";
bSelect=FALSE;
pBrowseDlg=this;
//}}AFX_DATA_INIT
}
void CBrowseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBrowseDlg)
DDX_Control(pDX, IDC_LIST1, m_LineInfo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBrowseDlg, CDialog)
//{{AFX_MSG_MAP(CBrowseDlg)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DEL, OnDel)
ON_BN_CLICKED(IDC_QUERY, OnQuery)
ON_BN_CLICKED(IDC_MODIFY, OnModify)
ON_BN_CLICKED(IDC_MAINTAIN, OnMaintain)
ON_BN_CLICKED(IDC_ALLDATA, OnAlldata)
ON_BN_CLICKED(IDC_DIANLAN, OnDianlan)
ON_BN_CLICKED(IDC_POSITION, OnPosition)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBrowseDlg message handlers
BOOL CBrowseDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow(CWnd::GetDesktopWindow());
//设置窗口标题
if(m_type==1)
SetWindowText("给水管线基本信息");
if(m_type==2)
SetWindowText("排水管线基本信息");
if(m_type==3)
SetWindowText("电力管线基本信息");
//设置表头
SetListTitle();
// 设置列表控件扩展样式
SetListStyle();
//如果是电力管线则电缆信息按钮出现
if(m_type==3)
GetDlgItem(IDC_DIANLAN)->ShowWindow(TRUE);
else
GetDlgItem(IDC_DIANLAN)->ShowWindow(FALSE);
// 显示列表数据
if(bSelect)
{
ShowData(pTree->SelID,pTree->n_SelID);
bSelect=FALSE;
}
else
ShowData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBrowseDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
//查找被点中的列表索引
POSITION pos;
pos = m_LineInfo.GetFirstSelectedItemPosition();
int IndexInFieldList = m_LineInfo.GetNextSelectedItem(pos); // 得到项目索引
//获得管线编号
CString f;
CString & f1=f;
f=m_LineInfo.GetItemText(IndexInFieldList,0);
//查找管线ID并保存在m_ID
CRecordset pSet(&((CDrawApp *)AfxGetApp())->m_pdatabase);
CString sqstr;
if(m_type==1)
sqstr="select ID from UPWATER where LINE_NO='"+f+"'";
else if(m_type==2)
sqstr="select ID from DOWNWATER where LINE_NO='"+f+"'";
else if(m_type==3)
sqstr="select ID from POWER where LINE_NO='"+f+"'";
pSet.Open(CRecordset::dynaset,sqstr);
pSet.GetFieldValue("ID",f1);
m_ID=CString(f);
*pResult = 0;
}
void CBrowseDlg::OnMaintain()
{
//判断是否选中了一条记录
if(SelectValid()==false)
return;
//弹出维修对话框
CMaintainDLG * mDlg=new CMaintainDLG(m_ID,this);
mDlg->DoModal();
}
void CBrowseDlg::OnAdd()
{
if(m_type==1)
{
CModifyDlg Dlg(this);
Dlg.IsAdd=true;
if(Dlg.DoModal()==IDOK)
{
ShowData();
m_ID="";
}
}
if(m_type==2)
{
CModifyDlg2 Dlg1(this);
Dlg1.IsAdd=true;
if(Dlg1.DoModal()==IDOK)
{
ShowData();
m_ID="";
}
}
if(m_type==3)
{
CModifyDlg3 Dlg3(this);
Dlg3.IsAdd=true;
if(Dlg3.DoModal()==IDOK)
{
ShowData();
m_ID="";
}
}
}
void CBrowseDlg::OnDel()
{
if(SelectValid()==false)
return;
if(MessageBox("你真的要删除这条记录吗?",
"民政校园管网管理系统",MB_YESNO)==IDNO)
return;
CString sqlStr;
//先删除MAINTAIN从表中的记录
sqlStr.Format("DELETE FROM MAINTAIN WHERE LINE_ID='%s'",m_ID);
((CDrawApp*)AfxGetApp())->m_pdatabase.ExecuteSQL(sqlStr);
//然后删除主表中选中的记录
if(m_type==1)//如果是供水管理,则在供水表中删除
sqlStr.Format("DELETE FROM UPWATER WHERE ID='%s'",m_ID);
else if(m_type==2)
sqlStr.Format("DELETE FROM DOWNWATER WHERE ID='%s'",m_ID);
else if(m_type==3)
sqlStr.Format("DELETE FROM POWER WHERE ID='%s'",m_ID);
((CDrawApp*)AfxGetApp())->m_pdatabase.ExecuteSQL(sqlStr);
ShowData();//显示列表数据
m_ID="";
}
void CBrowseDlg::OnQuery()
{
CString sqlStr;
if(m_type==1||m_type==2)
{
CQueryDlg Dlg(this);
if(Dlg.DoModal()==IDOK)
{
if(m_type==1)
sqlStr="select * from UPWATER where "+Dlg.m_sqlStr;
else if(m_type==2)
sqlStr="select * from DOWNWATER where "+Dlg.m_sqlStr;
}
}
else if(m_type==3)
{
CQueryDlg3 Dlg(this);
if(Dlg.DoModal()==IDOK)
{
sqlStr="select * from POWER where "+Dlg.m_sqlStr;
}
}
AfxMessageBox(sqlStr);
ShowData(sqlStr);//显示列表数据
m_ID="";
}
void CBrowseDlg::OnAlldata()
{
ShowData();
m_ID="";
}
void CBrowseDlg::OnModify()
{
if(SelectValid()==false)
return;
if(m_type==1)
{
CModifyDlg Dlg(this);
Dlg.IsAdd=false;
if(Dlg.DoModal()==IDOK)
{
ShowData();
m_ID="";
}
}
if(m_type==2)
{
CModifyDlg2 Dlg2(this);
Dlg2.IsAdd=false;
if(Dlg2.DoModal()==IDOK)
{
ShowData();
m_ID="";
}
}
if(m_type==3)
{
CModifyDlg3 Dlg3(this);
Dlg3.IsAdd=false;
if(Dlg3.DoModal()==IDOK)
{
ShowData();
m_ID="";
m_LineInfo.SetItemState(1,LVIS_SELECTED,LVIS_SELECTED);;
//m_LineInfo.SetSelectionMark(1);
}
}
}
void CBrowseDlg::OnDianlan()
{
if(SelectValid()==false)
return;
CDianlanDlg Dlg(m_ID,this);
Dlg.DoModal();
}
void CBrowseDlg::OnPosition()
{
if(SelectValid()==false)
return;
float minx,miny,maxx,maxy;
float width,height;
CDrawDoc * pDoc=(CDrawDoc *)p_View->GetDocument();
CString f;
CString & f1=f;
int *Lb=new int[2000];
int *element=new int[2000];
CDraw * pDraw;
int nSelect=0;
CRecordset * pSet=new CRecordset(&((CDrawApp*) AfxGetApp())->m_pdatabase);
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",f1);
element[nSelect]=atoi(f);
pSet->GetFieldValue("graph_id",f1);
Lb[nSelect++]=atoi(f);
pSet->MoveNext();
}
pSet->Close();
delete pSet;
}
if(nSelect==0)
{
AfxMessageBox("没有该记录的管线");
return;
}
pDoc->n_GraphSelect=0;
for(int 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -