?? assets.cpp
字號(hào):
// 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()
{
}
/**********************************************************
屬性設(shè)置
**********************************************************/
// 卡號(hào)
void CAssets::SetId(int iCId)
{
Id = iCId;
}
int CAssets::GetId()
{
return Id;
}
// 資產(chǎn)編號(hào)
void CAssets::SetAid(CString cAid)
{
Aid = cAid;
}
CString CAssets::GetAid()
{
return Aid;
}
// 資產(chǎn)名稱
void CAssets::SetAname(CString cAname)
{
Aname = cAname;
}
CString CAssets::GetAname()
{
return Aname;
}
// 類別編號(hào)
void CAssets::SetTypeId(int iTId)
{
TypeId = iTId;
}
int CAssets::GetTypeId()
{
return TypeId;
}
// 型號(hào)
void CAssets::SetModel(CString cModel)
{
Model = cModel;
}
CString CAssets::GetModel()
{
return Model;
}
// 生產(chǎn)廠家
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;
}
// 部門編號(hào)
void CAssets::SetDeptId(int iDeptId)
{
DeptId = iDeptId;
}
int CAssets::GetDeptId()
{
return DeptId;
}
// 負(fù)責(zé)人員
void CAssets::SetRepPerson(CString cRepPer)
{
RepPerson = cRepPer;
}
CString CAssets::GetRepPerson()
{
return RepPerson;
}
// 狀態(tài)
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;
}
// 計(jì)提折舊
void CAssets::SetIsDiscount(int iDis)
{
IsDiscount = iDis;
}
int CAssets::GetIsDiscount()
{
return IsDiscount;
}
/**********************************************************
方法設(shè)置
**********************************************************/
// 插入新的固定資產(chǎn)信息
void CAssets::sql_Insert()
{
try
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
//設(shè)置INSERT語句, 將數(shù)值轉(zhuǎn)換為字符串
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);
// 定義時(shí)間對(duì)象,取得當(dāng)前日期
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);
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
}
// 修改固定資產(chǎn)信息
void CAssets::sql_Update(CString cId)
{
try
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
//設(shè)置UPDATE語句, 將數(shù)值轉(zhuǎn)換為字符串
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);
// 定義時(shí)間對(duì)象,取得當(dāng)前日期
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);
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
}
// 刪除固定資產(chǎn)信息
void CAssets::sql_Delete(CString cId)
{
try
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
//設(shè)置DELETE語句
_bstr_t bSql;
bSql = "Delete From Assets Where Id="+cId;
m_AdoConn.ExecuteSQL(bSql);
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
}
// 變更固定資產(chǎn)信息,只能變更部門、人員、使用年限、殘值率
void CAssets::sql_Change(CString cId)
{
try
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
//設(shè)置UPDATE語句, 將數(shù)值轉(zhuǎn)換為字符串
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);
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
}
// 固定資產(chǎn)審核完畢
void CAssets::sql_Audit(CString cId)
{
try
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
_bstr_t bSql;
// 更新語句
bSql = "Update Assets Set IsAudit=1 Where Id="+cId;
m_AdoConn.ExecuteSQL(bSql);
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
}
//bstr_t bstrSQL
void CAssets::GetData(CString cId)
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
//設(shè)置SELECT語句
_bstr_t vSQL;
vSQL = "SELECT * FROM Assets WHERE Id=" + cId;
//執(zhí)行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");
}
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 判斷是否存在某個(gè)固定資產(chǎn)編號(hào)
int CAssets::HaveAid(CString cAid)
{
try
{
long lRscnt = 0;
_RecordsetPtr m_pRecordset;
// 連接數(shù)據(jù)庫
ADOConn m_AdoConn;
_bstr_t bSQL;
bSQL = "Select * From Assets Where Aid='" + cAid + "'";
// 執(zhí)行SELETE語句
m_pRecordset = m_AdoConn.GetRecordSet(bSQL);
// 如果adoEOF屬性為真,表示存在相同編號(hào)的資產(chǎn)信息,返回1,否則返回-1
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
return -1;
}
// 判斷是否存在某個(gè)固定資產(chǎn)名稱
int CAssets::HaveName(CString cAname)
{
try
{
long lRscnt = 0;
_RecordsetPtr m_pRecordset;
// 連接數(shù)據(jù)庫
ADOConn m_AdoConn;
_bstr_t bSQL;
bSQL = "Select * From Assets Where Aname='" + cAname + "'";
// 執(zhí)行SELETE語句
m_pRecordset = m_AdoConn.GetRecordSet(bSQL);
// 如果adoEOF屬性為真,表示存在相同名稱的資產(chǎn)信息,返回1,否則返回-1
if (m_pRecordset->adoEOF)
return -1;
else
return 1;
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
return -1;
}
// 開始每個(gè)月進(jìn)行計(jì)提折舊計(jì)算
void CAssets::BeginDiscount(CString cId)
{
try
{
//連接數(shù)據(jù)庫
ADOConn m_AdoConn;
_bstr_t bSql;
// 更新語句
bSql = "Update Assets Set IsDiscount=1 Where Id="+cId;
m_AdoConn.ExecuteSQL(bSql);
//斷開與數(shù)據(jù)庫的連接
m_AdoConn.ExitConnect();
}
// 捕捉異常
catch(_com_error e)
{
// 顯示錯(cuò)誤信息
AfxMessageBox(e.Description());
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -