📄 finalhomeworkdlg.cpp
字号:
// FINALHOMEWORKDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FINALHOMEWORK.h"
#include "FINALHOMEWORKDlg.h"
#include "DlgA.h"
#include "DlgB.h"
#include "DlgC.h"
#include "DlgD.h"
#include "DlgE.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()
/////////////////////////////////////////////////////////////////////////////
// CFINALHOMEWORKDlg dialog
CFINALHOMEWORKDlg::CFINALHOMEWORKDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFINALHOMEWORKDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFINALHOMEWORKDlg)
m_password = _T("");
m_user = _T("");
InfN=0;
m_jobN = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFINALHOMEWORKDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFINALHOMEWORKDlg)
DDX_Control(pDX, IDC_COMBOJOB, m_job);
DDX_Text(pDX, IDC_TPASSWORD, m_password);
DDX_Text(pDX, IDC_TUSER, m_user);
DDX_CBIndex(pDX, IDC_COMBOJOB, m_jobN);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFINALHOMEWORKDlg, CDialog)
//{{AFX_MSG_MAP(CFINALHOMEWORKDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_TUSER, OnChangeTuser)
ON_EN_CHANGE(IDC_TPASSWORD, OnChangeTpassword)
ON_BN_CLICKED(IDC_BLOGIN, OnBlogin)
ON_CBN_SELCHANGE(IDC_COMBOJOB, OnSelchangeCombojob)
ON_BN_CLICKED(IDC_QUIT, OnQuit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFINALHOMEWORKDlg message handlers
BOOL CFINALHOMEWORKDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CFINALHOMEWORKDlg::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 CFINALHOMEWORKDlg::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 CFINALHOMEWORKDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFINALHOMEWORKDlg::OnSelchangeCombojob()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFINALHOMEWORKDlg::OnChangeTuser()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFINALHOMEWORKDlg::OnChangeTpassword()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFINALHOMEWORKDlg::OnBlogin()
{
// TODO: Add your control notification handler code here
FILE *fp;
switch(m_jobN+1)
{
case 1:
fp=fopen("DataN1.dat","r");
break;
case 2:
fp=fopen("DataN2.dat","r");
break;
case 3:
fp=fopen("DataN3.dat","r");
break;
case 4:
fp=fopen("DataN4.dat","r");
break;
case 5:
fp=fopen("DataN5.dat","r");
break;
}
fscanf(fp,"%d",&InfN);
fclose(fp);
/*-------------将数据读出来一边检查要注册的帐号是否已注册--------------*/
switch(m_jobN+1)
{
case 1:
fp=fopen("Data1.dat","r");
break;
case 2:
fp=fopen("Data2.dat","r");
break;
case 3:
fp=fopen("Data3.dat","r");
break;
case 4:
fp=fopen("Data4.dat","r");
break;
case 5:
fp=fopen("Data5.dat","r");
break;
}
for(int i=0;i<InfN;i++)
{
// fscanf(fp,"%d",&information[i].JobN);
fscanf(fp,"%s",m_temp);
information[i].user=m_temp;
fscanf(fp,"%s",m_temp);
information[i].password=m_temp;
// fscanf(fp,"%s",m_temp);//无实际意义
}
fclose(fp);
if(InfN!=0)
{
for(int i=0;i<InfN;i++)
{
if((information[i].user==m_user)&&(information[i].password==m_password))
{
if(m_jobN==0){ //系统管理员信息窗口
CDlgA dlga;
dlga.DoModal();
}
else if(m_jobN==1){//项目管理员信息窗口
CDlgB dlgb;
dlgb.DoModal();
}
else if(m_jobN==2){//总经理信息窗口
CDlgC dlgc;
dlgc.DoModal();
}
else if(m_jobN==3){//项目经理信息窗口
CDlgD dlgd;
dlgd.DoModal();
}
else if(m_jobN==4){//项目组员信息窗口
CDlgE dlge(m_user);
dlge.DoModal();
}
break;
}
}
if(i==InfN)
{
AfxMessageBox("用户名或密码错误",MB_OK,-1);
}
}
else
{
AfxMessageBox("用户名或密码错误",MB_OK,-1);
}
}
/*void CFINALHOMEWORKDlg::OnBreg()
{
// TODO: Add your control notification handler code here
FILE *fp;
int flag=0;//flag为1时表示要注册帐号已存在,否则为不存在
//-------------将数据读出来一边检查要注册的帐号是否已注册--------------
fp=fopen("DataN.txt","r");
fscanf(fp,"%d",&InfN);
fclose(fp);
fp=fopen("Data.txt","r");
for(int i=0;i<InfN;i++)
{
fscanf(fp,"%d",&information[i].JobN);
fscanf(fp,"%s",m_temp);
information[i].user=m_temp;
fscanf(fp,"%s",m_temp);
information[i].password=m_temp;
// fscanf(fp,"%s",m_temp);//无实际意义
}
fclose(fp);
if(InfN!=0)
{
if(m_jobN!=0)
{
for(int i=0;i<InfN;i++)
{
if((information[i].user==m_user)&&(information[i].JobN==m_jobN))//检查用户名
{
flag=1;
AfxMessageBox("此类别注册名已存在",MB_OK,-1);
break;
}
}
}
else
{
AfxMessageBox("系统管理员只能有一个",MB_OK,-1);
}
}
////////////////////////////////////////////////////////////////
if(flag==0)//若注册数据不存在
{
fp=fopen("Data.txt","a");
fprintf(fp,"%d\n",m_jobN);
fprintf(fp,"%s\n",m_user);
fprintf(fp,"%s\n",m_password);
// fprintf(fp,"///////////////////////////");//画出分割标志
fclose(fp);
InfN++;
fp=fopen("DataN.txt","w+");
fprintf(fp,"%d",InfN);
fclose(fp);
}
}*/
void CFINALHOMEWORKDlg::OnQuit()
{
// TODO: Add your control notification handler code here
DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -