FinaceDlg.cpp
上传用户:tyjx315
上传日期:2015-01-18
资源大小:1685k
文件大小:7k
- // FinaceDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SuperMarket.h"
- #include "FinaceDlg.h"
- #include "afxdb.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFinaceDlg dialog
- CFinaceDlg::CFinaceDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CFinaceDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CFinaceDlg)
- m_month = _T("");
- m_investment = 0.0f;
- m_stock_money = 0.0f;
- //}}AFX_DATA_INIT
- }
- void CFinaceDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFinaceDlg)
- DDX_Control(pDX, IDC_LIST1, m_list);
- DDX_Text(pDX, IDC_EDIT1, m_month);
- DDX_Text(pDX, IDC_EDIT2, m_investment);
- DDX_Text(pDX, IDC_EDIT5, m_stock_money);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CFinaceDlg, CDialog)
- //{{AFX_MSG_MAP(CFinaceDlg)
- ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
- ON_BN_CLICKED(IDC_ACCOUNT, OnAccount)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFinaceDlg message handlers
- void CFinaceDlg::OnUpdate() //更新
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- CDatabase dbTemp;
- CRecordset rs( &dbTemp);
- CString strSQL;
- CString str0,str1;
- float invest,stock;
-
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 财务报表 where month='"+m_month+"'");
- if(!rs.IsEOF())
- {
- rs.GetFieldValue((short)1,str0);
- rs.GetFieldValue((short)5,str1);
- invest=atof(str0);
- stock=atof(str1);
- invest=invest+m_investment;
- stock=stock+m_stock_money;
- str0.Format("%.2f",invest);
- str1.Format("%.2f",stock);
- strSQL="update 财务报表 set investment='"+str0+"' where month='"+m_month+"'";
- dbTemp.ExecuteSQL(strSQL);
- strSQL="update 财务报表 set stock='"+str1+"' where month='"+m_month+"'";
- dbTemp.ExecuteSQL(strSQL);
- rs.Close();
- }
- else
- {
- str0.Format("%.2f",m_investment);
- str1.Format("%.2f",m_stock_money);
- strSQL="insert into 财务报表 values('"+m_month+"','"+str0+"','0.00','0.00','0.00','"+str1+"')";
- dbTemp.ExecuteSQL(strSQL);
- rs.Close();
- }
- MessageBox("更新成功!");
- m_month = _T("");
- m_investment = 0.0f;
- m_stock_money = 0.0f;
- UpdateData(false);
- }
- int CFinaceDlg::Cet_Month(CString str)
- {
- int year,month,day;
- sscanf(str,"%d-%d-%d",&year,&month,&day);
- return month;
- }
- void CFinaceDlg::OnAccount() //结算
- {
- // TODO: Add your control notification handler code here
- CTime time;
- UpdateData();
- CDatabase dbTemp;
- CRecordset rs( &dbTemp);
- CString str0,str1,str2,str3,str4,str5;
- CString strSQL;
- int month;
- float money,totalmoney=0;
- m_time = time.GetCurrentTime();
- m_time.GetMonth();
- month=atoi(m_month);
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
-
- if(month<m_time.GetMonth()) //如果是已结算过的月份,输出财务报表
- {
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 财务报表 where month='"+m_month+"'");
- rs.GetFieldValue((short)0,str0);
- rs.GetFieldValue((short)1,str1);
- rs.GetFieldValue((short)2,str2);
- rs.GetFieldValue((short)3,str3);
- rs.GetFieldValue((short)4,str4);
- rs.GetFieldValue((short)5,str5);
- m_list.InsertItem (addtime,str0);//写第一列;
- m_list.SetItemText (addtime,1,str1);//第二列;
- m_list.SetItemText (addtime,2,str2);//第三列;
- m_list.SetItemText (addtime,3,str3);//第四列;
- m_list.SetItemText (addtime,4,str4);//第五列;
- m_list.SetItemText (addtime,5,str5);//第五列;
- addtime++;
- UpdateData(false);
- rs.Close();
- }
- else if(month==m_time.GetMonth()) //如果是当前月份,计算财务报表并输出
- {
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 工资表");
- while(!rs.IsEOF()) //计算月工资发放额
- {
- rs.GetFieldValue((short)2,str2);
- money=atof(str2);
- totalmoney=totalmoney+money;
- rs.MoveNext();
- }
- str2.Format("%.2f",totalmoney);
- strSQL="update 财务报表 set totalsalary='"+str2+"' where month='"+m_month+"'";
- dbTemp.ExecuteSQL(strSQL);
- totalmoney=0;
- rs.Close();
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 销售表"); //计算月销售总额
- while(!rs.IsEOF())
- {
- rs.GetFieldValue((short)2,str2);
- month = Cet_Month(str2);
- if(month==m_time.GetMonth())
- {
- rs.GetFieldValue((short)1,str2);
- money=atof(str2);
- totalmoney=totalmoney+money;
- }
- rs.MoveNext();
- str2.Format("%.2f",totalmoney);
- strSQL="update 财务报表 set sale='"+str2+"' where month='"+m_month+"'";
- dbTemp.ExecuteSQL(strSQL);
- }
- totalmoney=0;
- rs.Close();
-
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 退货表"); //计算退货总额
- while(!rs.IsEOF())
- {
- rs.GetFieldValue((short)5,str2);
- month = Cet_Month(str2);
- if(month==m_time.GetMonth())
- {
- rs.GetFieldValue((short)4,str2);
- money=atof(str2);
- totalmoney=totalmoney+money;
- }
- rs.MoveNext();
- str2.Format("%.2f",totalmoney);
- strSQL="update 财务报表 set refundent='"+str2+"' where month='"+m_month+"'";
- dbTemp.ExecuteSQL(strSQL);
- }
- rs.Close();
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 财务报表 where month='"+m_month+"'");
- rs.GetFieldValue((short)0,str0);
- rs.GetFieldValue((short)1,str1);
- rs.GetFieldValue((short)2,str2);
- rs.GetFieldValue((short)3,str3);
- rs.GetFieldValue((short)4,str4);
- rs.GetFieldValue((short)5,str5);
- m_list.InsertItem (addtime,str0);//写第一列;
- m_list.SetItemText (addtime,1,str1);//第二列;
- m_list.SetItemText (addtime,2,str2);//第三列;
- m_list.SetItemText (addtime,3,str3);//第四列;
- m_list.SetItemText (addtime,4,str4);//第五列;
- m_list.SetItemText (addtime,5,str5);//第五列;
- addtime++;
- UpdateData(false);
- rs.Close();
- }
- else //如果是还未到的月份,输出不能结算
- {
- MessageBox("还未到该月份,不能结算");
- }
- m_month = _T("");
- m_investment = 0.0f;
- m_stock_money = 0.0f;
- UpdateData(false);
- }
- BOOL CFinaceDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- addtime=0;
-
- // TODO: Add extra initialization here
- m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
- m_list.InsertColumn(0,"月份",LVCFMT_LEFT,80);
- m_list.InsertColumn(1,"经理投资",LVCFMT_LEFT,100);
- m_list.InsertColumn(2,"工资额",LVCFMT_LEFT,100);
- m_list.InsertColumn(3,"销售额",LVCFMT_LEFT,100);
- m_list.InsertColumn(4,"退款额",LVCFMT_LEFT,100);
- m_list.InsertColumn(5,"采购金",LVCFMT_LEFT,100);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }