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

📄 dlgimportodbc.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	};     

   // Allow sheets with one or more column, provided its not an automatic column (F1)

   return nCol >= 1;
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnClose() 
{
	if (m_database.IsOpen())
	{
        m_database.Close();
	}
	
	CDialog::OnClose();
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnImport() 
{
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnDefine() 
{
   if (Define() == IDOK)
   {
      OnOK();
   }
}

///////////////////////////////////////////////////////////////////////////////

int CDlgImportODBC::Define()
{
   CString sTable;
   int i = m_lbTables.GetCaretIndex();

   if (i != LB_ERR)
   {
      m_lbTables.GetText(i, sTable);
      int index = m_importDB.Find(sTable);
      
      if (index != -1)
      {
         BOOL bImport = m_sTable != "";
         CDlgImportTable dlg(&m_database, m_importDB.GetAt(index), bImport, m_nFileType);
         int nRet = dlg.DoModal();
         if (nRet == IDOK || nRet == IDC_NEXT)
         {
	         m_lbTables.SetSel(i, TRUE);
            m_importDB.SetAt(i, dlg.GetImportTable());

            return nRet;
         }	
      };
   };
   return FALSE;
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnDblclkTables() 
{
	//OnDefine();	
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::ResizeWindow(int nControl)
{
   CRect rectW, rectC;   
         
   GetWindowRect(rectW);
   GetDlgItem(nControl)->GetWindowRect(rectC);   

   SetWindowPos(NULL,rectW.left,rectW.left,
                rectW.right - rectW.left, rectC.bottom-rectW.top +rectC.Height()/2, 
                SWP_NOZORDER);
};

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnSave() 
{
   CFileDialog dlg(FALSE, "nri", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
                   "NRDB Import Format|*.nri||");
   if (dlg.DoModal() == IDOK)
   {
      if (Validate())
      {
	      m_importDB.Write(dlg.GetPathName());
      };
   };
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnLoad() 
{
   BOOL bOK = TRUE;

   TRY
   {
	   CFileDialog dlg(TRUE, "nri", NULL, OFN_HIDEREADONLY, 
                      "NRDB Import Format|*.nri||");
      if (dlg.DoModal() == IDOK)
      {    
	      if (m_importDB.Read(dlg.GetPathName()))
         {
            // Restore selections

            for (int i = 0; i < m_importDB.GetSize(); i++)
            {
               int index = m_lbTables.FindStringExact(-1, m_importDB.GetAt(i).m_sTableImport);
               if (index != LB_ERR)
               {
                  m_lbTables.SetSel(index, m_importDB.GetAt(i).m_bImport);
               }
            }
         } else
         {
            bOK = FALSE;
         }            
      };

      // Load the tables not in format

       CString sTable;	 
	    for (int i = 0; i < m_lbTables.GetCount(); i++)
	    {
          m_lbTables.GetText(i, sTable);    
          int index = m_importDB.Find(sTable);
          if (index == -1)
          {
             CImportTable table;
		       table.m_sTableImport = sTable;
		       m_importDB.Add(table);          
          }
	    };	
       OnSelchangeTables();
   }

   // Error handling

   CATCH (CFileException, pEx)
   {
      bOK = FALSE;
   } END_CATCH

   if (!bOK)
   {
      AfxMessageBox(BDString(IDS_ERRORFORMAT));
      m_importDB = CImportDB();
   }
}

///////////////////////////////////////////////////////////////////////////////
//
// void CDlgImportODBC::OnOK() 
//

void CDlgImportODBC::OnOK() 
{
   if (m_lbTables.GetSelCount() == 0)
   {
      AfxMessageBox(BDString(IDS_NOTABLESSEL));
      return;
   }   

	if (Validate())
   {
      // Autosave      
	   CDialog::OnOK();
   };
}

///////////////////////////////////////////////////////////////////////////////

BOOL CDlgImportODBC::Validate()
{
      CString sTable;

  // For each table determine if it shall be imported
   
   for (int i = 0; i < m_lbTables.GetCount(); i++)
   {      
      m_lbTables.GetText(i, sTable);
      int index = m_importDB.Find(sTable);
      ASSERT(index != -1);

      CImportTable table = m_importDB.GetAt(index);
      table.m_bImport = m_lbTables.GetSel(i);
      m_importDB.SetAt(index, table);
      
      // For each selected table ensure that its columns are defined

      if (m_importDB.GetAt(index).m_bImport && !m_bNRDB)
      {
         if (m_importDB.GetAt(index).m_aColumn.GetSize() == 0)
         {
            AfxMessageBox(BDString(IDS_DEFINEIMPORT));
            m_lbTables.SetCurSel(i);
            m_lbTables.SetFocus();
            return FALSE;
         }
      }
      
   }
   return TRUE;
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnSelectall() 
{
	BOOL bSelect = m_lbTables.GetCount() != m_lbTables.GetSelCount();
   for (int i = 0; i < m_lbTables.GetCount(); i++)
   {
      m_lbTables.SetSel(i, bSelect);
   }	
   OnSelchangeTables();
}

///////////////////////////////////////////////////////////////////////////////

void CDlgImportODBC::OnSelchangeTables() 
{
   BOOL bEnable = FALSE;
   int index = m_lbTables.GetCaretIndex();
   if (index != LB_ERR)
   {
      bEnable = m_lbTables.GetSel(index);
   }
   GetDlgItem(IDDEFINE)->EnableWindow(bEnable && !m_bNRDB);
   GetDlgItem(IDC_LOAD)->EnableWindow(!m_bNRDB);
   GetDlgItem(IDC_SAVE)->EnableWindow(!m_bNRDB);
}

///////////////////////////////////////////////////////////////////////////////
//
// If a natural resources database has been selected then display its feature
// types
//

void CDlgImportODBC::InitFTypes()
{
   BDHANDLE hConnect;

   CDlgProgress dlgProgress;

   CFeatureType ftype;
   CArray <CFeatureType, CFeatureType> m_aFType;
   CAttrArray aAttr;   

   m_lbTables.ResetContent();

   // Connect to the database

   if (BDConnect(m_sDatabase, &hConnect))
   {
      // Retrieve the features

      BOOL bFound = BDFeatureType(hConnect, &ftype, BDGETINIT);
      while (bFound)
      {
         // Add them to the list
         
         m_aFType.Add(ftype);

         bFound = BDGetNext(hConnect);
      }
      BDEnd(hConnect);

      // Order the list of feature types so that linked items appear first

      for (int i = 0; i < m_aFType.GetSize(); i++)
      {
         dlgProgress.SetPercent((i*100) / m_aFType.GetSize());

         BDFTypeAttrInit(hConnect, m_aFType[i].m_lId, &aAttr);

         for (int j = 0; j < aAttr.GetSize(); j++)
         {
            // Find the linked item

            if (aAttr[j]->GetDataType() == BDLINK)
            {
               for (int k = 0; k < m_aFType.GetSize(); k++)
               {
                  if (m_aFType[k].m_lId == aAttr[j]->GetFTypeLink())
                  {
                     // Move the linked item before the item

                     if (k > i)
                     {
                        ftype = m_aFType[k];
                        m_aFType.RemoveAt(k);
                        m_aFType.InsertAt(i, ftype);
                     }
                  }
               }
            }
         }
      };

      // Add to the list

      for (i = 0; i < m_aFType.GetSize(); i++)
      {
         int index = m_lbTables.AddString(m_aFType[i].m_sDesc);
         m_lbTables.SetItemData(index, m_aFType[i].m_lId);
      }

      // Disconnect

      BDDisconnect(hConnect);
   };
}

⌨️ 快捷键说明

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