MFC 编写的超市收银系统 毛病太多 请大家帮帮忙

III__III 2011-12-03 09:38:15
// 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();
}
...全文
176 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dahaiI0 2011-12-03
  • 打赏
  • 举报
回复
这样不行的,很少有人闲的蛋疼去检查别人写的一大堆代码,楼主说点关键的,比如说能不能跑起来,如果不能跑起来在哪个地方崩了,然后贴相应段的代码,稍微描述下。
III__III 2011-12-03
  • 打赏
  • 举报
回复
这里只是一小部分的代码,我用的数据库是MYSQL,我的邮箱是578933066@qq.com 扣扣是578933066 可以吧整个代码发过去 希望能帮助我解决,这是一个C++的课业设计 MFC编程
III__III 2011-12-03
  • 打赏
  • 举报
回复
不是的,这个只是一小部分,可以留下一个邮箱我把整个代码给你们发过去
用户 昵称 2011-12-03
  • 打赏
  • 举报
回复
这么一点就是一个系统了?楼主又想让我等改什么毛病呢?

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