📄 mdbsavedat.cpp
字号:
// MdbSaveDat.cpp: implementation of the CMdbSaveDat class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Invoice.h"
#include "MdbSaveDat.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
////////////////////////////
char databasee[256];
CMdbSaveDat::CMdbSaveDat()
{
char systemdir[256];
GetSystemDirectory(systemdir,256);
sprintf(databasee,"%s\\goods.mdb",systemdir);
}
CMdbSaveDat::~CMdbSaveDat()
{
}
int CMdbSaveDat::InsertMdbDao(CString trade_protcol,CString trade_client,CString *goods_num,CString *goods_mode,double *goods_unitprice,int *goods_maxno,int report_maxno)
{
CDaoDatabase db; //数据库
CDaoRecordset RecSet(&db); //记录集
int i;
int trade_goods_maxno=0;
double trade_goods_maxprice=0;
CString str;
CTime DToday;
//打开已创建的数据库
db.Open(databasee);
/////////////////////////打开已创建的表
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM Goods_Table_save2", 0);
for(i=0;i<report_maxno;i++)
{
//加入记录,用DAO涵数
RecSet.AddNew();
RecSet.SetFieldValue("t_goods_tradeprotcol",(LPCSTR)trade_protcol);
RecSet.SetFieldValue("t_goods_num",(LPCSTR)goods_num[i]);
RecSet.SetFieldValue("t_goods_mode",(LPCSTR)goods_mode[i]);
str.Format("%1.2f",goods_unitprice[i]);
RecSet.SetFieldValue("t_goods_unitprice",(LPCSTR)str);
str.Format("%d",goods_maxno[i]);
RecSet.SetFieldValue("t_goods_maxno",(LPCSTR)str);
RecSet.Update();
trade_goods_maxno+=goods_maxno[i];
trade_goods_maxprice+=(goods_unitprice[i]*goods_maxno[i]);
}
//关闭记录集
RecSet.Close();
////////////////////////////打开已创建的表
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,
"SELECT * FROM Goods_Table_save1", 0);
//加入记录,用DAO涵数
RecSet.AddNew();
DToday=CTime::GetCurrentTime();
str.Format("%04d%02d",DToday.GetYear(),DToday.GetMonth());
RecSet.SetFieldValue("t_goods_tradetime",(LPCSTR)str);
RecSet.SetFieldValue("t_goods_tradeprotcol",(LPCSTR)trade_protcol);
RecSet.SetFieldValue("t_goods_tradeclient",(LPCSTR)trade_client);
str.Format("%d",trade_goods_maxno);
RecSet.SetFieldValue("t_goods_trade_maxno",(LPCSTR)str);
str.Format("%1.2f",trade_goods_maxprice);
RecSet.SetFieldValue("t_goods_trade_maxprice",(LPCSTR)str);
RecSet.Update();
//关闭记录集
RecSet.Close();
//关闭库
db.Close();
return 1;
}
int CMdbSaveDat::QueryMdbSave1(char *m_time,CString *t_tradetime,CString *trade_protcol,CString *trade_client,CString *trade_maxno,CString *trade_maxprice)
{
CDaoDatabase db; //数据库
CDaoRecordset RecSet(&db); //记录集
COleVariant var; // 字段类型
int no=0;
var.ChangeType(VT_BSTR, NULL);
// 打开已创建的数据库及表
db.Open(databasee);
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM Goods_Table_save1 ", NULL);
no=0;
while(!RecSet.IsEOF()) // 有没有到表结尾
{
RecSet.GetFieldValue("t_goods_tradetime",var);
t_tradetime[no]= (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_tradeprotcol",var);
trade_protcol[no] = (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_tradeclient",var);
trade_client[no]= (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_trade_maxno",var);
trade_maxno[no]= (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_trade_maxprice",var);
trade_maxprice[no]= (LPCSTR)var.pbstrVal;
if(strlen(m_time)==0)//空记录查询
no++;
else
{
if(memcmp(m_time,t_tradetime[no],strlen(m_time))==0)no++;//查到结果
}
RecSet.MoveNext();
}
//关闭记录集及库
RecSet.Close();
db.Close();
return no;
}
int CMdbSaveDat::QueryMdbSave2(CString goods_protcol,CString *goods_num,CString *goods_mode,CString *goods_maxno,CString *goods_unitprice)
{
CDaoDatabase db; //数据库
CDaoRecordset RecSet(&db); //记录集
COleVariant var; // 字段类型
CString Sql;
int no=0;
var.ChangeType(VT_BSTR, NULL);
// 打开已创建的数据库及表
db.Open(databasee);
Sql="SELECT * FROM Goods_Table_save2 where t_goods_tradeprotcol='"+goods_protcol+"'";
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,Sql, NULL);
no=0;
while(!RecSet.IsEOF()) // 有没有到表结尾
{
RecSet.GetFieldValue("t_goods_num",var);
goods_num[no] = (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_mode",var);
goods_mode[no]= (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_unitprice",var);
goods_unitprice[no]= (LPCSTR)var.pbstrVal;
RecSet.GetFieldValue("t_goods_maxno",var);
goods_maxno[no]= (LPCSTR)var.pbstrVal;
no++;
RecSet.MoveNext();
}
//关闭记录集及库
RecSet.Close();
db.Close();
return no;
}
int CMdbSaveDat::DeleteMdbDao(CString trade_protcol)
{
CDaoDatabase db; //数据库
CDaoRecordset RecSet(&db); //记录集
CString buf,Sql;
COleVariant var; // 字段类型
int del_no=0;
var.ChangeType(VT_BSTR, NULL);
Sql="SELECT * FROM Goods_Table_save1 where t_goods_tradeprotcol='"+trade_protcol+"'";
// 打开已创建的数据库及表
db.Open(databasee);
RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,Sql, NULL);
while(!RecSet.IsEOF()) // 有没有到表结尾
{
/////////////////////删除
RecSet.Delete();
del_no++;
RecSet.MoveNext();
}
//关闭记录集及库
RecSet.Close();
db.Close();
return del_no;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -