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

📄 dlgkqproject.cpp

📁 用户管理系统
💻 CPP
字号:
// DlgKqProject.cpp : implementation file
//

#include "stdafx.h"
#include "Kvip.h"
#include "DlgKqProject.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include "MyMdi.H"
/////////////////////////////////////////////////////////////////////////////
// CDlgKqProject

IMPLEMENT_DYNCREATE(CDlgKqProject, CFormView)

CDlgKqProject::CDlgKqProject()
	: CFormView(CDlgKqProject::IDD)
{
	//{{AFX_DATA_INIT(CDlgKqProject)
	//}}AFX_DATA_INIT
	m_pApp = NULL;
	m_pConnection = NULL;
	m_crText = RGB(0,0,0);
	m_crBack = RGB(0,0,255);
    m_Brush.CreateSolidBrush(m_crBack);

}

CDlgKqProject::~CDlgKqProject()
{
 //  if(m_pConnection) delete m_pConnection;
}

void CDlgKqProject::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgKqProject)
	DDX_Control(pDX, IDC_CHECK_BEGIN, m_ckBegin);
	DDX_Control(pDX, IDC_TX_COLOR, m_btTxColor);
	DDX_Control(pDX, IDC_BK_COLOR, m_btBkColor);
	DDX_Control(pDX, IDC_COMBO_NO, m_cmNo);
	DDX_Control(pDX, IDC_CHECK_ZT, m_ckZT);
	DDX_Control(pDX, IDC_CHECK_QD, m_ckQD);
	DDX_Control(pDX, IDC_CHECK_KG, m_ckKG);
	DDX_Control(pDX, IDC_STATIC_COLOR, m_stColor);
	DDX_Control(pDX, IDC_MASTER, m_Master);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgKqProject, CFormView)
	//{{AFX_MSG_MAP(CDlgKqProject)
	ON_BN_CLICKED(IDC_INSERT, OnInsert)
	ON_BN_CLICKED(IDC_EDIT, OnEdit)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_WM_CTLCOLOR()
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_MASTER, OnItemchangedMaster)
	ON_BN_CLICKED(IDC_BK_COLOR, OnBkColor)
	ON_BN_CLICKED(IDC_TX_COLOR, OnTxColor)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_CHECK_QD, OnCheckQd)
	ON_BN_CLICKED(IDC_CHECK_ZT, OnCheckZt)
	ON_BN_CLICKED(IDC_CHECK_KG, OnCheckKg)
	ON_CBN_SELCHANGE(IDC_COMBO_NO, OnSelchangeComboNo)
	ON_BN_CLICKED(IDCANCEL, OnCancel)
	ON_BN_CLICKED(IDC_CHECK_BEGIN, OnCheckBegin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgKqProject diagnostics

#ifdef _DEBUG
void CDlgKqProject::AssertValid() const
{
	CFormView::AssertValid();
}

void CDlgKqProject::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDlgKqProject message handlers

void CDlgKqProject::OnInsert() 
{
	// TODO: Add your control notification handler code here
  CString sCode, sText;
  CEdit *pEdit;
//更新显示颜色
	if(m_cmNo.GetCurSel() == 0)
	{//更新显示颜色
	  pEdit = (CEdit*)m_ListDoc.GetClass("KP_CODE");
	  ASSERT(pEdit);
	  pEdit->GetWindowText(sCode);
	  m_Master.Add(sCode, m_crText, m_crBack);
	 //更新颜色
	   pEdit = (CEdit*)m_ListDoc.GetClass("KP_BK_COLOR");
	   ASSERT(pEdit);
	   sText.Format("%d", (long)m_crBack);
	   pEdit->SetWindowText(sText);
	   pEdit = (CEdit*)m_ListDoc.GetClass("KP_TX_COLOR");
	   ASSERT(pEdit);
	   sText.Format("%d", (long)m_crText);
	   pEdit->SetWindowText(sText);
	}
//更新次序
  pEdit = (CEdit *)m_ListDoc.GetClass("KP_NO");
  ASSERT(pEdit);
  int nSel = m_cmNo.GetCurSel();
  sText.Format("%d", nSel+1);
  pEdit->SetWindowText(sText);

  if(m_ListDoc.New())
  {
	  m_ListDoc.UpdateData(false);
	  m_ListDoc.Reset();
	  m_ListDoc.SetModify(true);
  }
}

void CDlgKqProject::OnEdit() 
{
	// TODO: Add your control notification handler code here
	CString sText, sCode;
	CEdit *pEdit;
//更新显示颜色
	if(m_cmNo.GetCurSel() == 0)
	{//更新显示颜色
	  pEdit = (CEdit*)m_ListDoc.GetClass("KP_CODE");
	  ASSERT(pEdit);
	  pEdit->GetWindowText(sCode);
	  m_Master.Add(sCode, m_crText, m_crBack);
	 //更新颜色
	   pEdit = (CEdit*)m_ListDoc.GetClass("KP_BK_COLOR");
	   ASSERT(pEdit);
	   sText.Format("%d", (long)m_crBack);
	   pEdit->SetWindowText(sText);
	   pEdit = (CEdit*)m_ListDoc.GetClass("KP_TX_COLOR");
	   ASSERT(pEdit);
	   sText.Format("%d", (long)m_crText);
	   pEdit->SetWindowText(sText);
	}
//更新次序
   pEdit = (CEdit *)m_ListDoc.GetClass("KP_NO");
   ASSERT(pEdit);
   int nSel = m_cmNo.GetCurSel();
   sText.Format("%d", nSel+1);
   pEdit->SetWindowText(sText);


   m_ListDoc.UpdateData(false);

}

void CDlgKqProject::OnDelete() 
{
	// TODO: Add your control notification handler code here
	m_ListDoc.Delete();
}

void CDlgKqProject::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	CString sSQL, sText;
//登记
	CMyMdi Mdi;
	Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);

	m_pApp = (CKvipApp *)AfxGetApp();
	//m_pConnection = m_pApp->CreaterAdoConnection();
	m_pConnection = m_pApp->m_pConWrite;
	if(m_pConnection == NULL) 
	{
		GetParent()->PostMessage(WM_CLOSE);
		return ;
	}

//设置主窗口
	if (!m_ListDoc.Init((CDialog*)this, &m_Master))
	{
      MessageBox("注意:WK-00002生成窗体失败!", "系统提示", MB_OK|MB_ICONEXCLAMATION);
	  GetParent()->PostMessage(WM_CLOSE);
	  return;
	}
	m_ListDoc.SetConnection(m_pConnection);
	m_ListDoc.ResetAll();
    sSQL = _T("Select * From kv_kq_project Order by kp_code, kp_no ");
	if (m_ListDoc.Retrieve(sSQL, false) < 0)
	{
      MessageBox("错误:错误位置" + sSQL, "系统提示", MB_OK|MB_ICONEXCLAMATION);
	  GetParent()->PostMessage(WM_CLOSE);
	  return;
	}
    _FillColor();
	m_Master.SetCheckBox(2);
	m_Master.SetCheckBox(4);
	m_Master.SetCheckBox(6);
	m_Master.SetCheckBox(8);
	m_Master.SetCheckBox(10);

//导入班次
	for (int i = 1; i <= 20; i++)
	{
	  if((i%2) > 0)
	    sText.Format("%2d 上班", i); 
	  else
	    sText.Format("%2d 下班", i); 
	  m_cmNo.InsertString(i-1,sText);
	}
	m_cmNo.SetCurSel(0);
	// TODO: Add your specialized code here and/or call the base class
	
}


//DEL void CDlgKqProject::OnItemchangedMaster(NMHDR* pNMHDR, LRESULT* pResult) 
//DEL {
//DEL 	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
//DEL 	// TODO: Add your control notification handler code here
//DEL   int nItem = m_Master.GetSelected();
//DEL   if (nItem >= 0) m_ListDoc.UpdateData();
//DEL 	*pResult = 0;
//DEL }

void CDlgKqProject::OnCancel() 
{
	// TODO: Add your control notification handler code here
  GetParent()->PostMessage(WM_CLOSE);
}





HBRUSH CDlgKqProject::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	CEdit *pEdit = (CEdit*)m_ListDoc.GetClass("KP_CODE","NUMERICEDIT");
	ASSERT(pEdit);
	if(pWnd == pEdit)
		pDC->SetTextColor(RGB(255,0,0));
//	pEdit = (CEdit*)m_ListDoc.GetClass("KP_TX_COLOR");
//	ASSERT(pEdit);
	if(nCtlColor == CTLCOLOR_STATIC &&
	   pWnd->GetDlgCtrlID() == IDC_STATIC_COLOR)
	{
		pDC->SetTextColor(m_crText);
		pDC->SetBkMode(TRANSPARENT);
		return m_Brush;
	}
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CDlgKqProject::OnItemchangedMaster(NMHDR* pNMHDR, LRESULT* pResult) 
{
   NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
   const int nItem = pNMListView->iItem;
	// TODO: Add your control notification handler code here
   int nSubItem = m_Master.GetSubItem("次序");
   CString  sText;
//得到光标
   if (pNMListView->uNewState == 3 && nItem >= 0) 
   {
	m_ListDoc.UpdateData();
	sText = m_Master.GetItemText(nItem, nSubItem);
	if (sText == _T("1"))  //在第1次考勤设置中,锁定颜色
	{
	  CEdit *pEdit = (CEdit*)m_ListDoc.GetClass("KP_BK_COLOR");
	  ASSERT(pEdit);
  	  pEdit->GetWindowText(sText);
	  m_crBack = atoi(sText);
	  m_Brush.DeleteObject();
	  m_Brush.CreateSolidBrush(m_crBack);
	  pEdit = (CEdit*)m_ListDoc.GetClass("KP_TX_COLOR");
	  ASSERT(pEdit);
	  pEdit->GetWindowText(sText);
	  m_crText = atoi(sText);
	  m_stColor.Invalidate();
	  pEdit = (CEdit*)m_ListDoc.GetClass("KP_NO");
	  ASSERT(pEdit);
	  pEdit->GetWindowText(sText);
	  m_stColor.ShowWindow(SW_SHOW);
	  m_btTxColor.EnableWindow(true);
	  m_btBkColor.EnableWindow(true);
	}
	else
	{
	  m_stColor.ShowWindow(SW_HIDE);
	  m_btTxColor.EnableWindow(false);
	  m_btBkColor.EnableWindow(false);
	}
	m_cmNo.SetCurSel(atoi(sText)-1);
    OnCheckKg();	
    OnCheckZt();	
    OnCheckQd();	
	OnCheckBegin();
   }
	*pResult = 0;
}



void CDlgKqProject::OnBkColor() 
{
	// TODO: Add your control notification handler code here
	CColorDialog dlg;
	//CString  sText;
    if(dlg.DoModal() == IDOK)
	{
	   m_crBack = dlg.GetColor();
	   //sText.Format("%d", m_crBack);
	   //CEdit *pEdit = (CEdit*)m_ListDoc.GetClass("KP_BK_COLOR");
	   //ASSERT(pEdit);
	   m_Brush.DeleteObject();
	   m_Brush.CreateSolidBrush(m_crBack);
	   //pEdit->SetWindowText(sText);
	   m_stColor.Invalidate();
	}
}

void CDlgKqProject::OnTxColor() 
{
	// TODO: Add your control notification handler code here
	CColorDialog dlg;
	//CString  sText;
    if(dlg.DoModal() == IDOK)
	{
	   m_crText = dlg.GetColor();
	   //sText.Format("%d", m_crText);
	   //CEdit *pEdit = (CEdit*)m_ListDoc.GetClass("KP_TX_COLOR");
	   //ASSERT(pEdit);
	   //pEdit->SetWindowText(sText);
	   m_stColor.Invalidate();
	}
	
}

void CDlgKqProject::OnSave(WPARAM nExit) 
{
	// TODO: Add your control notification handler code here
    if (m_ListDoc.IsModify())
	{//数据已修改
      if(nExit == 1 || MessageBox("注意:是否保存数据???", "系统提示", MB_OKCANCEL|MB_ICONEXCLAMATION) ==	IDOK)
	  {
 	    m_ListDoc.Save();
		return ;
	  }
	}
}

void CDlgKqProject::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
    int nRet = IDNO;
	if(m_ListDoc.IsModify())
	   nRet= MessageBox("注意:你确定要关闭窗口吗???", "系统提示", MB_YESNOCANCEL|MB_ICONQUESTION);
    if(nRet == IDYES)
	  {
 	    OnSave(1);
		return ;
	  }
	 else if(nRet == IDCANCEL) //返回
	 {
		CMyMdi::m_bExitCode = false;
		return ;
	 }
	CFormView::OnClose();
}



void CDlgKqProject::OnCheckQd() 
{
	// TODO: Add your control notification handler code here
  CWnd *pEdit;
  BOOL bChecked = (BOOL)m_ckQD.GetCheck();
  pEdit = (CWnd *)m_ListDoc.GetClass("KP_QD");
  ASSERT(pEdit);
  pEdit->EnableWindow(bChecked);
	
}

void CDlgKqProject::OnCheckZt() 
{
	// TODO: Add your control notification handler code here
  CWnd *pEdit;
  BOOL bChecked = (BOOL)m_ckZT.GetCheck();
  pEdit = (CWnd *)m_ListDoc.GetClass("KP_ZT");
  ASSERT(pEdit);
  pEdit->EnableWindow(bChecked);
	
}

void CDlgKqProject::OnCheckKg() 
{
	// TODO: Add your control notification handler code here
  CWnd *pEdit;
  BOOL bChecked = (BOOL)m_ckKG.GetCheck();
  pEdit = (CWnd *)m_ListDoc.GetClass("KP_KG");
  ASSERT(pEdit);
  pEdit->EnableWindow(bChecked);
}

void CDlgKqProject::_FillColor()
{
 CAdoRecordSet *pRecordSet = m_ListDoc.GetRecordSet();
 if (pRecordSet==NULL) return ;

 CString sCode;
 long lColor, lBkColor, lNo;
 pRecordSet->MoveFirst();
 while(pRecordSet->IsEOF() == false)
 {
    pRecordSet->GetCollect("kp_code", sCode);
    pRecordSet->GetCollect("kp_tx_color", lColor);
    pRecordSet->GetCollect("kp_bk_color", lBkColor);
    pRecordSet->GetCollect("kp_no", lNo);
	if(lNo == 1)
      m_Master.Add(sCode, (COLORREF)lColor, (COLORREF)lBkColor);
    
	pRecordSet->MoveNext();
 }//end while
}

void CDlgKqProject::OnSelchangeComboNo() 
{
	// TODO: Add your control notification handler code here
  int nSel = m_cmNo.GetCurSel();
  if(nSel < 0) return ;
  if (m_cmNo.GetCurSel() == 0)  
	{
	  m_stColor.ShowWindow(SW_SHOW);
	  m_btTxColor.EnableWindow(true);
	  m_btBkColor.EnableWindow(true);
	}
	else
	{
	  m_stColor.ShowWindow(SW_HIDE);
	  m_btTxColor.EnableWindow(false);
	  m_btBkColor.EnableWindow(false);
	}

}

void CDlgKqProject::OnCheckBegin() 
{
	// TODO: Add your control notification handler code here
  CWnd *pEdit;
  BOOL bChecked = (BOOL)m_ckBegin.GetCheck();
  pEdit = (CWnd *)m_ListDoc.GetClass("KP_BEGIN");
  ASSERT(pEdit);
  pEdit->EnableWindow(bChecked);
	
}

⌨️ 快捷键说明

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