“成员信息表”(学生信息管理系统)代码续

// DeleteLieDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "ListCtrl.h"
#include "DeleteLieDlg.h"
#include "afxdialogex.h"


// CDeleteLieDlg 对话框

IMPLEMENT_DYNAMIC(CDeleteLieDlg, CDialogEx)

CDeleteLieDlg::CDeleteLieDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDeleteLieDlg::IDD, pParent)
	, m_delete(_T(""))
{

}

CDeleteLieDlg::~CDeleteLieDlg()
{
}

void CDeleteLieDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_delete);
}


BEGIN_MESSAGE_MAP(CDeleteLieDlg, CDialogEx)
END_MESSAGE_MAP()


// CDeleteLieDlg 消息处理程序
#pragma once




// CDeleteLieDlg 对话框


class CDeleteLieDlg : public CDialogEx
{
	DECLARE_DYNAMIC(CDeleteLieDlg)


public:
	CDeleteLieDlg(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CDeleteLieDlg();


// 对话框数据
	enum { IDD = IDD_DIALOG3 };


protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持


	DECLARE_MESSAGE_MAP()
public:
	CString m_delete;
	afx_msg void OnBnClickedOk();
};
// FilterDlg.cpp : 实现文件
//


#include "stdafx.h"
#include "ListCtrl.h"
#include "FilterDlg.h"
#include "afxdialogex.h"




// CFilterDlg 对话框


IMPLEMENT_DYNAMIC(CFilterDlg, CDialogEx)


CFilterDlg::CFilterDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CFilterDlg::IDD, pParent)
{
	iCount = 3;
	mapFilter.RemoveAll();
}


CFilterDlg::~CFilterDlg()
{
}


void CFilterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST2, m_ListFilter);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
}




BEGIN_MESSAGE_MAP(CFilterDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CFilterDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON1, &CFilterDlg::OnBnClickedButton1)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST2, &CFilterDlg::OnDblclkList2)
	ON_EN_KILLFOCUS(IDC_EDIT1, &CFilterDlg::OnKillfocusEdit1)
	ON_BN_CLICKED(IDCANCEL, &CFilterDlg::OnBnClickedCancel)
	ON_WM_SIZE()
	ON_WM_DRAWITEM()
END_MESSAGE_MAP()




// CFilterDlg 消息处理程序




void CFilterDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	if(JudgeData())
	{
	   CDialogEx::OnOK();
	}
}




//初始化控件
void CFilterDlg::InitCtrl()
{  
	m_edit.ShowWindow(SW_HIDE);


	//设置招展风格
	m_ListFilter.ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS);
	DWORD dwStyle = m_ListFilter.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
	dwStyle |= LVS_EX_GRIDLINES;
	m_ListFilter.SetExtendedStyle(dwStyle);  
	m_ListFilter.SetRowHeight(40);
	
	//插入数据
	CRect rect;
	m_ListFilter.GetClientRect(&rect);
	int nWidth = rect.Width()/3;
	m_ListFilter.InsertColumn(0,_T("条件1"),LVCFMT_CENTER,nWidth);
	m_ListFilter.InsertColumn(1,_T("条件2"),LVCFMT_CENTER,nWidth);
	m_ListFilter.InsertColumn(2,_T("条件3"),LVCFMT_CENTER,nWidth);


	m_ListFilter.InsertItem(0,_T(""));
	m_ListFilter.SetItemText(0,1,_T(""));
	m_ListFilter.SetItemText(0,2,_T(""));
	m_ListFilter.SetItemText(0,3,_T(""));


	m_ListFilter.InsertItem(1,_T(""));
	m_ListFilter.SetItemText(1,1,_T(""));
	m_ListFilter.SetItemText(1,2,_T(""));
	m_ListFilter.SetItemText(1,3,_T(""));
}    


BOOL CFilterDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();


	// TODO:  在此添加额外的初始化
	SetCtrlFont();
	InitCtrl();


	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}


//插入条件
void CFilterDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	iCount++;
	CRect rect;
	m_ListFilter.GetClientRect(&rect);


	int nWidth = rect.Width()/iCount;	
	CString strTemp;
	strTemp.Format("条件%d",iCount);


	m_ListFilter.InsertColumn(iCount-1,strTemp,LVCFMT_CENTER,nWidth);


	for(UINT i=0;i<iCount;i++)
	{
	   m_ListFilter.SetColumnWidth(i,nWidth);
	}


	iCount++;
}




void CFilterDlg::OnDblclkList2(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
    CRect rc;  
    CString strTemp;  
    NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)pNMHDR;  
    m_Row = pNMListView->iItem;  
    m_Col = pNMListView->iSubItem;  


	if (pNMListView->iItem == -1)    //选择空白处,添加一行,并设置焦点为最后一行,第二列  
	{
	   return;
	}


    if (m_Col >= 0) // 选择子项  
    {  
        m_ListFilter.GetSubItemRect(m_Row, m_Col, LVIR_LABEL, rc);  
        m_edit.SetParent(&m_ListFilter);  
        m_edit.MoveWindow(rc);  
        m_edit.SetWindowText(m_ListFilter.GetItemText(m_Row, m_Col));  
        m_edit.ShowWindow(SW_SHOW);  
        m_edit.SetFocus();//设置Edit焦点  
        m_edit.ShowCaret();//显示光标  
        m_edit.SetSel(0, -1);//全选  
		m_edit.SetFont(&m_Font); 
    }  
	*pResult = 0;
}




void CFilterDlg::OnKillfocusEdit1()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;  
    m_edit.GetWindowText(str);  
    m_ListFilter.SetItemText(m_Row, m_Col, str);  
    m_edit.ShowWindow(SW_HIDE);  


	m_arrary[m_Col][m_Row] = str;
}


void CFilterDlg::SetCtrlFont()      //设置字体大小
{
	m_Font.CreatePointFont(150, _T("宋体"));
    m_ListFilter.SetFont(&m_Font);
	m_ListFilter.GetHeaderCtrl()->SetFont(&m_Font);
	
	//CFont m_btnFont;
	//m_btnFont.CreatePointFont(50, _T("微软雅黑"));
	//GetDlgItem(IDC_BUTTON1)->SetFont(&m_btnFont);
	//GetDlgItem(IDOK)->SetFont(&m_btnFont);
	//GetDlgItem(IDCANCEL)->SetFont(&m_btnFont);
}


BOOL CFilterDlg::JudgeData()     //判断数据
{   
	BOOL bFlag = TRUE;
  
	for(UINT i=0;i<iCount;i++)
	{
		if(m_arrary[i][0] != _T(""))
		{
			if(m_arrary[i][1] == _T(""))
			{   
				mapFilter.RemoveAll();
				CString strTemp;
				strTemp.Format(_T("存在条件%d数据为空,请输入数据"),i+1);				
				AfxMessageBox(strTemp);
				bFlag = FALSE;
				break;
			}
			else
			{
			   CString strKey   = m_arrary[i][0]; 
  	           CString strValue = m_arrary[i][1];
			   mapFilter.SetAt(strKey,strValue);
			}
		}
	}
	return bFlag;
}


void CFilterDlg::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	mapFilter.RemoveAll();
	CDialogEx::OnCancel();
}




#pragma once
#include "MylistCtrl.h"
#include "afxcmn.h"
#include "afxwin.h"
// CFilterDlg 对话框


class CFilterDlg : public CDialogEx
{
	DECLARE_DYNAMIC(CFilterDlg)


public:
	CFilterDlg(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CFilterDlg();


// 对话框数据
	enum { IDD = IDD_DIALOG4 };


protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持


	DECLARE_MESSAGE_MAP()


private:
	
	CEdit m_edit;
	CMyListCtrl m_ListFilter;   // 筛选条件列表
	UINT iCount;              //条件个数
	int m_Row;                //行数
	int m_Col;                //列数
	CString m_arrary[10][2];
	CRect m_rect;
	CFont m_Font;
public:
	
	CMap<CString,LPCTSTR,CString,LPCTSTR>mapFilter;


	void InitCtrl();           //初始化控件
	void SetCtrlFont();            //设置字体大小
	virtual BOOL OnInitDialog();
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedButton1();
	afx_msg void OnDblclkList2(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnKillfocusEdit1();
	afx_msg void OnBnClickedCancel();
	BOOL JudgeData();     //判断数据


};
/*******************************************************************************
	Author						: Aravindan Premkumar
	Unregistered Copyright 2003	: Aravindan Premkumar
	All Rights Reserved
	
	This piece of code does not have any registered copyright and is free to be 
	used as necessary. The user is free to modify as per the requirements. As a
	fellow developer, all that I expect and request for is to be given the 
	credit for intially developing this reusable code by not removing my name as 
	the author.
*******************************************************************************/


#include "stdafx.h"
#include "InPlaceCombo.h"


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


/////////////////////////////////////////////////////////////////////////////
// CInPlaceCombo


CInPlaceCombo* CInPlaceCombo::m_pInPlaceCombo = NULL; 


CInPlaceCombo::CInPlaceCombo()
{
	m_iRowIndex = -1;
	m_iColumnIndex = -1;
	m_bESC = FALSE;
}


CInPlaceCombo::~CInPlaceCombo()
{
}


BEGIN_MESSAGE_MAP(CInPlaceCombo, CComboBox)
	//{{AFX_MSG_MAP(CInPlaceCombo)
	ON_WM_CREATE()
	ON_WM_KILLFOCUS()
	ON_WM_CHAR()
	ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CInPlaceCombo message handlers


int CInPlaceCombo::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CComboBox::OnCreate(lpCreateStruct) == -1)
	{
		return -1;
	}
	
	// Set the proper font
	CFont* pFont = GetParent()->GetFont();
	SetFont(pFont);
	
	SetFocus();


	ResetContent(); 
	for (POSITION Pos_ = m_DropDownList.GetHeadPosition(); Pos_ != NULL;)
	{
		AddString((LPCTSTR) (m_DropDownList.GetNext(Pos_)));
	}


	return 0;
}


BOOL CInPlaceCombo::PreTranslateMessage(MSG* pMsg) 
{
	// If the message if for "Enter" or "Esc"
	// Do not process
	if (pMsg->message == WM_KEYDOWN)
	{
		if(pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
		{
			::TranslateMessage(pMsg);
			::DispatchMessage(pMsg);
			// DO NOT process further
			return TRUE;				
		}
	}
	
	return CComboBox::PreTranslateMessage(pMsg);
}


void CInPlaceCombo::OnKillFocus(CWnd* pNewWnd) 
{
	CComboBox::OnKillFocus(pNewWnd);
	
	// Get the current selection text
	CString str;
	GetWindowText(str);


	// Send Notification to parent of ListView ctrl
	LV_DISPINFO dispinfo;
	dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
	dispinfo.hdr.idFrom = GetDlgCtrlID();
	dispinfo.hdr.code = LVN_ENDLABELEDIT;


	dispinfo.item.mask = LVIF_TEXT;
	dispinfo.item.iItem = m_iRowIndex;
	dispinfo.item.iSubItem = m_iColumnIndex;
	dispinfo.item.pszText = m_bESC ? LPTSTR((LPCTSTR)m_strWindowText) : LPTSTR((LPCTSTR)str);
	dispinfo.item.cchTextMax = m_bESC ? m_strWindowText.GetLength() : str.GetLength();
	
	GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo);


	// Close the control
	PostMessage(WM_CLOSE);
}


void CInPlaceCombo::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// If the key is "Esc" set focus back to the list control
	if (nChar == VK_ESCAPE || nChar == VK_RETURN)
	{
		if (nChar == VK_ESCAPE)
		{
			m_bESC = TRUE;
		}


		GetParent()->SetFocus();
		return;
	}
	
	CComboBox::OnChar(nChar, nRepCnt, nFlags);
}


void CInPlaceCombo::OnCloseup() 
{
	// Set the focus to the parent list control
	GetParent()->SetFocus();
}


CInPlaceCombo* CInPlaceCombo::GetInstance()
{
	if(m_pInPlaceCombo == NULL)
	{
		m_pInPlaceCombo = new CInPlaceCombo;
	}
	return m_pInPlaceCombo;
}


void CInPlaceCombo::DeleteInstance()
{
	delete m_pInPlaceCombo;
	m_pInPlaceCombo = NULL;
}


BOOL CInPlaceCombo::ShowComboCtrl(DWORD dwStyle, const CRect &rCellRect, CWnd* pParentWnd, UINT uiResourceID,
								  int iRowIndex, int iColumnIndex, CStringList* pDropDownList, 
								  CString strCurSelecetion /*= ""*/, int iCurSel /*= -1*/)
{


	m_iRowIndex = iRowIndex;
	m_iColumnIndex = iColumnIndex;
	m_bESC = FALSE;
	
	m_DropDownList.RemoveAll(); 
	m_DropDownList.AddTail(pDropDownList);


	BOOL bRetVal = TRUE;


	if (-1 != iCurSel)
	{
		GetLBText(iCurSel, m_strWindowText);
	}
	else if (!strCurSelecetion.IsEmpty()) 
	{
		m_strWindowText = strCurSelecetion;
	}
	
	if (NULL == m_pInPlaceCombo->m_hWnd) 
	{
		bRetVal = m_pInPlaceCombo->Create(dwStyle, rCellRect, pParentWnd, uiResourceID); 
	}


	SetCurSel(iCurSel);


	return bRetVal;
}
/*******************************************************************************
	Author						: Aravindan Premkumar
	Unregistered Copyright 2003	: Aravindan Premkumar
	All Rights Reserved
	
	This piece of code does not have any registered copyright and is free to be 
	used as necessary. The user is free to modify as per the requirements. As a
	fellow developer, all that I expect and request for is to be given the 
	credit for intially developing this reusable code by not removing my name as 
	the author.
*******************************************************************************/


#if !defined(AFX_INPLACECOMBO_H__2E04D8D9_827F_4FBD_9E87_30AF8C31639D__INCLUDED_)
#define AFX_INPLACECOMBO_H__2E04D8D9_827F_4FBD_9E87_30AF8C31639D__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CInPlaceCombo : public CComboBox
{
public:
		
// Implementation
	
	// Returns the instance of the class
	static CInPlaceCombo* GetInstance(); 


	// Deletes the instance of the class
	static void DeleteInstance(); 


	// Creates the Windows combo control and attaches it to the object, if needed and shows the combo ctrl
	BOOL ShowComboCtrl(DWORD dwStyle, const CRect& rCellRect, CWnd* pParentWnd, UINT uiResourceID,
					   int iRowIndex, int iColumnIndex, CStringList* pDropDownList, CString strCurSelecetion = "", int iCurSel = -1);


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CInPlaceCombo)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL


protected:


	// Generated message map functions
	//{{AFX_MSG(CInPlaceCombo)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnCloseup();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()


private:


// Implementation
	// Constructor
	CInPlaceCombo();


	// Hide the copy constructor and operator =
	CInPlaceCombo (CInPlaceCombo&) {}


	int operator = (CInPlaceCombo) {}


	// Destructor
	virtual ~CInPlaceCombo();


// Attributes


	// Index of the item in the list control
	int m_iRowIndex;


	// Index of the subitem in the list control
	int m_iColumnIndex;


	// To indicate whether ESC key was pressed
	BOOL m_bESC;
	
	// Singleton instance
	static CInPlaceCombo* m_pInPlaceCombo;


	// Previous selected string value in the combo control
	CString m_strWindowText;


	// List of items to be shown in the drop down
	CStringList m_DropDownList;
};


/////////////////////////////////////////////////////////////////////////////


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_INPLACECOMBO_H__2E04D8D9_827F_4FBD_9E87_30AF8C31639D__INCLUDED_)
/*******************************************************************************
	Author						: Aravindan Premkumar
	Unregistered Copyright 2003	: Aravindan Premkumar
	All Rights Reserved
	
	This piece of code does not have any registered copyright and is free to be 
	used as necessary. The user is free to modify as per the requirements. As a
	fellow developer, all that I expect and request for is to be given the 
	credit for intially developing this reusable code by not removing my name as 
	the author.
*******************************************************************************/


#include "stdafx.h"
#include "InPlaceEdit.h"


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


#define CTRL_C	0x3
#define CTRL_V	0x16
#define CTRL_X	0x18


/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit


CInPlaceEdit* CInPlaceEdit::m_pInPlaceEdit = NULL;  


CInPlaceEdit::CInPlaceEdit()
{
	m_iRowIndex= -1;
	m_iColumnIndex = -1;
	m_bESC = FALSE;
	m_strValidChars.Empty();
}


CInPlaceEdit::~CInPlaceEdit()
{
}


BEGIN_MESSAGE_MAP(CInPlaceEdit, CEdit)
	//{{AFX_MSG_MAP(CInPlaceEdit)
	ON_WM_KILLFOCUS()
	ON_WM_CHAR()
	ON_MESSAGE(WM_PASTE, OnPaste)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit message handlers


LRESULT CInPlaceEdit::OnPaste(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
	if (m_strValidChars.IsEmpty())
	{
		return 0;	
	}


    CString strFromClipboard;


	// get the text from clipboard
	if(OpenClipboard()) {
		HANDLE l_hData = GetClipboardData(CF_TEXT);
		if(NULL == l_hData) {
			return 0;
		}
		
		char *l_pBuffer = (char*)GlobalLock(l_hData);
		if(NULL != l_pBuffer) {
			strFromClipboard = l_pBuffer;
		}


		GlobalUnlock(l_hData);
		CloseClipboard();
	}


	// Validate the characters before pasting 
	for(int iCounter_ = 0; iCounter_ < strFromClipboard.GetLength(); iCounter_++)
	{
		if (-1 == m_strValidChars.Find(strFromClipboard.GetAt(iCounter_)))
		{
			return 0;
		}
	}
		
	//let the individual control handle other processing
	CEdit::Default();	
}


void CInPlaceEdit::OnKillFocus(CWnd* pNewWnd) 
{
	CEdit::OnKillFocus(pNewWnd);
	
	// TODO: Add your message handler code here


	// Get the text in the edit ctrl
	CString strEdit;
	GetWindowText(strEdit);


	// Send Notification to parent of edit ctrl
	LV_DISPINFO dispinfo;
	dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
	dispinfo.hdr.idFrom = GetDlgCtrlID();
	dispinfo.hdr.code = LVN_ENDLABELEDIT;


	dispinfo.item.mask = LVIF_TEXT;
	dispinfo.item.iItem = m_iRowIndex;
	dispinfo.item.iSubItem = m_iColumnIndex;
	dispinfo.item.pszText = m_bESC ? LPTSTR((LPCTSTR)m_strWindowText) : LPTSTR((LPCTSTR)strEdit);
	dispinfo.item.cchTextMax = m_bESC ? m_strWindowText.GetLength() : strEdit.GetLength();
	
	GetParent()->SendMessage(WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo);


	PostMessage(WM_CLOSE);
}


void CInPlaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default


 	if ((m_strValidChars.IsEmpty()) || ((-1 != m_strValidChars.Find(static_cast<TCHAR> (nChar))) || 
		(nChar == VK_BACK) || (nChar == CTRL_C) || (nChar == CTRL_V) || (nChar == CTRL_X)))
	{
		CEdit::OnChar(nChar, nRepCnt, nFlags);
	}
	else
	{
		MessageBeep(MB_ICONEXCLAMATION);
		return;
	}
}


BOOL CInPlaceEdit::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (WM_KEYDOWN == pMsg->message && (VK_ESCAPE == pMsg->wParam || VK_RETURN == pMsg->wParam))
	{
		if (VK_ESCAPE == pMsg->wParam)
		{
			m_bESC = TRUE;
		}


		GetParent()->SetFocus();
		return TRUE;
	}


	return CEdit::PreTranslateMessage(pMsg);
}


int CInPlaceEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEdit::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	// Set the proper font
	CFont* pFont = GetParent()->GetFont();
	SetFont(pFont);


	ShowWindow(SW_SHOW);
	SetWindowText(m_strWindowText);
	SetSel(0, -1);
	SetFocus();
	
	  
	return 0;
}


CInPlaceEdit* CInPlaceEdit::GetInstance()
{
	if(m_pInPlaceEdit == NULL)
	{
		m_pInPlaceEdit = new CInPlaceEdit;
	}
	return m_pInPlaceEdit;
}


void CInPlaceEdit::DeleteInstance()
{
	delete m_pInPlaceEdit;
	m_pInPlaceEdit = NULL;
}


BOOL CInPlaceEdit::ShowEditCtrl(DWORD dwStyle, const RECT &rCellRect, CWnd* pParentWnd, 
								UINT uiResourceID, int iRowIndex, int iColumnIndex,
								CString& strValidChars, CString& rstrCurSelection)
{
	m_iRowIndex = iRowIndex;
	m_iColumnIndex = iColumnIndex;
	m_strValidChars = strValidChars;
	m_strWindowText = rstrCurSelection;
	m_bESC = FALSE;


	if (NULL == m_pInPlaceEdit->m_hWnd) 
	{
		return m_pInPlaceEdit->Create(dwStyle, rCellRect, pParentWnd, uiResourceID); 
	}	


	return TRUE;
}
/*******************************************************************************
	Author						: Aravindan Premkumar
	Unregistered Copyright 2003	: Aravindan Premkumar
	All Rights Reserved
	
	This piece of code does not have any registered copyright and is free to be 
	used as necessary. The user is free to modify as per the requirements. As a
	fellow developer, all that I expect and request for is to be given the 
	credit for intially developing this reusable code by not removing my name as 
	the author.
*******************************************************************************/


#if !defined(AFX_INPLACEEDIT_H__175AEDFF_731E_4721_8399_DE406A465861__INCLUDED_)
#define AFX_INPLACEEDIT_H__175AEDFF_731E_4721_8399_DE406A465861__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CInPlaceEdit : public CEdit
{


public:
	
// Implementation
	
	// Returns the instance of the class
	static CInPlaceEdit* GetInstance(); 


	// Deletes the instance of the class
	static void DeleteInstance(); 


	// Creates the Windows edit control and attaches it to the object
	// Shows the edit ctrl
	BOOL ShowEditCtrl(DWORD dwStyle, const RECT& rCellRect, CWnd* pParentWnd, 
					  UINT uiResourceID, int iRowIndex, int iColumnIndex,
					  CString& strValidChars, CString& rstrCurSelection);


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CInPlaceEdit)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL




// Attributes


protected:	
	// Generated message map functions
	//{{AFX_MSG(CInPlaceEdit)
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg LRESULT OnPaste(WPARAM wParam, LPARAM lParam);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG


	DECLARE_MESSAGE_MAP()


private:


// Implementation


	// Constructor
	CInPlaceEdit();


	// Hide the copy constructor and operator =
	CInPlaceEdit (CInPlaceEdit&) {}


	int operator = (CInPlaceEdit) {}
	
	// Destructor
	virtual ~CInPlaceEdit();


// Attributes


	// Index of the item in the list control
	int m_iRowIndex;


	// Index of the subitem in the list control
	int m_iColumnIndex;


	// To indicate whether ESC key was pressed
	BOOL m_bESC;
	
	// Valid characters
	CString m_strValidChars;


	// Singleton instance
	static CInPlaceEdit* m_pInPlaceEdit;


	// Previous string value in the edit control
	CString m_strWindowText;
};


/////////////////////////////////////////////////////////////////////////////


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_INPLACEEDIT_H__175AEDFF_731E_4721_8399_DE406A465861__INCLUDED_)
// KeyDlg.cpp : 实现文件
//


#include "stdafx.h"
#include "ListCtrl.h"
#include "KeyDlg.h"
#include "afxdialogex.h"




// CKeyDlg 对话框


IMPLEMENT_DYNAMIC(CKeyDlg, CDialogEx)


CKeyDlg::CKeyDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CKeyDlg::IDD, pParent)
	, m_keywords(_T(""))
{


}


CKeyDlg::~CKeyDlg()
{
}


void CKeyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_KeyCI, m_keywords);
}




BEGIN_MESSAGE_MAP(CKeyDlg, CDialogEx)
	ON_BN_CLICKED(IDCANCEL, &CKeyDlg::OnBnClickedCancel)
	ON_BN_CLICKED(IDC_BUTTON1, &CKeyDlg::OnBnClickedButton1)
END_MESSAGE_MAP()




// CKeyDlg 消息处理程序




void CKeyDlg::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnCancel();
}




void CKeyDlg::OnBnClickedButton1()
{
	CString strKey = _T("");
	((CEdit*)GetDlgItem(IDC_EDIT_KeyCI))->GetWindowText(strKey);
	if(strKey.IsEmpty())
	{
		AfxMessageBox(_T("输入内容不能为空!"));
	}
	else
	{
	  CDialogEx::OnOK();
	}
}
#pragma once




// CKeyDlg 对话框


class CKeyDlg : public CDialogEx
{
	DECLARE_DYNAMIC(CKeyDlg)


public:
	CKeyDlg(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CKeyDlg();


// 对话框数据
	enum { IDD = IDD_DIALOG1 };


protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持


	DECLARE_MESSAGE_MAP()
public:
	CString m_keywords;
	afx_msg void OnBnClickedCancel();
	afx_msg void OnBnClickedButton1();
};
// ListCtrl.cpp : Defines the class behaviors for the application.
//


#include "stdafx.h"
#include "ListCtrl.h"
#include "ListCtrlDlg.h"


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


/////////////////////////////////////////////////////////////////////////////
// CListCtrlApp


BEGIN_MESSAGE_MAP(CListCtrlApp, CWinApp)
	//{{AFX_MSG_MAP(CListCtrlApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CListCtrlApp construction


CListCtrlApp::CListCtrlApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


/////////////////////////////////////////////////////////////////////////////
// The one and only CListCtrlApp object


CListCtrlApp theApp;


/////////////////////////////////////////////////////////////////////////////
// CListCtrlApp initialization


BOOL CListCtrlApp::InitInstance()
{
	AfxEnableControlContainer();


	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.


#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif


	 
	CListCtrlDlg dlg;


	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	// 初始化 OLE 库
	if (!AfxOleInit())
	{
		return FALSE;
	}


	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}


	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
// ListCtrl.h : main header file for the LISTCTRL application
//


#if !defined(AFX_LISTCTRL_H__1E6D1574_50E9_4BC8_9DD5_F903BF60EBB9__INCLUDED_)
#define AFX_LISTCTRL_H__1E6D1574_50E9_4BC8_9DD5_F903BF60EBB9__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif


#include "resource.h"		// main symbols


/////////////////////////////////////////////////////////////////////////////
// CListCtrlApp:
// See ListCtrl.cpp for the implementation of this class
//


class CListCtrlApp : public CWinApp
{
public:
	CListCtrlApp();


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CListCtrlApp)
	public:
	virtual BOOL InitInstance();
	//}}AFX_VIRTUAL


// Implementation


	//{{AFX_MSG(CListCtrlApp)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};




/////////////////////////////////////////////////////////////////////////////


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_LISTCTRL_H__1E6D1574_50E9_4BC8_9DD5_F903BF60EBB9__INCLUDED_)
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"


#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"


/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS


/////////////////////////////////////////////////////////////////////////////
// 中文(简体) resources


#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_NEUTRAL


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//


IDD_ABOUTBOX DIALOG 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "关于成员信息表"
FONT 8, "MS Sans Serif"
BEGIN
    ICON            IDR_MAINFRAME,IDC_STATIC,11,17,20,20
    LTEXT           "成员信息表 v1.0",IDC_STATIC,40,10,119,8,SS_NOPREFIX
    LTEXT           "Copyright (C) 2018-2021 刁肥宅",IDC_STATIC,40,25,119,8
    DEFPUSHBUTTON   "确定",IDOK,178,7,50,14,WS_GROUP
END




/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//


#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    IDD_ABOUTBOX, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 228
        TOPMARGIN, 7
        BOTTOMMARGIN, 48
    END
END
#endif    // APSTUDIO_INVOKED


#endif    // 中文(简体) resources
/////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////
// 中文(简体,中国) resources


#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//


IDD_LISTCTRL_DIALOG DIALOGEX 0, 0, 308, 121
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CLIENTEDGE | WS_EX_APPWINDOW
CAPTION "成员信息表"
FONT 18, "MS Shell Dlg", 400, 0, 0x86
BEGIN
    EDITTEXT        IDC_EDIT_CHARU,53,58,33,14,ES_AUTOHSCROLL
    CONTROL         "List1",IDC_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_NOLABELWRAP | LVS_AUTOARRANGE | LVS_EDITLABELS | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_TABSTOP,7,15,286,97,WS_EX_DLGMODALFRAME | WS_EX_STATICEDGE
    PUSHBUTTON      "返回",IDC_BUTTON_OPEN,270,3,27,10
    PUSHBUTTON      "删除项目",IDC_BUTTON_DELETE,229,3,40,10
    PUSHBUTTON      "添加项目",IDC_BUTTON_ADD,188,3,40,10
    PUSHBUTTON      "检索",IDC_BUTTON_INDEX,98,3,28,10
    PUSHBUTTON      "退出",IDC_BUTTON_EXIT,69,3,28,10
    PUSHBUTTON      "另存为",IDC_BUTTON_LINGSAVE,35,3,33,10
    PUSHBUTTON      "保存",IDC_BUTTON_SAVE,7,3,28,10
    PUSHBUTTON      "导入",IDC_BUTTON_IMPORT,157,3,28,10
    PUSHBUTTON      "筛选",IDC_BUTTON_FILTER,128,3,28,10
END


IDD_DIALOG1 DIALOGEX 0, 0, 163, 101
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "输入检索关键词"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    PUSHBUTTON      "取消",IDCANCEL,103,80,50,14
    EDITTEXT        IDC_EDIT_KeyCI,51,23,65,16,ES_AUTOHSCROLL
    LTEXT           "关键词:",IDC_STATIC,15,25,33,11
    PUSHBUTTON      "确定",IDC_BUTTON1,7,80,50,14
END


IDD_DIALOG2 DIALOGEX 0, 0, 161, 87
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "插入标题"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "确定",IDOK,7,66,50,14
    PUSHBUTTON      "取消",IDCANCEL,93,66,50,14
    LTEXT           "列名:",IDC_STATIC,15,27,24,13
    EDITTEXT        IDC_EDIT1,42,26,44,13,ES_AUTOHSCROLL
END


IDD_DIALOG3 DIALOGEX 0, 0, 147, 79
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "删除标题"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "确定",IDOK,2,58,50,14
    PUSHBUTTON      "取消",IDCANCEL,89,59,50,14
    LTEXT           "列名:",IDC_STATIC,12,25,29,14
    EDITTEXT        IDC_EDIT1,53,25,59,15,ES_AUTOHSCROLL
END


IDD_DIALOG4 DIALOGEX 0, 0, 316, 110
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "筛选功能"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "确定",IDOK,201,88,50,15
    PUSHBUTTON      "取消",IDCANCEL,257,88,52,15
    CONTROL         "",IDC_LIST2,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_OWNERDRAWFIXED | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,7,302,68
    PUSHBUTTON      "添加条件",IDC_BUTTON1,139,89,50,14
    EDITTEXT        IDC_EDIT1,7,89,47,14,ES_AUTOHSCROLL
END


IDD_DIALOG5 DIALOGEX 0, 0, 148, 121
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "检索功能对话框"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    LTEXT           "向下检索",IDC_DOWN,46,74,65,15,SS_NOTIFY
    LTEXT           "向上检索",IDC_UP,46,50,65,15,SS_NOTIFY
    LTEXT           "",IDC_TIP,20,17,110,24
    LTEXT           "退出检索",IDC_EXIT,46,99,69,15,SS_NOTIFY
END




/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//


#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    IDD_LISTCTRL_DIALOG, DIALOG
    BEGIN
        LEFTMARGIN, 6
        RIGHTMARGIN, 302
        TOPMARGIN, 2
        BOTTOMMARGIN, 114
    END


    IDD_DIALOG1, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 156
        TOPMARGIN, 7
        BOTTOMMARGIN, 94
    END


    IDD_DIALOG2, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 154
        TOPMARGIN, 7
        BOTTOMMARGIN, 80
    END


    IDD_DIALOG3, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 140
        TOPMARGIN, 7
        BOTTOMMARGIN, 72
    END


    IDD_DIALOG4, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 309
        TOPMARGIN, 7
        BOTTOMMARGIN, 103
    END


    IDD_DIALOG5, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 141
        TOPMARGIN, 6
        BOTTOMMARGIN, 114
    END
END
#endif    // APSTUDIO_INVOKED




/////////////////////////////////////////////////////////////////////////////
//
// Menu
//


IDR_LIST_POPUP MENUEX
BEGIN
    POPUP "_Popup_",                        65535,MFT_STRING,MFS_ENABLED
    BEGIN
        MENUITEM "插入",                          ID_LST_INSERT,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
        MENUITEM "删除",                          ID_LST_DELETE,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
        MENUITEM "修改",                          ID_XIU,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
        MENUITEM "最小化",                        ID_LST_MINISIZE,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
        MENUITEM "最大化",                        ID_LST_MAXISIZE,MFT_STRING,MFS_ENABLED
        MENUITEM "联系作者",                      ID_LST_Display,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
    END
END




/////////////////////////////////////////////////////////////////////////////
//
// Icon
//


// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1               ICON                    "res\\wh1.ico"


#endif    // 中文(简体,中国) resources
/////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////
// 英语(美国) resources


#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US


/////////////////////////////////////////////////////////////////////////////
//
// Icon
//


// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME           ICON                    "res\\wh1.ico"




#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//


1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END


2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END


3 TEXTINCLUDE 
BEGIN
    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
    "#define _AFX_NO_OLE_RESOURCES\r\n"
    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
    "\r\n"
    "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
    "#ifdef _WIN32\r\n"
    "LANGUAGE 9, 1\r\n"
    "#pragma code_page(1252)\r\n"
    "#endif //_WIN32\r\n"
    "#include ""res\\ListCtrl.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
    "#include ""afxres.rc""         // Standard components\r\n"
    "#endif\r\n"
    "\0"
END


#endif    // APSTUDIO_INVOKED




/////////////////////////////////////////////////////////////////////////////
//
// Version
//


VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "Comments", "給倩女神的成员信息表"
            VALUE "CompanyName", "合肥工业大学宣城校区"
            VALUE "FileDescription", "成员信息表"
            VALUE "FileVersion", "1, 0, 0, 1"
            VALUE "InternalName", "成员信息表"
            VALUE "LegalCopyright", "Copyright (C) 2018-2021 刁肥宅"
            VALUE "OriginalFilename", "成员信息表.EXE"
            VALUE "PrivateBuild", "作者邮箱:[email protected]"
            VALUE "ProductName", "成员信息表"
            VALUE "ProductVersion", "1, 0, 0, 1"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END




/////////////////////////////////////////////////////////////////////////////
//
// String Table
//


STRINGTABLE
BEGIN
    IDS_ABOUTBOX            "&关于成员信息表"
END


#endif    // 英语(美国) resources
/////////////////////////////////////////////////////////////////////////////






#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES


#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\ListCtrl.rc2"  // non-Microsoft Visual C++ edited resources
#include "afxres.rc"         // Standard components
#endif


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


// ListCtrlDlg.cpp : implementation file
//


#include "stdafx.h"
#include "ListCtrl.h"
#include "ListCtrlDlg.h"
#include "CApplication.h"
#include "CRange.h"
#include "CWorkbooks.h"
#include "CWorksheets.h"
#include "CWorkbook.h"
#include "CWorksheet.h"
#include "afxdialogex.h"
#include <afxdb.h>
#include <Afxdlgs.h>
#include "comutil.h"
//#include "ListCtrl.rc"




#pragma comment(lib, "comsupp.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About


class CAboutDlg : public CDialog
{
public:
	CAboutDlg();


// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA


	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL


// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}


void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CListCtrlDlg dialog


CListCtrlDlg::CListCtrlDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CListCtrlDlg::IDD)
{
	//{{AFX_DATA_INIT(CListCtrlDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_iItemCount = 0;
	m_Index.first = 0;
	m_Index.second = 0;
	m_vecSerach.clear();
	pDlg = NULL;
	iSerachIndex = 0;
	mapAllData.RemoveAll();
	mapCheckData.RemoveAll();
	pColName = NULL;
}


void CListCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CListCtrlDlg)
	DDX_Control(pDX, IDC_LIST1, m_List);
	//}}AFX_DATA_MAP
	//  DDX_Text(pDX, IDC_EDIT_CHARU, m_charu);
	DDX_Control(pDX, IDC_EDIT_CHARU, m_charu);
}


BEGIN_MESSAGE_MAP(CListCtrlDlg, CDialog)
	//{{AFX_MSG_MAP(CListCtrlDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_LST_DELETE, OnLstDelete)
	ON_COMMAND(ID_LST_INSERT, OnLstInsert)
	ON_COMMAND(ID_LST_MINISIZE, OnLstMinisizeScreen)
	ON_COMMAND(ID_LST_MAXISIZE,OnLstMaxisizeScreen)
	ON_COMMAND(ID_LST_Display, DisplayAuthor)
	ON_NOTIFY(NM_RCLICK, IDC_LIST, OnRclickList)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_VALIDATE, OnEndLabelEditVariableCriteria)
	ON_MESSAGE(WM_SET_ITEMS, PopulateComboList)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CListCtrlDlg::OnButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_LINGSAVE, &CListCtrlDlg::OnButtonLingsave)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, &CListCtrlDlg::OnButtonExit)
	ON_BN_CLICKED(IDC_BUTTON_INDEX, &CListCtrlDlg::OnButtonIndex)
	ON_BN_CLICKED(IDC_BUTTON_ADD, &CListCtrlDlg::OnButtonAdd)
	ON_COMMAND(ID_XIU, &CListCtrlDlg::OnButtonXiu)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, &CListCtrlDlg::OnButtonDelete)
	ON_BN_CLICKED(IDC_BUTTON_OPEN, &CListCtrlDlg::OnButtonOpen)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST, &CListCtrlDlg::OnDblclkList)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BUTTON_FILTER, &CListCtrlDlg::OnBnClickedButtonFilter)
	ON_MESSAGE(WM_USER_UP_SERACH, &CListCtrlDlg::OnUserUpSerach)
	ON_MESSAGE(WM_USER_DOWN_SERACH, &CListCtrlDlg::OnUserDownSerach)
	ON_BN_CLICKED(IDC_BUTTON_IMPORT, &CListCtrlDlg::OnBnClickedButtonImport)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CListCtrlDlg message handlers


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


	// Add "About..." menu item to system menu.


	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);


	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}




	m_hIcon1 = AfxGetApp()->LoadIcon(IDI_ICON1);
	SetIcon(m_hIcon1, TRUE);
	SetIcon(m_hIcon1, FALSE);
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	//SetIcon(m_hIcon, TRUE);			// Set big icon
	//SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_charu.ShowWindow(SW_HIDE);
	// Make the necessary initializations
	length = rect.Width();
	m_List.GetClientRect(&rect);
	m = 0;
	//初始化列表框
	m_List.ModifyStyle(0, LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS);
	m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);
	//显示字体的颜色
	m_List.SetTextColor(RGB(0, 0, 0));
	m_List.InsertColumn(m, "序号", LVCFMT_CENTER, 70);
	m_List.InsertColumn(m + 1, "姓名", LVCFMT_CENTER, 125);
	m_List.InsertColumn(m + 2, "学号", LVCFMT_CENTER, 145);
	m_List.InsertColumn(m + 3, "班级", LVCFMT_CENTER, 335);


	m_List.SetReadOnlyColumns(0);
	//m_List.SetComboColumns(1);


	CString strValidChars = "";
	m_List.SetValidEditCtrlCharacters(strValidChars);
	m_List.EnableVScroll(); 
	
	int iCount = m + 4;     //列总数
	//pColName = new CString[iCount];
	pColName = new CString[20];
	pColName[0]= "序号";
	pColName[1]= "姓名";
	pColName[2]= "学号";
	pColName[3]= "班级";
	
	
	//  执行此操作
	SetIcon(m_hIcon1, TRUE);			// 设置大图标
	SetIcon(m_hIcon1, FALSE);		// 设置小图标
	CRect rc;
	GetClientRect(&rc);//获取对话框客户区大小  
	GetDlgItem(IDC_BUTTON_OPEN)->ShowWindow(SW_HIDE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}


void CListCtrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}


// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.


void CListCtrlDlg::OnPaint() 
{
	// 不为绘图消息调用 CDialogEx::OnPaint()
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文
		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon1);
	}
	else
	{
		CDialog::OnPaint();
		CDialog::UpdateWindow(); //UpdateWindow一下
	}
}


// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CListCtrlDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon1;
}


//void CListCtrlDlg::ReadVersion(CString& strVersion, CString& strCopyriht)
//{
//	char szAppFullPath[_MAX_PATH] = { 0 };
//	::GetModuleFileName(NULL, szAppFullPath, _MAX_PATH);
//
//
//	DWORD dwLen = GetFileVersionInfoSize(szAppFullPath, NULL);
//	char *pszAppVersion = new char[dwLen + 1];
//	if (NULL != pszAppVersion)
//	{
//		ZeroMemory(pszAppVersion, dwLen + 1);
//		::GetFileVersionInfo(szAppFullPath, 0, dwLen, pszAppVersion);
//
//		UINT nLen = 0;
//		char *pInfo = NULL;
//		CString strVersionValues;
//		struct LANGANDCODEPAGE {
//			WORD wLanguage;
//			WORD wCodePage;
//		} *lpTranslate;
//
//		VerQueryValue(pszAppVersion, "\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &nLen);
//		strVersionValues.Format(_T("\\StringFileInfo\\%04x%04x\\FileVersion"),
//			lpTranslate->wLanguage, lpTranslate->wCodePage);
//		VerQueryValue(pszAppVersion, strVersionValues.GetBuffer(strVersionValues.GetLength()),
//			(LPVOID*)&pInfo, &nLen);
//		strVersion = pInfo;
//
//		strVersionValues.Format(_T("\\StringFileInfo\\%04x%04x\\LegalCopyright"),
//			lpTranslate->wLanguage, lpTranslate->wCodePage);
//		VerQueryValue(pszAppVersion, strVersionValues.GetBuffer(strVersionValues.GetLength()),
//			(LPVOID*)&pInfo, &nLen);
//		m_strCopyriht = pInfo;
//
//		delete[] pszAppVersion;
//		pszAppVersion = NULL;
//		lpTranslate = NULL;
//		pInfo = NULL;
//	}
//}


void CListCtrlDlg::OnLstDelete() 
{
	// TODO: Add your command handler code here
	// Get the current selected item
	POSITION SelectionPos = m_List.GetFirstSelectedItemPosition();
	int iCurSel = -1;


	// Delete the selected item from the list control 
	while (NULL != SelectionPos)
	{
		SelectionPos = m_List.GetFirstSelectedItemPosition();
		iCurSel = m_List.GetNextSelectedItem(SelectionPos);
		m_List.DeleteItem(iCurSel);
	}
}


void CListCtrlDlg::OnLstInsert() 
{
	 //TODO: Add your command handler code here
	 //Insert a new row below the selected row or at the end
	CString strResource;
	strResource.Format("%d", ++m_iItemCount);


	int iCount = m_List.GetItemCount();


	int iRow = -1;


	POSITION SelectedItemPos = m_List.GetFirstSelectedItemPosition();
	int iIndex = -1;
	int iLastSelectedIndex = -1;


	while (SelectedItemPos)
	{
		iIndex = m_List.GetNextSelectedItem(SelectedItemPos);


		if ((LVIS_SELECTED == m_List.GetItemState(iIndex, LVIS_SELECTED)) && 
			(LVIS_FOCUSED == m_List.GetItemState(iIndex, LVIS_FOCUSED)))
		{
			iRow = iIndex;
		}
		m_List.SetItemState(iIndex, 0, LVIS_SELECTED|LVIS_FOCUSED);
	}




	if (-1 == iRow)
	{
		m_List.InsertItem(LVIF_TEXT | LVIF_STATE, iCount,
		strResource, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED, 0, 0);
	}
	else
	{
		m_List.InsertItem(LVIF_TEXT | LVIF_STATE, iRow,
		strResource, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED, 0, 0);
	}
	UpdateData(FALSE);
	SortFirstColumn();
}


void CListCtrlDlg::OnButtonXiu()
{
	// TODO:  在此添加命令处理程序代码
	int nResult = ::AfxMessageBox("是否修改", MB_YESNO);
	if (nResult == IDNO)
	{
		return;
	}


	int iCount = m_List.GetItemCount();
	int iRow = -1;
	CString strResource;
	strResource.Format("%d", ++m_iItemCount);


	POSITION SelectedItemPos = m_List.GetFirstSelectedItemPosition();
	int iIndex = -1;
	int iLastSelectedIndex = -1;


	while (SelectedItemPos)
	{
		iIndex = m_List.GetNextSelectedItem(SelectedItemPos);


		if ((LVIS_SELECTED == m_List.GetItemState(iIndex, LVIS_SELECTED)) &&
			(LVIS_FOCUSED == m_List.GetItemState(iIndex, LVIS_FOCUSED)))
		{
			iRow = iIndex;
		}
		m_List.SetItemState(iIndex - 1, 0, LVIS_SELECTED | LVIS_FOCUSED);
	}


	m_List.InsertItem(LVIF_TEXT | LVIF_STATE, iCount,
		strResource, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED, 0, 0);
	
	
}


void CListCtrlDlg::OnLstMinisizeScreen()
{
	ShowWindow(SW_MINIMIZE);
}


void CListCtrlDlg::OnLstMaxisizeScreen()
{
	ShowWindow(SW_MAXIMIZE);
}




void CListCtrlDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	// Create the pop up menu
	CMenu obMenu;
	obMenu.LoadMenu(IDR_LIST_POPUP); 


	CMenu* pPopupMenu = obMenu.GetSubMenu(0);
	ASSERT(pPopupMenu); 
	
	// Get the cursor position
	CPoint obCursorPoint = (0, 0);
	
	GetCursorPos(&obCursorPoint);


	if (0 >= m_List.GetSelectedCount())
	{
		pPopupMenu->EnableMenuItem(ID_LST_DELETE, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED); 
	}
	else
	{
		pPopupMenu->EnableMenuItem(ID_LST_DELETE, MF_BYCOMMAND | MF_ENABLED);
	}


	// Track the popup menu
	pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, obCursorPoint.x, 
									obCursorPoint.y, this);


	*pResult = 0;
}


LRESULT CListCtrlDlg::OnEndLabelEditVariableCriteria(WPARAM wParam, LPARAM lParam) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)lParam;
	// TODO: Add your control notification handler code here
	
	if (wParam == IDC_LIST)
	{
		// Update the item text with the new text
		CString strUpdatedTxt = pDispInfo->item.pszText;  
		
		// Validate the format of the new string for the edit columns
		// If invalid then
		// Set pResult to 1 
		switch(pDispInfo->item.iSubItem)
		{
		case 0:
		case 1:
			break;
		default:
			{
				if (!strUpdatedTxt.IsEmpty()) 
				{
					// Get the left most non numeral characters
					// Get the remaining numerals
					// If the left most part does not contain the mandatory conditions 
					// Or the rest contains the mandatory conditions 
					// Display an error and set focus back onto the control
					int iFirstNumeralOccurrance = strUpdatedTxt.FindOneOf("");
					CString strNonNumerals = strUpdatedTxt.Left(iFirstNumeralOccurrance);
					CString strNumerals = strUpdatedTxt.Mid(iFirstNumeralOccurrance);
					
					strNonNumerals.TrimLeft(); 
					strNonNumerals.TrimRight();
					strNumerals.TrimLeft();
					strNumerals.TrimRight();  


					int iDecimalIndex = strNumerals.Find(".");
					
					if ((-1 != iDecimalIndex) && (iDecimalIndex != (strNumerals.GetLength() - 1)))  
					{
						iDecimalIndex = strNumerals.Find(".", iDecimalIndex + 1);
					}


					// Check that the condition is either
					// Not empty or "=" or "!=" or "<" or ">" or "<=" or ">="
					// The Numerals do not contain 
					// Space or more than 1 "." or any of the conditions
					if (
						(!strNonNumerals.IsEmpty()) || 
						(-1 != strNumerals.Find(" ")) ||
						(-1 != iDecimalIndex)
						)
					{
						AfxMessageBox("插入格式不对,数据将恢复!"); 
						m_List.SetItemText(pDispInfo->item.iItem, pDispInfo->item.iSubItem, "");
					}
					return 0;
				}
			}
			break;
		}
	}


	return 1;
}


LRESULT CListCtrlDlg::PopulateComboList(WPARAM wParam, LPARAM lParam)
{
	// Get the Combobox window pointer
	CComboBox* pInPlaceCombo = static_cast<CComboBox*> (GetFocus());


	// Get the inplace combbox top left
	CRect obWindowRect;


	pInPlaceCombo->GetWindowRect(&obWindowRect);
	
	CPoint obInPlaceComboTopLeft(obWindowRect.TopLeft()); 
	
	// Get the active list
	// Get the control window rect
	// If the inplace combobox top left is in the rect then
	// The control is the active control
	m_List.GetWindowRect(&obWindowRect);
	
	int iColIndex = wParam;
	
	CStringList* pComboList = reinterpret_cast<CStringList*>(lParam);
	pComboList->RemoveAll(); 


	if (obWindowRect.PtInRect(obInPlaceComboTopLeft)) 
	{
		if (1 == iColIndex)
		{
			pComboList->AddTail("男");
			pComboList->AddTail("女");
		}
	}
	
	return true;
	//return 0;
}




void CListCtrlDlg::OnButtonSave()
{
	// TODO:  在此添加控件通知处理程序代码
	//首先判断列表框中是否有记录
	if (m_List.GetItemCount() <= 0)
	{
		AfxMessageBox(_T("列表中没有记录需要保存!"));
		return;
	}
	else
	{
		if (AfxMessageBox("确定要保存吗?", MB_OKCANCEL) == IDOK)
		{
			CString stText;
			stText = "学生信息";


			CString cStrFile;//%d年%d月%d日%d时%d分%d秒
			CTime m_time = CTime::GetCurrentTime();
			cStrFile.Format("C:\\" + stText + "-" + "%d年%d月%d日%d时%d分%d秒.xls", m_time.GetYear(), m_time.GetMonth(), m_time.GetDay(), m_time.GetHour(), m_time.GetMinute(),
				m_time.GetSecond());


			if (::PathFileExists(cStrFile))
				DeleteFile(cStrFile);


			COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);


			CApplication app; //Excel程序  
			CWorkbooks books; //工作簿集合  
			CWorkbook book;  //工作表  
			CWorksheets sheets;  //工作簿集合  
			CWorksheet sheet; //工作表集合  
			CRange range; //使用区域  


			book.PrintPreview(_variant_t(false));


			if (!app.CreateDispatch(_T("Excel.Application")))//创建IDispatch接口对象  
			{
				AfxMessageBox(_T("保存失败!"));
			}
			else
			{
				AfxMessageBox(_T("保存成功!"));
			}
			books = app.get_Workbooks();
			book = books.Add(covOptional);


			sheets = book.get_Worksheets();
			sheet = sheets.get_Item(COleVariant((short)1));  //得到第一个工作表  


			CHeaderCtrl   *pmyHeaderCtrl = m_List.GetHeaderCtrl(); //获取表头  


			int   m_cols = pmyHeaderCtrl->GetItemCount(); //获取列数  
			int   m_rows = m_List.GetItemCount();  //获取行数  


			TCHAR     lpBuffer[256];


			HDITEM   hdi; //This structure contains information about an item in a header control. This structure has been updated to support header item images and order values.  
			hdi.mask = HDI_TEXT;
			hdi.pszText = lpBuffer;
			hdi.cchTextMax = 256;


			CString   colname;
			CString strTemp;


			int   iRow, iCol;
			for (iCol = 0; iCol < m_cols; iCol++)//将列表的标题头写入EXCEL   
			{
				GetCellName(1, iCol + 1, colname); //(colname就是对应表格的A1,B1,C1,D1)  
				range = sheet.get_Range(COleVariant(colname), COleVariant(colname));
				pmyHeaderCtrl->GetItem(iCol, &hdi); //获取表头每列的信息  
				range.put_Value2(COleVariant(hdi.pszText));  //设置每列的内容  
				int   nWidth = m_List.GetColumnWidth(iCol) / 6;
				//得到第iCol+1列 
				range.AttachDispatch(range.get_Item(_variant_t((long)(iCol + 1)), vtMissing).pdispVal, true);
				//设置列宽    
				range.put_ColumnWidth(_variant_t((long)nWidth));




			}
			range = sheet.get_Range(COleVariant(_T("A1 ")), COleVariant(colname));
			range.put_RowHeight(_variant_t((long)50));//设置行的高度   
			range.put_VerticalAlignment(COleVariant((short)-4108));//xlVAlignCenter   =   -4108   


			COleSafeArray   saRet; //COleSafeArray类是用于处理任意类型和维数的数组的类  
			DWORD   numElements[] = { m_rows, m_cols };       //行列写入数组  
			saRet.Create(VT_BSTR, 2, numElements); //创建所需的数组  


			range = sheet.get_Range(COleVariant(_T("A2 ")), covOptional); //从A2开始  
			range = range.get_Resize(COleVariant((short)m_rows), COleVariant((short)m_cols)); //表的区域  


			long   index[2];


			for (iRow = 1; iRow <= m_rows; iRow++)//将列表内容写入EXCEL   
			{
				for (iCol = 1; iCol <= m_cols; iCol++)
				{
					index[0] = iRow - 1;
					index[1] = iCol - 1;
					CString   szTemp;
					szTemp = m_List.GetItemText(iRow - 1, iCol - 1); //取得m_list控件中的内容  
					BSTR   bstr = szTemp.AllocSysString(); //The AllocSysString method alloscates a new BSTR string that is Automation compatible  
					saRet.PutElement(index, bstr); //把m_list控件中的内容放入saRet
					SysFreeString(bstr);
				}
			}
			range.put_Value2(COleVariant(saRet)); //将得到的数据的saRet数组值放入表格  
			book.SaveCopyAs(COleVariant(cStrFile)); //保存到cStrFile文件 
			book.put_Saved(true);
			books.Close();


			//释放对象 
			range.ReleaseDispatch();
			sheet.ReleaseDispatch();
			sheets.ReleaseDispatch();
			book.ReleaseDispatch();
			books.ReleaseDispatch();


			//调用顺序不能变
			app.Quit();
			app.ReleaseDispatch();
		}
		else
		{
			return;
		}
	}


}




void CListCtrlDlg::OnButtonLingsave()
{
	// TODO:  在此添加控件通知处理程序代码
	//首先判断列表框中是否有记录
	if (m_List.GetItemCount() <= 0)
	{
		AfxMessageBox(_T("列表中没有记录需要保存!"));
		return;
	}
	else
	{
		if (AfxMessageBox("确定要保存吗?", MB_OKCANCEL) == IDOK)
		{
			CFileDialog FileDialog(FALSE, "xls", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Microsoft Excel(*.xls)|*.xls|所有文件(*.*)"), this);
			if (FileDialog.DoModal() != IDOK)
			{
				return;
			}
			
			CString cStrFile = FileDialog.GetPathName();  //选择保存路径名称  


			if (::PathFileExists(cStrFile))
				DeleteFile(cStrFile);


			COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);


			CApplication app; //Excel程序  
			CWorkbooks books; //工作簿集合  
			CWorkbook book;  //工作表  
			CWorksheets sheets;  //工作簿集合  
			CWorksheet sheet; //工作表集合  
			CRange range; //使用区域  


			book.PrintPreview(_variant_t(false));


			if (!app.CreateDispatch(_T("Excel.Application")))//创建IDispatch接口对象  
			{
				AfxMessageBox(_T("保存失败!"));
			}
			else
			{
				AfxMessageBox(_T("保存成功!"));
			}
			books = app.get_Workbooks();
			book = books.Add(covOptional);


			sheets = book.get_Worksheets();
			sheet = sheets.get_Item(COleVariant((short)1));  //得到第一个工作表  


			CHeaderCtrl   *pmyHeaderCtrl = m_List.GetHeaderCtrl(); //获取表头  


			int   m_cols = pmyHeaderCtrl->GetItemCount(); //获取列数  
			int   m_rows = m_List.GetItemCount();  //获取行数  


			TCHAR     lpBuffer[256];


			HDITEM   hdi; //This structure contains information about an item in a header control. This structure has been updated to support header item images and order values.  
			hdi.mask = HDI_TEXT;
			hdi.pszText = lpBuffer;
			hdi.cchTextMax = 256;


			CString   colname;
			CString strTemp;


			int   iRow, iCol;
			for (iCol = 0; iCol < m_cols; iCol++)//将列表的标题头写入EXCEL   
			{
				GetCellName(1, iCol + 1, colname); //(colname就是对应表格的A1,B1,C1,D1)  


				range = sheet.get_Range(COleVariant(colname), COleVariant(colname));
				pmyHeaderCtrl->GetItem(iCol, &hdi); //获取表头每列的信息  
				range.put_Value2(COleVariant(hdi.pszText));  //设置每列的内容  


				int   nWidth = m_List.GetColumnWidth(iCol) / 6;


				//得到第iCol+1列 
				range.AttachDispatch(range.get_Item(_variant_t((long)(iCol + 1)), vtMissing).pdispVal, true);


				//设置列宽    
				range.put_ColumnWidth(_variant_t((long)nWidth));




			}
			range = sheet.get_Range(COleVariant(_T("A1 ")), COleVariant(colname));
			range.put_RowHeight(_variant_t((long)50));//设置行的高度   
			range.put_VerticalAlignment(COleVariant((short)-4108));//xlVAlignCenter   =   -4108   


			COleSafeArray   saRet; //COleSafeArray类是用于处理任意类型和维数的数组的类  
			DWORD   numElements[] = { m_rows, m_cols };       //行列写入数组  
			saRet.Create(VT_BSTR, 2, numElements); //创建所需的数组  


			range = sheet.get_Range(COleVariant(_T("A2 ")), covOptional); //从A2开始  
			range = range.get_Resize(COleVariant((short)m_rows), COleVariant((short)m_cols)); //表的区域  


			long   index[2];


			for (iRow = 1; iRow <= m_rows; iRow++)//将列表内容写入EXCEL   
			{
				for (iCol = 1; iCol <= m_cols; iCol++)
				{
					index[0] = iRow - 1;
					index[1] = iCol - 1;
					CString   szTemp;
					szTemp = m_List.GetItemText(iRow - 1, iCol - 1); //取得m_list控件中的内容  
					BSTR   bstr = szTemp.AllocSysString(); //The AllocSysString method alloscates a new BSTR string that is Automation compatible  
					saRet.PutElement(index, bstr); //把m_list控件中的内容放入saRet
					SysFreeString(bstr);
				}
			}
			range.put_Value2(COleVariant(saRet)); //将得到的数据的saRet数组值放入表格  
			book.SaveCopyAs(COleVariant(cStrFile)); //保存到cStrFile文件 
			book.put_Saved(true);
			books.Close();


			//释放对象 
			range.ReleaseDispatch();
			sheet.ReleaseDispatch();
			sheets.ReleaseDispatch();
			book.ReleaseDispatch();
			books.ReleaseDispatch();


			//调用顺序不能变
			app.Quit();
			app.ReleaseDispatch();
		}
		else
		{
			return;
		}
	}
}




void CListCtrlDlg::OnButtonExit()
{
	// TODO:  在此添加控件通知处理程序代码
	//
	if (pDlg != NULL)
	{  
		pDlg->OnDestroy();
		pDlg = NULL;
	}


	if(pColName != NULL)
		delete[] pColName;


	CListCtrlDlg::OnOK();
}




void CListCtrlDlg::OnButtonIndex()
{
	// TODO:  在此添加控件通知处理程序代码
	int iCount = 0;   //检索个数
	iSerachIndex = 0;
	dlg.DoModal();
	m_vecSerach.clear();
	if(dlg.m_keywords.IsEmpty())
	{
		return;
	}


	for (int i = 0; i < m_List.GetItemCount(); i++ )
	{
		for (int j = 0; j <m_List.GetHeaderCtrl()->GetItemCount(); j++)
		{
			CString s = m_List.GetItemText(i, j); //i是行,j是列 m_list是个list control 对象
			if (s == dlg.m_keywords)
			{  
				std::pair<int,int>keyIndex;
				keyIndex.first = i;
				keyIndex.second = j;
				m_vecSerach.push_back(keyIndex);
				iCount++;
			}
		}
	}
	
	if(pDlg == NULL)
	{
	  pDlg = new CSerachDlg();
	  pDlg->Create(IDD_DIALOG5,this);
	}
	pDlg->SetSerachInfo(iCount,dlg.m_keywords);
	iSerachIndex= iCount;
	pDlg->ShowWindow(SW_SHOW);


	ShowFirstSerach(); //显示检索到的第一项


}




void CListCtrlDlg::OnButtonAdd()
{
	// TODO:  在此添加控件通知处理程序代码
		dlg2.DoModal();
		if (dlg2.m_lieming.IsEmpty())
		{
			AfxMessageBox(_T("输入内容不能为空!"));
			return;
		}
		m_List.InsertColumn(m + 6 , dlg2.m_lieming, LVCFMT_LEFT, 50);
		m++;
		UpdateData(FALSE);
		
		int nCount = m_List.GetHeaderCtrl()->GetItemCount();		
		pColName[nCount-1] = dlg2.m_lieming;
		//m_List.SetComboColumns(5);
}


void CListCtrlDlg::OnButtonDelete()
{
	// TODO:  在此添加控件通知处理程序代码
	dlg3.DoModal();
	int nColumnCount = m_List.GetHeaderCtrl()->GetItemCount();
	// Delete all of the columns.


	for (int i = 0; i < nColumnCount; i++)
	{
		HDITEM hdi;
		TCHAR  lpBuffer[256];
		bool   fFound = false;
		hdi.mask = HDI_TEXT;
		hdi.pszText = lpBuffer;
		hdi.cchTextMax = 256;
		m_List.GetHeaderCtrl()->GetItem(i, &hdi);//i列的名
		if (dlg3.m_delete == hdi.pszText)
		{
			m_List.DeleteColumn(i);
		}
	}
}


void  CListCtrlDlg::GetCellName(int nRow, int nCol, CString &strName)
{
	int nSeed = nCol;
	CString strRow;
	char cCell = 'A' + nCol - 1;
	strName.Format(_T("%c"), cCell);
	strRow.Format(_T("%d "), nRow);
	strName += strRow;
}






void CListCtrlDlg::OnButtonOpen()
{
	// TODO:  在此添加控件通知处理程序代码
	
	CString strKey = _T("");
	int nCol = m_List.GetHeaderCtrl()->GetItemCount();
	
	//删除所有行(除第一行)
	for(int i=m_List.GetItemCount(); i>=0;i--)
	{
		m_List.DeleteItem(i);
	}


	m_List.SetRedraw(TRUE); //恢复刷新   
    m_List.Invalidate();
    m_List.UpdateWindow();


	int nItems = m_List.GetItemCount();  //获取现在的行数
	POSITION ps = mapAllData.GetStartPosition();
	while(ps)
    {
	   CString* strData = NULL;
       mapAllData.GetNextAssoc(ps, strKey, strData);


	   CString strTemp = strData[0];
	   m_List.InsertItem(nItems,strTemp);  //插入行


	   for(int i=1;i<nCol;i++)
	   {
		   strTemp = strData[i];
		   m_List.SetItemText(nItems, i, strTemp);    //设置数据
	   }
	}
	GetDlgItem(IDC_BUTTON_OPEN)->ShowWindow(SW_HIDE);
	UpdateData(FALSE);




}




void CListCtrlDlg::OnDblclkList(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO:  在此添加控件通知处理程序代码
	CRect rc;
	CString strTemp;
	NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)pNMHDR;
	m_Row = pNMListView->iItem;
	m_Col = pNMListView->iSubItem;


	if (pNMListView->iItem == -1)    //选择空白处,添加一行,并设置焦点为最后一行,第二列  
	{
		m_Row = m_List.GetItemCount();
		strTemp.Format(_T("%d"), m_Row + 1);
		m_List.InsertItem(m_Row, strTemp);
		m_List.SetItemState(m_Row, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
		m_List.EnsureVisible(m_Row, FALSE);
		m_iItemCount++; 
		//m_Col = 1;  
	}


	if (m_Col != 0) // 选择子项  
	{
		m_List.GetSubItemRect(m_Row, m_Col, LVIR_LABEL, rc);
		m_charu.SetParent(&m_List);
		m_charu.MoveWindow(rc);
		m_charu.SetWindowText(m_List.GetItemText(m_Row, m_Col));
		m_charu.ShowWindow(SW_HIDE);
		m_charu.SetFocus();//设置Edit焦点  
		m_charu.ShowCaret();//显示光标  
		m_charu.SetSel(0, -1);//全选
	}
	*pResult = 0;
}




void CListCtrlDlg::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);
	// TODO:  在此处添加消息处理程序代码
	if (nType != SIZE_MINIMIZED)
	{


		int a[11] = {  IDC_LIST, IDC_EDIT_CHARU, IDC_BUTTON_ADD, IDC_BUTTON_DELETE, IDC_BUTTON_EXIT, IDC_BUTTON_INDEX,IDC_BUTTON_FILTER,IDC_BUTTON_IMPORT,
			IDC_BUTTON_LINGSAVE, IDC_BUTTON_OPEN, IDC_BUTTON_SAVE
		};
		int i;
		for (i = 0; i < 11; i++)
			ReSizes(a[i], m_rect, cx, cy);


		


		GetClientRect(&m_rect);//将变化后的对话框大小设为旧大小
	}
}




//======================================
//设置对话框尺寸函数
//======================================
void CListCtrlDlg::ReSizes(int idc, CRect client, int x, int y)
{
	CWnd *pWin;
	pWin = GetDlgItem(idc);//获取控件句柄
	if (pWin)//判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
	{
		CRect Editrect;//获取控件变化前大小
		pWin->GetWindowRect(&Editrect);
		ScreenToClient(&Editrect);//将控件大小转换为在对话框中的区域坐标
		//x/client.Width()为对话框在横向的变化比例


		Editrect.left = Editrect.left*x / client.Width();//调整控件大小
		Editrect.right = Editrect.right*x / client.Width();
		Editrect.top = Editrect.top*y / client.Height();
		Editrect.bottom = Editrect.bottom*y / client.Height();
		pWin->MoveWindow(Editrect);//调整控件大小


	}
}


void CListCtrlDlg::OnBnClickedButtonFilter()
{
	// TODO: 在此添加控件通知处理程序代码
	CFilterDlg FilterDlg;
	FilterDlg.DoModal();
	if(FilterDlg.mapFilter.IsEmpty())
		return;


	int nSize = FilterDlg.mapFilter.GetCount();
	int *pIndex = new int[nSize];   //用于记录符合条件列名的序号
	ZeroMemory(pIndex,nSize);


	CString strkey = "";
	CString strValue = "";
	std::vector<CString>vecKey;     //条件名 
    std::vector<CString>vecValue;   //条件内容


	POSITION ps = FilterDlg.mapFilter.GetStartPosition();
	while(ps)
	{  
		FilterDlg.mapFilter.GetNextAssoc(ps, strkey, strValue);
		vecKey.push_back(strkey);
		vecValue.push_back(strValue);
	}




	if(!CheackConditions(vecKey,pIndex))
	{   
		AfxMessageBox(_T("条件名称错误,查询条件功能失败!"));
		return;
	}
	else
	{
	    SaveData();                 //保持当前列表控件所有数据
	    QueryInfo(vecValue,pIndex); //条件查询数据
		GetDlgItem(IDC_BUTTON_OPEN)->ShowWindow(SW_SHOW);
	}


	delete FilterDlg;


}




//保存所有数据
void CListCtrlDlg::SaveData()
{
	mapAllData.RemoveAll();
	int nCol = m_List.GetHeaderCtrl()->GetItemCount();
	CString* pColName = NULL;
	CString  strKey = "";
	CString* strValue = NULL;


	for (int i = 0; i < m_List.GetItemCount(); i++ )
	{   
		//存放列名
		pColName = NULL;
		pColName = new CString[nCol];


		for (int j = 0; j <m_List.GetHeaderCtrl()->GetItemCount(); j++)
		{
			CString s = m_List.GetItemText(i, j); //i是行,j是列 m_list是个list control 对象
			pColName[j] = s;
		}


		strKey = pColName[0];
		strValue = pColName;


		mapAllData.SetAt(strKey,strValue);
	}
}  




//显示检索第一个
void CListCtrlDlg::ShowFirstSerach()
{
	if(m_vecSerach.empty())
		return ;


	iSerachIndex = 1;
	int iKey = iSerachIndex - 1;


	m_Index.first  = m_vecSerach[iKey].first;
	m_Index.second = m_vecSerach[iKey].second;
	CRect rect;
	BOOL bReturn = m_List.GetSubItemRect(m_Index.first,m_Index.second,LVIR_BOUNDS,rect);
	if(!bReturn)
	{
		AfxMessageBox(_T("调用CListCtrl::GetSubItemRect函数错误!"));
		return;
	}
	else
	{
		CRect r;
		m_List.GetWindowRect(&r);
		int x = rect.TopLeft().x  + 25;
		int y = rect.TopLeft().y  + 55;
		if(m_Index.second == 0)
		{
		   int nCol = m_List.GetHeaderCtrl()->GetItemCount();
		   CreateSolidCaret(rect.Width()/nCol, rect.Height());
		}
		else
		{
		  CreateSolidCaret(rect.Width(), rect.Height());
		}


		::SetCaretPos(x,y);   //将光标移动指定位置
		ShowCaret();
		UpdateData(FALSE);
	}
}      


//移动向上光标
afx_msg LRESULT CListCtrlDlg::OnUserUpSerach(WPARAM wParam, LPARAM lParam)
{
	if(m_vecSerach.empty())
		return 0;


	iSerachIndex--;
    if(iSerachIndex == 0)
	{   
		iSerachIndex++;
		AfxMessageBox("已是第一项");
		return 0;
	}
	
	int iKey = iSerachIndex - 1;
	
	m_Index.first  = m_vecSerach[iKey].first;
	m_Index.second = m_vecSerach[iKey].second;
	CRect rect;
	BOOL bReturn = m_List.GetSubItemRect(m_Index.first,m_Index.second,LVIR_BOUNDS,rect);
	if(!bReturn)
	{
		AfxMessageBox(_T("调用CListCtrl::GetSubItemRect函数错误!"));
		return 0;
	}
	else
	{
		CRect r;
		m_List.GetWindowRect(&r);
		int x = rect.TopLeft().x  + 25;
		int y = rect.TopLeft().y  + 55;


		if(m_Index.second == 0)
		{
		   int nCol = m_List.GetHeaderCtrl()->GetItemCount();
		   CreateSolidCaret(rect.Width()/nCol, rect.Height());
		}
		else
		{
		  CreateSolidCaret(rect.Width(), rect.Height());
		}
		::SetCaretPos(x,y);   //将光标移动指定位置
		ShowCaret();
		UpdateData(FALSE);
	}


	
	return 0;
}


//移动向下光标
afx_msg LRESULT CListCtrlDlg::OnUserDownSerach(WPARAM wParam, LPARAM lParam)
{
	if(m_vecSerach.empty())
		return 0;
	
	iSerachIndex++;
	if(iSerachIndex > m_vecSerach.size())
	{
		iSerachIndex = m_vecSerach.size();
		AfxMessageBox("已是最后一项");
		return 0;
	}


	int iKey = iSerachIndex - 1;
	
	m_Index.first  = m_vecSerach[iKey].first;
	m_Index.second = m_vecSerach[iKey].second;
	CRect rect;
	BOOL bReturn = m_List.GetSubItemRect(m_Index.first,m_Index.second,LVIR_BOUNDS,rect);
	if(!bReturn)
	{
		AfxMessageBox(_T("调用CListCtrl::GetSubItemRect函数错误!"));
		return 0;
	}
	else
	{
		CRect r;
		m_List.GetWindowRect(&r);
		int x = rect.TopLeft().x  + 25;
		int y = rect.TopLeft().y  + 55;


		if(m_Index.second == 0)
		{
		   int nCol = m_List.GetHeaderCtrl()->GetItemCount();
		   CreateSolidCaret(rect.Width()/nCol, rect.Height());
		}
		else
		{
		  CreateSolidCaret(rect.Width(), rect.Height());
		}


		::SetCaretPos(x,y);   //将光标移动指定位置
		ShowCaret();
		UpdateData(FALSE);
	}




	
	return 0;
}




void CListCtrlDlg::OnBnClickedButtonImport()
{
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog dlg( TRUE, //TRUE或FALSE。TRUE为打开文件;FALSE为保存文件
		"xls", //为缺省的扩展名
		"FileList", //为显示在文件名组合框的编辑框的文件名,一般可选NULL 
		OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,//为对话框风格,一般为OFN_HIDEREADONLY   |   OFN_OVERWRITEPROMPT,即隐藏只读选项和覆盖已有文件前提示。
		"Excel 文件(*.xls)|*.xls||"//为下拉列表枢中显示文件类型
		);
	dlg.m_ofn.lpstrTitle = "导入数据";


	if (dlg.DoModal() != IDOK)
		return;
	CString strFilePath;
	//获得文件路径名
	strFilePath = dlg.GetPathName();
	//判断文件是否已经存在,存在则打开文件
	DWORD dwRe = GetFileAttributes(strFilePath);
	if ( dwRe != (DWORD)-1 )
	{
		//ShellExecute(NULL, NULL, strFilePath, NULL, NULL, SW_RESTORE); 
	}
	else return;


	CDatabase db;//数据库库需要包含头文件 #include <afxdb.h>
	CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // Excel驱动
	CString sSql,arr[4];


	sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",sDriver, strFilePath, strFilePath);
	if(!db.OpenEx(sSql,CDatabase::noOdbcDialog))//连接数据源DJB.xls
	{
		MessageBox("打开EXCEL文件失败!","错误");
		return;
	}
	//打开EXCEL表
	CRecordset pset(&db);
	m_List.DeleteAllItems();


	AfxMessageBox("OK");


	sSql.Format("SELECT 序号,姓名,学号,班级 FROM DSO_DX");
	pset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);
	while(!pset.IsEOF())
	{
		pset.GetFieldValue("序号",arr[0]);//前面字段必须与表中的相同,否则出错。
		pset.GetFieldValue("姓名",arr[1]);
		pset.GetFieldValue("学号",arr[2]);
		pset.GetFieldValue("班级",arr[2]);


		int count = m_List.GetItemCount();//插入到ListCtrl中
		m_List.InsertItem(count,arr[0]);
		m_List.SetItemText(count,1,arr[1]);
		m_List.SetItemText(count,2,arr[2]);
		m_List.SetItemText(count,3,arr[3]);
		pset.MoveNext();
	}
	db.Close();


	MessageBox("Excel数据成功导入系统!","导入成功");






}




//条件查询数据
void CListCtrlDlg::QueryInfo(std::vector<CString>&vecDataTemp,int nColIndex[])
{
	int nSize = sizeof(nColIndex)/4;
	int nCol = m_List.GetHeaderCtrl()->GetItemCount();
	CString  strKey = "";
	
	POSITION pos = mapAllData.GetStartPosition();
    while(pos)
	{  
	   CString*  strData = NULL;
	   strData = new CString[nCol];
	   mapAllData.GetNextAssoc(pos, strKey, strData);


	   bool  bFlag = true;
	   for(int i = 0;i<nSize;i++)
	   {
	       int nKey = nColIndex[i];
		   if(strData[nKey] != vecDataTemp[i])
		   {
			   bFlag = false;
			   break;
		   }
	   }  


	   if(bFlag)
	   {
		   mapCheckData.SetAt(strKey,strData);
	   }
	}


	//删除所有行(除第一行)
	for(int i=m_List.GetItemCount(); i>=0;i--)
	{
		m_List.DeleteItem(i);
	}


	m_List.SetRedraw(TRUE); //恢复刷新   
    m_List.Invalidate();
    m_List.UpdateWindow();


	int nItems = m_List.GetItemCount();  //获取现在的行数
	POSITION ps = mapCheckData.GetStartPosition();
	while(ps)
    {
	   CString* strData = NULL;
       mapCheckData.GetNextAssoc(ps, strKey, strData);


	   CString strTemp = strData[0];
	   m_List.InsertItem(nItems,strTemp);  //插入行


	   for(int i=1;i<nCol;i++)
	   {
		   strTemp = strData[i];
		   m_List.SetItemText(nItems, i, strTemp);    //设置数据
	   }
	}
	UpdateData(FALSE);
}






// 判断查询条件内容是否符合列名
bool CListCtrlDlg::CheackConditions(std::vector<CString>&vecTemp,int nColIndex[])
{   
	//listctrl控件的列名
	if(pColName == NULL)
		return false;


	//获取listctrl列的总数
	UINT iCount = m_List.GetHeaderCtrl()->GetItemCount();
	bool bFlag = false;
	int nIdex = 0;
	for(UINT i=0;i<vecTemp.size();i++)
	{
	    for(UINT j = 0;j <iCount;j++)
		{
		   if(vecTemp[i] == pColName[j])
		   {   
			   nColIndex[nIdex++] = j;
		       bFlag= true;
		   }
		}


		if(!bFlag)
				   //手动释放内存
		   delete[]	nColIndex;
		   nColIndex = NULL;
		   return false;
		}
	}


	return true;
}


//列表框第一列排序
void  CListCtrlDlg::SortFirstColumn()//神特么的还有bug!!!
{
	int nItemNum  = m_List.GetItemCount();


	for (int i = 0; i <= nItemNum ; i++)
	{
		CString strIndex = _T("");
		strIndex.Format(_T("%d"),i+1);


		m_List.SetItemText(i,0, strIndex);
	}
}


void  CListCtrlDlg::DisplayAuthor()
{
	AfxMessageBox("邮箱:[email protected]\nQQ :2046195761");
	//AfxMessageBox("QQ:592551037");
}


#include "ComboListCtrl.h"// ListCtrlDlg.h : header file
#include "InPlaceEdit.h"
#include "afxcmn.h"
#include <afxwin.h>
#include <windows.h>
#include <vector>
#include "KeyDlg.h"
#include "ChaRuDlg.h"
#include "DeleteLieDlg.h"
#include "SerachDlg.h"
#include "FilterDlg.h"
#include "StdAfx.h"
//


#if !defined(AFX_LISTCTRLDLG_H__714B2AD4_9E96_43B7_BB6A_C176A6BD68AA__INCLUDED_)
#define AFX_LISTCTRLDLG_H__714B2AD4_9E96_43B7_BB6A_C176A6BD68AA__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


/////////////////////////////////////////////////////////////////////////////
// CListCtrlDlg dialog
//struct StuductInfo
//{
//   CString strNumber;   //序号
//   CString strName;     //姓名
//   CString strID;       //学号
//   CString strClass;    //班级
//   CString strGrade;    //年级
//   CString strSex;      //性别
//};






class CListCtrlDlg : public CDialog
{
// Construction
public:
	CListCtrlDlg(CWnd* pParent = NULL);	// standard constructor


// Dialog Data
	//{{AFX_DATA(CListCtrlDlg)
	enum { IDD = IDD_LISTCTRL_DIALOG };
	CComboListCtrl m_List;
	//}}AFX_DATA


	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CListCtrlDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL


// Implementation
protected:
	//HICON m_hIcon;
	HICON m_hIcon1;
	// Generated message map functions
	//{{AFX_MSG(CListCtrlDlg)
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	virtual BOOL OnInitDialog();
	afx_msg void OnLstDelete();
	afx_msg void OnLstInsert();
	afx_msg void OnLstMinisizeScreen();
	afx_msg void OnLstMaxisizeScreen();
	afx_msg void OnRclickList(NMHDR* pNMHDR, LRESULT* pResult);
	//}}AFX_MSG
	afx_msg LRESULT OnEndLabelEditVariableCriteria(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT PopulateComboList(WPARAM wParam, LPARAM lParam);
	afx_msg void OnButtonSave();
	afx_msg void OnButtonLingsave();
	afx_msg void OnButtonExit();
	afx_msg void OnButtonIndex();
	afx_msg void OnButtonAdd();
	afx_msg void ReadVersion(CString& strVersion, CString& strCopyriht);
	afx_msg void DisplayAuthor();
	
	DECLARE_MESSAGE_MAP()


public:
	int m_iItemCount;
	void  GetCellName(int nRow, int nCol, CString &strName);//获得excel单元名
	int length;
	CRect rect;
	char* m_strCopyriht;
	int m;
	int m_Row, m_Col;
	CKeyDlg dlg;
	CChaRuDlg dlg2;
	CDeleteLieDlg dlg3;
    CSerachDlg*  pDlg;


	CRect m_rect;
	CEdit m_charu;


	int  iSerachIndex;
	std::pair<int,int>m_Index;                  //检索当前位置
	std::vector<std::pair<int,int>>m_vecSerach; //检索的全部位置数据	




	//查询条件
	CString* pColName;
	CMap<CString,LPCSTR,CString*,CString*>mapAllData;     //所有数据,用于列表控件显示
	CMap<CString,LPCSTR,CString*,CString*>mapCheckData;   //查询条件后的数据,用于列表控控件显示


	bool CheackConditions(std::vector<CString>&vecTemp,int nColIndex[]);  // 判断查询条件内容是否符合列名
	void QueryInfo(std::vector<CString>&vecDataTemp,int nColIndex[]);          //条件查询数据
	void SaveData();           //保存所有数据
	void ShowFirstSerach();     //显示检索第一个 


	afx_msg void OnButtonXiu();
	afx_msg void OnButtonDelete();
	afx_msg void OnButtonOpen();
//	CString m_charu;
	afx_msg void OnDblclkList(NMHDR *pNMHDR, LRESULT *pResult);
	void ReSizes(int idc, CRect client, int x, int y);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnBnClickedButtonFilter();
	void SortFirstColumn();


protected:
	afx_msg LRESULT OnUserUpSerach(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUserDownSerach(WPARAM wParam, LPARAM lParam);
public:
	afx_msg void OnBnClickedButtonImport();
};


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_LISTCTRLDLG_H__714B2AD4_9E96_43B7_BB6A_C176A6BD68AA__INCLUDED_)


猜你喜欢

转载自blog.csdn.net/u25th_engineer/article/details/80752703