📄 family_financ_systemdlg.cpp
字号:
temp=pRst->GetCollect("生活计划支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_l_plain);
temp=pRst->GetCollect("休闲计划支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_p_plain);
temp=pRst->GetCollect("实际生活支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_l_true_out);
temp=pRst->GetCollect("实际休闲支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_p_true_out);
}
else
{
/////////////////////////////////////////////////
// 创建本月记录
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pConnection->Open(_bstr_t(Title1),"","",adModeUnknown);
m_pRecordset->Open(_variant_t(sqlstr), // 查询Demo表中所有字段
(IDispatch*)m_pConnection.GetInterfacePtr(), // 获取数据库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(m_pRecordset->EndEOF)
{
// 写入各字段值
m_this_money_in=0.0;m_this_money_out=0.0;
m_pRecordset->AddNew();
m_pRecordset->PutCollect("总收入",m_money_sum_in);;
m_pRecordset->PutCollect("总支出", m_money_sum_out);
m_pRecordset->PutCollect("月收入", m_this_money_in);
m_pRecordset->PutCollect("月支出",m_this_money_out);
m_pRecordset->PutCollect("总计划支出",m_this_total_plain);
m_pRecordset->PutCollect("生活计划支出",m_this_l_plain);
m_pRecordset->PutCollect("休闲计划支出",m_this_p_plain);
m_pRecordset->PutCollect("实际生活支出",m_this_l_true_out);
m_pRecordset->PutCollect("实际休闲支出",m_this_p_true_out);
m_pRecordset->PutCollect("年",_variant_t((long)this_year));
m_pRecordset->PutCollect("月",_variant_t((long)this_month));
m_pRecordset->PutCollect("日期",_variant_t(t_time));
m_pRecordset->Update();
}
m_pRecordset->Close();
m_pConnection->Close();
}
m_money_sum_end=m_money_sum_in-m_money_sum_out;
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
pRst->Close(); //关闭对象
pConn->Close();
pCmd.Release(); //释放对象
pRst.Release();
pConn.Release();
CoUninitialize(); //卸载COM组件
/////////////////////////////////////////////////////////////////////
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFamily_financ_systemDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFamily_financ_systemDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFamily_financ_systemDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFamily_financ_systemDlg::OnInsert()
{
// TODO: Add your control notification handler code here
m_insert.EnableWindow(FALSE);
UpdateData(TRUE);
CString m__day,m__f_mb,m__io_t,beizhu,leibie,string_temp;
float jine=m_money;
_bstr_t temp;char *char_temp;
int i=0;
int nstep;
int nYear,nMonth,nDay;
float total_in=0.0,total_out=0.0,total_end,l_t_out=0.0,p_t_out=0.0;
try
{
sscanf(m_day,"%d-%d-%d",&nYear,&nMonth,&nDay);
if((m_day!="")&&(m_f_mb!="")&&(m_io_t!="")&&(nYear!=0)&&(nMonth!=0)&&(nDay!=0))
{
m__day=m_day;m__f_mb=m_f_mb;m__io_t=m_io_t;beizhu=m_beizhu;
if((m_io_t=="工资(奖金)")|(m_io_t=="其他收入"))
{
leibie="收入";
}
else
{
leibie="支出";
}
COleDateTime t_time(nYear,nMonth,1,0,0,0);
COleDateTime t_time1(nYear,nMonth,nDay,0,0,0);
////////////////////////////////////////////////////////////////////////////////
//
// 添加记录需要用记录的打开方法
//
///////////////////////////////////////////////////////////////////////////////
CoInitialize(NULL); //初始化COM组件
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pConnection->Open(_bstr_t(Title1),"","",adModeUnknown);
CString sqlstr="SELECT * FROM 家庭财务表 where (时间='";
sqlstr=sqlstr+m_day;sqlstr=sqlstr+"') and (种类='";
sqlstr=sqlstr+m__io_t;sqlstr=sqlstr+"') and (金额=";
string_temp.Format("%f",m_money);
sqlstr=sqlstr+string_temp;sqlstr=sqlstr+") and (经手人='";
sqlstr=sqlstr+m_f_mb+"')";
m_pRecordset->Open(_variant_t(sqlstr), // 查询Demo表中所有字段
(IDispatch*)m_pConnection.GetInterfacePtr(), // 获取数据库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(m_pRecordset->EndEOF)
{
// 写入各字段值
m_pRecordset->AddNew();
m_pRecordset->PutCollect("时间",_variant_t(m__day));;
m_pRecordset->PutCollect("种类", _variant_t(m__io_t));
m_pRecordset->PutCollect("金额", jine);
m_pRecordset->PutCollect("经手人",_variant_t(m__f_mb));
m_pRecordset->PutCollect("收支类别",_variant_t(leibie));
m_pRecordset->PutCollect("备注(具体情况)",_variant_t(beizhu));
m_pRecordset->PutCollect("年",_variant_t((long)nYear));
m_pRecordset->PutCollect("月",_variant_t((long)nMonth));
m_pRecordset->PutCollect("日期",_variant_t(t_time1));
m_pRecordset->Update();
m_pRecordset->Close();
m_pConnection->Close();
//////////////////////////////////////////////////////
//CoInitialize(NULL); //初始化COM组件
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pConnection->Open(_bstr_t(Title1),"","",adModeUnknown);
sqlstr="SELECT * FROM 月统计表 where (年=";
string_temp.Format("%d",nYear);
sqlstr=sqlstr+string_temp;
sqlstr=sqlstr+") and (月=";
string_temp.Format("%d",nMonth);
sqlstr=sqlstr+string_temp;
sqlstr=sqlstr+")";
m_pRecordset->Open(_variant_t(sqlstr), // 查询Demo表中所有字段
(IDispatch*)m_pConnection.GetInterfacePtr(), // 获取数据库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(leibie=="收入")
{
m_money_sum_in=m_money_sum_in+m_money;
total_in=m_money;
}
else
{
m_money_sum_out=m_money_sum_out+m_money;
total_out=m_money;
if((m_io_t=="饮食消费")|(m_io_t=="生活用品消费"))
{
l_t_out=m_money;
}
else
{
if(m_io_t=="文娱消费")
{
p_t_out=m_money;
}
}
}
total_end=m_money_sum_end;
if(m_pRecordset->EndEOF)
{ /// 创建新月统计记录
m_money_sum_end=m_money_sum_in-m_money_sum_out;
// 写入各字段值
m_pRecordset->AddNew();
m_pRecordset->PutCollect("年",_variant_t((long)nYear));;
m_pRecordset->PutCollect("月",_variant_t((long)nMonth));
m_pRecordset->PutCollect("总收入",m_money_sum_in);
m_pRecordset->PutCollect("总支出",m_money_sum_out);
m_pRecordset->PutCollect("实际生活支出",l_t_out);
m_pRecordset->PutCollect("实际休闲支出",p_t_out);
m_pRecordset->PutCollect("月收入",total_in);
m_pRecordset->PutCollect("月支出",total_out);
m_pRecordset->PutCollect("日期",_variant_t(t_time));
m_pRecordset->Update();
}
else
{
temp=m_pRecordset->GetCollect("月支出");
char_temp=temp;
sscanf(char_temp,"%f",&total_out);
temp=m_pRecordset->GetCollect("月收入");
char_temp=temp;
sscanf(char_temp,"%f",&total_in);
temp=m_pRecordset->GetCollect("实际生活支出");
char_temp=temp;
sscanf(char_temp,"%f",&l_t_out);
temp=m_pRecordset->GetCollect("实际休闲支出");
char_temp=temp;
sscanf(char_temp,"%f",&p_t_out);
if(leibie=="收入")
{
total_in=total_in+m_money;
}
else
{
total_out=total_out+m_money;
if((m_io_t=="饮食消费")|(m_io_t=="生活用品消费"))
{
l_t_out=l_t_out+m_money;
}
else
{
if(m_io_t=="文娱消费")
{
p_t_out=p_t_out+m_money;
}
}
}
m_pRecordset->PutCollect("总收入",m_money_sum_in);
m_pRecordset->PutCollect("总支出",m_money_sum_out);
m_pRecordset->PutCollect("实际生活支出",l_t_out);
m_pRecordset->PutCollect("实际休闲支出",p_t_out);
m_pRecordset->PutCollect("月收入",total_in);
m_pRecordset->PutCollect("月支出",total_out);
m_pRecordset->Update();
}
/////////////////////////////////////////////////////////////////////
m_pRecordset->Close();
m_pConnection->Close();
string_temp="go_on";
//////////////////////////////////////////////////////////////////////////////
}
else
{
AfxMessageBox("已有该记录!");
string_temp="end";
}
/////////////////////////////////////////////////////////////////////
if(string_temp=="go_on")
{
////////////////////////////////////////////////////////////////////////////////
_ConnectionPtr pConn(__uuidof(Connection)); //实例化一个connection对象pConn
_RecordsetPtr pRst(__uuidof(Recordset)); //实例化一个Recordset对象pRst
_CommandPtr pCmd(__uuidof(Command)); //实例化一个Command对象pCmd
pConn->ConnectionString=(_bstr_t)Title1;//通过pConn对象连接字符串,连接到ACCESS数据库
HRESULT hr = pConn->Open("","","",adConnectUnspecified);
// 以同步的方式进行连接 open("连接字串","用户名","密码","连接方式")
// 连接方式有"adConnectUnspecified"(同步) 和 "adAsyncConnect" (异步)
pCmd->put_ActiveConnection(_variant_t((IDispatch*)pConn));
pCmd->CommandText="SELECT * FROM 家庭财务表"; //通过pCmd对象访问数据库
pRst=pCmd->Execute(NULL,NULL,adCmdText);
m_list.DeleteAllItems();
for(;!pRst->EndEOF; pRst->MoveNext()) // 在数据库中寻找 pRecord->MoveFirst()
{
temp=pRst->GetCollect("时间");
nstep=m_list.InsertItem(i,temp);
temp=pRst->GetCollect("种类");
m_list.SetItemText(nstep,1,temp);
temp=pRst->GetCollect("金额");
m_list.SetItemText(nstep,2,temp);
temp=pRst->GetCollect("经手人");
m_list.SetItemText(nstep,3,temp);
temp=pRst->GetCollect("备注(具体情况)");
m_list.SetItemText(nstep,4,temp);
}
sqlstr="SELECT * FROM 月统计表 where (年=";
string_temp.Format("%d",this_year);
sqlstr=sqlstr+string_temp;
sqlstr=sqlstr+") and (月=";
string_temp.Format("%d",this_month);
sqlstr=sqlstr+string_temp;
sqlstr=sqlstr+")";
//char_temp=sqlstr;
pCmd->CommandText=_bstr_t(sqlstr); //通过pCmd对象访问数据库
pRst=pCmd->Execute(NULL,NULL,adCmdText);
if(!pRst->EndEOF)
{
temp=pRst->GetCollect("总收入");
char_temp=temp;
sscanf(char_temp,"%f",&m_money_sum_in);
temp=pRst->GetCollect("总支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_money_sum_out);
temp=pRst->GetCollect("月收入");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_money_in);
temp=pRst->GetCollect("月支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_money_out);
temp=pRst->GetCollect("总计划支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_total_plain);
temp=pRst->GetCollect("生活计划支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_l_plain);
temp=pRst->GetCollect("休闲计划支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_p_plain);
temp=pRst->GetCollect("实际生活支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_l_true_out);
temp=pRst->GetCollect("实际休闲支出");
char_temp=temp;
sscanf(char_temp,"%f",&m_this_p_true_out);
}
/////////////////////////////////////////////////////////////////////
pRst->Close(); //关闭对象
pConn->Close();
pCmd.Release(); //释放对象
pRst.Release();
pConn.Release();
CoUninitialize(); //卸载COM组件
/////////////////////////////////////////////////////////////////////
}
}
else
{
AfxMessageBox("请认真填写!不能有空");
}
}
catch(_com_error e)
{
AfxMessageBox("出现异常,请重新填写");
}
m_money_sum_end=m_money_sum_in-m_money_sum_out;
m_beizhu="";
m_money=0;
UpdateData(FALSE);
m_insert.EnableWindow(TRUE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -