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

📄 sjsys.cpp

📁 本程序使用Visual C++6.0编写
💻 CPP
字号:
// Sjsys.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Sjsys.h"

#include "MainFrm.h"
#include "SjsysDoc.h"
#include "SjsysView.h"
#include "MyCrypt.h"
#include "LoginDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSjsysApp

BEGIN_MESSAGE_MAP(CSjsysApp, CWinApp)
	//{{AFX_MSG_MAP(CSjsysApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSjsysApp construction

CSjsysApp::CSjsysApp()
{
	// TODO: add construction code here,
	
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSjsysApp object

CSjsysApp theApp;

// This identifier was generated to be statistically unique for your app.
// You may change it if you prefer to choose a specific identifier.

// {B953E5C8-DC5D-4AF4-8C0B-12F7BE9EC8AA}
static const CLSID clsid =
{ 0xb953e5c8, 0xdc5d, 0x4af4, { 0x8c, 0xb, 0x12, 0xf7, 0xbe, 0x9e, 0xc8, 0xaa } };

/////////////////////////////////////////////////////////////////////////////
// CSjsysApp initialization
BOOL CSjsysApp::InitInstance()
{
	// 初始化COM库,以支持ADO
	if (!AfxOleInit())
	{
		AfxMessageBox("初始化COM库失败!");
		return FALSE;
	}
    
//	_ConnectionPtr m_pConnection; 
	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)
    




	// 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(CSjsysDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CSjsysView));
    	pDocTemplate->SetContainerInfo(IDR_CNTR_INPLACE);
	AddDocTemplate(pDocTemplate);
	// Connect the COleTemplateServer to the document template.
	//  The COleTemplateServer creates new documents on behalf
	//  of requesting OLE containers by using information
	//  specified in the document template.
	m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
	
	
    SetDialogBkColor(RGB(160,180,220),RGB(0,0,0));
	/////////////////////////////////
	//	初始化数据库连接
	/////////////////////////////////
	//从.ini获得数据库配置
	CString Path =_T("");
    GetCurrentDirectory(MAX_PATH,Path.GetBuffer(MAX_PATH)); 
    Path.ReleaseBuffer(); 

	Path=Path+"\\DBConfig.ini";
	::GetPrivateProfileString("DBConfig","Server","Server",Server.GetBuffer(MAX_PATH),MAX_PATH,Path);
	::GetPrivateProfileString("DBConfig","DBName","DBName",DBName.GetBuffer(MAX_PATH),MAX_PATH,Path);
	::GetPrivateProfileString("DBConfig","User","User",User.GetBuffer(MAX_PATH),MAX_PATH,Path);
	::GetPrivateProfileString("DBConfig","Password","Password",Password.GetBuffer(MAX_PATH),MAX_PATH,Path);
    
	
	
	if(!m_myConnection.Open(Server,User,Password,DBName))
	{
		AfxMessageBox("数据库连接失败!");
		return false;
	}
     
	::CoInitialize(NULL);
	pDetailRecordset.CreateInstance("ADODB.Recordset");
	pDeviceRecordset.CreateInstance(__uuidof(Recordset));
	pDepartmentRecordset.CreateInstance(__uuidof(Recordset));
	pFlowRecordset.CreateInstance(__uuidof(Recordset));
	pConnection=m_myConnection.GetConnection();
   	bool isLogin=false;//用来判断登录是否成功,初始是不成功?
	while(!isLogin) 
	{ 
		//先弹出登陆对话框
 	   CLoginDlg login; //CLoginDialog为登陆对话框
		int nLogin; 
		nLogin=login.DoModal(); //显示 
		if(nLogin==IDOK) 
		{ 
			
		//CString tUser=login.m_sUser; //这里获得输入的帐号和密码 
		  CString tPass; 
		  CString SQLStr;
		  if((login.m_sUser!="") && (login.m_sPass!=""))
          {
			tPass=CMyCrypt::MyEncrypt(login.m_sPass,123);  //解密
			SQLStr.Format("select * from user1 where Name='%s' and Password='%s'",login.m_sUser,tPass);
		   // AfxMessageBox(SQLStr); 
			try
			{
				//从数据库中寻找用户名和密码
				if(pConnection)
				{
			        //打开数据集,按照用户名和密码到数据库的对应表中查找
 		        	pDetailRecordset->Open(_bstr_t(SQLStr),
						                   _variant_t(pConnection,true),
										   adOpenDynamic, 
										   adLockOptimistic,
										   adCmdText); 

				}
			}
			
	        catch(_com_error *e)
			{
		        CString  errormessage;
		        errormessage.Format("打开记录集失败!\r\n错误信息:%s",e->ErrorMessage());
	            AfxMessageBox(errormessage);
		        return TRUE;
			}
			
			//若查找到了对应的用户,则通过认证;否则认证失败
			if (!pDetailRecordset->adoEOF) 	
			{
				// 若登陆认证成功,先初始化,再进入主窗口。
				isLogin = true;
				m_UserID= pDetailRecordset->GetCollect("ID").lVal;
				CCommandLineInfo cmdInfo;
	             ParseCommandLine(cmdInfo);
				 if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
				 {
	                COleTemplateServer::RegisterAll();
		            return TRUE;
				 }
                 
	             m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
	             COleObjectFactory::UpdateRegistryAll();
				 //最大化显示窗口
	          	m_nCmdShow = SW_SHOWMAXIMIZED;
	            if (!ProcessShellCommand(cmdInfo))
		          return FALSE;
			
			    m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
	            m_pMainWnd->UpdateWindow();
				
			}
               else AfxMessageBox("认证失败!");
			pDetailRecordset->Close();

         }
		else  
			AfxMessageBox("请注意:用户名或者用户密码为空!");
		}
		else 
			if(nLogin==IDCANCEL) //如果取消登陆,则登陆失败,退出循环,即退出登陆 
				break; 
	}



	 // Note: SDI applications register server objects only if /Embedding
	 //   or /Automation is present on the command line.

	// Parse command line for standard shell commands, DDE, file open
	



   return isLogin;    //返回登陆情况。
 
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#include "HyperLink.h"				// 加入超链接类
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CHyperLink	m_Email;
	CWinXPButtonST	m_Ok;
	//}}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)
	virtual BOOL OnInitDialog();
	//}}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)
	DDX_Control(pDX, IDC_EMAILSTATIC, m_Email);
	DDX_Control(pDX, IDOK, m_Ok);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CSjsysApp message handlers
// App command to run the dialog
void CSjsysApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CSjsysApp message handlers
/////////////////////////////////////////////////////////////////////////////
// CSjsysApp message handlers


int CSjsysApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	m_myConnection.Close();
	return CWinApp::ExitInstance();
}

CString CSjsysApp::GetStringFromVariant(_variant_t var)
{
	return var.vt==VT_NULL?"":(char*)(_bstr_t)var;
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//设置“关于”对话框的XP风格按钮显示
	m_Ok.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(100,155,100));
	m_Ok.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(0,155,155));
	m_Ok.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
	m_Ok.SetBkColor(RGB(162,189,252));
	m_Ok.SetRounded(TRUE);
	m_Ok.SetTooltipText(_T("关闭"));

	//加入EMAIL的超连接
    m_Email.SetURL(_T("mailto:meyangyihua@163.com"));
	m_Email.SetUnderline(TRUE);	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


⌨️ 快捷键说明

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