⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setreminddlg2.cpp

📁 这是一个学生信息管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		    m_pSet.m_strFilter .Empty ();
		    m_pSet.Requery ();
	        if(m_pSet.GetRecordCount ()==0)
			{
				m_pSet.Close ();
				EndWaitCursor();
				return ;
			}
			m_pSet.MoveFirst ();
	        while (!m_pSet.IsEOF ())
			{
				//在这里来判断可以轻松地跳过CTime与CString的差别
				StartDate=DateToString(m_pSet.m_rStartDate) ;
				EndDate=DateToString(m_pSet.m_rEndDate) ;
			    if(StartDate<=SearchTime&&EndDate>=SearchTime)
			    {
					m_cRemindListCtrl.InsertItem(i,m_pSet.m_rContent ,0);
					m_cRemindListCtrl.SetItemText (i,1,FormatDate(m_pSet.m_rStartDate ));
					m_cRemindListCtrl.SetItemText (i,2,FormatDate(m_pSet.m_rEndDate ));
					s.Format (L"%d",m_pSet.m_rFrequency );
					m_cRemindListCtrl.SetItemText (i,3,s);
					if(m_pSet.m_rFinished ==true)
						m_cRemindListCtrl.SetItemText (i,4,L"是");
					else 
						m_cRemindListCtrl.SetItemText (i,4,L"否");
					m_cRemindListCtrl.SetItemText (i,5,m_pSet.m_rKind );
					m_cRemindListCtrl.SetItemText (i,6,m_pSet.m_rRemark );
					s.Format (L"%d",m_pSet.m_rId );
					m_cRemindListCtrl.SetItemText (i,7,s);
                    i++;
				}
			    m_pSet.MoveNext ();
			} 
	        m_pSet.Close ();
			break;//case 2
		}
	    //现在在右边显示个数
		if(i==0)
		{
		    m_iRemindAmount=i;
			s.Format (L"%d",m_iRemindAmount);
			SetDlgItemText(IDC_REMIND_AMOUNT_STATIC,s);//显示
			MessageBox(L"\n不存在这样的记录!\n",L"提示",MB_ICONEXCLAMATION);
			EndWaitCursor();
			return ;
		}
	    m_iRemindAmount=i;
	    s.Format (L"%d",m_iRemindAmount);
	    SetDlgItemText(IDC_REMIND_AMOUNT_STATIC,s);//显示
		EndWaitCursor();
	}
}
void CSetRemindDlg2::OnBnClickedRemindSearchBt()
{
	// TODO: 在此添加控件通知处理程序代码
    Search();
}

void CSetRemindDlg2::Print ()
{
	if(m_cRemindListCtrl.GetItemCount()<= 0)
	{
		MessageBox(L"\n打印列表为空!\n",L"提示",MB_ICONEXCLAMATION);
		return;
	}
	PRNINFO PrnInfo = {0};
	PrnInfo.hListView = m_cRemindListCtrl.m_hWnd;
	PrnInfo.hWnd = this->m_hWnd;
	PrnInfo.IsPrint = FALSE;
	PrnInfo.nCurPage = 1;
	PrnInfo.nMaxLine = m_cRemindListCtrl.GetItemCount();
	
	CPreParentDlg DlgPreView;
	DlgPreView.SetCallBackFun(DrawInfo, PrnInfo);
	DlgPreView.DoModal();
}
void CSetRemindDlg2::OnBnClickedRemindPrintBt()
{
	// TODO: 在此添加控件通知处理程序代码
    Print();
}
//打印
HCURSOR CSetRemindDlg2::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//
void CSetRemindDlg2::DrawInfo(CDC &memDC, PRNINFO PrnInfo) 
{
     PrintRemind(memDC,PrnInfo);
}


BOOL CSetRemindDlg2::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化
	SetTimer(REMIND_TIMER_SHORT,100,NULL);
	SetTimer(REMIND_TIMER_LONG,5000,NULL);
	m_cRemindListCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_cRemindListCtrl.InsertColumn (0,L"提醒内容",LVCFMT_IMAGE|LVCFMT_LEFT);
	m_cRemindListCtrl.InsertColumn (1,L"开始日期");
	m_cRemindListCtrl.InsertColumn (2,L"到期日期");
	m_cRemindListCtrl.InsertColumn (3,L"到期频率");
	m_cRemindListCtrl.InsertColumn (4,L"是否完成");
	m_cRemindListCtrl.InsertColumn (5,L"提醒类型");
	m_cRemindListCtrl.InsertColumn (6,L"备注");
	m_cRemindListCtrl.InsertColumn (7,L"主键");
	m_cRemindListCtrl.SetColumnWidth (0,130);
	for (int i=1; i<7; i++)
		m_cRemindListCtrl.SetColumnWidth (i,63);
	m_cRemindListCtrl.SetColumnWidth (7,0);
	//初始化提醒
	CString StrTime;
	CString StrStartDate;
	CString StrEndDate;
	CTime tTime=CTime::GetCurrentTime();
	CString StrRemindInfo;
	if(m_pSet.IsOpen())
		m_pSet.Close();
	m_pSet.Open(AFX_DB_USE_DEFAULT_TYPE,L"Select * From Remind Order By rStartDate");
	if(m_pSet.GetRecordCount()==0)//若提醒为空,则跳过
		m_pSet.Close();
	else
	{
		StrTime=DateToString(tTime);
		m_pSet.MoveFirst();
		while(!m_pSet.IsEOF())
		{
				
			if(m_pSet.m_rFinished==true)//若完成了提醒,则不需要再提醒
			{
				m_pSet.MoveNext();
				continue;
			}
			StrStartDate=DateToString(m_pSet.m_rStartDate);
			StrEndDate=DateToString(m_pSet.m_rEndDate);
			if(StrStartDate<=StrTime&&StrEndDate>=StrTime)//若该提醒在这天当中,则显示
			{
				StrRemindInfo+=m_pSet.m_rContent;
				StrRemindInfo+=L";  ";
				SetDlgItemText(IDC_TODAY_REMIND_STATIC,StrRemindInfo);	
			}
			m_pSet.MoveNext();
		}
		m_pSet.Close();
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

HBRUSH CSetRemindDlg2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何属性
	if(m_bColor)//如果用系统的,则直接返回
		return hbr;
	pDC->SetTextColor (m_RGB_CtrlColor);
	pDC->SetBkMode(BKMODE_LAST);pDC->SetBkColor (m_RGB_BkColor);
	return (HBRUSH)m_brush.GetSafeHandle ();
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
//	return hbr;
}

void CSetRemindDlg2::OnHdnItemclickSetRemindList(NMHDR *pNMHDR, LRESULT *pResult)
{
	BeginWaitCursor();
	LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	CDataClass DataClass;
    int nCount=m_cRemindListCtrl.GetItemCount ();//列表中的个数
	if(nCount==0)
	{
		EndWaitCursor();
		return ;
	}
	DataClass.Init (nCount);//初始化类对象
	for(int i=0; i<nCount; i++)
	{
		DataClass.m_Data [i].m_sCol_1 =m_cRemindListCtrl.GetItemText (i,0);
		DataClass.m_Data [i].m_sCol_2 =m_cRemindListCtrl.GetItemText (i,1);
		DataClass.m_Data [i].m_sCol_3 =m_cRemindListCtrl.GetItemText (i,2);
		DataClass.m_Data [i].m_sCol_4 =m_cRemindListCtrl.GetItemText (i,3);
		DataClass.m_Data [i].m_sCol_5 =m_cRemindListCtrl.GetItemText (i,4);
		DataClass.m_Data [i].m_sCol_6 =m_cRemindListCtrl.GetItemText (i,5);
		DataClass.m_Data [i].m_sCol_7 =m_cRemindListCtrl.GetItemText (i,6);
		DataClass.m_Data [i].m_sId    =m_cRemindListCtrl.GetItemText (i,7);
	}//初始化完毕
	//现在排序
	int nSelectCol=phdr->iItem ;
	switch(nSelectCol)
	{
	case 0:
		DataClass.SortDataByCol_1 (m_bSortUp,0);
		break;
	case 1:
		DataClass.SortDataByCol_2 (m_bSortUp,1);
		break;
	case 2:
		DataClass.SortDataByCol_3 (m_bSortUp,1);
		break;
	case 3:
		DataClass.SortDataByCol_4 (m_bSortUp,0);
		break;
	case 4:
		DataClass.SortDataByCol_5 (m_bSortUp,0);
        break;
	case 5:
		DataClass.SortDataByCol_6 (m_bSortUp,0);
		break;
	case 6:
		DataClass.SortDataByCol_7 (m_bSortUp,0);
        break;
	default:break;
	}
	//现在把排好序的放回列表
	//先删除
	m_cRemindListCtrl.DeleteAllItems ();
	for(int j=0; j<nCount; j++)
	{
		m_cRemindListCtrl.InsertItem(j,DataClass.m_Data [j].m_sCol_1  ,0);
		m_cRemindListCtrl.SetItemText (j,1,DataClass.m_Data [j].m_sCol_2 );
		m_cRemindListCtrl.SetItemText (j,2,DataClass.m_Data [j].m_sCol_3 );
		m_cRemindListCtrl.SetItemText (j,3,DataClass.m_Data [j].m_sCol_4 );
		m_cRemindListCtrl.SetItemText (j,4,DataClass.m_Data [j].m_sCol_5 );
		m_cRemindListCtrl.SetItemText (j,5,DataClass.m_Data [j].m_sCol_6 );
		m_cRemindListCtrl.SetItemText (j,6,DataClass.m_Data [j].m_sCol_7 );
		m_cRemindListCtrl.SetItemText (j,7,DataClass.m_Data [j].m_sId );
	}
	*pResult = 0;
	if(m_bSortUp)
		m_bSortUp=false;
	else
		m_bSortUp=true;
	EndWaitCursor();
}

void CSetRemindDlg2::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
    KillTimer(REMIND_TIMER_SHORT);
	KillTimer(REMIND_TIMER_LONG);
	CDialog::OnClose();
}

void CSetRemindDlg2::OnContextMenu(CWnd* pWnd, CPoint point)
{
	// TODO: 在此处添加消息处理程序代码
   CMenu menu;
    CPoint pos=point;
	ScreenToClient(&pos);
	CRect rect;
	GetClientRect(&rect);
	if(rect.PtInRect (pos))
	{
	menu.LoadMenu(IDR_REMIND_MENU);
	menu.GetSubMenu (0)->TrackPopupMenu (TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
	return ;
	}
	CWnd::OnContextMenu (pWnd,point);
}

void CSetRemindDlg2::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	if(nIDEvent==REMIND_TIMER_SHORT)
	{
		POSITION pos = m_cRemindListCtrl.GetFirstSelectedItemPosition();
		if (pos != NULL)//如果有列表项被选中
		{
			m_bItemClick=true;
			m_cDeleteBt.EnableWindow (true);
			m_cUpdateBt.EnableWindow (true);
		}
		else
		{
			m_bItemClick=false;
			m_cDeleteBt.EnableWindow (false);
			m_cUpdateBt.EnableWindow (false);
		}
		if(m_iRemindAmount!=0)
		{
			m_cPrintBt.EnableWindow (true);
		}
		else
		{
			m_cPrintBt.EnableWindow (false);
		}
	}
	else
	{
		CString StrTime;
		CString StrStartDate;
		CString StrEndDate;
		CTime tTime=CTime::GetCurrentTime();
		CString StrRemindInfo;
		if(m_pSet.IsOpen())
			m_pSet.Close();
		m_pSet.Open(AFX_DB_USE_DEFAULT_TYPE,L"Select * From Remind Order By rStartDate");
		if(m_pSet.GetRecordCount()==0)//若提醒为空,则跳过
			m_pSet.Close();
		else
		{
			StrTime=DateToString(tTime);
			m_pSet.MoveFirst();
			while(!m_pSet.IsEOF())
			{
				
				if(m_pSet.m_rFinished==true)//若完成了提醒,则不需要再提醒
				{
					m_pSet.MoveNext();
					continue;
				}
				StrStartDate=DateToString(m_pSet.m_rStartDate);
				StrEndDate=DateToString(m_pSet.m_rEndDate);
				if(StrStartDate<=StrTime&&StrEndDate>=StrTime)//若该提醒在这天当中,则显示
				{
					StrRemindInfo+=m_pSet.m_rContent;
					StrRemindInfo+=L";  ";
					SetDlgItemText(IDC_TODAY_REMIND_STATIC,StrRemindInfo);	
				}
				m_pSet.MoveNext();
			}
			m_pSet.Close();
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void CSetRemindDlg2::PostNcDestroy()
{
	// TODO: 在此添加专用代码和/或调用基类
	CDialog::PostNcDestroy();
	AfxGetMainWnd()->SendMessage(WM_USER_SETREMINDDLG_DESTROYED,0,0);
	delete this;
}

void CSetRemindDlg2::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类
	this->DestroyWindow ();
}
void CSetRemindDlg2::OnRemindAll()
{
	// TODO: 在此添加命令处理程序代码
	ViewAll();
	Invalidate();
}
void CSetRemindDlg2::OnRemindKind()
{
	// TODO: 在此添加命令处理程序代码
	Kind();
	Invalidate();
}
void CSetRemindDlg2::OnRemindAdd()
{
	// TODO: 在此添加命令处理程序代码
	Add();
	Invalidate();
}
void CSetRemindDlg2::OnRemindUpdate()
{
	// TODO: 在此添加命令处理程序代码
	Update();
	Invalidate();
}
void CSetRemindDlg2::OnRemindDelete()
{
	// TODO: 在此添加命令处理程序代码
	Delete();
	Invalidate();
}
void CSetRemindDlg2::OnRemindSearch()
{
	// TODO: 在此添加命令处理程序代码
	Search();
	Invalidate();
}
void CSetRemindDlg2::OnRemindPrint()
{
	// TODO: 在此添加命令处理程序代码
	Print();
	Invalidate();
}

void CSetRemindDlg2::OnUpdateRemindUpdate(CCmdUI *pCmdUI)
{
	// TODO: 在此添加命令更新用户界面处理程序代码
	if(m_bItemClick)
	   pCmdUI->Enable (true);
	else		
	   pCmdUI->Enable(false);
}
void CSetRemindDlg2::OnUpdateRemindDelete (CCmdUI *pCmdUI)
{
	// TODO: 在此添加命令更新用户界面处理程序代码
	if(m_bItemClick)
	   pCmdUI->Enable (true);
	else		
	   pCmdUI->Enable(false);
}
void CSetRemindDlg2::OnUpdateRemindPrint (CCmdUI *pCmdUI)
{
	// TODO: 在此添加命令更新用户界面处理程序代码
	if(m_iRemindAmount)
	   pCmdUI->Enable (true);
	else		
	   pCmdUI->Enable(false);
}

void CSetRemindDlg2::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{   
	ASSERT(pPopupMenu != NULL);    // Check the enabled state of various menu items.    
    CCmdUI state;    
	state.m_pMenu = pPopupMenu;    
	ASSERT(state.m_pOther == NULL);    
	ASSERT(state.m_pParentMenu == NULL);    // Determine if menu is popup in top-level menu and set m_pOther to    
	// it if so (m_pParentMenu == NULL indicates that it is secondary popup).    
	HMENU hParentMenu;    
	if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)        state.m_pParentMenu = pPopupMenu;   
	// Parent == child for tracking popup.    
	else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)    
	{        
		CWnd* pParent = this;           
		// Child windows don't have menus--need to go to the top!       
		if (pParent != NULL &&(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)        
		{           
			int nIndexMax = ::GetMenuItemCount(hParentMenu);          
			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)           
			{            
				if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)            
				{               
					// When popup is found, m_pParentMenu is containing menu.                
					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);                
					break;            
				}           
			}        
		}    
	}    
	state.m_nIndexMax = pPopupMenu->GetMenuItemCount();    
	for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;      
		state.m_nIndex++)    
	{        
		state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);        
		if (state.m_nID == 0)           
			continue; // Menu separator or invalid cmd - ignore it.        
		ASSERT(state.m_pOther == NULL);        
		ASSERT(state.m_pMenu != NULL);        
		if (state.m_nID == (UINT)-1)        
		{           
			// Possibly a popup menu, route to first item of that popup.          
			state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);  
			if (state.m_pSubMenu == NULL||(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||state.m_nID == (UINT)-1)           
			{            
				continue;       // First item of popup can't be routed to.           
			}           
			state.DoUpdate(this, TRUE);   // Popups are never auto disabled.       
		}        
		else        
		{           // Normal menu item.           
			// Auto enable/disable if frame window has m_bAutoMenuEnable           
			// set and command is _not_ a system command.           
			state.m_pSubMenu = NULL;           
			state.DoUpdate(this, FALSE);        
		}        
		// Adjust for menu deletions and additions.        
		UINT nCount = pPopupMenu->GetMenuItemCount();        
		if (nCount < state.m_nIndexMax)        
		{           
			state.m_nIndex -= (state.m_nIndexMax - nCount);           
			while (state.m_nIndex < nCount &&            
				pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID) 
			{            
				state.m_nIndex++;          
			}        
		}        
		state.m_nIndexMax = nCount;    
	}
} 

void CSetRemindDlg2::OnRemindClose()
{
	// TODO: 在此添加命令处理程序代码
	this->DestroyWindow ();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -