// Pay.cpp : implementation file
//
#include "stdafx.h"
#include "超市收银管理系统.h"
#include "Pay.h"
//#include <odbcinst.h>
//#include <afxdb.h>
#include "PaySet.h"
#include "MainFrm.h"
extern CDatabase m_database;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CPay, CFormView)
CPay::CPay()
: CFormView(CPay::IDD)
{
//{{AFX_DATA_INIT(CPay)
m_allpay = _T("");
m_zhaoling = _T("");
m_goodsid = _T("");
m_totalprice = _T("");
//}}AFX_DATA_INIT
}
CPay::~CPay()
{
}
void CPay::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPay)
DDX_Control(pDX, IDC_ALLPAY, m_allpaycontrol);
DDX_Control(pDX, IDC_TOTALPRICE, m_totalpricecontrol);
DDX_Control(pDX, IDC_E_ZHAOLING, m_zhaolingcontrol);
DDX_Control(pDX, IDC_GOODS_ID, m_goodsidcontrol);
DDX_Control(pDX, IDC_GOODSLIST, m_goodslist);
DDX_Text(pDX, IDC_ALLPAY, m_allpay);
DDX_Text(pDX, IDC_E_ZHAOLING, m_zhaoling);
DDX_Text(pDX, IDC_GOODS_ID, m_goodsid);
DDX_Text(pDX, IDC_TOTALPRICE, m_totalprice);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPay, CFormView)
//{{AFX_MSG_MAP(CPay)
ON_BN_CLICKED(IDC_BUTTON_IN, OnButtonIn)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_B_ZHAOLING, OnBZhaoling)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#ifdef _DEBUG
void CPay::AssertValid() const
{
CFormView::AssertValid();
}
void CPay::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
void CPay::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
//初始化列表控件字段
m_goodslist.InsertColumn(0,"商品号");
m_goodslist.InsertColumn(1,"商品名称");
m_goodslist.InsertColumn(2,"商品价格");
m_goodslist.InsertColumn(3,"卖出时间");
m_goodslist.InsertColumn(4,"打折率");
m_goodslist.InsertColumn(5,"有无存货");
//初始化列表控件各字段大小.
RECT rect;
m_goodslist.GetWindowRect(&rect);
int width=rect.right-rect.left;
m_goodslist.SetColumnWidth(0,width/7);
m_goodslist.SetColumnWidth(1,width/5);
m_goodslist.SetColumnWidth(2,width/7);
m_goodslist.SetColumnWidth(3,width/7);
m_goodslist.SetColumnWidth(4,width/7);
m_goodslist.SetColumnWidth(5,width/7);
m_goodslist.SetExtendedStyle(LVS_EX_FULLROWSELECT);
totalprice=0; //设置商品总额为0
i=0; //初始化list为第一行
//删除列表中的已有信息
m_goodslist.DeleteAllItems();
}
void CPay::OnButtonIn()
{
// TODO: Add your control notification handler code here
m_recordset=new CPaySet(&m_database);
CDBVariant varValue; //varValue能够转换为其他类型的值
char buf[20];
CString strSQL;
double fprice;
CTime systime; //获取系统时间
systime=CTime::GetCurrentTime();
//显示systime的值
int year=systime.GetYear();
int month=systime.GetMonth();
int day=systime.GetDay();
int hour=systime.GetHour();
int minute=systime.GetMinute();
int second=systime.GetSecond();
sprintf(buf,"%d-%d-%d %d:%d:%d",year,month,day,hour,minute,second);
// MessageBox(buf);
UpdateData(TRUE); //将编辑框中的内容提取出来
//按输入的商品号从数据库中读取记录
strSQL.Format("update goods set SALES_TIME=\'%d-%d-%d %d:%d:%d'\
where goods_id='%s'",systime.GetYear(),systime.GetMonth(),systime.GetDay(),systime.GetHour(),systime.GetMinute(),systime.GetSecond(),m_goodsid);
m_database.ExecuteSQL(strSQL);
//GOODS
strSQL.Format("select * from goods where goods_id='%s'",m_goodsid);
//m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//出错
m_recordset->Open(CRecordset::forwardOnly,strSQL,CRecordset::readOnly);
if(m_recordset->GetRecordCount()!=0)
{
int temp=0;
//对字符串进行处理
m_recordset->GetFieldValue(temp,varValue);
我觉得应该是这里的原因 但是不知道怎么改
m_goodslist.InsertItem(i,varValue.m_pstring->GetBuffer(1));
m_recordset->GetFieldValue(1,varValue);
m_goodslist.SetItemText(i,1,varValue.m_pstring->GetBuffer(1));
//对(price)进行处理
m_recordset->GetFieldValue(2,varValue);
m_goodslist.SetItemText(i,2,varValue.m_pstring->GetBuffer(1));
fprice=atof(varValue.m_pstring->GetBuffer(1)); //把字符串转换成浮点型
totalprice=fprice+totalprice;
// char fpricestr[20];
// sprintf(fpricestr,"%f",fprice);
// MessageBox(fpricestr);
//对日期类型进行处理
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_goodslist.SetItemText(i,3,buf);
// AfxMessageBox("buf");
//对(是否打折)进行处理
m_recordset->GetFieldValue(4,varValue);
m_goodslist.SetItemText(i,4,varValue.m_pstring->GetBuffer(1));
//对整型数据进行处理
m_recordset->GetFieldValue(5,varValue);
sprintf(buf,"%d",varValue.m_iVal);
m_goodslist.SetItemText(i,5,buf);
//移到下一条记录
// m_recordset.MoveNext();
// i++;
UpdateData(FALSE);
i++;
}
else
{
MessageBox("不存在该商品!!");
UpdateData(FALSE);
m_goodsidcontrol.Clear();
}
}
void CPay::OnOK()
{
// TODO: Add your control notification handler code here
}
void CPay::OnButton1()
{
// TODO: Add your control notification handler code here
m_recordset->Close();
char totalpricestr[20];
sprintf(totalpricestr,"%.2f",totalprice);
m_totalprice=totalpricestr;
UpdateData(FALSE);
m_totalpricecontrol.Clear();
}
void CPay::OnBZhaoling()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
double zhaoling=atof(m_allpay)-atof(m_totalprice);
m_zhaoling.Format("%.2f",zhaoling);
UpdateData(false);
m_allpaycontrol.Clear();
m_zhaolingcontrol.Clear();
}