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

📄 laborageview.cpp

📁 It is good
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if(k!=-1)
	{
    m_bIsAsc=1-m_bIsAsc;
	Sort(m_bIsAsc,k);
	Show();
	}

	*pResult = 0;
}

void CLaborageView::OnFind() 
{
	// TODO: Add your command handler code here
	if(m_find->m_hWnd==NULL) 
	{
		m_find->Create(IDD_FIND);
		m_find->m_parent=this;
	}
	m_find->ShowWindow(SW_NORMAL);
	m_find->SetActiveWindow();
}

void CLaborageView::OnBeginFind(WPARAM wParam,LPARAM lParam)
{
	m_Set.Open();
	m_Set.m_strFilter=m_find->m_title;
	m_Set.Requery();
	if(m_Set.IsEOF()) 
	{
        m_Set.m_strFilter.Empty();
	    m_Set.Close(); 
		MessageBox("找不到符合条件的记录");
	}
	else
	{
	    m_Set.Close(); 
		Show();
	}
}

void CLaborageView::OnDelete() 
{
	// TODO: Add your command handler code here	
	int l=GetListCtrl().GetSelectedCount();
	if(l<=0) 
	{
		MessageBox("您还没选中记录!");
		return;
	}
    
	POSITION pos=GetListCtrl().GetFirstSelectedItemPosition();
    CNode<int> count;
	while(pos!=NULL)
    count.Add(GetListCtrl().GetNextSelectedItem(pos));

    m_Set.Open();
	while(count.GetLen()>0)
	{
	    m_Set.Move(count[0]);
		if(m_Set.IsEOF()==FALSE) 
		{
			m_Set.Delete();
            m_RecordCounts--;
			for(int i=1;i<count.GetLen();i++)
				if(count[i]>count[0]) count.SetAt(i,count[i]-1);
			count.Delete(0);
		m_Set.Requery();
		}
		else break;
	}

	m_Set.Requery();
	m_Set.Close();
	Show();
    
	CMainFrame *frame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	char inf[255];
	sprintf(inf,"记录总数:  %d ",m_RecordCounts);
	frame->m_wndStatusBar.SetPaneText(1,inf);
}

void CLaborageView::OnShow() 
{
	// TODO: Add your command handler code here
    m_Set.m_strFilter.Empty();
	Show();
}


void CLaborageView::OnAdd() 
{
	// TODO: Add your command handler code here
	CRecord dlg;
	if(dlg.DoModal()==IDOK)
	{
		m_Set.Open();

	    if(CheckRecord(dlg.m_number,dlg.m_name)==FALSE)
		{
           m_Set.Close();
		   return;
		}

		m_Set.AddNew();

        m_RecordCounts++;
		m_Set.m_column1=dlg.m_number;
		m_Set.m_column2=dlg.m_name;
		m_Set.m_column3=dlg.m_sex;
		m_Set.m_column4=CTime::GetCurrentTime().GetYear()-dlg.m_age;
		m_Set.m_column5=dlg.m_phone;
		m_Set.m_column6=dlg.m_work;
		m_Set.m_column7=dlg.m_treat;
		CTime time(dlg.m_firstdate.GetYear(),dlg.m_firstdate.GetMonth(),dlg.m_firstdate.GetDay(),0,0,0);
		m_Set.m_column8=time;
		m_Set.m_column9=dlg.m_fakedays;
		m_Set.m_column10=dlg.m_expanddays;
		m_Set.m_column11=dlg.m_extramoney;

		m_Set.Update();
		m_Set.Requery();
		m_Set.Close();
		Show();

        CMainFrame *frame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	    char inf[255];
	    sprintf(inf,"记录总数:  %d ",m_RecordCounts);
	    frame->m_wndStatusBar.SetPaneText(1,inf);
	}
}

