?? assets.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 + -