LinkDlg.cpp
资源名称:vc开发gis代码.rar [点击查看]
上传用户:jndfzt02
上传日期:2007-04-25
资源大小:391k
文件大小:6k
源码类别:
GIS编程
开发平台:
Visual C++
- // LinkDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "draw.h"
- #include "drawdoc.h"
- #include "linkdataset.h"
- #include "LinkDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CLinkDlg dialog
- CLinkDlg::CLinkDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CLinkDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CLinkDlg)
- m_pSet = NULL;
- //}}AFX_DATA_INIT
- }
- CLinkDlg::CLinkDlg(CDrawDoc* pDoc,CLinkDataSet* pSet,short LinkMode,short DatabaseID,int RecordID,CWnd* pParent /*=NULL*/)
- : CDialog(CLinkDlg::IDD, pParent)
- {
- m_pDoc=pDoc;
- m_pSet=pSet;
- m_DatabaseID=DatabaseID;
- m_RecordID=RecordID;
- m_LinkMode=LinkMode;
- if(m_pSet->IsOpen())
- m_pSet->Close();
- m_pSet->Open();
- m_NumbLink=0;
- if(!m_pSet->IsBOF())
- {
- m_pSet->MoveFirst();
- while(!m_pSet->IsEOF())
- {
- m_GraphLB[m_NumbLink]=m_GraphLB1[m_NumbLink]=m_pSet->m_graph_id;
- m_GraphID[m_NumbLink]=m_GraphID1[m_NumbLink]=m_pSet->m_element_id;
- m_NumbLink++;
- m_pSet->MoveNext();
- }
- m_pSet->MoveFirst();
- }
- m_NumbLink1=m_NumbLink;
- }
- void CLinkDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CLinkDlg)
- DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_database_id, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT3, m_pSet->m_record_id, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT4, m_pSet->m_graph_id, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT5, m_pSet->m_element_id, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_link_mode, m_pSet);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CLinkDlg, CDialog)
- //{{AFX_MSG_MAP(CLinkDlg)
- ON_BN_CLICKED(IDC_LINK_ADD, OnLinkAdd)
- ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
- ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
- ON_BN_CLICKED(IDC_LINK_DELETE, OnLinkDelete)
- ON_BN_CLICKED(IDC_LINK_DELALL, OnLinkDelAll)
- ON_BN_CLICKED(IDC_LINK_ADDALL, OnLinkAddAll)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CLinkDlg message handlers
- BOOL CLinkDlg::OnInitDialog()
- {
- //CDialog::OnInitDialog();
- CString m_str;
- char p1[10];
- plist1=(CListBox *)GetDlgItem(IDC_LIST1);
- plist2=(CListBox *)GetDlgItem(IDC_LIST2);
- plist1->ResetContent();
- plist2->ResetContent();
- graph_Name[0]="直线";
- graph_Name[1]="连续直线";
- graph_Name[2]="圆";
- graph_Name[3]="圆弧";
- graph_Name[4]="标注文本";
- for(int i=0;i<m_NumbLink;i++)
- {
- sprintf(p1,"%7d",m_GraphID[i]);
- m_str=p1;
- m_str+=" ";
- m_str+=graph_Name[m_GraphLB[i]-1];
- plist1->AddString(m_str);
- }
- for(i=0;i<m_pDoc->n_GraphSelect;i++)
- {
- m_str.Empty();
- sprintf(p1,"%7d",m_pDoc->GraphSelect[i].pbh);
- m_str+=p1;
- m_str+=" ";
- m_str+=graph_Name[m_pDoc->GraphSelect[i].Lb-1];
- plist2->AddString(m_str);
- }
- sprintf(p1,"%d",m_LinkMode);
- SetDlgItemText(IDC_EDIT1,"1");
- sprintf(p1,"%d",m_DatabaseID);
- SetDlgItemText(IDC_EDIT2,p1);
- sprintf(p1,"%d",m_RecordID);
- SetDlgItemText(IDC_EDIT3,p1);
- if(m_NumbLink>0)
- {
- UpdateData(FALSE);
- plist1->SetCurSel(0);
- OnSelchangeList1();
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CLinkDlg::OnLinkAdd()
- {
- // TODO: Add your control notification handler code here
- CString m_str;
- char p1[8];
- GetDlgItemText(IDC_EDIT4,m_str);
- m_str.TrimLeft();
- if(m_str.GetLength()<1)
- return;
- int lb=atoi(m_str);
- m_str.Empty();
- if(lb<0)
- return;
- GetDlgItemText(IDC_EDIT5,m_str);
- int id=atoi(m_str);
- if(!IsExistLink(lb,id))
- {
- m_GraphID[m_NumbLink]=id;
- m_GraphLB[m_NumbLink++]=lb;
- sprintf(p1,"%7d",id);
- m_str=p1;
- m_str+=" ";
- m_str+=graph_Name[lb-1];
- plist1->AddString(m_str);
- plist1->SetCurSel(m_NumbLink-1);
- }
- }
- BOOL CLinkDlg::IsExistLink(short lb, int id)
- {
- for(int i=0;i<m_NumbLink;i++)
- {
- if(m_GraphID[i]==id&&m_GraphLB[i]==lb)
- return TRUE;
- }
- return FALSE;
- }
- BOOL CLinkDlg::IsExistLink1(short lb, int id)
- {
- for(int i=0;i<m_NumbLink1;i++)
- {
- if(m_GraphID1[i]==id&&m_GraphLB1[i]==lb)
- return TRUE;
- }
- return FALSE;
- }
- void CLinkDlg::OnSelchangeList2()
- {
- // TODO: Add your control notification handler code here
- int nlist2=plist2->GetCurSel();
- if(nlist2<0)
- return;
- char p1[10];
- SetDlgItemText(IDC_STATIC1,graph_Name[m_pDoc->GraphSelect[nlist2].Lb-1]);
- sprintf(p1,"%d",m_pDoc->GraphSelect[nlist2].Lb);
- SetDlgItemText(IDC_EDIT4,p1);
- sprintf(p1,"%d",m_pDoc->GraphSelect[nlist2].pbh);
- SetDlgItemText(IDC_EDIT5,p1);
- }
- void CLinkDlg::OnSelchangeList1()
- {
- // TODO: Add your control notification handler code here
- int nlist1=plist1->GetCurSel();
- if(nlist1<0)
- return;
- char p1[10];
- SetDlgItemText(IDC_STATIC1,graph_Name[m_GraphLB[nlist1]-1]);
- sprintf(p1,"%d",m_GraphLB[nlist1]);
- SetDlgItemText(IDC_EDIT4,p1);
- sprintf(p1,"%d",m_GraphID[nlist1]);
- SetDlgItemText(IDC_EDIT5,p1);
- }
- void CLinkDlg::OnLinkDelete()
- {
- // TODO: Add your control notification handler code here
- int nlist1=plist1->GetCurSel();
- if(nlist1<0)
- return;
- for(int i=nlist1;i<m_NumbLink-1;i++)
- {
- m_GraphLB[i]=m_GraphLB[i+1];
- m_GraphID[i]=m_GraphID[i+1];
- }
- m_NumbLink--;
- plist1->DeleteString(nlist1);
- if(nlist1==m_NumbLink)
- plist1->SetCurSel(nlist1-1);
- else
- plist1->SetCurSel(nlist1);
- OnSelchangeList1();
- }
- void CLinkDlg::OnLinkDelAll()
- {
- m_NumbLink=0;
- plist1->ResetContent();
- // TODO: Add your control notification handler code here
- }
- void CLinkDlg::OnLinkAddAll()
- {
- for(int i=0;i<m_pDoc->n_GraphSelect;i++)
- {
- plist2->SetCurSel(i);
- OnSelchangeList2();
- OnLinkAdd();
- }
- // TODO: Add your control notification handler code here
- }
- void CLinkDlg::OnOK()
- {
- // TODO: Add extra validation here
- for(int i=m_NumbLink1-1;i>=0;i--) //从数据库中删除已经存在的连接
- {
- if(!IsExistLink(m_GraphLB1[i],m_GraphID1[i])) //如果原来的连接不存在,即现在删除了这个连接
- {
- m_pSet->MoveFirst();
- m_pSet->Move(i);
- m_pSet->Delete();
- }
- }
- for(i=0;i<m_NumbLink;i++) //增加连接
- {
- if(!IsExistLink1(m_GraphLB[i],m_GraphID[i])) //如果这个连接原来不存在,即现在增加了这个连接
- {
- plist1->SetCurSel(i);
- OnSelchangeList1();
- m_pSet->AddNew();
- UpdateData(); //保存数据
- if(m_pSet->CanUpdate())
- m_pSet->Update();
- }
- }
- m_pSet->Close();
- EndDialog(IDOK);
- }
- void CLinkDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
- m_pSet->Close();
- CDialog::OnCancel();
- }