SortDlg.cpp
资源名称:vc开发gis代码.rar [点击查看]
上传用户:jndfzt02
上传日期:2007-04-25
资源大小:391k
文件大小:7k
源码类别:
GIS编程
开发平台:
Visual C++
- // SortDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "draw.h"
- #include "data1ret.h"
- #include "SortDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSortDlg dialog
- CSortDlg::CSortDlg(CDataBaseSet* pSet,CWnd* pParent /*=NULL*/)
- : CDialog(CSortDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSortDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pSet=pSet;
- if(!m_pSet->IsOpen())
- m_pSet->Open();
- m_strSort=m_pSet->m_strSort;
- m_NumbField=m_pSet->GetODBCFieldCount();
- CODBCFieldInfo fieldinfo1;
- CODBCFieldInfo& fieldinfo=fieldinfo1;
- for(int i=0;i<m_NumbField;i++)
- {
- m_pSet->GetODBCFieldInfo(i,fieldinfo);
- pFieldInfo[i]=fieldinfo1;
- }
- m_NumbSort=0;
- }
- void CSortDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSortDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSortDlg, CDialog)
- //{{AFX_MSG_MAP(CSortDlg)
- ON_BN_CLICKED(IDC_SORT_ADD, OnSortAdd)
- ON_BN_CLICKED(IDC_SORT_DELETE, OnSortDelete)
- ON_BN_CLICKED(IDC_SORT_INSERT, OnSortInsert)
- ON_BN_CLICKED(IDC_SORT_MODIFY, OnSortModify)
- ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSortDlg message handlers
- BOOL CSortDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- plist1=(CListBox *)GetDlgItem(IDC_LIST1);
- pcom1=(CComboBox *)GetDlgItem(IDC_COMBO1);
- plist1->ResetContent();
- pcom1->ResetContent();
- BreakSortStr(m_strSort);
- CString m_str;
- for(int i=0;i<m_NumbSort;i++)
- {
- if(b_Sort[i])
- m_str="↑ ";
- else
- m_str="↓ ";
- m_str+=strSort[i];
- plist1->AddString(m_str);
- }
- MakeStr();
- for(i=0;i<m_NumbField;i++)
- pcom1->AddString(pFieldInfo[i].m_strName);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- int CSortDlg::BreakSortStr(CString m_str)
- {
- int nChar;
- m_str.TrimLeft();
- m_str.TrimRight();
- nChar=m_str.GetLength();
- CString m_str1=m_str;
- CString m_str2;
- int nStart;
- nStart=0;
- m_NumbSort=0;
- int n;
- do
- {
- n=m_str1.Find(",",nStart);
- if(n>=0)
- {
- if(n>nStart)
- {
- m_str2=m_str.Mid(nStart,n-nStart);
- m_str2.TrimLeft();
- m_str2.TrimRight();
- if(m_str2.GetLength()>0)
- strSort[m_NumbSort++]=m_str2;
- m_str2.Empty();
- }
- nStart=n+1;
- }
- else
- {
- if(nStart<nChar)
- {
- m_str2=m_str.Mid(nStart,nChar);
- m_str2.TrimLeft();
- m_str2.TrimRight();
- if(m_str2.GetLength()>0)
- strSort[m_NumbSort++]=m_str2;
- m_str2.Empty();
- }
- }
- } while(n>=0);
- for(int i=0;i<m_NumbSort;i++)
- {
- m_str2=strSort[i];
- int nn=m_str2.GetLength();
- n=m_str2.Find(" ");
- if(n>0)
- {
- strSort[i]=m_str2.Mid(0,n);
- m_str1=m_str2.Right(nn-n-1);
- m_str1.TrimLeft();
- m_str1.MakeUpper();
- if(!m_str1.Compare("ASC"))
- b_Sort[i]=1;
- else if(!m_str1.Compare("DESC"))
- b_Sort[i]=0;
- else
- b_Sort[i]=1;
- }
- else
- b_Sort[i]=1;
- }
- return m_NumbSort;
- }
- void CSortDlg::OnSortAdd()
- {
- if(m_NumbSort>=10)
- {
- AfxMessageBox("最多只能有10个排序字段");
- return;
- }
- int ncom1=pcom1->GetCurSel();
- if(ncom1<0)
- {
- AfxMessageBox("没有选择排序字段");
- return;
- }
- strSort[m_NumbSort]=pFieldInfo[ncom1].m_strName;
- CButton *pcheck1=(CButton *)GetDlgItem(IDC_CHECK1);
- b_Sort[m_NumbSort]=1-pcheck1->GetCheck();
- CString m_str;
- if(b_Sort[m_NumbSort])
- m_str="↑ ";
- else
- m_str="↓ ";
- m_str+=strSort[m_NumbSort];
- plist1->AddString(m_str);
- plist1->SetCurSel(m_NumbSort);
- m_NumbSort++;
- MakeStr();
- }
- void CSortDlg::OnSortDelete()
- {
- // TODO: Add your control notification handler code here
- int nlist1=plist1->GetCurSel();
- if(nlist1<0)
- return;
- for(int i=nlist1;i<m_NumbSort-1;i++)
- {
- strSort[i]=strSort[i+1];
- b_Sort[i]=b_Sort[i+1];
- }
- plist1->DeleteString(nlist1);
- if(nlist1==m_NumbSort-1)
- plist1->SetCurSel(nlist1-1);
- else
- plist1->SetCurSel(nlist1);
- m_NumbSort--;
- MakeStr();
- OnSelchangeList1();
- }
- void CSortDlg::OnSortInsert()
- {
- // TODO: Add your control notification handler code here
- if(m_NumbSort>=10)
- {
- AfxMessageBox("最多只能有10个排序字段");
- return;
- }
- int nlist1=plist1->GetCurSel();
- if(nlist1<0)
- return;
- int ncom1=pcom1->GetCurSel();
- for(int i=m_NumbSort;i>nlist1;i--)
- {
- strSort[i]=strSort[i-1];
- b_Sort[i]=b_Sort[i-1];
- }
- strSort[nlist1]=pFieldInfo[ncom1].m_strName;
- CButton *pcheck1=(CButton *)GetDlgItem(IDC_CHECK1);
- b_Sort[nlist1]=1-pcheck1->GetCheck();
- CString m_str;
- if(b_Sort[nlist1])
- m_str="↑ ";
- else
- m_str="↓ ";
- m_str+=strSort[nlist1];
- plist1->InsertString(nlist1,m_str);
- plist1->SetCurSel(nlist1);
- m_NumbSort++;
- MakeStr();
- }
- void CSortDlg::OnSortModify()
- {
- // TODO: Add your control notification handler code here
- int nlist1=plist1->GetCurSel();
- if(nlist1<0)
- return;
- int ncom1=pcom1->GetCurSel();
- strSort[nlist1]=pFieldInfo[ncom1].m_strName;
- CButton *pcheck1=(CButton *)GetDlgItem(IDC_CHECK1);
- b_Sort[nlist1]=1-pcheck1->GetCheck();
- CString m_str;
- if(b_Sort[nlist1])
- m_str="↑ ";
- else
- m_str="↓ ";
- m_str+=strSort[nlist1];
- plist1->DeleteString(nlist1);
- if(nlist1==m_NumbSort-1)
- plist1->AddString(m_str);
- else
- plist1->InsertString(nlist1,m_str);
- plist1->SetCurSel(nlist1);
- MakeStr();
- }
- void CSortDlg::MakeStr()
- {
- m_strSort.Empty();
- for(int i=0;i<m_NumbSort;i++)
- {
- if(i>0)
- m_strSort+=",";
- strSort[i].TrimLeft();
- strSort[i].TrimRight();
- m_strSort+=strSort[i];
- if(!b_Sort[i])
- m_strSort+=" DESC";
- }
- SetDlgItemText(IDC_EDIT1,m_strSort);
- }
- void CSortDlg::OnOK()
- {
- // TODO: Add extra validation here
- if(m_pSet->IsOpen())
- m_pSet->Close();
- CString m_str=m_pSet->m_strSort;
- m_pSet->m_strSort=m_strSort;
- if(m_pSet->Open())
- CDialog::OnOK();
- else
- m_pSet->m_strSort=m_str;
- }
- void CSortDlg::OnSelchangeList1()
- {
- // TODO: Add your control notification handler code here
- int n=plist1->GetCurSel();
- if(n<0)
- return;
- CString m_str1=strSort[n];
- m_str1.TrimLeft();
- m_str1.TrimRight();
- BOOL yn=0;
- for(int i=0;i<m_NumbField;i++)
- {
- if(!m_str1.Compare(pFieldInfo[i].m_strName))
- {
- yn=1;
- break;
- }
- }
- if(yn)
- pcom1->SetCurSel(i);
- else
- pcom1->SetCurSel(-1);
- CButton *pcheck1=(CButton *)GetDlgItem(IDC_CHECK1);
- pcheck1->SetCheck(1-b_Sort[n]);
- }