📄 物业管理系统dlg.cpp
字号:
// 物业管理系统Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "物业管理系统.h"
#include "物业管理系统Dlg.h"
#include"Xinzeng.h"
#include"Xiougai.h"
#include"Shanchu.h"
#include"Tongji.h"
#include"Denglu.h"
#include"Inf.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
// 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);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_LIST1, m_Mylist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, Onxinzeng)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
DWORD dwStyle=::GetWindowLong(m_Mylist.m_hWnd,GWL_STYLE);
SetWindowLong(m_Mylist.m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT);
DWORD ExStyle=m_Mylist.GetExtendedStyle();
m_Mylist.SetExtendedStyle(ExStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_Mylist.InsertColumn(0,"用户名",LVCFMT_CENTER,120,0);
m_Mylist.InsertColumn(1,"月份",LVCFMT_CENTER,90,0);
m_Mylist.InsertColumn(2,"管理费",LVCFMT_CENTER,120,0);
m_Mylist.InsertColumn(3,"水费",LVCFMT_CENTER,110,0);
CInf recordset;
CString strSQL;
strSQL.Format("select * from inf");
if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据失败!");
}
int i=0,n=1;
CString str;
int ipos;
while(!recordset.IsEOF())
{
str.Format("%d",n);
ipos=m_Mylist.InsertItem(n,recordset.m_name);
m_Mylist.SetItemText(ipos,1,recordset.m_month);
m_Mylist.SetItemText(ipos,2,recordset.m_mang);
m_Mylist.SetItemText(ipos,3,recordset.m_water);
i++;
n++;
recordset.MoveNext();
}
recordset.Close();
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::Onxinzeng()
{
// TODO: Add your control notification handler code here
CXinzeng d;
d.DoModal();
}
void CMyDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CXiougai d;
d.DoModal();
}
void CMyDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CShanchu d;
d.DoModal();
}
void CMyDlg::OnButton6()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
void CMyDlg::OnButton5()
{
// TODO: Add your control notification handler code here
CTongji d;
d.DoModal();
}
void ReGISterDBSource(CString strDSName, CString strDBPath);
int CMyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CString sExcelFile,sPath;
CString se;
CString sSql;
//获取主程序所在路径,存在sPath中
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos);
sExcelFile = sPath + "\\物业管理系统.mdb";
ReGISterDBSource("wuye",sExcelFile);
CDenglu d;
if(d.DoModal()!=IDOK)
return -1;
return 0;
}
void ReGISterDBSource(CString strDSName, CString strDBPath)
{
HKEY hKey;
DWORD nLabel;
CString strBaseKey = _T("SOFTWARE\\ODBC\\ODBC.INI");
CString strMid = strBaseKey + _T("\\ODBC Data Sources") ;
if(strDSName.IsEmpty()) return;
if(strDBPath.IsEmpty()) return;
CString strDataSource = strBaseKey + _T("\\") + strDSName;
CString strMdb = _T("Microsoft Access Driver (*.mdb)");
CString strDBDriver = _T("C:\\WINNT\\System32\\odbcjt32.dll");
CString strFIL = _T("Ms Access;");
CString strUID = _T("");
RegCreateKeyEx(HKEY_CURRENT_USER,
strMid,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&nLabel );//获取数据源键值句柄
RegSetValueEx(hKey,
strDSName,
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)strMdb),
strlen((LPCTSTR)strMdb)+1);///设置数据源类型
RegCreateKeyEx(HKEY_CURRENT_USER,
strDataSource,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&nLabel );//创建数据源子键
RegSetValueEx(hKey,
_T("DBQ"),
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)strDBPath),
strlen((LPCTSTR)strDBPath)+1);//数据库表的全路径
RegSetValueEx(hKey,
_T("Driver"),
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)strDBDriver),
strlen((LPCTSTR)strDBDriver)+1);//ODBC驱动的全路径
RegSetValueEx(hKey,
_T("FIL"),
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)strFIL),
strlen((LPCTSTR)strFIL)+1);//表的类型
RegSetValueEx(hKey,
_T("UID"),
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)strUID),
strlen((LPCTSTR)strUID)+1);//必须项
DWORD DriverId = (DWORD)25;
RegSetValueEx(hKey,
_T("DriverId"),
0,
REG_DWORD,
(const BYTE *)(&DriverId),
sizeof(DWORD));//必须项
DWORD SafeTrans = (DWORD)0;
RegSetValueEx(hKey,
_T("SafeTransactions"),
0,
REG_DWORD,
(const BYTE *)(&SafeTrans),
sizeof(DWORD));//可选项
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -