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

📄 assets.cpp

📁 直接打开
💻 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;
	RepPerson = "";
	Status = "未使用";
	AddWay = "";
	IsAudit = 0;
	IsDiscount = 0;
}

CAssets::~CAssets()
{

}

   /**********************************************************
                              属性设置
   **********************************************************/
// 卡号
void CAssets::SetId(int iCId)
{
	Id = iCId;
}

int CAssets::GetId()
{
	return Id;
}

// 资产编号
void CAssets::SetAid(CString cAid)
{
	Aid = cAid;
}

CString CAssets::GetAid()
{
	return Aid;
}

// 资产名称
void CAssets::SetAname(CString cAname)
{
	Aname = cAname;
}

CString CAssets::GetAname()
{
	return Aname;
}

// 类别编号
void CAssets::SetTypeId(int iTId)
{
	TypeId = iTId;
}

int CAssets::GetTypeId()
{
	return TypeId;
}

// 型号
void CAssets::SetModel(CString cModel)
{
	Model = cModel;
}

CString CAssets::GetModel()
{
	return Model;
}

// 生产厂家
void CAssets::SetProducer(CString cProducer)
{
	Producer = cProducer;
}

CString CAssets::GetProducer() 
{
	return Producer;
}

// 使用日期
void CAssets::SetUseDate(CString cUseDate)
{
	UseDate = cUseDate;
}

CString CAssets::GetUseDate()
{
	return UseDate;
}

// 使用年限
void CAssets::SetUsedYear(int iUsedYear)
{
	UsedYear = iUsedYear;
}

int CAssets::GetUsedYear()
{
	return UsedYear;
}

// 原值
void CAssets::SetOrgPrice(double dOrgPrc)
{
	OrgPrice = dOrgPrc;
}

double CAssets::GetOrgPrice()
{
	return OrgPrice;
}

// 残值率
void CAssets::SetRatio(float fRatio)
{
	Ratio = fRatio;
}

float CAssets::GetRatio()
{
	return Ratio;
}

// 部门编号
void CAssets::SetDeptId(int iDeptId)
{
	DeptId = iDeptId;
}

int CAssets::GetDeptId()
{
	return DeptId;
}

// 负责人员
void CAssets::SetRepPerson(CString cRepPer)
{
	RepPerson = cRepPer;
}

CString CAssets::GetRepPerson()
{
	return RepPerson;
}

// 状态
void CAssets::SetStatus(CString iStatus)
{
	Status = iStatus;
}

CString CAssets::GetStatus()
{
	return Status;
}

// 增加方式
void CAssets::SetAddWay(CString cAddWay)
{
	AddWay = cAddWay;
}

CString CAssets::GetAddWay()
{
	return AddWay;
}

// 是否审核
void CAssets::SetIsAudit(int iIsAud)
{
	IsAudit = iIsAud;
}

int CAssets::GetIsAudit()
{
	return IsAudit;
}

// 提交日期
void CAssets::SetPostDate(CString cPostDate)
{
	PostDate = cPostDate;
}

CString CAssets::GetPostDate()
{
	return PostDate;
}

// 计提折旧
void CAssets::SetIsDiscount(int iDis)
{
	IsDiscount = iDis;
}

int CAssets::GetIsDiscount()
{
	return IsDiscount;
}

/**********************************************************
                           方法设置
**********************************************************/
//  插入新的固定资产信息
	void CAssets::sql_Insert()
{
	try
	{
		//连接数据库
		ADOConn m_AdoConn;
		//设置INSERT语句, 将数值转换为字符串
		CString cSql,cDate,cOrgPrc,cRatio,cDeptId,cTypeId,cYear;
		_bstr_t bSql;
		cOrgPrc.Format("%f",OrgPrice);
		cRatio.Format("%f",Ratio);
		cDeptId.Format("%d",DeptId);
		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,DeptId,";
		cSql += "RepPerson,Status,AddWay,IsAudit,PostDate, IsDiscount) Values('";
		cSql += Aid+"','"+Aname+"',"+cTypeId+",'"+Model+"','"+Producer+"','";
		cSql += UseDate+"',"+cYear+","+cOrgPrc+",";
		cSql += cRatio+","+cDeptId+",'"+RepPerson+"','";
		cSql += Status+"','"+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,cDeptId,cTypeId,cYear;
		_bstr_t bSql;
		cOrgPrc.Format("%f",OrgPrice);
		cRatio.Format("%f",Ratio);
		cDeptId.Format("%d",DeptId);
		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+",DeptId="+cDeptId+","
			+"RepPerson='"+RepPerson+"',Status='"+Status+"',AddWay='"+AddWay+"',"
			+"PostDate='"+cDate+"' Where Id="+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 Id="+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,cDeptId,cYear;
		_bstr_t bSql;
		cRatio.Format("%f",Ratio);
		cDeptId.Format("%d",DeptId);
		cYear.Format("%d",UsedYear);
		// 更新语句
		bSql = "Update Assets Set UsedYear=" + cYear + ", Ratio=" + cRatio + ", DeptId= "+ cDeptId + ","
			 + "RepPerson='" + RepPerson + "', Status='" + Status + "',IsAudit=2 Where Id=" + 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 Id="+cId;
		m_AdoConn.ExecuteSQL(bSql);
		//断开与数据库的连接
		m_AdoConn.ExitConnect();
	}
	// 捕捉异常
	catch(_com_error e)
	{
		// 显示错误信息
		AfxMessageBox(e.Description());
	}
}

//bstr_t bstrSQL
void  CAssets::GetData(CString cId)
{
	//连接数据库
	ADOConn m_AdoConn;
	//设置SELECT语句
	_bstr_t vSQL;
	vSQL = "SELECT * FROM Assets WHERE Id=" + cId;
	//执行SELETE语句
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

	//返回各列的值
	if (m_pRecordset->adoEOF)
		CAssets();
	else
	{
		Id = atoi(cId);
		Aid = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Aid");
		Aname = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Aname");
		TypeId = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TypeId"));
		Model = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Model");
		Producer = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Producer");
		UseDate = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UseDate");
		UsedYear = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UsedYear"));
		OrgPrice = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("OrgPrice"));
		Ratio = atof((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Ratio"));
		RepPerson = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("RepPerson");
		DeptId = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("DeptId"));
		Status = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Status");
		AddWay = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("AddWay");
		PostDate = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("PostDate");
	}
	//断开与数据库的连接
	m_AdoConn.ExitConnect();
}

// 判断是否存在某个固定资产编号
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 Id="+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 + -