📄 srmsdlg.cpp
字号:
// SRMSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SRMS.h"
#include "SRMSDlg.h"
#include "column.h"
#include "columns.h"
#include "COMDEF.h"
#include "EditDlg.h"
#include "_recordset.h"
#include "datagrid.h"
#include "Results.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()
/////////////////////////////////////////////////////////////////////////////
// CSRMSDlg dialog
CSRMSDlg::CSRMSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSRMSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSRMSDlg)
m_radio = -1;
m_name = _T("");
m_id = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSRMSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSRMSDlg)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_ADODC1, m_adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
DDX_Radio(pDX, IDC_RADIO_NAME, m_radio);
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_ID, m_id);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSRMSDlg, CDialog)
//{{AFX_MSG_MAP(CSRMSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DEL, OnDel)
ON_BN_CLICKED(IDC_ALL, OnAll)
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_BN_CLICKED(IDC_RADIO_NAME, OnRadioName)
ON_BN_CLICKED(IDC_RADIO_ID, OnRadioId)
ON_BN_CLICKED(IDC_ORDER, OnOrder)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSRMSDlg message handlers
BOOL CSRMSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_list.SetCurSel(0);
// 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
_bstr_t vSQL;
vSQL="SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results";
RefreshData(vSQL);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CSRMSDlg::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 CSRMSDlg::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 CSRMSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSRMSDlg::OnAdd()
{
// TODO: Add your control notification handler code here
CEditDlg dlg;
dlg.strSex="男";
_bstr_t vSQL;
vSQL="SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results";
if(dlg.DoModal()==IDOK)
RefreshData(vSQL);
}
void CSRMSDlg::OnDel()
{
_bstr_t vSQL;
vSQL="SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results";
if (m_adodc.GetRecordset().GetEof() == 1)
{
MessageBox("请选择要删除的数据");
return;
}
if (MessageBox("是否删除当前记录?","请确认", MB_YESNO) == IDYES)
{
Results stu;
stu.sql_delete(m_datagrid.GetItem(0));
RefreshData(vSQL);
} // TODO: Add your control notification handler code here
}
void CSRMSDlg::RefreshData(_bstr_t vSQL)
{
m_adodc.SetRecordSource(vSQL);
m_adodc.Refresh();
_variant_t vIndex;
vIndex = long(0);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
vIndex = long(1);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(70);
vIndex = long(2);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(30);
vIndex = long(3);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(4);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(5);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(6);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(58);
}
void CSRMSDlg::OnAll()
{
// TODO: Add your control notification handler code here
_bstr_t vSQL;
vSQL="SELECT Stu_id AS 学号,Stu_name AS 姓名,Sex AS 性别,math AS 数学,chinese AS 语文,computer AS 计算机,average AS 均分 FROM Results";
RefreshData(vSQL);
}
void CSRMSDlg::OnFind()
{
UpdateData(TRUE);
Results stu;
if(m_radio==0)
{
stu.SetName(m_name);
stu.sql_search(0,&m_adodc,&m_datagrid);
}
if (m_radio==1) {
stu.SetId(m_id);
stu.sql_search(1,&m_adodc,&m_datagrid);
}
m_id=0;
m_name="";
}
void CSRMSDlg::OnRadioName()
{
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_ID);
pEdit->SetReadOnly(TRUE);
m_id=0;
pEdit = (CEdit*)GetDlgItem(IDC_NAME);
pEdit->SetReadOnly(FALSE);
}
void CSRMSDlg::OnRadioId()
{
m_name="";
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_ID);
pEdit->SetReadOnly(FALSE);
pEdit = (CEdit*)GetDlgItem(IDC_NAME);
pEdit->SetReadOnly(TRUE); // TODO: Add your control notification handler code here
}
void CSRMSDlg::OnOrder()
{
Results stu;
m_list.GetLBText(m_list.GetCurSel(), strList);
if(strList=="数学")
stu.sql_order(0,&m_adodc,&m_datagrid);
else
if(strList=="语文")
stu.sql_order(1,&m_adodc,&m_datagrid);
else
if(strList=="计算机")
stu.sql_order(2,&m_adodc,&m_datagrid);
else
if(strList=="均分")
stu.sql_order(3,&m_adodc,&m_datagrid);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -