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

📄 assets.cpp

📁 固定资产管理系统,VC++做的,很有参考价值,源码也说明文档都有.
💻 CPP
字号:
// Assets.cpp: implementation of the CAssets class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AssetsMan.h"
#include "Assets.h"
#include "ADOConn.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAssets::CAssets()
{
	Aid = "";
	Aname = "";
	Model = "";
	Producer = "";
	UsedYear = 1;
	OrgPrice = 0;
	Ratio = 0;
	Status = "未使用";
	AddWay = "";
	IsAudit = 0;
	IsDiscount = 0;
}

CAssets::~CAssets()
{

}

/**********************************************************
                           方法设置
**********************************************************/
//  插入新的固定资产信息
	void CAssets::sql_Insert()
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置INSERT语句, 将数值转换为字符串
		CString cSql,cDate,cOrgPrc,cRatio,cTypeId,cYear;
		_bstr_t bSql;
		cOrgPrc.Format("%f",OrgPrice);
		cRatio.Format("%f",Ratio);
		cTypeId.Format("%d",TypeId);
		cYear.Format("%d",UsedYear);
		// 定义时间对象,取得当前日期
		CTime t = CTime::GetCurrentTime();
		cDate.Format(_T("%04d-%02d-%02d"),t.GetYear(),t.GetMonth(),t.GetDay());
		// 插入语句
		cSql = "Insert Into Assets(Aid,Aname,TypeId,Model,Producer,";
		cSql += "UseDate,UsedYear,OrgPrice,Ratio,";
		cSql += "Status,AddWay,IsAudit,PostDate, IsDiscount) Values('";
		cSql += Aid+"','"+Aname+"',"+cTypeId+",'"+Model+"','"+Producer+"','";
		cSql += UseDate+"',"+cYear+","+cOrgPrc+",";
		cSql += cRatio+",'未使用','"+AddWay+"',0,'"+cDate+"', 0)";
		bSql = (LPCTSTR)(_bstr_t)cSql;
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}
//  修改固定资产信息
void CAssets::sql_Update(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置UPDATE语句, 将数值转换为字符串
		CString cDate,cOrgPrc,cRatio,cTypeId,cYear;
		_bstr_t bSql;
		cOrgPrc.Format("%f",OrgPrice);
		cRatio.Format("%f",Ratio);
		cTypeId.Format("%d",TypeId);
		cYear.Format("%d",UsedYear);
		// 定义时间对象,取得当前日期
		CTime t = CTime::GetCurrentTime();
		cDate.Format(_T("%04d-%02d-%02d"),t.GetYear(),t.GetMonth(),t.GetDay());
		// 更新语句
		bSql = "Update Assets Set Aid='"+Aid+"',Aname='"+Aname+"',"
			+"TypeId="+cTypeId+",Model='"+Model+"',Producer='"+Producer+"',"
			+"UseDate='"+UseDate+"',UsedYear="+cYear+",OrgPrice="+cOrgPrc+","
			+"Ratio="+cRatio+", AddWay='"+AddWay+"',"
			+"PostDate='"+cDate+"' Where Aid='"+cId + "'";
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}
//  删除固定资产信息
void CAssets::sql_Delete(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置DELETE语句
		_bstr_t bSql;
		bSql = "Delete From Assets Where Aid='" + cId + "'";
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}
//  变更固定资产信息,只能变更部门、人员、使用年限、残值率
void CAssets::sql_Change(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置UPDATE语句, 将数值转换为字符串
		CString cRatio, cYear;
		_bstr_t bSql;
		cRatio.Format("%f",Ratio);
		cYear.Format("%d",UsedYear);
		// 更新语句
		bSql = "Update Assets Set UsedYear=" + cYear + ", Ratio=" + cRatio + ","
			 + " IsAudit=2 Where Aid='" + cId + "'";
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}
//  固定资产审核完毕
void CAssets::sql_Audit(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		_bstr_t bSql;
		// 更新语句
		bSql = "Update Assets Set IsAudit=1 Where Aid='"+cId+"'";
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}

void CAssets::sql_Status(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		_bstr_t bSql;
		// 更新语句
		bSql = "Update Assets Set Status='" + Status + "' Where Aid='"+cId+"'";
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}


// 判断是否存在某个固定资产编号
int CAssets::HaveAid(CString cAid)
{
	try
	{
		long lRscnt = 0;
		_RecordsetPtr m_pRecordset;
		// 连接数据库
		ADOConn m_AdoConn;
		_bstr_t bSQL;
		bSQL = "Select * From Assets Where Aid='" + cAid + "'";

		// 执行SELETE语句
		m_pRecordset = m_AdoConn.GetRecordSet(bSQL);
		// 如果adoEOF属性为真,表示存在相同编号的资产信息,返回1,否则返回-1
		if (m_pRecordset->adoEOF)
			return -1;
		else
			return 1;
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
	return -1;
}

// 判断是否存在某个固定资产名称
int CAssets::HaveName(CString cAname)
{
	try
	{
		long lRscnt = 0;
		_RecordsetPtr m_pRecordset;
		// 连接数据库
		ADOConn m_AdoConn;
		_bstr_t bSQL;
		bSQL = "Select * From Assets Where Aname='" + cAname + "'";

		// 执行SELETE语句
		m_pRecordset = m_AdoConn.GetRecordSet(bSQL);
		// 如果adoEOF属性为真,表示存在相同名称的资产信息,返回1,否则返回-1
		if (m_pRecordset->adoEOF)
			return -1;
		else
			return 1;
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
	return -1;
}

// 开始每个月进行计提折旧计算
void CAssets::BeginDiscount(CString cId)
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		_bstr_t bSql;
		// 更新语句
		bSql = "Update Assets Set IsDiscount=1 Where Aid='"+cId+"'";
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}

⌨️ 快捷键说明

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