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

📄 sgadrlstmsdlg.cpp

📁 通讯录管理系统1.0 可以为您方便地, 安全地管理你的通讯录, 是您的家庭好帮手. 本系统使用Visual C++(MFC)开发, ODBC开放式数据库源
💻 CPP
字号:
// SGAdrLstMSDlg.cpp : implementation file
//

#include "stdafx.h" //应用程序框架

#include "SGAdrLstMS.h"// 应用程序
#include "SGAdrLstMSDlg.h" //主对话框

#include "SysRecordSet.h"  //数据库连接

#include "AddDlg.h"    // '添加' 对话框
#include "DeleteDlg.h"	   // '删除' 对话框
#include "ModifyDlg.h" //'修改对话框'
#include "QueryDlg.h"  //'查询对话框'
#include "SetPWDDlg.h" //'设置密码对话框'
#include "InputPwdDlg.h"  //'登陆对话框'
#include "HelpDlg.h" //'帮助主题对话框'

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

/////////////////////////////////////////////////////////////////////////////
// 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)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSGAdrLstMSDlg dialog

CSGAdrLstMSDlg::CSGAdrLstMSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSGAdrLstMSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSGAdrLstMSDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	this->count = 0;
}

void CSGAdrLstMSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSGAdrLstMSDlg)
	DDX_Control(pDX, IDC_MAINLIST, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSGAdrLstMSDlg, CDialog)
	//{{AFX_MSG_MAP(CSGAdrLstMSDlg)
	ON_BN_CLICKED(IDC_SHOW, OnShow)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
	ON_COMMAND(ID_MABOUT, OnMabout)
	ON_COMMAND(ID_MADD, OnMadd)
	ON_COMMAND(ID_MDEL, OnMdel)
	ON_COMMAND(ID_MEXIT, OnMexit)
	ON_COMMAND(ID_MMOD, OnMmod)
	ON_COMMAND(ID_MREF, OnMref)
	ON_COMMAND(ID_MTOP, OnMtop)
	ON_BN_CLICKED(IDC_QURY, OnQury)
	ON_COMMAND(IDM_MQUREY, OnMqurey)
	ON_WM_SHOWWINDOW()
	ON_COMMAND(IDM_PASS, OnPass)
	ON_BN_CLICKED(IDC_HELP, OnHelp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSGAdrLstMSDlg message handlers

BOOL CSGAdrLstMSDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	db2.Open();
	db2.MoveFirst();

	if (db2.m_startup == TRUE)
	{
		
		CInputPwdDlg dlg;
		if (dlg.DoModal() == IDCANCEL)
		{
			exit(0);
		}	

	}

	db2.Close();

	MessageBox("欢迎登陆通讯录管理系统", "通讯录管理系统",MB_ICONINFORMATION);
    CODBCFieldInfo Info;
	CSysRecordSet  db;
	db.Open();

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

	for( int i=0; i < db.m_nFields;i++)
	{
	    db.GetODBCFieldInfo(i,Info);
		m_list.InsertColumn(i,Info.m_strName);
	    m_list.SetColumnWidth(i,120);
	}
	db.Close();
	
    this->OnShow();

	return TRUE;  // return TRUE  unless you set the focus to a control
}


void CSGAdrLstMSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSGAdrLstMSDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSGAdrLstMSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSGAdrLstMSDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	this->OnCancel();
	
}


void CSGAdrLstMSDlg::OnShow()
{
	
	db.RefreshConnection();
	db.Open();
	db.MoveFirst();
	
	this->count = 0;
	CString  cs;

	int i = 0;
	m_list.DeleteAllItems();

	while (!db.IsEOF())
	{
		cs.Format("%s",db.m_column2);
		m_list.InsertItem(count,cs,0);

		m_list.SetItemText(count,0,cs);

        cs.Format("%s",db.m_column3); 
		m_list.SetItemText(count,1,cs);


        cs.Format("%s",db.m_column4); 
		m_list.SetItemText(count,2,cs);

        cs.Format("%s",db.m_column5); 
		m_list.SetItemText(count,3,cs);

        cs.Format("%s",db.m_QQ__); 
		m_list.SetItemText(count,4,cs);


        cs.Format("%s",db.m_column6); 
		m_list.SetItemText(count,5,cs);

		db.MoveNext();
		count++;
	}


}

void CSGAdrLstMSDlg::OnAdd() 
{
	CAddDlg dlg;
	
	db.RefreshConnection();
	db.Open();

	if (dlg.DoModal() == IDOK)
	{
		db.AddNew();
		db.m_column2 = dlg.m_name;
		db.m_column3 = dlg.m_tel;
		db.m_column4 = dlg.m_mobile;
		db.m_column5 = dlg.m_email;
		db.m_QQ__ = dlg.m_qq;
		db.m_column6 = dlg.m_bak;

		db.Update();
		MessageBox("添加完成","操作成功",MB_ICONINFORMATION);
		db.Requery();
		db.Close();
		this->OnShow();
	}
	
}

void CSGAdrLstMSDlg::OnDelete() 
{
	CDeleteDlg dlg;

	db.RefreshConnection();
	db.Open();
	db.MoveFirst();

	if (dlg.DoModal() == IDOK)
	{
		while (!db.IsEOF())
		{
			if ( db.m_column2 == dlg.m_deletename)
			{
				if (MessageBox("确实要删除这个联系人吗?","确认",

					MB_YESNO|MB_ICONQUESTION) == IDNO)
					{
						return;
					}
					db.Delete();
					MessageBox("删除完成",
						"操作成功",
						MB_ICONINFORMATION);
					break;
			}
			db.MoveNext();
		}
		if (db.IsEOF())
		{
			MessageBox("无此联系人,操作失败","操作失败",MB_ICONSTOP);
		}

	}
	db.Close();
	this->OnShow();
}

void CSGAdrLstMSDlg::OnUpdate() 
{
	// TODO: Add your control notification handler code here
	CModifyDlg dlg;
	if (dlg.DoModal() == IDOK)
	{
		db.RefreshConnection();
		db.Open();
		db.MoveFirst();
	

		while (!db.IsEOF())
		{

			if ( db.m_column2 == dlg.m_modifyname )
			{
				db.Edit();
				db.m_column3 = dlg.m_newtel;
				db.m_column4 = dlg.m_newmobile;
				db.m_column5 = dlg.m_newemail;
				db.m_column6 = dlg.m_newbak;
				db.m_QQ__ = dlg.m_newqq;
				db.Update();
				MessageBox("修改完成","操作成功",MB_ICONINFORMATION);
			break;
		}
		db.MoveNext();
	}

	db.Requery();

	db.Close();
	this->OnShow();
	}
}

void CSGAdrLstMSDlg::OnMabout() 
{
	// TODO: Add your command handler code here

	CAboutDlg a;
	a.DoModal();
}

void CSGAdrLstMSDlg::OnMadd() 
{

	this->OnAdd();
}


void CSGAdrLstMSDlg::OnMdel() 
{

	this->OnDelete();
}



void CSGAdrLstMSDlg::OnMexit() 
{

	this->OnOK();
}


void CSGAdrLstMSDlg::OnMmod() 
{

	this->OnUpdate();
}

void CSGAdrLstMSDlg::OnMref() 
{

	this->OnShow();
}



void CSGAdrLstMSDlg::OnMtop() 
{

	CHelpDlg dlg;
	dlg.DoModal();
}

void CSGAdrLstMSDlg::OnQury() 
{
	CQueryDlg  dlg;

	dlg.DoModal();
}

void CSGAdrLstMSDlg::OnMqurey() 
{

	this->OnQury();
}

void CSGAdrLstMSDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	

	this->GetDlgItem(IDC_MAINLIST)->SetFocus();
}

void CSGAdrLstMSDlg::OnPass() 
{

	CInputPwdDlg dlg;
	//dlg.SetWindowText("登陆安全系统");
	db2.Open();

	if (db2.m_startup == TRUE)
	{
		if (dlg.DoModal()!=IDOK)
		{
			db2.Close();
			return;
		}
	}
	db2.Close();
	CSetPWDDlg dlg2;
	dlg2.DoModal();
}

void CSGAdrLstMSDlg::OnHelp() 
{

	CHelpDlg dlg;
	dlg.DoModal();
}

⌨️ 快捷键说明

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