⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.cpp

📁 在本次课程设计中
💻 CPP
字号:
// Search.cpp : implementation file
//

#include "stdafx.h"
#include "超市收银管理系统.h"
#include "Search.h"

#include "SearchSet.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSearch
extern CDatabase m_database;

IMPLEMENT_DYNCREATE(CSearch, CFormView)

CSearch::CSearch()
	: CFormView(CSearch::IDD)
{
	//{{AFX_DATA_INIT(CSearch)
	m_starttime = COleDateTime::GetCurrentTime();
	m_endtime = COleDateTime::GetCurrentTime();
	m_searchsd = 0;
	m_searchst = 0;
	m_searched = 0;
	m_searchet = 0;
	//}}AFX_DATA_INIT
}

CSearch::~CSearch()
{
}

void CSearch::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSearch)
	DDX_Control(pDX, IDC_LIST_SEARCH, m_listsearch);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_SD, m_searchsd);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ST, m_searchst);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ED, m_searched);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ET, m_searchet);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSearch, CFormView)
	//{{AFX_MSG_MAP(CSearch)
	ON_BN_CLICKED(IDC_BUTTON_START_SEARCH, OnButtonStartSearch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSearch diagnostics

#ifdef _DEBUG
void CSearch::AssertValid() const
{
	CFormView::AssertValid();
}

void CSearch::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSearch message handlers

void CSearch::OnButtonStartSearch() 
{
	i=0;//初始化i为第一行
		m_listsearch.DeleteAllItems();  //清除list表中的内容
	// TODO: Add your control notification handler code here
	m_recordset=new CSearchSet(&m_database);

	CDBVariant varValue;   //varValue能够转换为其他类型的值
	char buf[20];
    CString strSQL;

	UpdateData(TRUE);   //将日期控件中的内容提取出来
	int syear=m_searchsd.GetYear();
	int smonth=m_searchsd.GetMonth();
	int sday=m_searchsd.GetDay();
	int shour=m_searchst.GetHour();
	int sminute=m_searchst.GetMinute();
	int ssecond=m_searchst.GetSecond();
	CTime stime(syear,smonth,sday,shour,sminute,ssecond);

	int eyear=m_searched.GetYear();
	int emonth=m_searched.GetMonth();
	int eday=m_searched.GetDay();
	int ehour=m_searchet.GetHour();
	int eminute=m_searchet.GetMinute();
	int esecond=m_searchet.GetSecond();
	CTime etime(eyear,emonth,eday,ehour,eminute,esecond);

	CString strstart,strend;
	strstart.Format("%d-%d-%d %d:%d:%d",syear,smonth,sday,shour,sminute,ssecond);
	strend.Format("%d-%d-%d %d:%d:%d",eyear,emonth,eday,ehour,eminute,esecond);
//	MessageBox(strstart);
//	MessageBox(strend);

	strSQL.Format("SELECT * FROM GOODS WHERE SALES_TIME BETWEEN '%s' AND '%s'",strstart,strend);
	m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);

		
	if(m_recordset->GetRecordCount()!=0)
	{
		m_recordset->MoveFirst();
		while(!m_recordset->IsEOF())
		{
			int temp=0;

			//对字符串进行处理
			m_recordset->GetFieldValue(temp,varValue);
			m_listsearch.InsertItem(i,varValue.m_pstring->GetBuffer(1));

			m_recordset->GetFieldValue(1,varValue);
			m_listsearch.SetItemText(i,1,varValue.m_pstring->GetBuffer(1));

			//对(price)进行处理
			m_recordset->GetFieldValue(2,varValue);
			m_listsearch.SetItemText(i,2,varValue.m_pstring->GetBuffer(1));
     
		
			//对日期类型进行处理
			m_recordset->GetFieldValue(3,varValue);
			sprintf(buf,"%d-%d-%d %d:%d:%d",varValue.m_pdate->year,varValue.m_pdate->month,varValue.m_pdate->day,varValue.m_pdate->hour,varValue.m_pdate->minute,varValue.m_pdate->second);
			m_listsearch.SetItemText(i,3,buf);
			

			//对(是否打折)进行处理
			m_recordset->GetFieldValue(4,varValue);
			m_listsearch.SetItemText(i,4,varValue.m_pstring->GetBuffer(1));


			//对整型数据进行处理
			m_recordset->GetFieldValue(5,varValue);
			sprintf(buf,"%d",varValue.m_iVal);
			m_listsearch.SetItemText(i,5,buf);

			//移到下一条记录
			m_recordset->MoveNext();
			i++;
			UpdateData(FALSE);
			}

	}
	else
		MessageBox("该时间段内没有售货");
	m_recordset->Close();

	//strSQL.Format("SELECT * FROM myTable WHERE startTime BETWEEN '%s' AND '%s'",strBegin,strEnd);
/*测试CTime类型中的数据
	int year=stime.GetYear();
	int month=stime.GetMonth();
	int day=stime.GetDay();
	int hour=stime.GetHour();
	int minute=stime.GetMinute();	
	int second=stime.GetSecond();

	sprintf(buf,"%d-%d-%d %d:%d:%d",year,month,day,hour,minute,second);
	MessageBox(buf);*/
}

void CSearch::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	m_listsearch.InsertColumn(0,"商品号");
	m_listsearch.InsertColumn(1,"商品名称");
	m_listsearch.InsertColumn(2,"商品价格");
	m_listsearch.InsertColumn(3,"卖出时间");
	m_listsearch.InsertColumn(4,"打折率");
	m_listsearch.InsertColumn(5,"有无存货");


	//初始化列表控件各字段大小.
	RECT rect;
	m_listsearch.GetWindowRect(&rect);
	int width=rect.right-rect.left;
	m_listsearch.SetColumnWidth(0,width/7);
	m_listsearch.SetColumnWidth(1,width/7);
	m_listsearch.SetColumnWidth(2,width/7);
	m_listsearch.SetColumnWidth(3,width/7);
	m_listsearch.SetColumnWidth(4,width/7);
	m_listsearch.SetColumnWidth(5,width/7);

	m_listsearch.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	
	i=0;//初始化i为第一行

	
//	m_recordset->Open();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -