《11嵌入式鲜奶配送系统设计报告.docx》由会员分享,可在线阅读,更多相关《11嵌入式鲜奶配送系统设计报告.docx(18页珍藏版)》请在三一办公上搜索。
1、嵌入式系统课程设计报告题目11鲜奶配送系统专 业:计算机科学与技术班 级:学 号:指导教师:题目11鲜奶配送系统1设计目的利用嵌入式SQLite数据库,在WINCE中实现鲜奶配送系统。掌握SQLite 数据库的安装与使用方法。2、开发环境程序在Visual Studio 2005开发环境中编写与编译,使用C+与MFC作为开 发的语言环境。利用SQLite数据库实现数据表的建立。3、设计任务及要求在Visual Studio 2005环境下,编写WINCE对话框程序。在程序中添加 SQLite数据库文件,使用SQLite数据库。设计要求:能够显示鲜奶配送列表。能够实现鲜奶订单的增加,修改,删除,
2、查询操作。数据库设计:订单列表:牛奶单号,客户id,奶品名称,奶品单价,奶品数量。4、实现过程4.1硬件DMA-6410 开发平台/CHSINT WINCE6.0 模拟器+-|1+_|-|一一/。一丁0-3壬-心芯&赖ld-翊 FOapJF 扉(Jvv-nd 口言 -lmymcl=r用h15 昭 3 旧、2、添加成员3、删除成员 01 0321 完达山 20 a 创建数据库创建表查询订阜牛奶单号 p4客尸ID |wewdd奶品名称ed奶品单价|dd奶品数量 怕添加数据删除数据修改数据卷开蛇叵协悄如域|蜀mysqlit日5|窗15:2口 |画4、修改成员4.3用户应用程序设计/ mysqlite
3、sDlg.cpp :实现文件/#include stdafx.h#include mysqlites.h#include mysqlitesDlg.h#ifdef _DEBUG#define new DEBUG_NEW#endif/ CmysqlitesDlg 对话框CmysqlitesDlg:CmysqlitesDlg(CWnd* pParent /*=NULL*/):CDialog(CmysqlitesDlg:IDD, pParent),m_edit(_T()m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CmysqlitesDlg:D
4、oDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);DDX_Text(pDX, IDC_EDIT1, m_edit);BEGIN_MESSAGE_MAP(CmysqlitesDlg, CDialog)#if defined(_DEVICE_RESOLUTION_AWARE) & !defined(WIN32_PLATFORM_WFSP)ON_WM_SIZE()#endif/AFX_MSG_MAPON_BN_CLICKED(IDC_BUTTON1, &CmysqlitesDlg:OnBnClickedButton1)ON_BN
5、_CLICKED(IDC_BUTTON2, &CmysqlitesDlg:OnBnClickedButton2)ON_BN_CLICKED(IDC_BUTTON3, &CmysqlitesDlg:OnBnClickedButton3)ON_EN_CHANGE(IDC_EDIT2, &CmysqlitesDlg:OnEnChangeEdit2)ON_BN_CLICKED(IDC_BUTTON4, &CmysqlitesDlg:OnBnClickedButton4)ON_EN_CHANGE(IDC_EDIT3, &CmysqlitesDlg:OnEnChangeEdit3)ON_EN_CHANGE
6、(IDC_EDIT4, &CmysqlitesDlg:OnEnChangeEdit4)ON_BN_CLICKED(IDC_BUTTON5, &CmysqlitesDlg:OnBnClickedButton5)ON_BN_CLICKED(IDC_BUTTON7, &CmysqlitesDlg:OnBnClickedButton7)ON_EN_CHANGE(IDC_EDIT5, &CmysqlitesDlg:OnEnChangeEdit5)ON_EN_CHANGE(IDC_EDIT6, &CmysqlitesDlg:OnEnChangeEdit6)END_MESSAGE_MAP()BOOL Cmy
7、sqlitesDlg:OnInitDialog()CDialog:OnInitDialog();/设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动/执行此操作SetIcon(m_hIcon, TRUE);/ 设置大图标SetIcon(m_hIcon, FALSE);设置小图标/ TODO:在此添加额外的初始化代码return TRUE; /除非将焦点设置到控件,否则返回TRUE#if defined(_DEVICE_RESOLUTION_AWARE) & !defined(WIN32_PLATFORM_WFSP) void CmysqlitesDlg:OnSize(UINT /*n
8、Type*/, int /*cx*/, int /*cy*/) if (AfxIsDRAEnabled()DRA:RelayoutDialog(AfxGetResourceHandle(),this-m_hWnd,DRA:GetDisplayMode() != DRA:Portrait ?MAKEINTRESOURCE(IDD_MYSQLITES_DIALOG_WIDE): MAKEINTRESOURCE(IDD_MYSQLITES_DIALOG);#endif void CmysqlitesDlg:OnBnClickedButton1()CppSQLite3DB db;db. open(LM
9、y Documentstest.db);/打开或新建数据库,文件名为test.dbMessageBox(_T(SUCCESS), _T(INFORMATION), MB_OK);/创建成功显示db. close ();/关闭 void CmysqlitesDlg:OnBnClickedButton2 () CppSQLite3DB db;db. open (LMy Documentstest.db);/打开数据库/新建表CppSQLite3Query q=db. execQuery (Lcreate table PSRB(nndh varchar(8),khid varchar(8),npmc
10、 varchar(8),npdj varchar(8),npsl varchar(8);/使用 execQuery 方法执行 SQL 语句创建表。插入数据q=db. execQuery (Linsert into PSRB values(01,0321,完达山,20,3);/执行SQL语句 插入一条数据MessageBox (_T(SUCCESS), _T(INFORMATION), MB_OK);/成功则显示SUCCESS db. close ();/关闭void CmysqlitesDlg:OnBnClickedButton3()CppSQLite3DB db;db.open(LMy Do
11、cumentstest.db);CppSQLite3Query q=db. execQuery (Lselect * from PSRB);/查询CString strTemp;while(!q. eof ()/返回值按行循环strTemp. Format (_T(%s %s %s %s %s), q. fieldValue (0), q. fieldValue (1), q. fieldValue (2), q. fieldValue (3), q. fieldValue (4);/返回的每一行的数据中,依次保存在q.fieldValue (0),q.fieldValue (1),q.fie
12、ldValue (2)。中,本例中每行数据有列。将这些数据以“%s空格%s空格%s” 的形式赋给strTemp。m_edit += strTemp;/将strTemp 赋给 EDIT 框成员变量 m_edit。m_edit+=rn;UpdateData (FALSE); 更新,使 EDIT 显示数据q. nextRow ();/下一行,循环q. finalize ();/SQL返回结束db. close ();/关闭void CmysqlitesDlg:OnEnChangeEdit2 ()/ TODO: If this is a RICHEDIT control, the control wi
13、ll not/ send this notification unless you override the CDialog:OnInitDialog()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code herevoid CmysqlitesDlg:OnBnClickedButton4 () CppSQLite3DB db;db.open(LMy Doc
14、umentstest.db);CString nndh, khid, npmc, npdj, npsl;GetDlgItem(IDC_EDIT2)-GetWindowText(nndh);GetDlgItem(IDC_EDIT3)-GetWindowText(khid);GetDlgItem(IDC_EDIT4)-GetWindowText(npmc);GetDlgItem(IDC_EDIT5)-GetWindowText(npdj);GetDlgItem(IDC_EDIT6)-GetWindowText(npsl);CString strTemp;strTemp. Format(_T(ins
15、ert into PSRB values(%s,%s,%s,%s,%s), nndh, khid, npmc, npdj, npsl);CppSQLite3Query q=db. execQuery(strTemp);MessageBox (L添加成功);db.close();void CmysqlitesDlg:OnEnChangeEdit3()/ TODO: If this is a RICHEDIT control, the control will not/ send this notification unless you override the CDialog:OnInitDia
16、log()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code herevoid CmysqlitesDlg:OnEnChangeEdit4()/ TODO: If this is a RICHEDIT control, the control will not/ send this notification unless you override the
17、CDialog:OnInitDialog()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code herevoid CmysqlitesDlg:OnBnClickedButton5()CppSQLite3DB db;db.open(LMy Documentstest.db);CString nndh;GetDlgltem (IDC_EDIT2)-GetWin
18、dowText(nndh);CString strTemp;strTemp. Format(_T(delete from PSRB where nndh=%s), nndh);CppSQLite3Query q=db. execQuery(strTemp);MessageBox (L删除成功);db.close();void CmysqlitesDlg:OnBnClickedButton7()CppSQLite3DB db;db.open(LMy Documentstest.db);CString nndh, khid, npmc, npdj, npsl;GetDlgItem(IDC_EDIT
19、2)-GetWindowText(nndh);GetDlgItem(IDC_EDIT3)-GetWindowText(khid);GetDlgItem(IDC_EDIT4)-GetWindowText(npmc);GetDlgItem(IDC_EDIT5)-GetWindowText(npdj);GetDlgItem(IDC_EDIT6)-GetWindowText(npsl);CString strTemp;strTemp. Format(_T(UPDATE PSRB SET khid=%s WHERE nndh=%s),khid, nndh);CppSQLite3Query q=db. e
20、xecQuery(strTemp);strTemp. Format(_T(UPDATE PSRB SET npmc=%s WHERE nndh=%s),npmc, nndh); q=db. execQuery(strTemp);MessageBox (L修改成功);db.close();1、创建牛奶配送代码CppSQLite3DB db;db. open(LMy Documentstest.db);/打开或新建数据库,文件名为test.db MessageBox(_T(SUCCESS), _T(INFORMATION), MB_OK);/创建成功显示db. close ();/关闭2、建立牛奶
21、配送void CmysqlitesDlg:OnBnClickedButton2() CppSQLite3DB db;db. open (LMy Documentstest.db);/打开数据库/新建表CppSQLite3Query q=db. execQuery (Lcreate table PSRB(nndh varchar(8),khid varchar(8),npmc varchar(8),npdj varchar(8),npsl varchar(8);/使用 execQuery 方法执行 SQL 语句创建表。插入数据q=db. execQuery (Linsert into PSRB
22、values(01,0321,完达山,20,3);/执行SQL语句 插入一条数据MessageBox (_T(SUCCESS), _T(INFORMATION), MB_OK);/成功则显示SUCCESSdb. close ();/关闭3、查询客户void CmysqlitesDlg:OnBnClickedButton3() CppSQLite3DB db;db.open(LMy Documentstest.db);CppSQLite3Query q=db. execQuery (Lselect * from PSRB);/查询CString strTemp;while(!q. eof ()/
23、返回值按行循环strTemp. Format (_T(%s %s %s %s %s), q. fieldValue (0), q. fieldValue (1), q. fieldValue (2), q. fieldValue (3), q. fieldValue (4);/返回的每一行的数据中,依次保存在q.fieldValue (0),q.fieldValue (1),q.fieldValue (2)。中,本例中每行数据有列。将这些数据以“%s空格%s空格%s” 的形式赋给strTemp。m_edit += strTemp;/将strTemp 赋给 EDIT 框成员变量 m_edit。
24、m_edit+=rn”;UpdateData (FALSE); 更新,使 EDIT 显示数据q. nextRow ();/下一行,循环q. finalize ();/SQL返回结束db. close ();/关闭4、建立客户void CmysqlitesDlg:OnBnClickedButton4 ()CppSQLite3DB db;db.open(LMy Documentstest.db);CString nndh, khid, npmc, npdj, npsl;GetDlgItem(IDC_EDIT2)-GetWindowText(nndh);GetDlgItem(IDC_EDIT3)-G
25、etWindowText(khid);GetDlgItem(IDC_EDIT4)-GetWindowText(npmc);GetDlgItem(IDC_EDIT5)-GetWindowText(npdj);GetDlgItem(IDC_EDIT6)-GetWindowText(npsl);CString strTemp;strTemp. Format(_T(insert into PSRB values(%s,%s,%s,%s,%s), nndh, khid, npmc, npdj, npsl);CppSQLite3Query q=db. execQuery(strTemp);MessageB
26、ox (L添加成功);db.close();6、删除客户void CmysqlitesDlg:OnBnClickedButton5()CppSQLite3DB db;db.open(LMy Documentstest.db);CString nndh;GetDlgItem(IDC_EDIT2)-GetWindowText(nndh);CString strTemp;strTemp. Format(_T(delete from PSRB where nndh=%s), nndh);CppSQLite3Query q=db. execQuery(strTemp);MessageBox (L删除成功
27、);db.close();7、修改客户void CmysqlitesDlg:OnBnClickedButton7()CppSQLite3DB db;db.open(LMy Documentstest.db);CString nndh, khid, npmc, npdj, npsl;GetDlgItem(IDC_EDIT2)-GetWindowText(nndh);GetDlgItem(IDC_EDIT3)-GetWindowText(khid);GetDlgItem(IDC_EDIT4)-GetWindowText(npmc);GetDlgItem(IDC_EDIT5)-GetWindowTe
28、xt(npdj);GetDlgItem(IDC_EDIT6)-GetWindowText(npsl);CString strTemp;strTemp. Format(_T(UPDATE PSRB SET khid=%s WHERE nndh=%s),khid, nndh);CppSQLite3Query q=db. execQuery(strTemp);strTemp. Format(_T(UPDATE PSRB SET npmc=%s WHERE nndh=%s),npmc, nndh); q=db. execQuery(strTemp);strTemp. Format(_T(UPDATE PSRB SET npdj=%s WHERE nndh=%s),npdj, nndh);q=db.execQuery(strTemp);strTemp. Format(_T(UPDATE PSRB SET npsl=%s WHERE nndh=%s),npsl, nndh); q=db.execQuery(strTemp);MessageBox (L修改成功”); db.close();4.4编译与运行结果5、总结通过本次试验进一步的了解win CE环境下的通讯录 系统开发,对于vs2005平台也学会了熟练的使用以及在 vs2005中熟练使用各类控件。