📄 overtime.cpp
字号:
// Overtime.cpp : implementation file
//
#include "stdafx.h"
#include "Practical.h"
#include "Overtime.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr m_pConnection; //连接对象指针
extern _RecordsetPtr m_pRecordset; //记录集对象指针
/////////////////////////////////////////////////////////////////////////////
// COvertime dialog
COvertime::COvertime(CWnd* pParent /*=NULL*/)
: CDialog(COvertime::IDD, pParent)
{
//{{AFX_DATA_INIT(COvertime)
//}}AFX_DATA_INIT
}
void COvertime::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COvertime)
DDX_Control(pDX, IDC_DATE, m_Time);
DDX_Control(pDX, IDC_BUTOK, m_Ok);
DDX_Control(pDX, IDC_BUTCLOSE, m_Close);
DDX_Control(pDX, IDC_LIST2, m_Jbyg);
DDX_Control(pDX, IDC_LIST1, m_Gsyg);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COvertime, CDialog)
//{{AFX_MSG_MAP(COvertime)
ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
ON_COMMAND(ID_MENUREFURBISH, OnMenurefurbish)
ON_COMMAND(ID_MENUCLEAR, OnMenuclear)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_WM_TIMER()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COvertime message handlers
BOOL COvertime::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CTime time;
time=time.GetCurrentTime();
CString stime;
stime.Format("%s",time.Format("%Y-%m-%d %H:%M:%S"));
m_Time.SetWindowText(stime);
SetTimer(1,1000,NULL);
GetPrivateProfileString("文件路径","路径","default",m_Buffer,512,"./Client.ini");
m_FilePath.Format("%s%s",m_Buffer,"Practical.ini");
m_ImageList.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_Gsyg.SetImageList(&m_ImageList,LVSIL_NORMAL);
m_Jbyg.SetImageList(&m_ImageList,LVSIL_NORMAL);
CString sql = "select * from tb_employes";
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
int i=0,n=0;
char buf[128];
while(!m_pRecordset->adoEOF)
{
CString sex,name,str;
sex = (char*)(_bstr_t)m_pRecordset->GetCollect("性别");
name = (char*)(_bstr_t)m_pRecordset->GetCollect("姓名");
if(sex == "男")
{
m_Gsyg.InsertItem(i,name,1);
int j = 0,N = 0;
while(N!=7)
{
str.Format("%d",j+1);
N = GetPrivateProfileString("加班名单",str,"default",buf,128,m_FilePath);
if(N!=7)
{
if(name == buf)
{
m_Jbyg.InsertItem(j,buf,1);
n++;
}
j++;
}
}
}
else
{
m_Gsyg.InsertItem(i,name,0);
int j = 0,N = 0;
while(N!=7)
{
str.Format("%d",j+1);
N = GetPrivateProfileString("加班名单",str,"default",buf,128,m_FilePath);
if(N!=7)
{
if(name == buf)
{
m_Jbyg.InsertItem(j,buf,0);
n++;
}
j++;
}
}
}
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
m_Menu.LoadMenu(IDR_MENU1);
CString nstr;
nstr.Format("员工总人数:%d",i);
m_ToolTip.Create(this);
m_ToolTip.SetDelayTime(1000);
m_ToolTip.SetMaxTipWidth(300);
m_ToolTip.AddTool(GetDlgItem(IDC_LIST1),nstr);
m_Text.Format("加班人数:%d",n);
m_ToolTip.AddTool(GetDlgItem(IDC_LIST2),m_Text);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL COvertime::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_ToolTip.RelayEvent(pMsg);
CPoint point;
if(pMsg->message == WM_RBUTTONUP)
{
CMenu* pPopup = m_Menu.GetSubMenu(0);
CRect rc;
GetCursorPos(&point);
rc.top=point.x;
rc.left=point.y;
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,rc.top
,rc.left,this,&rc);
}
if(pMsg->message == WM_LBUTTONDOWN)
{
CRect rect,rc;
m_Ok.GetWindowRect(&rect);
m_Close.GetWindowRect(&rc);
GetCursorPos(&point);
if(rect.PtInRect(point))
{
CString str,name;
char buf[128];
int i=0,j;
DWORD N;
j = m_Gsyg.GetSelectionMark();
name = m_Gsyg.GetItemText(j,0);
while(N!=7)
{
str.Format("%d",i+1);
N = GetPrivateProfileString("加班名单",str,"default",buf,128,m_FilePath);
if(buf == name)
{
MessageBox("你已经填写过加班信息!");
return false;
}
if(N!=7)
{
i++;
}
}
if(MessageBox(name+":请确定你是否加班!","加班信使服务",MB_YESNO)==IDYES)
{
str.Format("%d",i+1);
WritePrivateProfileString(_T("加班名单"),_T(str),_T(name),_T(m_FilePath));
CString sql;
sql.Format("select * from tb_employes where 姓名='%s'",name);
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
CString sex = (char*)(_bstr_t)m_pRecordset->GetCollect("性别");
if(sex == "男")
m_Jbyg.InsertItem(i,name,1);
else
m_Jbyg.InsertItem(i,name,0);
}
m_pRecordset->Close();
}
m_Text.Format("加班人数:%d",i+1);
m_ToolTip.UpdateTipText(m_Text,GetDlgItem(IDC_LIST2));
}
else if(rc.PtInRect(point))
{
CDialog::OnCancel();
}
m_Gsyg.SetFocus();
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
}
return CDialog::PreTranslateMessage(pMsg);
}
void COvertime::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString str,name;
int i,j;
j = m_Jbyg.GetSelectionMark();
name = m_Jbyg.GetItemText(j,0);
if(MessageBox(name+":请确定是否取消加班!","加班信使服务",MB_YESNO)==IDYES)
{
char server[32];
GetPrivateProfileString("服务器", "机器名", "", server,32,"./Client.ini");
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name;
Name = Buffer;
if(Name == server)
{
m_Jbyg.DeleteItem(j);
CFile file;
file.Open(m_FilePath,CFile::modeCreate|CFile::modeWrite);
CString str="[加班名单]";
file.Write(str,str.GetLength());
file.Close();
for(i=0;i<m_Jbyg.GetItemCount();i++)
{
str.Format("%d",i+1);
name = m_Jbyg.GetItemText(i,0);
WritePrivateProfileString(_T("加班名单"),_T(str),_T(name),_T(m_FilePath));
}
}
else
{
MessageBox("对不起,你没有足够权限清除加班信息!", "注意");
return;
}
}
m_Jbyg.UpdateWindow();
m_Text.Format("加班人数:%d",i);
m_ToolTip.UpdateTipText(m_Text,GetDlgItem(IDC_LIST2));
*pResult = 0;
}
void COvertime::OnMenurefurbish()
{
// TODO: Add your command handler code here
m_Jbyg.DeleteAllItems();
CString str;
char buf[128];
int i=0;
DWORD N;
while(N!=7)
{
str.Format("%d",i+1);
N = GetPrivateProfileString("加班名单",str,"default",buf,128,m_FilePath);
CString sql;
sql.Format("select * from tb_employes where 姓名='%s'",buf);
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
CString sex = (char*)(_bstr_t)m_pRecordset->GetCollect("性别");
if(sex == "男")
m_Jbyg.InsertItem(i,buf,1);
else
m_Jbyg.InsertItem(i,buf,0);
}
m_pRecordset->Close();
if(N!=7)
{
i++;
}
}
}
void COvertime::OnMenuclear()
{
// TODO: Add your command handler code here
if(MessageBox("请确定是否清空加班名单!","加班信使服务",MB_YESNO)==IDYES)
{
char server[32];
GetPrivateProfileString("服务器", "机器名", "", server,32,"./Client.ini");
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name;
Name = Buffer;
if(Name == server)
{
CFile file;
file.Open(m_FilePath,CFile::modeCreate|CFile::modeWrite);
CString str="[加班名单]";
file.Write(str,str.GetLength());
file.Close();
m_Jbyg.DeleteAllItems();
}
else
{
MessageBox("对不起,你没有足够权限清除加班信息!", "注意");
return;
}
m_Text.Format("加班人数:%d",0);
m_ToolTip.UpdateTipText(m_Text,GetDlgItem(IDC_LIST2));
}
}
void COvertime::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString str,name;
char buf[128];
int i=0,j;
DWORD N;
j = m_Gsyg.GetSelectionMark();
name = m_Gsyg.GetItemText(j,0);
while(N!=7)
{
str.Format("%d",i+1);
N = GetPrivateProfileString("加班名单",str,"default",buf,128,m_FilePath);
if(buf == name)
{
MessageBox("你已经填写过加班信息!");
return;
}
if(N!=7)
{
i++;
}
}
if(MessageBox(name+":请确定你是否加班!","加班信使服务",MB_YESNO)==IDYES)
{
str.Format("%d",i+1);
WritePrivateProfileString(_T("加班名单"),_T(str),_T(name),_T(m_FilePath));
CString sql;
sql.Format("select * from tb_employes where 姓名='%s'",name);
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open((_bstr_t)sql,m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
CString sex = (char*)(_bstr_t)m_pRecordset->GetCollect("性别");
if(sex == "男")
m_Jbyg.InsertItem(i,name,1);
else
m_Jbyg.InsertItem(i,name,0);
}
m_pRecordset->Close();
}
m_Text.Format("加班人数:%d",i+1);
m_ToolTip.UpdateTipText(m_Text,GetDlgItem(IDC_LIST2));
m_Gsyg.SetFocus();
*pResult = 0;
}
void COvertime::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime time;
time=time.GetCurrentTime();
CString stime;
stime.Format("%s",time.Format("%Y-%m-%d %H:%M:%S"));
m_Time.SetWindowText(stime);
CDialog::OnTimer(nIDEvent);
}
HBRUSH COvertime::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkColor(RGB(255,255,255));
pDC->SetTextColor(RGB(0,0,255));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -