MFC + ACCESS user verification program (preliminary database programming)

Source: Internet
Author: User

MFC + ACCESS user verification program (preliminary database programming)

Transferred from: Enterprise Instant Messaging

Software Process:
In the pop-up dialog box, enter the user name and password. If the user name and password are correct, the dialog box is displayed. If the user name and password are incorrect, the dialog box is displayed. If the user name and password are closed, the system does not exit.
Three no program, useful or just learning ADO look.

 

//////////////////////////////////////// // Stdafx. h

// Stdafx. h: Include File for standard system include files,
// Or project specific include files that are used frequently,
// Are changed infrequently
//

# If! Defined (afx_stdafx_h1_b170e8a6_57b5_4b19_a471_c1_c30871f11_encoded _)
# Define afx_stdafx_h1_b170e8a6_57b5_4b19_a471_c1_c30871f11_encoded _

# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000

# Define vc_extralean // exclude rarely-used stuff from Windows Headers

# Include <afxwin. h> // MFC core and standard components
# Include <afxext. h> // MFC extensions
# Include <afxdisp. h> // MFC automation classes
# Include <afxdtctl. h> // MFC support for Internet Explorer 4 common controls
# Ifndef _ afx_no_afxcmn_support
# Include <afxcmn. h> // MFC support for Windows Common controls
# Endif // _ afx_no_afxcmn_support

# Include <icrsint. h>
# Import "C:/program files/common files/system/ADO/msado15.dll" no_namespace Rename ("EOF", "adoeof ")

// {Afx_insert_location }}
// Microsoft Visual C ++ will insert additional declarations immediately before the previous line.

# Endif //! Defined (afx_stdafx_h1_b170e8a6_57b5_4b19_a471_c1_c30871f11_encoded _)
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------

# If! Defined (afx_logindlg_hsf-c757dd49_652b_41a1_84c3_ec0d3c40a07f109included _)
# Define afx_logindlg_hsf-c757dd49_652b_41a1_84c3_ec0d3c40a07f109included _

# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000
// Logindlg. h: header file
//

//////////////////////////////////////// /////////////////////////////////////
// Clogindlg Dialog

Class clogindlg: Public cdialog
{
// Construction
Public:
Bool uservalid ();
Clogindlg (cwnd * pparent = NULL); // standard Constructor

// Dialog data
// {Afx_data (clogindlg)
Enum {IDD = idd_dialog1 };
// Note: The classwizard will add data members here
//} Afx_data

// Overrides
// Classwizard generated virtual function overrides
// {Afx_virtual (clogindlg)
Protected:
Virtual void dodataexchange (cdataexchange * PDX); // DDX/DDV support
//} Afx_virtual

// Implementation
Protected:

// Generated message map Functions
// {Afx_msg (clogindlg)
Virtual void onok ();
Virtual void oncancel ();
Virtual bool oninitdialog ();
//} Afx_msg
Declare_message_map ()
};

// {Afx_insert_location }}
// Microsoft Visual C ++ will insert additional declarations immediately before the previous line.

# Endif //! Defined (afx_logindlg_hsf-c757dd49_652b_41a1_84c3_ec0d3c40a07f109included _)

Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------

// Logindlg. cpp: implementation file
//

# Include "stdafx. H"
# Include "userlogin. H"
# Include "logindlg. H"
# Include "userlogindlg. H"

# Ifdef _ debug
# Define new debug_new
# UNDEF this_file
Static char this_file [] = _ file __;
# Endif

//////////////////////////////////////// /////////////////////////////////////
// Clogindlg Dialog

Clogindlg: clogindlg (cwnd * pparent/* = NULL */)
: Cdialog (clogindlg: IDD, pparent)
{
// {Afx_data_init (clogindlg)
// Note: The classwizard will add member initialization here
//} Afx_data_init
}

Void clogindlg: dodataexchange (cdataexchange * PDX)
{
Cdialog: dodataexchange (PDX );
// {Afx_data_map (clogindlg)
// Note: The classwizard will add DDX and DDV cballs here
//} Afx_data_map
}

Begin_message_map (clogindlg, cdialog)
// {Afx_msg_map (clogindlg)
//} Afx_msg_map
End_message_map ()

//////////////////////////////////////// /////////////////////////////////////
// Clogindlg message handlers

Void clogindlg: onok ()
{
// Todo: add extra validation here
/* Char * szbuf = new char [2, 128];
Getdlgitemtext (idc_edit1, szbuf, 128 );
MessageBox (szbuf );*/
If (! Uservalid ())
Return;

Cdialog: onok ();
}

Void clogindlg: oncancel ()
{
// Todo: add extra cleanup here

Cdialog: oncancel ();
}

Bool clogindlg: uservalid ()
{
_ Connectionptr & cptr = (cuserlogindlg *) getparent ()-> m_pconn;
Char * szusername = (char *) (cuserlogindlg *) getparent ()-> m_szusername;

_ Recordsetptr PRS;
PRS. createinstance (_ uuidof (recordset ));

// Make sure that the user name is not empty
Char szname [128];
Getdlgitemtext (idc_edit1, szname, 128 );
If (null = szname [0])
{
Afxmessagebox ("the user name cannot be blank! ");
Return false;
}
Char szpw [128];
Getdlgitemtext (idc_edit2, szpw, 128 );
If (null = szpw [0])
{
Afxmessagebox ("the password cannot be blank! ");
Return false;
}

// Read user information from the account table
Char szsql [256];
Sprintf (szsql, "% S % s", "select * from account where username = '", szname );
Strcat (szsql ,"'");

Try
{
Hresult hR = PRS-> open (szsql,
Cptr. getinterfaceptr (), adopendynamic, adlockoptimistic, adshorttext );

// Ensure that the user exists
If (PRS-> adoeof)
{
Afxmessagebox ("the user name is invalid. Please enter it again! ");
PRS-> close ();
PRS. Release ();
Return false;
}
}

Catch (_ com_error E)
{
Afxmessagebox (E. errormessage ());
}

Cstring l_str;
Variant_t var;

Try
{
Var = PRS-> getcollect (_ variant_t ("password "));
If (var. VT! = Vt_null)
{
Rochelle STR = (lpctstr) _ bstr_t (VAR );
If (l_str = szpw)
{
// Afxmessagebox ("correct password ");
Strcpy (szusername, szname );
}
Else
{
Afxmessagebox ("the password is incorrect. Please try again! ");
Return false;
}
}
Else
{
Rochelle STR = _ T ("NONE ");
Afxmessagebox (l_str );
Return false;
}
}
Catch (_ com_error E)
{
Afxmessagebox (E. Description ());
}
PRS-> close ();
PRS. Release ();
}

Bool clogindlg: oninitdialog ()
{
Cdialog: oninitdialog ();
 
// Todo: add extra initialization here
Return true; // return true unless you set the focus to a control
// Exception: OCX property pages shold return false
}

Certificate --------------------------------------------------------------------------------------------------------------------------------------------------

// Userlogin. h: Main header file for the userlogin Application
//

# If! Defined (afx_userlogin_h1_433a5c98_5c19_49a2_8aca_5ad5ff1_d771_encoded _)
# Define afx_userlogin_h1_433a5c98_5c19_49a2_8aca_5ad5ff1_d771_encoded _

# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000

# Ifndef _ afxwin_h __
# Error include 'stdafx. H' before including this file for PCH
# Endif

# Include "resource. H" // Main Symbols

//////////////////////////////////////// /////////////////////////////////////
// Cuserloginapp:
// See userlogin. cpp for the implementation of this class
//

Class cuserloginapp: Public cwinapp
{
Public:
Cuserloginapp ();

// Overrides
// Classwizard generated virtual function overrides
// {Afx_virtual (cuserloginapp)
Public:
Virtual bool initinstance ();
//} Afx_virtual

// Implementation

// {Afx_msg (cuserloginapp)
// Note-The classwizard will add and remove member functions here.
// Do not edit what you see in these blocks of generated code!
//} Afx_msg
Declare_message_map ()
};

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

// {Afx_insert_location }}
// Microsoft Visual C ++ will insert additional declarations immediately before the previous line.

# Endif //! Defined (afx_userlogin_h1_433a5c98_5c19_49a2_8aca_5ad5ff1_d771_encoded _)

Certificate ----------------------------------------------------------------------------------------------------------------------------------------------

// Userlogin. cpp: defines the class behaviors for the application.
//

# Include "stdafx. H"
# Include "userlogin. H"
# Include "userlogindlg. H"

# Ifdef _ debug
# Define new debug_new
# UNDEF this_file
Static char this_file [] = _ file __;
# Endif

//////////////////////////////////////// /////////////////////////////////////
// Cuserloginapp

Begin_message_map (cuserloginapp, cwinapp)
// {Afx_msg_map (cuserloginapp)
// Note-The classwizard will add and remove mapping macros here.
// Do not edit what you see in these blocks of generated code!
//} Afx_msg
On_command (id_help, cwinapp: onhelp)
End_message_map ()

//////////////////////////////////////// /////////////////////////////////////
// Cuserloginapp Construction

Cuserloginapp: cuserloginapp ()
{
// Todo: Add construction code here,
// Place all significant initialization in initinstance
}

//////////////////////////////////////// /////////////////////////////////////
// The one and only cuserloginapp object

Cuserloginapp theapp;

//////////////////////////////////////// /////////////////////////////////////
// Cuserloginapp Initialization

Bool cuserloginapp: initinstance ()
{
Oleinitialize (null );
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

Cuserlogindlg DLG;
M_pmainwnd = & DLG;
Int nresponse = DLG. domodal ();
If (nresponse = idok)
{
// Todo: Place code here to handle when the dialog is
// Dismissed with OK
}
Else if (nresponse = idcancel)
{
// Todo: Place code here to handle when the dialog is
// Dismissed with cancel
}

// Since the dialog has been closed, return false so that we exit
// Application, rather than start the application's message pump.
Return false;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.