📄 datamanger.cpp
字号:
// DataManger.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "DataManger.h"
#include "MainFrm.h"
#include "DataMangerDoc.h"
#include "DataMangerView.h"
#include "login.h"
#include "configdeal.h"
#include <direct.h>
#include <afxsock.h>
#include "afxdb.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDataMangerApp
int System_Status =-1;
int System_Import_Data =-1;
int System_SmsSqlServer=-1;
int System_LocalRoute=-1;
class Cconfigdeal pCfg;
class CDatabase g_Database; //系统数据库类查询对象
class CDatabase g_UpdDatabase; //系统数据库类修改对象
class CDatabase g_ImportData; //系统数据库类导入对象
BEGIN_MESSAGE_MAP(CDataMangerApp, CWinApp)
//{{AFX_MSG_MAP(CDataMangerApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDataMangerApp construction
CDataMangerApp::CDataMangerApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDataMangerApp object
CDataMangerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDataMangerApp initialization
BOOL CDataMangerApp::InitInstance()
{
_mkdir("log");
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
//1.当然也可用MFC函数来读配置文件
if (pCfg.setfilename(CONFIGUREFILE) == -1)
{
AfxMessageBox("读指定文件出错!");
return false;
}
//2.
//2.1.选择数据库类型
if ( pCfg.readcfgdata("SerCfg", "System_Status", &System_Status) == -1)
{
AfxMessageBox("读选择数据库类型出错!");
return false;
}
//2.2.导入数据库
if ( pCfg.readcfgdata("SerCfg", "Import_Data", &System_Import_Data) == -1)
{
AfxMessageBox("读测试号码出错!");
return false;
}
//2.3.
if ( pCfg.readcfgdata("SerCfg", "SmsSqlServer", &System_SmsSqlServer) == -1)
{
AfxMessageBox("读SmsSqlServer失败出错!");
return false;
}
//2.5.判断是单机版,还是网络版
if ( pCfg.readcfgdata("SerCfg", "LocalRoute", &System_LocalRoute) == -1)
{
AfxMessageBox("读SmsSqlServer失败出错!");
return false;
}
//2.4.连接数据库
CString g_sDSN;
CString g_errorSDNS;
CString g_SuccessSDNS;
CString g_sImportDsn;
if (System_Status == 0)
{
g_sDSN="ODBC;DRIVER=SQL Server;SRVR='220.168.31.84';DBQ=newlifeivrdb;UID=ivr;PWD='newlifeivr'";
g_errorSDNS="无法连接到SQL Server数据库";
g_SuccessSDNS="连接到SQL Server数据库成功";
}
else if (System_Status == 1)
{
g_sDSN="ODBC;DRIVER=Microsoft Access Driver (*.mdb);SRVR='';DBQ=SmsSend.mdb;UID=sa;PWD=''";
g_errorSDNS="无法连接到本地ACESS数据库";
g_SuccessSDNS="连接到本地ACESS数据库成功";
}
else if (System_Status == 2)
{
g_sDSN="ODBC;DRIVER=SQL Server;SRVR=ZXR;DBQ='';UID=ivr;PWD=newlifeivr";
g_errorSDNS="无法连接到本地SQL Server数据库";
g_SuccessSDNS="连接到本地SQL Server数据库成功";
}
else
{
//从文件导入,就不要连接数据操作
goto TabelToFile;
}
//查询数据库
try
{
if(!g_Database.Open(NULL,FALSE,FALSE,g_sDSN,FALSE))
{
AfxMessageBox(g_errorSDNS);
return false ;
}
}
catch(CDBException* pEx)
{
pEx->ReportError();
g_Database.Close();
}
//修改数据库
try
{
if(!g_UpdDatabase.Open(NULL,FALSE,FALSE,g_sDSN,FALSE))
{
AfxMessageBox(g_errorSDNS);
return false ;
}
}
catch(CDBException* pEx)
{
pEx->ReportError();
g_UpdDatabase.Close();
}
TabelToFile:
//置查询数据库,并导入到指定数据库表中
if (System_Import_Data ==1)
{
if (System_SmsSqlServer == 1)
{
g_sImportDsn="ODBC;DRIVER=Microsoft Access Driver (*.mdb);SRVR='sms';DBQ=db1.mdb;UID=sa;PWD=''";
g_errorSDNS="无法连接到导入数据的ACCESS数据库";
g_SuccessSDNS="连接到导入数据的ACCESS数据库成功";
}
else if (System_SmsSqlServer == 2)
{
g_sImportDsn="ODBC;DRIVER=SQL Server;SRVR='(local)';DBQ=sms;UID=sms;PWD='sms'";
g_errorSDNS="无法连接到本地短信SQL Server数据库";
g_SuccessSDNS="连接到本地短信SQL Server数据库成功";
}
else //3
{
if (System_LocalRoute == 0)//单机版
{
g_sImportDsn="ODBC;DRIVER=Microsoft Access Driver (*.mdb);SRVR='sms_Lovedb';DBQ=smsdb.mdb;UID=sa;PWD=''";
}
else//网络版
{
g_sImportDsn="ODBC;DRIVER=Microsoft Access Driver (*.mdb);SRVR='sms_Lovedb';DBQ=edison-gw.mdb;UID=sa;PWD=''";
}
g_errorSDNS="无法连接到导入数据爱迪生数据库";
g_SuccessSDNS="连接到导入数据爱迪生数据库成功";
}
try
{
if(!g_ImportData.Open(NULL,FALSE,FALSE,g_sImportDsn,FALSE))
{
AfxMessageBox(g_errorSDNS);
return false ;
}
}
catch(CDBException* pEx)
{
pEx->ReportError();
g_ImportData.Close();
}
}
/*
//登陆界面
CLogin dlg;
if (dlg.DoModal() != IDOK)
{
AfxMessageBox("您没有输入相关信息,不能登陆本系统!");
return false ;
}
*/
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDataMangerDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CDataMangerView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->SetWindowText("_业务导入数据服务器_");
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
HICON hicon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pMainWnd->SetIcon(hicon,true);
DestroyIcon(hicon);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CDataMangerApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CDataMangerApp message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -