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

📄 luludlg.cpp

📁 数据库连接访问显示、增加删除更新记录、打开上一条下一条记录
💻 CPP
字号:
// LULUDlg.cpp : implementation file
//

#include "StdAfx.h"
#include "LULU.h"
#include "LULUDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CLULUDlg dialog

CLULUDlg::CLULUDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLULUDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLULUDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLULUDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLULUDlg)
	DDX_Control(pDX, IDC_BTN_PREVIOUS, m_btnPrevious);
	DDX_Control(pDX, IDC_BTN_LAST, m_btnLast);
	DDX_Control(pDX, IDC_EDIT_VOICE, m_edtVoice);
	DDX_Control(pDX, IDC_EDIT_EMOTION, m_edtEmotion);
	DDX_Control(pDX, IDC_BTN_INSERT, m_btnInsert);
	DDX_Control(pDX, IDC_BTN_DELETE, m_btnDelete);
	DDX_Control(pDX, IDC_BTN_REFRESHUPDATE, m_btnRefreshUpdatenew);
	DDX_Control(pDX, IDC_BTN_FIRST, m_btnFirst);
	DDX_Control(pDX, IDC_BTN_NEXT, m_btnNext);
	DDX_Control(pDX, IDC_BTN_UPDATE, m_btnUpdate);
	DDX_Control(pDX, IDC_EDIT_NUMBER, m_edtNumber);
	DDX_Control(pDX, IDC_EDIT_CLASS, m_edtClass);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLULUDlg, CDialog)
	//{{AFX_MSG_MAP(CLULUDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_FIRST, OnBtnFirst)
	ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
	ON_BN_CLICKED(IDC_BTN_UPDATE, OnBtnUpdate)
	ON_BN_CLICKED(IDC_BTN_REFRESHUPDATE, OnBtnRefreshupdate)
	ON_BN_CLICKED(IDC_BTN_INSERT, OnBtnInsert)
	ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
	ON_BN_CLICKED(IDC_BTN_LAST, OnBtnLast)
	ON_BN_CLICKED(IDC_BTN_PREVIOUS, OnBtnPrevious)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLULUDlg message handlers

BOOL CLULUDlg::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
	
	// TODO: Add extra initialization here

	m_btnFirst.EnableWindow(TRUE);
    m_btnNext.EnableWindow(FALSE);
    m_btnUpdate.EnableWindow(FALSE);
   // m_btnUpdate.EnableWindow(FALSE);
    m_ds.InitData();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLULUDlg::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 CLULUDlg::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 CLULUDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
void CLULUDlg::LoadData()
{
	m_edtClass.SetWindowText(m_ds.GetAsString("CLASS"));
	m_edtVoice.SetWindowText(m_ds.GetAsString("VOICE"));
	
	m_edtNumber.SetWindowText(m_ds.GetAsString("NUMBER"));
    m_edtEmotion.SetWindowText(m_ds.GetAsString("EMOTION"));
	
}
BOOL CLULUDlg::IsNeedUpdate()  //检查是否需要更新数据,是否要使能“OK”按钮
{
	CString strTemp;
	m_edtNumber.GetWindowText(strTemp);
	if(strTemp!=m_ds.GetAsString("NUMBER"))
		return TRUE;

		

	m_edtVoice.GetWindowText(strTemp);
	if(strTemp!=m_ds.GetAsString("VOICE"))
		return TRUE;


    m_edtClass.GetWindowText(strTemp);
	if(strTemp!=m_ds.GetAsString("CLASS"))
		return TRUE;
  	

    m_edtEmotion.GetWindowText(strTemp);
	if(strTemp!=m_ds.GetAsString("EMOTION"))
		return TRUE;
  

	return FALSE;
}
void CLULUDlg::RefreshUpdateBtn() //  调用判断函数IsNeedUpdate()  看是否需要更新  刷新更新按钮,允许用户更新数据
{
	// TODO: Add your control notification handler code here
	 if(IsNeedUpdate())
	{
		m_btnUpdate.EnableWindow(TRUE);  //OK
	}
	else
	{
		m_btnUpdate.EnableWindow(FALSE);//OK
	}
}

void CLULUDlg::RefreshView()//刷新界面上的“按钮和编辑框”是否有效
{   
     if(m_ds.IsBOF()||m_ds.IsEOF())
	{
 	/*
	    m_edtClass.EnableWindow(FALSE);
		m_edtNumber.EnableWindow(FALSE);
    	m_edtVoice.EnableWindow(FALSE);
    	m_edtEmotion.EnableWindow(FALSE);
     */
	}
	 else
	 {
		 m_edtClass.EnableWindow(TRUE);
		 m_edtNumber.EnableWindow(TRUE);
	     m_edtVoice.EnableWindow(TRUE);
	     m_edtEmotion.EnableWindow(TRUE);
	 }
/*
m_btnFirst.EnableWindow(TRUE);
m_btnNext.EnableWindow(TRUE);
m_btnUpdate.EnableWindow(FALSE);
*/

if(m_ds.IsFirst())
{
	m_btnFirst.EnableWindow(FALSE);
    m_btnNext.EnableWindow(TRUE);
}
if(m_ds.IsLast())
{
    m_btnNext.EnableWindow(FALSE);
    m_btnFirst.EnableWindow(TRUE);
}


}

void CLULUDlg::OnBtnFirst() 
{
	// TODO: Add your control notification handler code here

     if(m_ds.IsBOF()||m_ds.IsEOF())
	{
		 m_edtNumber.SetWindowText("请输入"); 
	}
	 else
	 {
     m_ds.MoveFirst();
	 LoadData();//数据装载到编辑框
	 RefreshView();
	 }
}

void CLULUDlg::OnBtnNext() 
{
	// TODO: Add your control notification handler code here
	m_ds.MoveNext();
	LoadData();
	RefreshView();
}

void CLULUDlg::OnBtnUpdate()   //OK
{
	// TODO: Add your control notification handler code here
	CString strTemp;
    m_edtClass.GetWindowText(strTemp);  
	m_ds.SetAsString("CLASS",strTemp);

	m_edtNumber.GetWindowText(strTemp); 
    m_ds.SetAsString("NUMBER",strTemp);
	

	//m_edtVoice.GetWindowText(strTemp);
	//m_ds.SetAsString("VOICE",strTemp);


//	m_edtEmotion.GetWindowText(strTemp);
//	m_ds.SetAsString("EMOTION",strTemp);

	m_ds.Update();   //更新数据库
	m_btnUpdate.EnableWindow(FALSE);
}



void CLULUDlg::OnBtnRefreshupdate() 
{
	// TODO: Add your control notification handler code here
//检查是否需要更新数据,是否要使能“更新”按钮
	RefreshUpdateBtn();

}

void CLULUDlg::OnBtnInsert() 
{
	// TODO: Add your control notification handler code here
	CString strClass;
	CString strNumber;
    m_edtClass.GetWindowText(strClass); 
	m_edtNumber.GetWindowText(strNumber); 
 
	m_ds.New(strNumber,strClass);
    LoadData();
	RefreshView();
	
}

void CLULUDlg::OnBtnDelete() 
{
	// TODO: Add your control notification handler code here
	if(!m_ds.IsBOF())
	{
	m_ds.Delete();
    LoadData();
	RefreshView();
	}
}

void CLULUDlg::OnBtnLast() 
{
	// TODO: Add your control notification handler code here
	m_ds.MoveLast();
    LoadData();
	RefreshView();
	
}

void CLULUDlg::OnBtnPrevious() 
{
	// TODO: Add your control notification handler code here
	if(!m_ds.IsFirst())
	{
 		m_ds.MovePrev();
		LoadData();
		RefreshView();
	}
	else
	{
		m_ds.MoveFirst();
		LoadData();
		RefreshView();
	}

}

⌨️ 快捷键说明

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