📄 systemview.cpp
字号:
// SystemView.cpp : implementation of the CSystemView class
//
#include "stdafx.h"
#include "System.h"
#include "MainFrm.h"
#include "SystemSet.h"
#include "SystemDoc.h"
#include "SystemView.h"
#include "adduser.h"
#include "upassword.h"
#include "deluser.h"
#include "alteradpass.h"
#include "alteradpaset.h"
#include "upasschange.h"
#include "utime.h"
#include "adpass.h"
#include "kanallDlg.h"
#include "delsnoDlg.h"
#include "useralltimeDlg.h"
#include "dalltimeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSystemView
IMPLEMENT_DYNCREATE(CSystemView, CRecordView)
BEGIN_MESSAGE_MAP(CSystemView, CRecordView)
//{{AFX_MSG_MAP(CSystemView)
ON_BN_CLICKED(IDC_ADDUSER, OnAdduser)
ON_BN_CLICKED(IDC_DELUSER, OnDeluser)
ON_BN_CLICKED(IDC_ADCHANGE, OnAdchange)
ON_BN_CLICKED(IDC_ZHUXIAO, OnZhuxiao)
ON_BN_CLICKED(IDC_CHONGQI, OnChongqi)
ON_BN_CLICKED(IDC_SHUTDOWN, OnShutdown)
ON_BN_CLICKED(IDC_UCHANGEPASS, OnUchangepass)
ON_BN_CLICKED(IDC_DENGLU, OnDenglu)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_TIMECHA, OnTimecha)
ON_COMMAND(IDC_KANALL, OnKanall)
ON_BN_CLICKED(IDC_KILLTIME, OnKilltime)
ON_COMMAND(IDC_DELJILU, OnDeljilu)
ON_COMMAND(IDC_DALLTIME, OnDalltime)
ON_COMMAND(IDC_UCHANGEPASS, OnUchangepass)
ON_COMMAND(IDC_ADDUSER, OnAdduser)
ON_COMMAND(IDC_USERALLTIME, OnUseralltime)
//}}AFX_MSG_MAP
//ON_WM_SYSCOMMAND()///托盘
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_NOTIFYICON, OnNotifyIcon)///托盘
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSystemView construction/destruction
CSystemView::CSystemView()
: CRecordView(CSystemView::IDD)
{
//{{AFX_DATA_INIT(CSystemView)
m_pSet = NULL;
m_dusno = _T("");
m_dupass = _T("");
m_time = _T("");
m_chasno = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
flag1=false;
m_position=true;
hour=minute=second=0;
hour1=minute1=second1=0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CSystemView::~CSystemView()
{
}
void CSystemView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSystemView)
DDX_Text(pDX, IDC_DUSNO, m_dusno);
DDX_Text(pDX, IDC_DUPASS, m_dupass);
DDX_Control(pDX, IDC_MSFLEXGRID1, m_MSFGird);
DDX_Text(pDX, IDC_TIME, m_time);
DDX_Text(pDX, IDC_CDASNO, m_chasno);
DDX_Control(pDX, IDC_MSFLEXGRID2, m_MSFGrid);
//}}AFX_DATA_MAP
}
BOOL CSystemView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CSystemView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_systemSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
SetIcon(m_hIcon, TRUE); // Set big icon//托盘
SetIcon(m_hIcon, FALSE); // Set small icon//托盘
NOTIFYICONDATA nd;//托盘
nd.cbSize = sizeof (NOTIFYICONDATA);
nd.hWnd = m_hWnd;
nd.uID = IDI_ICON;
nd.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
nd.uCallbackMessage = WM_NOTIFYICON;
nd.hIcon= m_hIcon;
strcpy(nd.szTip, "学生登录管理系统");
Shell_NotifyIcon(NIM_ADD, &nd);//托盘
CMainFrame *pFrame=(CMainFrame *)AfxGetApp()->GetMainWnd();
pFrame->SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//窗口在最前面
utime utime;
utime.Open();
utime.MoveFirst();
while(!utime.IsEOF()){
utime.MoveNext();
utime.GetRecordCount();
}
utime.MoveFirst();
m_MSFGird.SetCols(utime.m_nFields+1);
m_MSFGird.SetRows(utime.GetRecordCount()+1);
//m_MSFGird.SetColWidth(-1,400);
m_MSFGird.SetColWidth(1,1000);
m_MSFGird.SetColWidth(2,800);
m_MSFGird.SetColWidth(3,1800);
m_MSFGird.SetColWidth(4,1800);
m_MSFGird.SetColWidth(5,1400);
m_MSFGird.SetRow(0);
m_MSFGird.SetCol(1);
m_MSFGird.SetText("学号");
m_MSFGird.SetRow(0);
m_MSFGird.SetCol(2);
m_MSFGird.SetText("姓名");
m_MSFGird.SetRow(0);
m_MSFGird.SetCol(3);
m_MSFGird.SetText("登录时间");
m_MSFGird.SetRow(0);
m_MSFGird.SetCol(4);
m_MSFGird.SetText("注销时间");
m_MSFGird.SetRow(0);
m_MSFGird.SetCol(5);
m_MSFGird.SetText("本次登录时间");
upassword upass;
upass.Open();
upass.MoveFirst();
while(!upass.IsEOF()){
upass.MoveNext();
upass.GetRecordCount();
}
upass.MoveFirst();
m_MSFGrid.SetCols(upass.m_nFields);
m_MSFGrid.SetRows(upass.GetRecordCount()+1);
m_MSFGrid.SetColWidth(1,1200);
m_MSFGrid.SetColWidth(2,1100);
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(1);
m_MSFGrid.SetText("学号");
m_MSFGrid.SetRow(0);
m_MSFGrid.SetCol(2);
m_MSFGrid.SetText("姓名");
int iRow=1;
while(!upass.IsEOF())
{
CString str;
str.Format("记录%d",iRow);
m_MSFGrid.SetRow(iRow);
m_MSFGrid.SetCol(0);
m_MSFGrid.SetText(str);
m_MSFGrid.SetRow(iRow);
m_MSFGrid.SetCol(1);
m_MSFGrid.SetText(upass.m_usno);
m_MSFGrid.SetRow(iRow);
m_MSFGrid.SetCol(2);
m_MSFGrid.SetText(upass.m_uname);
iRow++;
upass.MoveNext();
}
m_MSFGrid.SetRow(1);
m_MSFGrid.SetCol(1);
upass.MoveFirst();
}
/////////////////////////////////////////////////////////////////////////////
// CSystemView printing
BOOL CSystemView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSystemView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSystemView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSystemView diagnostics
#ifdef _DEBUG
void CSystemView::AssertValid() const
{
CRecordView::AssertValid();
}
void CSystemView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CSystemDoc* CSystemView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSystemDoc)));
return (CSystemDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSystemView database support
CRecordset* CSystemView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CSystemView message handlers
void CSystemView::OnAdduser()
{
upassword m_pSet1;
CRecordsetStatus status;
status.m_lCurrentRecord=0;
adduser dlg;
adpass maindlg;
m_pSet1.Open();
//m_pSet1.MoveFirst();
if(maindlg.DoModal()==IDOK)
{
if(maindlg.m_adpassnum==m_pSet->m_apassword)
{
if(dlg.DoModal()==IDOK)
{
m_pSet1.AddNew();
m_pSet1.m_uname=dlg.m_addname;
m_pSet1.m_upassword=dlg.m_addpassword;
m_pSet1.m_usno=dlg.m_addsno;
m_pSet1.Update();
m_pSet1.Requery();
MessageBox("添加记录成功!");
m_pSet1.Close();
}
}
else
MessageBox("管理员口令不对,请重新输入!");
}
// TODO: Add your control notification handler code here
}
void CSystemView::OnDeluser()
{
CRecordsetStatus status;
deluser dlg;
adpass maindlg;
upassword deluser;
deluser.Open();
deluser.MoveFirst();
status.m_lCurrentRecord=0;
if(maindlg.DoModal()==IDOK)
{
if(maindlg.m_adpassnum==m_pSet->m_apassword)
{
if(dlg.DoModal()==IDOK)
{
for( status.m_lCurrentRecord=0; status.m_lCurrentRecord<deluser.GetRecordCount();status.m_lCurrentRecord++)
{
if(dlg.m_delsno==deluser.m_usno&&dlg.m_delname==deluser.m_uname)
{
deluser.Delete();
MessageBox("成功删除用户!");
break;
}
else
deluser.MoveNext();
}
if(status.m_lCurrentRecord==deluser.GetRecordCount()-1)
MessageBox("你要删除的用户并不存在!");
}
}
else
MessageBox("管理员口令不对,请重新输入!");
}
// TODO: Add your control notification handler code here
}
void CSystemView::OnAdchange()
{
alteradpass dlg;
alteradpaset alterset;
alterset.Open();
if(dlg.DoModal()==IDOK)
{
UpdateData();
if(dlg.m_newpassword==dlg.m_newpass)
{
if(dlg.m_oldpassword==alterset.m_apassword)
{
alterset.Edit();
alterset.m_apassword=dlg.m_newpassword;
alterset.Update();
alterset.Requery();
MessageBox("修改口令成功!");
}
}
else
{
MessageBox("你两次输入的口令不相同,请重新输入!");
}
}
// TODO: Add your control notification handler code here
}
void CSystemView::OnZhuxiao()
{
//double time1;
int temph;
int tempm;
int temps;
temph=tempm=temps=0;
utime utime;
utime.Open();
utime.MoveLast();
CTime Time = CTime::GetCurrentTime();
hour1=Time.GetHour();
minute1=Time.GetMinute();
tempm=abs(minute1-minute);
if(minute1>minute)
temph=(hour1-hour)*60+tempm;
else
temph=(hour1-hour)*60-tempm;
utime.Edit();
utime.m_ztime=Time;
utime.m_total=temph;
utime.Update();
utime.Requery();
utime.Close();
//隐藏图标
NOTIFYICONDATA nd;//托盘
nd.cbSize = sizeof (NOTIFYICONDATA);
nd.hWnd = m_hWnd;
Shell_NotifyIcon(NIM_DELETE, &nd);//托盘
MessageBox("你确定注销当前用户吗?");
ExitWindowsEx(EWX_LOGOFF,0);
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -