📄 buystatview.cpp
字号:
// BuyStatView.cpp : implementation file
//
#include "stdafx.h"
#include "Remedy.h"
#include "BuyStatView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 定义静态变量
const int CBuyStatView::m_nFieldCount = 12;
const CString CBuyStatView::m_strFields[m_nFieldCount] =
{"品名","规格","剂型","产地", "数量","单位","进价","零售价","备注","金额","日期","进货单位"};
// 声明全局变量
extern CRemedyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBuyStatView
IMPLEMENT_DYNCREATE(CBuyStatView, CFormView)
CBuyStatView::CBuyStatView()
: CFormView(CBuyStatView::IDD)
{
//{{AFX_DATA_INIT(CBuyStatView)
m_nDay = 0;
m_strMedName = _T("");
m_nDay2 = 0;
m_nMonth = 0;
m_nMonth2 = 0;
m_nYear = 0;
m_nYear2 = 0;
m_strWhere = _T("");
//}}AFX_DATA_INIT
}
CBuyStatView::~CBuyStatView()
{
}
void CBuyStatView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBuyStatView)
DDX_Control(pDX, IDC_LIST, m_ctlList);
DDX_Text(pDX, IDC_DAY, m_nDay);
DDX_Text(pDX, IDC_MEDNAME, m_strMedName);
DDX_Text(pDX, IDC_DAY2, m_nDay2);
DDX_Text(pDX, IDC_MONTH, m_nMonth);
DDX_Text(pDX, IDC_MONTH2, m_nMonth2);
DDX_Text(pDX, IDC_YEAR, m_nYear);
DDX_Text(pDX, IDC_YEAR2, m_nYear2);
DDX_Text(pDX, IDC_BUYER, m_strWhere);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBuyStatView, CFormView)
//{{AFX_MSG_MAP(CBuyStatView)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_VIEWRESULT, OnViewresult)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBuyStatView diagnostics
#ifdef _DEBUG
void CBuyStatView::AssertValid() const
{
CFormView::AssertValid();
}
void CBuyStatView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBuyStatView message handlers
void CBuyStatView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->SetWindowText("药品进货统计");
AddListHeader();
CTime t= CTime::GetCurrentTime();
m_nYear = m_nYear2 = t.GetYear();
m_nMonth = m_nMonth2 = t.GetMonth();
m_nDay = m_nDay2 = t.GetDay();
UpdateData(FALSE);
m_nType = 1; // 默认是按月统计
CheckDlgButton(IDC_RADIO1, 1);
GetDlgItem(IDC_DAY)->EnableWindow(FALSE);
GetDlgItem(IDC_DAY2)->EnableWindow(FALSE);
GetDlgItem(IDC_MONTH2)->EnableWindow(FALSE);
GetDlgItem(IDC_YEAR2)->EnableWindow(FALSE);
HRESULT hr = m_pRecordset.CreateInstance("ADODB.Recordset");
if (!SUCCEEDED(hr))
{
MessageBox("创建Recordset对象失败!");
}
}
void CBuyStatView::OnDestroy()
{
CFormView::OnDestroy();
((CMainFrame*)AfxGetMainWnd())->m_pBuyStat = NULL; // 清空窗口指针
}
void CBuyStatView::AddListHeader()
{
int width[m_nFieldCount] = {130, 110, 80, 120, 58, 60, 70, 70, 68, 68, 69, 70};
m_ctlList.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
for (int i = 0; i < m_nFieldCount; i++)
m_ctlList.InsertColumn(i, m_strFields[i], LVCFMT_CENTER, width[i]);
}
void CBuyStatView::OnViewresult()
{
UpdateData();
if (m_ctlList.GetItemCount() > 0)
m_ctlList.DeleteAllItems();
char buf[MAX_PATH];
sprintf(buf,
"select * from 进货 where 品名 like \'%s\' and 进货单位 like \'%s\'",
m_strMedName + "%",m_strWhere + "%");
m_pRecordset->Open( _variant_t(buf),
_variant_t((IDispatch*)theApp.m_pConnection,true),
adOpenStatic, adLockOptimistic, adCmdText);
if (m_pRecordset->adoEOF)
{
m_pRecordset->Close();
return;
}
_variant_t values[m_nFieldCount];
int index = 0; // 行号
while(!m_pRecordset->adoEOF)
{
CString strValues[m_nFieldCount];
_variant_t field;
for (int i = 0; i < m_nFieldCount; i++) // 依次读取每个字段的值
{
field.SetString(LPCTSTR(m_strFields[i]));
values[i] = m_pRecordset->GetCollect(field);
field.Clear();
strValues[i] = ::GetString(values[i]);
}
UINT nYear = ::GetYear(strValues[m_nFieldCount - 2]);
UINT nMonth = ::GetMonth(strValues[m_nFieldCount - 2]);
UINT nDay = ::GetDay(strValues[m_nFieldCount - 2]);
if (m_nType == 1)
{
if (m_nYear == nYear && m_nMonth == nMonth)
{
m_ctlList.InsertItem(index,strValues[0]);
for (int j = 1; j < m_nFieldCount; j++)
m_ctlList.SetItemText(index,j,strValues[j]);
index++;
}
}
else
{
CTime t1(m_nYear, m_nMonth, m_nDay, 0, 0 ,0);
CTime t2(m_nYear2, m_nMonth2, m_nDay2, 0, 0 ,0);
CTime t(nYear, nMonth, nDay, 0 ,0 ,0);
if (t >= t1 && t <= t2)
{
m_ctlList.InsertItem(index,strValues[0]);
for (int j = 1; j < m_nFieldCount; j++)
m_ctlList.SetItemText(index,j,strValues[j]);
index++;
}
}
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
GetTotalMoney();
}
void CBuyStatView::GetTotalMoney()
{
double fTotal = 0.0;
for (int i = 0; i < m_ctlList.GetItemCount(); i++)
{
double curPrice;
CString strTemp = m_ctlList.GetItemText(i,9);
curPrice = atof(LPCTSTR(strTemp));
fTotal += curPrice;
}
CString str;
str.Format("%.2f",fTotal);
SetDlgItemText(IDC_TMONEY,str);
}
void CBuyStatView::OnRadio1()
{
GetDlgItem(IDC_DAY)->EnableWindow(FALSE);
GetDlgItem(IDC_DAY2)->EnableWindow(FALSE);
GetDlgItem(IDC_MONTH2)->EnableWindow(FALSE);
GetDlgItem(IDC_YEAR2)->EnableWindow(FALSE);
GetDlgItem(IDC_YEAR)->SetFocus();
m_nType = 1;
}
void CBuyStatView::OnRadio2()
{
GetDlgItem(IDC_DAY)->EnableWindow(TRUE);
GetDlgItem(IDC_DAY2)->EnableWindow(TRUE);
GetDlgItem(IDC_MONTH2)->EnableWindow(TRUE);
GetDlgItem(IDC_YEAR2)->EnableWindow(TRUE);
GetDlgItem(IDC_YEAR)->SetFocus();
m_nType = 2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -