📄 sdlg.cpp
字号:
// sDlg.cpp : implementation file
//
#include "stdafx.h"
#include "s.h"
#include "sDlg.h"
#include "finddata.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern CSApp theApp;
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()
/////////////////////////////////////////////////////////////////////////////
// CSDlg dialog
CString CSDlg::title[]=
{
"学号",
"姓名",
"性别",
"民族",
"籍贯",
"政治面貌",
"年龄",
"身高",
"体重",
"视力",
"学制",
"系别",
"班级",
"联系电话",
"联系地址",
"备份",
};
CSDlg::CSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
bonew=false;
modify=false;
}
void CSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSDlg)
DDX_Control(pDX, IDC_COMBO1, m_combo1);
DDX_Control(pDX, IDC_STATICALL2, m_staticall2);
DDX_Control(pDX, IDC_BUTFIRST, m_butfirst);
DDX_Control(pDX, IDC_STATICALL, m_staticall);
DDX_Control(pDX, IDC_STATIC9, m_static9);
DDX_Control(pDX, IDC_STATIC8, m_static8);
DDX_Control(pDX, IDC_STATIC7, m_static7);
DDX_Control(pDX, IDC_STATIC6, m_static6);
DDX_Control(pDX, IDC_STATIC5, m_static5);
DDX_Control(pDX, IDC_STATIC4, m_static4);
DDX_Control(pDX, IDC_STATIC3, m_static3);
DDX_Control(pDX, IDC_STATIC2, m_static2);
DDX_Control(pDX, IDC_STATIC16, m_static16);
DDX_Control(pDX, IDC_STATIC15, m_static15);
DDX_Control(pDX, IDC_STATIC14, m_static14);
DDX_Control(pDX, IDC_STATIC13, m_static13);
DDX_Control(pDX, IDC_STATIC12, m_static12);
DDX_Control(pDX, IDC_STATIC11, m_static11);
DDX_Control(pDX, IDC_STATIC10, m_static10);
DDX_Control(pDX, IDC_STATIC1, m_static1);
DDX_Control(pDX, IDC_BUEXIT, m_butexit);
DDX_Control(pDX, IDC_BUTUP, m_butup);
DDX_Control(pDX, IDC_BUTNEXT, m_butnext);
DDX_Control(pDX, IDC_BUTMODIFY, m_butmodify);
DDX_Control(pDX, IDC_BUTLAST, m_butlast);
DDX_Control(pDX, IDC_BUTFIND, m_butfind);
DDX_Control(pDX, IDC_BUTDEL, m_butdel);
DDX_Control(pDX, IDC_BUTADD, m_butadd);
DDX_Control(pDX, IDC_EDIT9, m_edit9);
DDX_Control(pDX, IDC_EDIT8, m_edit8);
DDX_Control(pDX, IDC_EDIT7, m_edit7);
DDX_Control(pDX, IDC_EDIT6, m_edit6);
DDX_Control(pDX, IDC_EDIT5, m_edit5);
DDX_Control(pDX, IDC_EDIT4, m_edit4);
DDX_Control(pDX, IDC_EDIT3, m_edit3);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_EDIT16, m_edit16);
DDX_Control(pDX, IDC_EDIT15, m_edit15);
DDX_Control(pDX, IDC_EDIT14, m_edit14);
DDX_Control(pDX, IDC_EDIT13, m_edit13);
DDX_Control(pDX, IDC_EDIT12, m_edit12);
DDX_Control(pDX, IDC_EDIT11, m_edit11);
DDX_Control(pDX, IDC_EDIT10, m_edit10);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSDlg, CDialog)
//{{AFX_MSG_MAP(CSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUEXIT, OnBuexit)
ON_BN_CLICKED(IDC_BUTFIRST, OnButfirst)
ON_BN_CLICKED(IDC_BUTUP, OnButup)
ON_BN_CLICKED(IDC_BUTNEXT, OnButnext)
ON_BN_CLICKED(IDC_BUTLAST, OnButlast)
ON_BN_CLICKED(IDC_BUTFIND, OnButfind)
ON_BN_CLICKED(IDC_BUTADD, OnButadd)
ON_BN_CLICKED(IDC_BUTDEL, OnButdel)
ON_BN_CLICKED(IDC_BUTMODIFY, OnButmodify)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
ON_WM_CTLCOLOR()
ON_CBN_KILLFOCUS(IDC_COMBO1, OnKillfocusCombo1)
ON_CBN_SETFOCUS(IDC_COMBO1, OnSetfocusCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSDlg message handlers
void CSDlg::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 CSDlg::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
{
CPaintDC dc(this);
CRect rect;
m_brush.CreateSolidBrush(RGB(227,243,251));
GetClientRect(&rect);
dc.FillRect(rect,&m_brush);
m_brush.DeleteObject();
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CSDlg::OnCancel()
{
// TODO: Add extra cleanup here
//m_Recordset->MoveFirst;
//CDialog::OnCancel();
}
void CSDlg::OnBuexit()
{
CDialog::OnOK();
}
Fields * CSDlg::GetField(_RecordsetPtr m_Recordset1)
{
FieldsPtr pFields;
ASSERT(m_Recordset1 != NULL);
try
{
if (SUCCEEDED(m_Recordset1->get_Fields(&pFields)))
{
return pFields;
}
}
catch (_com_error e)
{
TRACE(_T(":( GetField发生错误: %s\n"), e.ErrorMessage());
return NULL;
}
return NULL;
}
BOOL CSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_combo1.AddString("男");
m_combo1.AddString("女");
SetWindowText("苏永健毕业作品__VC制作");
if(OpenDatabase())
{
ShowEditData();
}
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
COLORREF m_backcolor,m_textcolor2;
m_textcolor2=RGB(0,0,0);
m_backcolor=RGB(237,221,251);
m_static1.SetBackColor(m_backcolor);
m_static1.SetTextColor(m_textcolor2,title[0]);
m_static2.SetBackColor(m_backcolor);
m_static2.SetTextColor(m_textcolor2,title[1]);
m_static3.SetBackColor(m_backcolor);
m_static3.SetTextColor(m_textcolor2,title[2]);
m_static4.SetBackColor(m_backcolor);
m_static4.SetTextColor(m_textcolor2,title[3]);
m_static5.SetBackColor(m_backcolor);
m_static5.SetTextColor(m_textcolor2,title[4]);
m_static6.SetBackColor(m_backcolor);
m_static6.SetTextColor(m_textcolor2,title[5]);
m_static7.SetBackColor(m_backcolor);
m_static7.SetTextColor(m_textcolor2,title[6]);
m_static8.SetBackColor(m_backcolor);
m_static8.SetTextColor(m_textcolor2,title[7]);
m_static9.SetBackColor(m_backcolor);
m_static9.SetTextColor(m_textcolor2,title[8]);
m_static10.SetBackColor(m_backcolor);
m_static10.SetTextColor(m_textcolor2,title[9]);
m_static11.SetBackColor(m_backcolor);
m_static11.SetTextColor(m_textcolor2,title[10]);
m_static12.SetBackColor(m_backcolor);
m_static12.SetTextColor(m_textcolor2,title[11]);
m_static13.SetBackColor(m_backcolor);
m_static13.SetTextColor(m_textcolor2,title[12]);
m_static14.SetBackColor(m_backcolor);
m_static14.SetTextColor(m_textcolor2,title[13]);
m_static15.SetBackColor(m_backcolor);
m_static15.SetTextColor(m_textcolor2,title[14]);
m_static16.SetBackColor(m_backcolor);
m_static16.SetTextColor(m_textcolor2,title[15]);
m_staticall.SetBackColor(RGB(237,221,251));
m_staticall.SetTextColor(m_textcolor2,"个人情况");
m_staticall2.SetBackColor(RGB(237,221,251));
// m_staticall2.SetTextColor(m_textcolor2,"个人情况");
return TRUE;
}
BOOL CSDlg::OpenDatabase()
{
m_Recordset.CreateInstance(__uuidof(Recordset));
try
{
m_Recordset->Open("select * from s1",theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
if(m_Recordset->adoEOF)
{
AfxMessageBox("数据库为空,请添加后在操作");
return false;
}
return true;
}
void CSDlg::SetEditdata(stitle m_stitle)
{
m_edit1.SetWindowText(m_stitle.name1);
m_edit2.SetWindowText(m_stitle.name2);
m_edit3.SetWindowText(m_stitle.name3);
if(strcmp(m_stitle.name3,"男")==0) m_combo1.SetCurSel(0);
if(strcmp(m_stitle.name3,"女")==0) m_combo1.SetCurSel(1);
m_edit4.SetWindowText(m_stitle.name4);
m_edit5.SetWindowText(m_stitle.name5);
m_edit6.SetWindowText(m_stitle.name6);
m_edit7.SetWindowText(m_stitle.name7);
m_edit8.SetWindowText(m_stitle.name8);
m_edit9.SetWindowText(m_stitle.name9);
m_edit10.SetWindowText(m_stitle.name10);
m_edit11.SetWindowText(m_stitle.name11);
m_edit12.SetWindowText(m_stitle.name12);
m_edit13.SetWindowText(m_stitle.name13);
m_edit14.SetWindowText(m_stitle.name14);
m_edit15.SetWindowText(m_stitle.name15);
m_edit16.SetWindowText(m_stitle.name16);
}
stitle CSDlg::GetEditData()
{
stitle m_stitle;
m_combo1.GetWindowText(m_stitle.name3);
// AfxMessageBox(dd);
m_edit1.GetWindowText(m_stitle.name1);
m_edit2.GetWindowText(m_stitle.name2);
// m_edit3.GetWindowText(m_stitle.name3);
m_edit4.GetWindowText(m_stitle.name4);
m_edit5.GetWindowText(m_stitle.name5);
m_edit6.GetWindowText(m_stitle.name6);
m_edit7.GetWindowText(m_stitle.name7);
m_edit8.GetWindowText(m_stitle.name8);
m_edit9.GetWindowText(m_stitle.name9);
m_edit10.GetWindowText(m_stitle.name10);
m_edit11.GetWindowText(m_stitle.name11);
m_edit12.GetWindowText(m_stitle.name12);
m_edit13.GetWindowText(m_stitle.name13);
m_edit14.GetWindowText(m_stitle.name14);
m_edit15.GetWindowText(m_stitle.name15);
m_edit16.GetWindowText(m_stitle.name16);
return m_stitle;
}
stitle CSDlg::SetListtostitle(CStringList &m_list)
{
stitle m_stitle;
m_stitle.name1=m_list.GetAt(m_list.FindIndex(15));
m_stitle.name2=m_list.GetAt(m_list.FindIndex(14));
m_stitle.name3=m_list.GetAt(m_list.FindIndex(13));
m_stitle.name4=m_list.GetAt(m_list.FindIndex(12));
m_stitle.name5=m_list.GetAt(m_list.FindIndex(11));
m_stitle.name6=m_list.GetAt(m_list.FindIndex(10));
m_stitle.name7=m_list.GetAt(m_list.FindIndex(9));
m_stitle.name8=m_list.GetAt(m_list.FindIndex(8));
m_stitle.name9=m_list.GetAt(m_list.FindIndex(7));
m_stitle.name10=m_list.GetAt(m_list.FindIndex(6));
m_stitle.name11=m_list.GetAt(m_list.FindIndex(5));
m_stitle.name12=m_list.GetAt(m_list.FindIndex(4));
m_stitle.name13=m_list.GetAt(m_list.FindIndex(3));
m_stitle.name14=m_list.GetAt(m_list.FindIndex(2));
m_stitle.name15=m_list.GetAt(m_list.FindIndex(1));
m_stitle.name16=m_list.GetAt(m_list.FindIndex(0));
return m_stitle;
}
void CSDlg::OnButfirst()
{
if(m_Recordset->adoEOF)
{
AfxMessageBox("数据库为空");
return;
}
m_Recordset->MoveFirst();
m_butnext.EnableWindow(true);
m_butlast.EnableWindow(true);
m_butup.EnableWindow(false);
m_butfirst.EnableWindow(false);
ShowEditData();
}
void CSDlg::OnButup()
{
if(m_Recordset->adoEOF)
{
AfxMessageBox("数据库为空");
return;
}
m_Recordset->MovePrevious();
if(m_Recordset->BOF)
{
m_Recordset->MoveFirst();
m_butup.EnableWindow(false);
m_butfirst.EnableWindow(false);
}
m_butnext.EnableWindow(true);
m_butlast.EnableWindow(true);
ShowEditData();
}
void CSDlg::OnButnext()
{
if(m_Recordset->adoEOF)
{
AfxMessageBox("数据库为空");
return;
}
m_Recordset->MoveNext();
if(m_Recordset->adoEOF)
{
m_Recordset->MoveLast();
m_butnext.EnableWindow(false);
m_butlast.EnableWindow(false);
}
m_butup.EnableWindow(true);
m_butfirst.EnableWindow(true);
ShowEditData();
}
void CSDlg::OnButlast()
{
if(m_Recordset->adoEOF)
{
AfxMessageBox("数据库为空");
return;
}
m_Recordset->MoveLast();
m_butup.EnableWindow(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -