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

📄 propertyrecord.cpp

📁 这是一个企业办公管理系统。实现了文件的制作、修改、传递、、保存、销毁、存档等一系列操作。为windows系统认证模式
💻 CPP
字号:
// PropertyRecord.cpp : implementation file
//

#include "stdafx.h"
#include "Office.h"
#include "PropertyRecord.h"
#include "Property.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPropertyRecord dialog


CPropertyRecord::CPropertyRecord(CWnd* pParent /*=NULL*/)
	: CDialog(CPropertyRecord::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPropertyRecord)
	m_propertyID = _T("");
	m_propertyName = _T("");
	m_holdDate = COleDateTime::GetCurrentTime();
	m_propertyType = _T("");
	m_num = 0;
	m_total = 0.0f;
	m_users = _T("");
	m_insured = _T("");
	m_remark = _T("");
	//}}AFX_DATA_INIT
}


void CPropertyRecord::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropertyRecord)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_CBString(pDX, IDC_PROPERTYID, m_propertyID);
	DDX_CBString(pDX, IDC_PROPERTYNAME, m_propertyName);
	DDX_DateTimeCtrl(pDX, IDC_HOLDDATE, m_holdDate);
	DDX_CBString(pDX, IDC_PROPERTYTYPE, m_propertyType);
	DDX_Text(pDX, IDC_NUM, m_num);
	DDX_Text(pDX, IDC_TOTAL, m_total);
	DDX_CBString(pDX, IDC_USERS, m_users);
	DDX_CBString(pDX, IDC_INSURED, m_insured);
	DDX_Text(pDX, IDC_REMARK, m_remark);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropertyRecord, CDialog)
	//{{AFX_MSG_MAP(CPropertyRecord)
	ON_BN_CLICKED(IDC_ADD1, OnAdd)
	ON_BN_CLICKED(IDC_DELETE1, OnDelete)
	ON_BN_CLICKED(IDC_MODIFY, OnModify)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_CANCELLATION, OnCancellation)
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropertyRecord message handlers

void CPropertyRecord::OnAdd() 
{
	UpdateData(true);

	m_propertyID = _T("");
	m_propertyName = _T("");
	m_holdDate = COleDateTime::GetCurrentTime();
	m_propertyType = _T("");
	m_num = 0;
	m_total = 0.0f;
	m_users = _T("");
	m_insured = _T("");
	m_remark = _T("");

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(true);
	cwnd_propertyName->EnableWindow(true);
	cwnd_holdDate->EnableWindow(true);
	cwnd_propertyType->EnableWindow(true);
	cwnd_num->EnableWindow(true);
	cwnd_total->EnableWindow(true);
	cwnd_users->EnableWindow(true);
	cwnd_insured->EnableWindow(true);
	cwnd_remark->EnableWindow(true);

	cwnd_add->EnableWindow(false);
	cwnd_cancel->EnableWindow(true);
	cwnd_delete->EnableWindow(false);
	cwnd_modify->EnableWindow(false);
	cwnd_save->EnableWindow(true);
	cwnd_exit->EnableWindow(false);

	flag=1;

	UpdateData(false);
}

void CPropertyRecord::OnDelete() 
{
	UpdateData(true);

	CProperty property;
	property.sqlDelete(m_propertyID);

	m_propertyID = _T("");
	m_propertyName = _T("");
	m_holdDate = COleDateTime::GetCurrentTime();
	m_propertyType = _T("");
	m_num = 0;
	m_total = 0.0f;
	m_users = _T("");
	m_insured = _T("");
	m_remark = _T("");

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(false);
	cwnd_propertyName->EnableWindow(false);
	cwnd_holdDate->EnableWindow(false);
	cwnd_propertyType->EnableWindow(false);
	cwnd_num->EnableWindow(false);
	cwnd_total->EnableWindow(false);
	cwnd_users->EnableWindow(false);
	cwnd_insured->EnableWindow(false);
	cwnd_remark->EnableWindow(false);

	cwnd_add->EnableWindow(true);
	cwnd_cancel->EnableWindow(false);
	cwnd_delete->EnableWindow(false);
	cwnd_modify->EnableWindow(false);
	cwnd_save->EnableWindow(false);
	cwnd_exit->EnableWindow(true);

	Refresh();

	UpdateData(false);
}

void CPropertyRecord::OnModify() 
{
	UpdateData(true);

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(false);
	cwnd_propertyName->EnableWindow(true);
	cwnd_holdDate->EnableWindow(true);
	cwnd_propertyType->EnableWindow(true);
	cwnd_num->EnableWindow(true);
	cwnd_total->EnableWindow(true);
	cwnd_users->EnableWindow(true);
	cwnd_insured->EnableWindow(true);
	cwnd_remark->EnableWindow(true);

	cwnd_add->EnableWindow(false);
	cwnd_cancel->EnableWindow(true);
	cwnd_delete->EnableWindow(false);
	cwnd_modify->EnableWindow(false);
	cwnd_save->EnableWindow(true);
	cwnd_exit->EnableWindow(false);

	flag=2;
	
	UpdateData(false);
}

void CPropertyRecord::OnSave() 
{
	UpdateData(true);

	if(flag==1)
	{
		CProperty property;
		
		property.SetPropertyType(m_propertyType);
		property.SetPropertyID(m_propertyID);
		property.SetPropertyName(m_propertyName);
		property.SetUsers(m_users);
		property.SetInsured(m_insured);
		property.SetRemark(m_remark);
		property.SetHoldDate(m_holdDate);
		property.SetNum(m_num);
		property.SetTotal(m_total);

		property.sqlInsert();
	}
	else if(flag==2)
	{
		CProperty property;
		
		property.SetPropertyType(m_propertyType);
		property.SetPropertyID(m_propertyID);
		property.SetPropertyName(m_propertyName);
		property.SetUsers(m_users);
		property.SetInsured(m_insured);
		property.SetRemark(m_remark);
		property.SetHoldDate(m_holdDate);
		property.SetNum(m_num);
		property.SetTotal(m_total);

		property.sqlUpdate(m_propertyID);
	}

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(false);
	cwnd_propertyName->EnableWindow(false);
	cwnd_holdDate->EnableWindow(false);
	cwnd_propertyType->EnableWindow(false);
	cwnd_num->EnableWindow(false);
	cwnd_total->EnableWindow(false);
	cwnd_users->EnableWindow(false);
	cwnd_insured->EnableWindow(false);
	cwnd_remark->EnableWindow(false);

	cwnd_add->EnableWindow(true);
	cwnd_cancel->EnableWindow(false);
	cwnd_delete->EnableWindow(true);
	cwnd_modify->EnableWindow(true);
	cwnd_save->EnableWindow(false);
	cwnd_exit->EnableWindow(true);
	
	Refresh();

	UpdateData(false);
}

void CPropertyRecord::OnCancellation() 
{
	m_propertyID = _T("");
	m_propertyName = _T("");
	m_holdDate = COleDateTime::GetCurrentTime();
	m_propertyType = _T("");
	m_num = 0;
	m_total = 0.0f;
	m_users = _T("");
	m_insured = _T("");
	m_remark = _T("");

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(false);
	cwnd_propertyName->EnableWindow(false);
	cwnd_holdDate->EnableWindow(false);
	cwnd_propertyType->EnableWindow(false);
	cwnd_num->EnableWindow(false);
	cwnd_total->EnableWindow(false);
	cwnd_users->EnableWindow(false);
	cwnd_insured->EnableWindow(false);
	cwnd_remark->EnableWindow(false);

	cwnd_add->EnableWindow(true);
	cwnd_cancel->EnableWindow(false);
	cwnd_delete->EnableWindow(false);
	cwnd_modify->EnableWindow(false);
	cwnd_save->EnableWindow(false);
	cwnd_exit->EnableWindow(true);

	UpdateData(false);
}

void CPropertyRecord::OnExit() 
{
	this->OnCancel();
	
}

BOOL CPropertyRecord::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	DWORD style;
	style=m_list.GetExStyle();
	style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
	m_list.SetExtendedStyle(style);
	
	m_list.InsertColumn(0,"拥有日期",LVCFMT_LEFT,100);
	m_list.InsertColumn(1,"财产编号",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"财产名称",LVCFMT_LEFT,100);
	
	cwnd_list = GetDlgItem(IDC_LIST);
	cwnd_propertyID = GetDlgItem(IDC_PROPERTYID);
	cwnd_propertyName = GetDlgItem(IDC_PROPERTYNAME);
	cwnd_holdDate = GetDlgItem(IDC_HOLDDATE);
	cwnd_propertyType = GetDlgItem(IDC_PROPERTYTYPE);
	cwnd_num = GetDlgItem(IDC_NUM);
	cwnd_total = GetDlgItem(IDC_TOTAL);
	cwnd_users = GetDlgItem(IDC_USERS);
	cwnd_insured = GetDlgItem(IDC_INSURED);
	cwnd_remark = GetDlgItem(IDC_REMARK);

	cwnd_add = GetDlgItem(IDC_ADD1);
	cwnd_cancel = GetDlgItem(IDC_CANCELLATION);
	cwnd_delete = GetDlgItem(IDC_DELETE1);
	cwnd_modify = GetDlgItem(IDC_MODIFY);
	cwnd_save = GetDlgItem(IDC_SAVE);
	cwnd_exit = GetDlgItem(IDC_EXIT);

	flag=0;

	_RecordsetPtr m_pRecordset;

	CString strSQL;
	strSQL="select * from propertyRecord";
	HRESULT hTRes;
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
		int i=0;
		
		while(!(m_pRecordset->adoEOF))
		{
			m_list.InsertItem(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("holdDate")));
			m_list.SetItemText(i,1,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("propertyID")));
			m_list.SetItemText(i,2,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("propertyName")));
			
			i++;
			if(!(m_pRecordset->adoEOF))
				m_pRecordset->MoveNext();
		}
	}

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(false);
	cwnd_propertyName->EnableWindow(false);
	cwnd_holdDate->EnableWindow(false);
	cwnd_propertyType->EnableWindow(false);
	cwnd_num->EnableWindow(false);
	cwnd_total->EnableWindow(false);
	cwnd_users->EnableWindow(false);
	cwnd_insured->EnableWindow(false);
	cwnd_remark->EnableWindow(false);

	cwnd_add->EnableWindow(true);
	cwnd_cancel->EnableWindow(false);
	cwnd_delete->EnableWindow(false);
	cwnd_modify->EnableWindow(false);
	cwnd_save->EnableWindow(false);
	cwnd_exit->EnableWindow(true);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPropertyRecord::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	UpdateData(true);
	POSITION pos = m_list.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_list.GetNextSelectedItem(pos);
		m_propertyID=m_list.GetItemText(nFirstSelItem,1);
	}

	CProperty property;
	property.GetData(m_propertyID);

	m_propertyID = property.GetPropertyID();
	m_propertyName = property.GetPropertyName();
	m_holdDate = property.GetHoldDate();
	m_propertyType = property.GetPropertyType();
	m_num = property.GetNum();
	m_total = property.GetTotal();
	m_users = property.GetUsers();
	m_insured = property.GetInsured();
	m_remark = property.GetRemark();

	cwnd_list->EnableWindow(true);
	cwnd_propertyID->EnableWindow(false);
	cwnd_propertyName->EnableWindow(false);
	cwnd_holdDate->EnableWindow(false);
	cwnd_propertyType->EnableWindow(false);
	cwnd_num->EnableWindow(false);
	cwnd_total->EnableWindow(false);
	cwnd_users->EnableWindow(false);
	cwnd_insured->EnableWindow(false);
	cwnd_remark->EnableWindow(false);

	cwnd_add->EnableWindow(true);
	cwnd_cancel->EnableWindow(false);
	cwnd_delete->EnableWindow(true);
	cwnd_modify->EnableWindow(true);
	cwnd_save->EnableWindow(false);
	cwnd_exit->EnableWindow(true);

	UpdateData(false);
	
	*pResult = 0;
}

void CPropertyRecord::Refresh()
{
	m_list.DeleteAllItems();
	_RecordsetPtr m_pRecordset;

	CString strSQL;
	strSQL="select * from propertyRecord";
	HRESULT hTRes;
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
		int i=0;
		
		while(!(m_pRecordset->adoEOF))
		{
			m_list.InsertItem(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("holdDate")));
			m_list.SetItemText(i,1,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("propertyID")));
			m_list.SetItemText(i,2,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("propertyName")));
			
			i++;
			if(!(m_pRecordset->adoEOF))
				m_pRecordset->MoveNext();
		}
	}
}

⌨️ 快捷键说明

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