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

📄 operatenotedialog.cpp

📁 VC+SQL SERVER 2000环境下开发的商品销售管理系统
💻 CPP
字号:
// OperateNoteDialog.cpp : 实现文件
//

#include "stdafx.h"
#include "SaleManager.h"
#include "OperateNoteDialog.h"
#include ".\operatenotedialog.h"


// COperateNoteDialog 对话框

IMPLEMENT_DYNAMIC(COperateNoteDialog, CDialog)
COperateNoteDialog::COperateNoteDialog(CWnd* pParent /*=NULL*/)
	: CDialog(COperateNoteDialog::IDD, pParent)
{
}

COperateNoteDialog::~COperateNoteDialog()
{
}

void COperateNoteDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_OPNOTE, m_ListOperateNote);
	DDX_Control(pDX, IDC_DATETIMEPICKER_DATE, m_Date);
	DDX_Control(pDX, IDC_COMBO_NAME, m_ComboBox);
}


BEGIN_MESSAGE_MAP(COperateNoteDialog, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()


// COperateNoteDialog 消息处理程序

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

	HRESULT   hr;
	try
	{
		hr = m_pConnection.CreateInstance (__uuidof(Connection));
		if(FAILED(hr))
		{
			AfxMessageBox(_T("创建实例失败"));
			return TRUE;
		}
		m_pConnection->ConnectionString = "File Name=SaleManagerdata.udl";
		m_pConnection->ConnectionTimeout = 20;

		hr = m_pConnection->Open ("", "", "",adConnectUnspecified);
		if(FAILED(hr))
		{
		   AfxMessageBox("打开失败");
		   return TRUE;
		}
	}
	catch(_com_error &e)
	{
		AfxMessageBox(e.ErrorMessage());
		return TRUE;
	}

	m_ListOperateNote.InsertColumn (0, _T("操作员"), LVCFMT_LEFT, 80, -1);
	m_ListOperateNote.InsertColumn (1, _T("操作模块"),LVCFMT_LEFT, 80, -1);
	m_ListOperateNote.InsertColumn (2, _T("操作时间"),LVCFMT_LEFT, 150,-1);

	m_ListOperateNote.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	m_Date.SetFormat("yyyMMdd");

	InitList();
	InitComboBox();

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

void COperateNoteDialog::InitList()
{
	_RecordsetPtr    m_pRecordsetAction;
	HRESULT          hrAction;

	try
	{
		hrAction = m_pRecordsetAction.CreateInstance(__uuidof(Recordset));
		if(FAILED(hrAction))
		{
			AfxMessageBox(_T("创建实例失败!"));
			return;
		}

		_variant_t  var;
		CString     strValue;
		int         Index = 0;

		CString     strDate;
		m_Date.GetWindowText(strDate);
		
		CString     strSQL;
		strSQL.Format( "select * from ActionTable where ActionDate = '%s'",strDate);
		hrAction = m_pRecordsetAction->Open (_bstr_t(strSQL),
			                     m_pConnection.GetInterfacePtr(),
			                     adOpenDynamic,
			                     adLockOptimistic,
			                     adCmdText);

		if(FAILED(hrAction))
		{
			AfxMessageBox(_T("打开数据库失败!"));
			return;
		}

		while( !m_pRecordsetAction->adoEOF)
		{
			var = m_pRecordsetAction->GetCollect ("OperatorName");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);
			m_ListOperateNote.InsertItem (Index, strValue);

			var = m_pRecordsetAction->GetCollect ("ActionName");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);
			m_ListOperateNote.SetItemText (Index, 1, strValue);

		    var = m_pRecordsetAction->GetCollect ("ActionDate");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);

			strDate = strValue;
			strDate += "  ";

		    var = m_pRecordsetAction->GetCollect ("ActionTime");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);

			strDate += strValue;      
			m_ListOperateNote.SetItemText (Index, 2, strDate);

			m_pRecordsetAction->MoveNext();
			Index++;
		}

		m_pRecordsetAction->Close();
		m_pRecordsetAction = NULL;
	}
	catch(_com_error &e)
	{
		AfxMessageBox(e.ErrorMessage());
		return;
	}
}

void COperateNoteDialog::InitComboBox()
{
	_RecordsetPtr  m_pRecordsetP;
	HRESULT        hrP;
	try
	{
		hrP = m_pRecordsetP.CreateInstance (__uuidof(Recordset));
		
		if(FAILED(hrP))
		{
			AfxMessageBox (_T("不能创建记录集实例!"));
			return;
		}
		hrP = m_pRecordsetP->Open ("select * from PowTable",
			                     m_pConnection.GetInterfacePtr(),
			                     adOpenDynamic,
			                     adLockOptimistic,
			                     adCmdText);
		if(SUCCEEDED(hrP))
		{
			_variant_t var;
			CString    strValue;

			while(!m_pRecordsetP->adoEOF)
			{
				var = m_pRecordsetP->GetCollect ("RealName");
				if(var.vt != VT_NULL)
					strValue = (LPCSTR) _bstr_t(var);
				m_ComboBox.InsertString (-1,strValue);

				m_pRecordsetP->MoveNext();
			}
			m_pRecordsetP->Close();
			m_pRecordsetP = NULL;
		}
	}
	catch(_com_error &e)
	{
		AfxMessageBox (e.ErrorMessage());
	}
}
void COperateNoteDialog::OnBnClickedOk()
{
	m_ListOperateNote.DeleteAllItems();
		_RecordsetPtr    m_pRecordsetAction;
	HRESULT          hrAction;

	try
	{
		hrAction = m_pRecordsetAction.CreateInstance(__uuidof(Recordset));
		if(FAILED(hrAction))
		{
			AfxMessageBox(_T("创建实例失败!"));
			return;
		}

		_variant_t  var;
		CString     strValue;
		int         Index = 0;

		CString     strDate;
		CString     OperateName;
		m_ComboBox.GetWindowText(OperateName);
		m_Date.GetWindowText(strDate);
		
		CString     strSQL;
		if(OperateName == "")
		   strSQL.Format( "select * from ActionTable where ActionDate = '%s'",strDate);
		else
           strSQL.Format( "select * from ActionTable where ActionDate = '%s'\
						   and OperatorName = '%s'",strDate, OperateName);
		hrAction = m_pRecordsetAction->Open (_bstr_t(strSQL),
			                     m_pConnection.GetInterfacePtr(),
			                     adOpenDynamic,
			                     adLockOptimistic,
			                     adCmdText);

		if(FAILED(hrAction))
		{
			AfxMessageBox(_T("打开数据库失败!"));
			return;
		}

		while( !m_pRecordsetAction->adoEOF)
		{
			var = m_pRecordsetAction->GetCollect ("OperatorName");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);
			m_ListOperateNote.InsertItem (Index, strValue);

			var = m_pRecordsetAction->GetCollect ("ActionName");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);
			m_ListOperateNote.SetItemText (Index, 1, strValue);

		    var = m_pRecordsetAction->GetCollect ("ActionDate");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);

			strDate = strValue;
			strDate += "  ";

		    var = m_pRecordsetAction->GetCollect ("ActionTime");
			if(var.vt != VT_NULL)
				strValue = (LPCSTR) _bstr_t(var);

			strDate += strValue;      
			m_ListOperateNote.SetItemText (Index, 2, strDate);

			m_pRecordsetAction->MoveNext();
			Index++;
		}

		m_pRecordsetAction->Close();
		m_pRecordsetAction = NULL;
	}
	catch(_com_error &e)
	{
		AfxMessageBox(e.ErrorMessage());
		return;
	}
}

⌨️ 快捷键说明

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