Display.cpp
资源名称:minisqlc.rar [点击查看]
上传用户:lkd6667
上传日期:2015-05-13
资源大小:1448k
文件大小:5k
源码类别:
其他数据库
开发平台:
C/C++
- #include"Display.h"
- #include"iostream"
- #include <afx.h>
- #include <stdlib.h>
- #include<direct.h>
- extern char CurLocation[256]; //<---存有当前正在使用的表的相对路径,
- extern char CurRelationName[33]; //<---存当前表的表名
- extern char CurDB[33];
- void ShowTable()
- {
- CFileFind finder;
- int iRowN = 0;
- char loc[256];
- CString Dbn(CurDB);
- int iNameLen = 0,iTemp = 0;
- std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'n';
- std::cout<<"| Tables in ";
- std::cout << (LPCTSTR) Dbn;
- int strNum = Dbn.GetLength();
- for(iTemp = 19 - iNameLen-strNum;iTemp != 0;iTemp--)
- std::cout<<' ';
- std::cout <<"|"<<'n';
- std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'n';
- strcpy(loc,CurLocation);
- strcat(loc,"*.dbf");
- int bWorking = finder.FindFile(loc);
- while(bWorking)
- {
- bWorking = finder.FindNextFile();
- if (finder.IsDots())
- continue;
- iRowN++;
- CString str = finder.GetFileTitle();
- iNameLen = str.GetLength();
- std::cout <<"| "<< (LPCTSTR) str;
- for(iTemp = 29 - iNameLen;iTemp != 0;iTemp--)
- std::cout<<' ';
- std::cout <<"|"<<'n';
- }
- std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'n';
- std::cout<<"There are" <<iRowN<<" rows in the table!";
- finder.Close();
- }
- void ShowDB()
- {
- CFileFind finder;
- int iRowN = 0;
- int iNameLen = 0,iTemp = 0;
- std::cout<<"These are the databases !n";
- int bWorking = finder.FindFile("..\Data\*.*");
- std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'n';//<---计32个字符
- std::cout<<"| Database |"<<'n';
- std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'n';//<---计32个字符
- while(bWorking)
- {
- bWorking = finder.FindNextFile();
- if (finder.IsDots())
- continue;
- if (finder.IsDirectory())
- {
- iRowN++;
- CString str = finder.GetFileTitle();
- iNameLen = str.GetLength();
- std::cout <<"| "<< (LPCTSTR) str;
- for(iTemp = 29 - iNameLen;iTemp != 0;iTemp--)
- std::cout<<' ';
- std::cout <<"|"<<'n';
- }
- }
- std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'n';//<---计32个字符
- std::cout<<"There are" <<iRowN<<" rows in the database!";
- finder.Close();
- }
- int CheckDB(char* pDb)
- {
- CFileFind finder;
- char loc[256];
- strcpy(loc,"..\Data\");
- strcat(loc,pDb);
- int bWorking = finder.FindFile(loc);
- int iNameLen = 0,iTemp = 0;
- return bWorking;
- }
- int CheckTB(char* pTb) //<---检查tb是否存在
- {
- CFileFind finder;
- char loc[256];
- strcpy(loc,"..\Data\");
- strcat(loc,CurDB);
- strcat(loc,"\");
- strcat(loc, pTb); //<---该目录下所有的文件
- strcat(loc , ".idx"); //<---该目录下所有的文件
- int bWorking = finder.FindFile(loc);
- int iNameLen = 0,iTemp = 0;
- return bWorking;
- }
- void DelDB(char* pDb)
- {
- char loc[256];
- char locfile[256];
- CFileFind finder;
- strcpy(locfile,pDb); //<---所要删除的目录的路径
- strcpy(loc,pDb); //<---所要删除的目录的路径
- strcat(locfile , "\*.*"); //<---该目录下所有的文件
- int bWorking = finder.FindFile(locfile);
- while(bWorking)
- {
- bWorking = finder.FindNextFile();
- if (finder.IsDots())
- continue;
- if (!finder.IsDirectory())
- {
- CString str = finder.GetFilePath();
- CFile::Remove( str );
- }
- }
- finder.Close();
- //删除空目录--->
- if( _rmdir( loc ) == 0 )
- std::cout<<"Directory "<<loc<<" was successfully removedn";
- else
- std::cout<<"Can not remove database"<<loc<<"n";
- ResetDBinfo(); //<---删除数据库之后将全局路径重新设置
- }
- void ResetDBinfo()
- {
- strcpy(CurLocation,"..\data\");
- strcpy(CurRelationName,"");
- strcpy(CurDB,"");
- }
- void DelTB(char* pTb)
- { char loc[256];
- char locfile[256];
- CFileFind finder;
- strcpy(locfile,pTb); //<---locfile为所要删除的table的目录
- strcpy(loc,locfile); //<---locfile为所要删除的table的目录
- strcat(locfile , ".idx"); //<---该目录下所有的文件
- int bWorking = finder.FindFile(locfile);
- while(bWorking)
- {
- bWorking = finder.FindNextFile();
- if (finder.IsDots())
- continue;
- if (!finder.IsDirectory())
- {
- CString str = finder.GetFilePath();
- CFile::Remove( str );
- }
- }
- finder.Close();
- strcat(loc , ".dbf"); //<---该目录下所有的文件
- bWorking = finder.FindFile(loc);
- while(bWorking)
- {
- bWorking = finder.FindNextFile();
- if (finder.IsDots())
- continue;
- if (!finder.IsDirectory())
- {
- CString str = finder.GetFilePath();
- CFile::Remove( str );
- }
- }
- finder.Close();
- }
- void CreateDB(char* pDb)
- {
- char loc[256]; //所要创建的目录的路径
- CFileFind finder;
- strcpy(loc,"..\Data\");
- strcat(loc,pDb);
- //创建目录
- if( _mkdir( loc ) == 0 )
- std::cout<<"database "<<pDb<<" was successfully createdn";
- else
- std::cout<<"Can not create database "<<pDb<<"n";
- finder.Close();
- }