博客转移:http://vivianke.blog.163.com/blog/static/29715271200781121321529/
说明:ADOExecute(_variant_t &sql)函数处理,无记录集返回的数据库操作,这部分需要事务处理,
ADOExecute(_RecordsetPtr &ADOSet, _variant_t &sql)处理无记录集返回的数据库操作,这部分不需要事务处理,
在ADOConn->BeginTrans()和ADOConn->CommitTrans()之间,只能建立一个_RecordsetPtr记录集对象
if (m_bAppend) { //添加入库
//开始事务
theApp.ADOConn->BeginTrans();
//形成入库编号
strNO=Time.Format("%Y%m%d%H%M%S");
sql="insert msave values('"
+strNO+"','"
+m_strID+"','"
+m_strName+"','"
+m_strSpec+"','"
+m_strKind+"','"
+m_strUnit+"',"
+m_strAccount+","
+m_strPrice+","
+m_strValue+",'"
+m_strDate+"','"
+m_strDeal_person+"','"
+m_strSave_person+"','"
+m_strBase+"','"
+m_strMemo+"')";
theApp.ADOExecute(sql);
//判断该物资是否有库存记录
sql="select * from msurplus where yeid='"
+m_strID
+"' and yebase='"
+m_strBase+"'";
theApp.ADOExecute(theApp.m_pADOSet,sql);
int iCount=theApp.m_pADOSet->GetRecordCount();
if (iCount!=0){ //修改库存表
_variant_t Holder;
CString strAccount;
int iSurplus,iSave;
Holder=theApp.m_pADOSet->GetCollect("yeaccount");
iSurplus=(int)Holder.dblVal;
sscanf(m_strAccount,"%d",&iSave);
iSurplus+=iSave;
strAccount.Format("%d",iSurplus);
//修改余额表
sql="update msurplus set yeaccount="
+strAccount+" where yeid='"
+m_strID
+"' and yebase='"
+m_strBase+"'";
theApp.ADOExecute(sql);
}
else{
//若没有库存记录,则添加新的记录
sql="insert msurplus values('"
+m_strID+"','"
+m_strName+"','"
+m_strSpec+"','"
+m_strKind+"','"
+m_strUnit+"',"
+m_strAccount+","
+m_strValue+",'"
+m_strBase+"','"
+m_strMemo+"')";
theApp.ADOExecute(sql);
}
//提交事务
theApp.ADOConn->CommitTrans();
}
BOOL CMaterial_MISApp::ADOExecute(_variant_t &sql)
{
try{
ADOConn->Execute((_bstr_t)sql,NULL,adCmdUnknown);
return true;
}
catch (_com_error e) {
CString strErr;
strErr.Format("%s",(char*)e.Description());
AfxMessageBox(strErr);
return false;
}
}
BOOL CMaterial_MISApp::ADOExecute(_RecordsetPtr &ADOSet, _variant_t &sql)
{
//to check state of recordset
if (ADOSet->GetState() ==adStateOpen) {
ADOSet->Close(); //close recordset
}
try
{
ADOSet->Open(sql,ADOConn.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdUnknown);
return true;
}
catch (_com_error e) {
CString strErr;
strErr.Format("%s",(char*)e.Description());
AfxMessageBox(strErr,MB_ICONEXCLAMATION);
return false;
}
}