// Check.cpp : 实现文件
//
#include "stdafx.h"
#include "rijizhang.h"
#include "Check.h"
#include "add.h"
// CCheck 对话框
IMPLEMENT_DYNAMIC(CCheck, CDialog)
add member;
CCheck::CCheck(CWnd* pParent /*=NULL*/)
: CDialog(CCheck::IDD, pParent)
, m_intRadio(0)
, m_editsmall(0)
, m_editBig(0)
, m_Tfront(0)
, m_Tback(0)
, m_checkStr(_T(""))
{
m_rectange.SetRect(0,0,0,0);
m_small.SetRect(0,0,0,0);
}
CCheck::~CCheck()
{
}
void CCheck::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RADIO1, m_radio1);
DDX_Text(pDX, IDC_EDIT1, m_editsmall);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT2, m_editBig);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_timeFront);
DDX_Control(pDX, IDC_DATETIMEPICKER2, m_timeBack);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_Tfront);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_Tback);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_LIST1, m_checkList);
DDX_Control(pDX, IDC_COMBO2, m_checkBox);
DDX_CBString(pDX, IDC_COMBO2, m_checkStr);
}
BEGIN_MESSAGE_MAP(CCheck, CDialog)
ON_BN_CLICKED(IDOK, &CCheck::OnBnClickedOk)
ON_BN_CLICKED(IDC_RADIO1, &CCheck::OnBnClickedRadio1)
ON_BN_CLICKED(IDC_RADIO2, &CCheck::OnBnClickedRadio2)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, &CCheck::OnLvnColumnclickList1)
ON_COMMAND(ID_32776, &CCheck::On32776)
ON_COMMAND(ID_PENGHAO_32778, &CCheck::OnPenghao32778)
ON_COMMAND(ID_PENGHAO_32780, &CCheck::OnPenghao32780)
ON_STN_CLICKED(IDC_STATIC1, &CCheck::OnStnClickedStatic1)
END_MESSAGE_MAP()
// CCheck 消息处理程序
BOOL CCheck::OnInitDialog()
{
CDialog::OnInitDialog();
CheckRadioButton(IDC_RADIO1,IDC_RADIO3,IDC_RADIO1);
GetDlgItem(IDC_DATETIMEPICKER1)->ShowWindow(false);
GetDlgItem(IDC_DATETIMEPICKER2)->ShowWindow(false);
if (m_rectange.IsRectNull())
{
CRect m_rectpic;
GetWindowRect(&m_rectange);
GetDlgItem(IDC_PIC)->GetWindowRect(&m_rectpic);
m_small.left=m_rectange.left;
m_small.top=m_rectange.top;
m_small.right=m_rectange.right;
m_small.bottom=m_rectpic.bottom;
}
SetWindowPos(NULL,0,0,m_small.Width(),m_small.Height(),SWP_NOMOVE|SWP_NOZORDER);
CTime tempTime=CTime::GetCurrentTime();
m_timeBack.SetTime(&tempTime);
m_timeFront.SetTime(&tempTime);
m_edit1.SetLimitText(6);
m_edit2.SetLimitText(6);
DWORD dwStyle = m_checkList.GetExtendedStyle(); //获取当前扩展样式
dwStyle |= LVS_EX_FULLROWSELECT; //选中某行使整行高亮(report风格时)
dwStyle |= LVS_EX_GRIDLINES; //网格线(report风格时)
//dwStyle |= LVS_EX_CHECKBOXES; //item前生成checkbox控件
m_checkList.SetExtendedStyle(dwStyle); //设置扩展风格
m_data.InitDatabase();
m_data.openTable();
m_checkList.InsertColumn( 0, _T("时间"), LVCFMT_CENTER, 80 );//插入列
m_checkList.InsertColumn( 1, _T("开支类型"), LVCFMT_CENTER, 80 );
m_checkList.InsertColumn( 2, _T("消费类别"), LVCFMT_CENTER, 100 );//插入列
m_checkList.InsertColumn( 3, _T("详细项目"), LVCFMT_CENTER, 120 );
m_checkList.InsertColumn( 4, _T("金额"), LVCFMT_CENTER, 80 );
m_checkList.InsertColumn( 5, _T("备注"), LVCFMT_LEFT,300 );
member.initIniFile();
m_checkBox.AddString(_T("全部"));
for (int i=0;i<member.m_keyName.GetSize();i++)
{
m_checkBox.AddString(member.m_keyName[i]);
}
m_checkBox.SetCurSel(0);
return TRUE;
}
int CCheck::checkData()
{
int num=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO3);
UpdateData(true);
switch(num)
{
case IDC_RADIO1:
if (m_editsmall>=m_editBig)
{
GetDlgItem(IDC_EDIT2)->SetFocus();
return 0;
}else return 1;
break;
case IDC_RADIO2:
m_timeFront.GetTime(m_Tfront);
m_timeBack.GetTime(m_Tback);
if (m_Tfront>m_Tback)
{
GetDlgItem(IDC_DATETIMEPICKER2)->SetFocus();
return 0;
}else return 2;
break;
case IDC_RADIO3:
return false;
}
return true;
}
_variant_t money ,leibie,yx,bz,rq,zhizhu;
CString str;
CString timeStrBack,timeStrFront;
void CCheck::OnBnClickedOk()
{
if (m_data.m_pRecord->BOF)
{
if (MessageBox(_T("当前还没有可以查询的数据,是否现在添加数据!"),_T("提示"),MB_YESNO)==IDYES)
{
CDialog::OnCancel();//关闭当前对话框
member.DoModal();
}
}else
{
m_data.m_pRecord->MoveFirst();
if (checkData()!=0)//判断查询的数据是否在范围之内
{
if (m_checkBox.GetCurSel()==0)
{
if (checkData()==1)
{
m_sqlStr.Format(_T("select * from table1 where 金额>=%d and 金额<=%d"),m_editsmall,m_editBig);
}else if(checkData()==2)
{
timeStrBack.Format(_T("%d-%d-%d" ),m_Tback.GetYear(),m_Tback.GetMonth(),m_Tback.GetDay());
timeStrFront.Format(_T("%d-%d-%d" ),m_Tfront.GetYear(),m_Tfront.GetMonth(),m_Tfront.GetDay());
m_sqlStr.Format(_T("select * from table1 where 时间 between #%s# and #%s#"),timeStrFront,timeStrBack);
}
}else
{
if (checkData()==1)
{
m_sqlStr.Format(_T("select * from table1 where 金额>=%d and 金额<=%d and 消费类别='%s'"),m_editsmall,m_editBig,m_checkStr);
}else if(checkData()==2)
{
timeStrBack.Format(_T("%d-%d-%d" ),m_Tback.GetYear(),m_Tback.GetMonth(),m_Tback.GetDay());
timeStrFront.Format(_T("%d-%d-%d" ),m_Tfront.GetYear(),m_Tfront.GetMonth(),m_Tfront.GetDay());
m_sqlStr.Format(_T("select * from table1 where 时间 between #%s# and #%s# and 消费类别='%s' "),timeStrFront,timeStrBack,m_checkStr);
}
}
m_ptr=m_data.CheckDatabase(_bstr_t(m_sqlStr));
if (m_ptr->BOF)
{
SetWindowPos(NULL,0,0,m_small.Width(),m_small.Height(),SWP_NOMOVE|SWP_NOZORDER);
MessageBox(_T("当前查询范围内还没有数据!"));
}else
{
SetWindowPos(NULL,0,0,m_rectange.Width(),m_rectange.Height(),SWP_NOMOVE|SWP_NOZORDER);
m_checkList.DeleteAllItems();
while(!m_ptr->adoEOF)
{
money = m_ptr->GetCollect("金额");
leibie =m_ptr->GetCollect("消费类别");
yx= m_ptr->GetCollect("详细类别");
bz=m_ptr->GetCollect("备注");
rq=m_ptr->GetCollect("时间");
zhizhu=m_ptr->GetCollect("开支形式");
str =(LPCSTR)_bstr_t(money);
int nRow = m_checkList.InsertItem(0,0);//插入行
m_checkList.SetItemText(nRow, 4, str);//设置数据
str =(LPCSTR)_bstr_t(yx);
m_checkList.SetItemText(nRow, 3, str);//设置数据
str =(LPCSTR)_bstr_t(leibie);
m_checkList.SetItemText(nRow, 2, str);//设置数据
str =(LPCSTR)_bstr_t(bz);
m_checkList.SetItemText(nRow, 5, str);//设置数据
str=(LPCSTR)_bstr_t(rq);
m_checkList.SetItemText(nRow, 0, str);//设置数据
str=(LPCSTR)_bstr_t(zhizhu);
m_checkList.SetItemText(nRow, 1, str);//设置数据
m_ptr->MoveNext();
}
int sum=0;
for (int i=0;i<m_checkList.GetItemCount();i++)
{
str = m_checkList.GetItemText(i,4);
sum+=m_checkList.StrToInt(str);
}
str.Format(_T("总金额为:¥%d"),sum);
GetDlgItem(IDC_STATIC1)->SetWindowText(str);
}
}else
{
SetWindowPos(NULL,0,0,m_small.Width(),m_small.Height(),SWP_NOMOVE|SWP_NOZORDER);
MessageBox(_T("你查询的范围不正确,请检查!"));
}
}
//OnOK();
}
void CCheck::OnBnClickedRadio1()
{
GetDlgItem(IDC_EDIT1)->ShowWindow(true);
GetDlgItem(IDC_EDIT2)->ShowWindow(true);
GetDlgItem(IDC_DATETIMEPICKER1)->ShowWindow(false);
GetDlgItem(IDC_DATETIMEPICKER2)->ShowWindow(false);
}
void CCheck::OnBnClickedRadio2()
{
GetDlgItem(IDC_EDIT1)->ShowWindow(false);
GetDlgItem(IDC_EDIT2)->ShowWindow(false);
GetDlgItem(IDC_DATETIMEPICKER1)->ShowWindow(true);
GetDlgItem(IDC_DATETIMEPICKER2)->ShowWindow(true);
}
int CALLBACK listSort(LPARAM lp1,LPARAM lp2,LPARAM lp)
{
CSortList * nList= (CSortList*)lp;
CString str1,str2;
int num1,num2,a;
switch(nList->m_nSortCol)
{
case 0:
str1=nList->GetItemText(lp1,nList->m_nSortCol);
str2=nList->GetItemText(lp2,nList->m_nSortCol);
a=nList-> DateCompare(str1,str2);
break;
case 4:
num1 =nList->StrToInt(nList->GetItemText(l