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

📄 dlgkqconfirm.cpp

📁 用户管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DlgKqConfirm.cpp : implementation file
//

#include "stdafx.h"
#include "Kvip.h"
#include "DlgKqConfirm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgKqConfirm

IMPLEMENT_DYNCREATE(CDlgKqConfirm, CFormView)

CDlgKqConfirm::CDlgKqConfirm()
	: CFormView(CDlgKqConfirm::IDD)
{
	//{{AFX_DATA_INIT(CDlgKqConfirm)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pConnection = NULL;
	m_pApp = NULL;
}

CDlgKqConfirm::~CDlgKqConfirm()
{
}

void CDlgKqConfirm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgKqConfirm)
	DDX_Control(pDX, IDC_DTX, m_btDtx);
	DDX_Control(pDX, IDC_RIGHT, m_Right);
	DDX_Control(pDX, IDC_DEP, m_Dep);
	DDX_Control(pDX, IDC_LEFT, m_Left);
	DDX_Control(pDX, IDC_SAVE, m_btSave);
	DDX_Control(pDX, IDC_RETRIEVE, m_btRetrieve);
	DDX_Control(pDX, IDC_INPUT, m_btInput);
	DDX_Control(pDX, IDC_ED_DATE, m_edDate);
	DDX_Control(pDX, IDC_MASTER, m_Master);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgKqConfirm, CFormView)
	//{{AFX_MSG_MAP(CDlgKqConfirm)
	ON_NOTIFY(NM_DBLCLK, IDC_MASTER, OnDblclkMaster)
	ON_BN_CLICKED(IDC_RETRIEVE, OnRetrieve)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_CBN_SELCHANGE(IDC_DEP, OnSelchangeDep)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_INPUT, OnInput)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LEFT, OnItemchangedLeft)
	ON_NOTIFY(NM_CLICK, IDC_MASTER, OnClickMaster)
	ON_BN_CLICKED(IDCANCEL, OnCancel)
	ON_BN_CLICKED(IDC_DTX, OnDtx)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgKqConfirm diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CDlgKqConfirm message handlers

void CDlgKqConfirm::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
//1登记
	CMyMdi Mdi;
	Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
   
	m_pApp = (CKvipApp *)AfxGetApp();
	m_pConnection = m_pApp->m_pConWrite;
	if(m_pConnection == NULL) 
	{
		GetParent()->PostMessage(WM_CLOSE);
		return ;
	}
	
	// TODO: Add your specialized code here and/or call the base class
	m_RecordSet.SetAdoConnection(m_pConnection);
//1装入部门
	CString sSQL, sText;
	sSQL = _T("Select sm_Dept From kv_staff_mr group by sm_dept");
	if(m_RecordSet.Open(sSQL))
	{
	   while(m_RecordSet.IsEOF() == false)
	   {
	    m_RecordSet.GetCollect("sm_dept", sText);
        m_Dep.AddString(sText);
        m_RecordSet.MoveNext();
	   }
	}
	m_Dep.InsertString(0,"所有部门");
    m_Dep.SetCurSel(0);
//2初始化员工列表
    CDlgDataCell Cell;
	m_ListDoc.SetConnection(m_pConnection);
	m_ListDoc.Construe(&Cell, _T("=sm_Code;TEXT=编号;INDEXCOL=0;WIDTH=0"));
	m_ListDoc.m_data.push_back(Cell);
	m_ListDoc.Construe(&Cell, _T("=sm_Name;TEXT=名称;INDEXCOL=1;WIDTH=60"));
	m_ListDoc.m_data.push_back(Cell);
	m_ListDoc.Construe(&Cell, _T("=sm_Dept;TEXT=部门;INDEXCOL=2;WIDTH=60"));
	m_ListDoc.m_data.push_back(Cell);
	m_ListDoc.SetListCtrl(&m_Left);
    m_ListDoc.InitList();
	//m_ListDoc.Retrieve("Select sm_code, sm_name, sm_dept From kv_staff_mr", false);
    OnSelchangeDep();
//3初始化员工列表
	m_RightDoc.SetConnection(m_pConnection);
	m_RightDoc.Construe(&Cell, _T("=km_Code;TEXT=编号;INDEXCOL=0;WIDTH=0"));
	m_RightDoc.m_data.push_back(Cell);
	m_RightDoc.Construe(&Cell, _T("=km_Id;TEXT=序号;INDEXCOL=5;WIDTH=40"));
	m_RightDoc.m_data.push_back(Cell);
	m_RightDoc.Construe(&Cell, _T("=km_Date;TEXT=时间;CLASS=TIMEEDIT;INDEXCOL=10;WIDTH=80"));
	m_RightDoc.m_data.push_back(Cell);
	m_RightDoc.SetListCtrl(&m_Right);
    m_RightDoc.InitList();

//装入主表
//初始化员工列表
	m_MasterDoc.SetConnection(m_pConnection);
	m_MasterDoc.Construe(&Cell, _T("=kt_date;TEXT=日期;INDEXCOL=0;WIDTH=0;CLASS=DATEEDIT"));
	m_MasterDoc.m_data.push_back(Cell);
	m_MasterDoc.Construe(&Cell, _T("=kt_code;TEXT=编号;INDEXCOL=1;WIDTH=80"));
	m_MasterDoc.m_data.push_back(Cell);
	m_MasterDoc.Construe(&Cell, _T("=sm_name;TEXT=名称;INDEXCOL=2;WIDTH=80"));
	m_MasterDoc.m_data.push_back(Cell);
	m_MasterDoc.Construe(&Cell, _T("=kt_state;TEXT=类型;INDEXCOL=3;WIDTH=0"));
	m_MasterDoc.m_data.push_back(Cell);
	m_MasterDoc.Construe(&Cell, _T("=kt_id;TEXT=ID;INDEXCOL=100;WIDTH=0;SETKEY=ID;STYLE=AUTOKEY"));
	m_MasterDoc.m_data.push_back(Cell);
	m_MasterDoc.SetListCtrl(&m_Master);
	m_MasterDoc.InitList();
	
	m_edDate.SetClassType("DATEEDIT");
	_InputProject();         //导入考勤记录
	SetState(0);
    int nSubItem = m_Master.GetHeaderCtrl()->GetItemCount();
	m_Master.InsertColumn(nSubItem, "正常", LVCFMT_LEFT, 40);
	m_Master.SetCheckBox(nSubItem++);
	m_Master.InsertColumn(nSubItem, "迟到", LVCFMT_LEFT, 40);
	m_Master.SetCheckBox(nSubItem++);
	m_Master.InsertColumn(nSubItem, "早退", LVCFMT_LEFT, 40);
	m_Master.SetCheckBox(nSubItem++);
	m_Master.InsertColumn(nSubItem, "扩工", LVCFMT_LEFT, 40);
	m_Master.SetCheckBox(nSubItem);
}
void CDlgKqConfirm::SetState(int nState)
{
  switch(nState)
  {
  case 0:
	     m_edDate.SetNow();
	     m_btRetrieve.SetWindowText(_T("(&R)检索"));
		 m_edDate.EnableWindow(true);
		 m_edDate.SetFocus();
		 m_btDtx.EnableWindow(false);
		 m_btInput.EnableWindow(true);
		 m_btSave.EnableWindow(false);
		 m_RightDoc.ResetAll();
	     break;
  case 1: 
	     m_btRetrieve.SetWindowText(_T("(&R)清除"));
		 m_edDate.EnableWindow(false);
		 m_btDtx.EnableWindow(true);
		 m_btInput.EnableWindow(false);
		 m_btSave.EnableWindow(true);
	     break;
  }

}

void CDlgKqConfirm::OnDblclkMaster(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
/*	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	const int nColumn = pNMListView->iSubItem;
	const int nItem = pNMListView->iItem;
	int nSubItem = m_Master.GetSubItem("编号");
	CString sCode = m_Master.GetItemText(nItem, nSubItem);
	CString sSQL = _T("Select * From kv_kt_tmp Where km_code = '");
	sSQL = sSQL + sCode + _T("'");
	m_RightDoc.ResetAll();
	m_RightDoc.Retrieve(sSQL, false);
*/
	PostMessage(WM_COMMAND, IDC_DTX, 0);
	*pResult = 0;
}

void CDlgKqConfirm::OnRetrieve() 
{
	// TODO: Add your control notification handler code here
	CString sProject = _T(""), sText;
	CString sSQL, sDate;

	m_btRetrieve.GetWindowText(sText);
	if(sText == _T("(&R)检索"))
	{
		//输入效对
		m_edDate.GetWindowText(sDate);
		sSQL = _T("Select * From kv_kt_confirm, kv_staff_mr Where ");
		sSQL = sSQL + _T("kt_date >= #") + sDate + _T("#");
		sSQL = sSQL + _T(" AND kt_date <= #") + sDate  + _T("#");
		sSQL = sSQL + _T(" AND kt_code = sm_code");
		sSQL = sSQL + _T(" Order by kt_code");
		if(m_MasterDoc.Retrieve(sSQL) != 0)  return ;
		int nSubItem = m_Master.GetSubItem("类型");
		for(int i =0 ; i < m_Master.GetItemCount(); i++)
		{
			sText = m_Master.GetItemText(i, nSubItem);
			SetCheck(i, sText);
		}
		SetState(1);
	}
	else
	{
		OnSave(0);
		m_MasterDoc.ResetAll();
		SetState(0);
	}//end if

}



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

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



void CDlgKqConfirm::OnSelchangeDep() 
{
	// TODO: Add your control notification handler code here
	CStringSQL sSQL;
	CString sText, sProject;

//选择部门
	sSQL.SetSelect("Select * From kv_staff_mr");
	int nSel = m_Dep.GetCurSel();
	if(nSel > 0)
	{
	  m_Dep.GetWindowText(sText);
	  sSQL.SetWhere("sm_dept", sText);
	}
	sSQL.SetFoot("Order by sm_code, sm_dept");
    if(m_ListDoc.Retrieve(sSQL.GetSQL()) < 0)return;
	return;
	
}

void CDlgKqConfirm::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
    int nRet = IDNO;
//提示
	if(m_MasterDoc.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 CDlgKqConfirm::OnInput() 
{
// TODO: Add your control notification handler code here
  //CFile file;
  FILE *file;
  CString sDateItem, sName, sDept;
  CString sFileScr, sCode, sText, sTime, sInDate;
  COleDateTime tQdBegin, tQdEnd, tZtBegin, tZtEnd, tKgBegin, tKgEnd;
  CString sQdEnabled, sZtEnabled, sKgEnabled;
  CString sSQL;
  CString sDate, sAfterDate;
  COleDateTime tDate, tAfterDate;
  char szBuf[256];
  int nCount = 0, i, nItem;
  CInputTxt txt;
  BOOL bNew = false;
//取文件名
  CFileDialog dlg(TRUE, NULL, NULL, 
                  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | 
                  OFN_ALLOWMULTISELECT, 
                  "Txt (*.txt)|*.Txt|All files(*.*)|*.*||"); 
//取输入日期
  m_edDate.GetWindowText(sInDate);
  tDate = COleDateTime(COleVariant(sInDate));
  tAfterDate = tDate + COleDateTimeSpan(1,0,0,0);
  sAfterDate = tAfterDate.Format("%Y-%m-%d");
  m_pConnection->BeginTrans();
//是否已经日结
   sSQL = _T("Select Count(*) From kv_kt_confirm Where ");
   sSQL = sSQL + _T("kt_date >= #") + sInDate +_T("#");
   sSQL = sSQL + _T(" AND kt_date  <= #") + sInDate + _T("#");
   if(!m_RecordSet.Open(sSQL)) goto err01;
   
   m_RecordSet.GetCollect((long)0, nCount);
   if(nCount > 0)
   {
	   if(MessageBox(sInDate+"已经日结!你确定要重新进行日结吗?", "提示",MB_OKCANCEL|MB_ICONWARNING)!=IDOK)
         return ;
      sSQL = _T("Delete From kv_kt_confirm Where ");
      sSQL = sSQL + _T("kt_date >= #") + sInDate +_T("#");
      sSQL = sSQL + _T(" AND kt_date <= #") + sInDate +_T("#");
      if(!m_RecordSet.Open(sSQL)) goto err03;

      sSQL = _T("Delete From kv_kt_tmp");
      if(!m_RecordSet.Open(sSQL)) goto err03;
   }

//取文件名
  if (dlg.DoModal() != IDOK)return;
  sFileScr = dlg.GetPathName();
//打开文件
  m_Txt.clear();
  file = fopen(sFileScr, "r") ;
  if(file == NULL) goto err01;
//一行一行的读入
//格式:编号,日期,时间\n
  while(fgets(szBuf, 255, file))
  {
    sText = szBuf;
	sText = sText.Left(sText.GetLength()-1); //去回车
	i = sText.Find(',');
	if(i > 0) 
	{//取Code

⌨️ 快捷键说明

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