void CLaborageView::OnModify() 
{
	// TODO: Add your command handler code here
	int l=GetListCtrl().GetSelectedCount();
	if(l<=0) MessageBox("您还没有选取记录!");
	else
	if(l>1) MessageBox("一次只能修改一个记录!");
	else
	{
		CRecord dlg;
		dlg.m_flags=TRUE;
		m_Set.Open();
	    POSITION pos=GetListCtrl().GetFirstSelectedItemPosition();
		int len=GetListCtrl().GetNextSelectedItem(pos);
        m_Set.Move(len);
        
        dlg.m_number=m_Set.m_column1;
		dlg.m_name=m_Set.m_column2;
		dlg.m_sex=m_Set.m_column3;
		dlg.m_age=CTime::GetCurrentTime().GetYear()-m_Set.m_column4;
		dlg.m_phone=m_Set.m_column5;
		dlg.m_work=m_Set.m_column6;
		dlg.m_treat=m_Set.m_column7;
        CTime time=CTime::GetCurrentTime();
        int total=(time.GetYear()-m_Set.m_column8.GetYear())*366+(time.GetMonth()-m_Set.m_column8.GetMonth())*31+time.GetDay()-m_Set.m_column8.GetDay();
		dlg.m_alldays=total;
		time=m_Set.m_column8;
		dlg.m_firstdate.SetDateTime(time.GetYear(),time.GetMonth(),time.GetDay(),0,0,0);
		dlg.m_fakedays=m_Set.m_column9;
		dlg.m_effectdays=total-m_Set.m_column9;
	    dlg.m_expanddays=m_Set.m_column10;
		dlg.m_leftdays=total-m_Set.m_column9-m_Set.m_column10;
		dlg.m_extramoney=m_Set.m_column11;
		dlg.m_allmoney=(total-m_Set.m_column9-m_Set.m_column10)*m_Set.m_column7+m_Set.m_column11;

		if(dlg.DoModal()==IDOK)
		{
			int num=m_Set.m_column1;
			if(dlg.m_number!=m_Set.m_column1)
			{
			  m_Set.MoveFirst();
			  do
			  {
			  if(m_Set.m_column1==dlg.m_number && m_Set.m_column1!=num)
			  {
				  MessageBox("该编号已存在!");
				  m_Set.Close();
				  return;
			  }
			  
			  m_Set.MoveNext();
			  }while(!m_Set.IsEOF());
			  m_Set.Requery();
              m_Set.Move(len);
			}
        
            
			m_Set.Edit();
            
			m_Set.m_column1=dlg.m_number;;
			m_Set.m_column2=dlg.m_name;
			m_Set.m_column3=dlg.m_sex;
			m_Set.m_column4=CTime::GetCurrentTime().GetYear()-dlg.m_age;;
			m_Set.m_column5=dlg.m_phone;
			m_Set.m_column6=dlg.m_work;
			m_Set.m_column7=dlg.m_treat;
		    CTime time(dlg.m_firstdate.GetYear(),dlg.m_firstdate.GetMonth(),dlg.m_firstdate.GetDay(),0,0,0);
		    m_Set.m_column8=time;
			m_Set.m_column9=dlg.m_fakedays;
			m_Set.m_column10=dlg.m_expanddays;
			m_Set.m_column11=dlg.m_extramoney;

			m_Set.Update();
	        m_Set.Requery();   
			m_Set.Close();
			Show();
		}
		else m_Set.Close();
         
	}
}

BOOL CLaborageView::CheckRecord(int num,CString name)
{
  if(m_RecordCounts<=0) return TRUE;

  m_Set.MoveFirst();
  do
  {
  if(m_Set.m_column1==num)
  {
	  MessageBox("该编号已存在!");
	  return FALSE;
  }
  if(m_Set.m_column2==name)
  {
      MessageBox("该职员已存在!");
	  return FALSE;
  }
  m_Set.MoveNext();
  }while(!m_Set.IsEOF());

  return TRUE;
}


BOOL CLaborageView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_LBUTTONDBLCLK)
	if(pMsg->hwnd==this->GetListCtrl().m_hWnd)
	{
	int l=GetListCtrl().GetSelectedCount();
	if(l==1) OnModify();
	return TRUE;
	}
	
	if(pMsg->message==WM_RBUTTONDOWN)
	if(pMsg->hwnd==this->GetListCtrl().m_hWnd)
	{
        CMenu menu;
	    CPoint xy;
        ::GetCursorPos(&xy);
		menu.CreatePopupMenu();
        menu.AppendMenu(MF_STRING,IDM_SHOW,"显示所有");
		menu.AppendMenu(MF_STRING,IDM_ADD,"增加记录");
		int count=this->GetListCtrl().GetSelectedCount();
		if(count==1)
		menu.AppendMenu(MF_STRING,IDM_MODIFY,"修改记录");
		else
        menu.AppendMenu(MF_STRING|MF_GRAYED,IDM_MODIFY,"修改记录");
        if(count>0)
	    menu.AppendMenu(MF_STRING,IDM_DELETE,"删除记录");
		else
        menu.AppendMenu(MF_STRING|MF_GRAYED,IDM_DELETE,"删除记录");
        menu.AppendMenu(MF_STRING,IDM_FIND,"查找记录");
        menu.AppendMenu(MF_STRING,IDM_MANAGE,"管理");
		menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,xy.x,xy.y,this);


		return TRUE;
	}
	return CListView::PreTranslateMessage(pMsg);
}

void CLaborageView::OnManage() 
{
	// TODO: Add your command handler code here
	CManage dlg;
	if(dlg.DoModal()==IDOK)
	{
      m_Set.Open();
	  m_Set.MoveFirst();
		  
	  do
	  {
        m_Set.Edit();
        m_Set.m_column7+=dlg.m_treat;
		m_Set.m_column9+=dlg.m_fake;
		m_Set.m_column10+=dlg.m_give;
		m_Set.m_column11+=dlg.m_extra;

		m_Set.Update();
		m_Set.MoveNext();
	  }
	  while(!m_Set.IsEOF());

	  m_Set.Requery();
	  m_Set.Close();
	  Show();
	}
}

⌨️ 快捷键说明

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