VC课设Word格式.docx
《VC课设Word格式.docx》由会员分享,可在线阅读,更多相关《VC课设Word格式.docx(13页珍藏版)》请在冰豆网上搜索。
⑴初始化:
voidCCompanyView:
:
OnInitialUpdate()
{
CFormView:
OnInitialUpdate();
GetParentFrame()->
RecalcLayout();
ResizeParentToFit();
m_list.InsertColumn(0,"
num"
);
m_list.InsertColumn(1,"
sex"
m_list.InsertColumn(2,"
age"
m_list.InsertColumn(3,"
name"
m_list.SetColumnWidth(0,100);
m_list.SetColumnWidth(1,100);
m_list.SetColumnWidth(2,100);
m_list.SetColumnWidth(3,100);
CStringsql="
select*from表1"
;
m_set.Open(AFX_DB_USE_DEFAULT_TYPE,sql);
inti=0;
while(!
m_set.IsEOF())
{
m_list.InsertItem(i,m_set.m_num);
m_list.SetItemText(i,1,m_set.m_sex);
CStringstr;
str.Format("
%d"
m_set.m_age);
m_list.SetItemText(i,2,str);
m_list.SetItemText(i,3,m_set.m_name);
m_set.MoveNext();
i++;
}
m_set.Close();
⑵“添加”调出新对话框(IDD_DIALOG1)
创建一个新类Cadddlg,并添加头文件”#include"
c1set.h"
”
及成员变量(CStringm_num;
intm_sex;
CStringm_wage;
intm_age;
)
Onadd()
cadddlg;
if(dlg.DoModal()==IDOK)
m_set.Open(AFX_DB_USE_DEFAULT_TYPE,NULL);
m_set.AddNew();
m_set.m_num=dlg.m_num2;
if(dlg.m_sex2==0)
m_set.m_sex="
男"
else
女"
m_set.m_age=dlg.m_age2;
m_set.m_name=dlg.m_name2;
m_set.Update();
m_set.Close();
}}
⑶“删除”
voidCMy1View:
Ondel()
inti=m_list.GetSelectionMark();
if(i<
0)
this->
MessageBox("
先选取记录"
else
CStringxnum1;
charxnum[10];
intx=m_list.GetItemText(i,0,xnum,10);
xnum1.Format("
%s"
xnum);
CStringsql="
select*from表1wherenum='
"
+xnum1+"
'
//"
select*fromstudwherenum='
10001'
"
m_set.Open(AFX_DB_USE_DEFAULT_TYPE,sql);
m_set.Delete();
⑷“浏览”
OnScan()
m_list.DeleteAllItems();
select*fromcomp"
m_list.SetItemText(i,3,m_set.m_wage);
}
⑸“修改”
Onedit()
return;
cadddlg;
CStringxnum1,xnum0;
charxnum[10];
m_list.GetItemText(i,0,xnum,10);
xnum1.Format("
dlg.m_num2=xnum1;
xnum0=xnum1;
m_list.GetItemText(i,1,xnum,10);
//dlg.m_sex2=0;
if(xnum1=="
dlg.m_sex2=0;
else
dlg.m_sex2=1;
m_list.GetItemText(i,2,xnum,10);
dlg.m_age2=atoi(xnum);
m_list.GetItemText(i,3,xnum,10);
dlg.m_name2=xnum;
//UpdataDate(0);
if(dlg.DoModal()!
=IDOK)return;
+xnum0+"
m_set.Edit();
m_set.m_age=dlg.m_age2;
m_set.m_num=dlg.m_num2;
m_set.m_name=dlg.m_name2;
if(dlg.m_sex2==0)
m_set.m_sex="
m_set.Update();
⑹“查询”
Oncha()
this->
UpdateData
(1);
+m_num1+"
if(m_set.m_num!
=m_num1)
无记录"
m_list.InsertItem(0,m_set.m_num);
m_list.SetItemText(0,1,m_set.m_sex);
m_list.SetItemText(0,2,str);
m_list.SetItemText(0,3,m_set.m_name);
购物表设计
添加了一个新类
structGoodsType
char*type;
char*name;
intprice;
}goods[]={
日常用品"
"
牙刷"
2,
牙膏"
3,
毛巾"
5,
脸盆"
香皂"
4,
文具"
铅笔"
1,
圆珠笔"
钢笔"
12,
水彩笔"
6,
签字笔"
球类"
篮球"
22,
足球"
25,
羽毛球"
62,
网球"
82,
乒乓球"
50
};
添加的变量:
inttotal;
intcount;
CListBoxm_isSelGoods;
CListBoxm_isName;
CComboBoxm_cmbType;
CStringm_Type;
CStringm_Name;
CStringm_singleprice;
CStringm_totalprice;
intm_count;
CStringm_SelGoods;
1初始化
BOOLCShoppingDlg:
OnInitDialog()
m_singleprice="
单价"
m_totalprice="
共计:
total=0;
count=0;
m_cmbType.AddString("
m_Type="
for(inti=0;
i<
5;
i++)
m_isName.AddString(goods[i].name);
UpdateData(0);
2左侧列表框
voidCShoppingDlg:
OnSelchangeSaleList1()
UpdateData();
15;
if(m_Name==goods[i].name)
{
charx[100];
sprintf(x,"
单价:
%d元"
goods[i].price);
//int型转换成字符串型
m_singleprice=x;
UpdateData(0);
break;
}
3组合框
voidCShoppingDlg:
OnSelchangeSaleType()
intstart;
intx=m_cmbType.GetCurSel();
//组合框中选取当前商品类型
m_cmbType.GetLBText(x,m_Type);
//传到列表框中
if(m_Type=="
start=0;
elseif(m_Type=="
start=5;
start=10;
m_isName.ResetContent();
//重置列表框1的内容
for(inti=start;
start+5;
//追加商品名称
4确定
OnShop()
UpdateData();
if(m_Name==goods[i].name)
total=total+goods[i].price*m_count;
break;
m_isSelGoods.AddString(m_Name);
charx[100];
sprintf(x,"
%d元"
total);
m_totalprice=x;
5取消选择
OnCansel()
if(m_Name==goods[i].name)
total-=goods[i].price*m_count;
ints=m_isSelGoods.GetCurSel();
m_isSelGoods.DeleteString(s);
6取消
OnCancel()
CDialog:
OnCancel();
四、运行结果
1.数据库
⑴添加listcontrol控件
⑵添加“添加”按钮
⑶添加“删除”按钮
⑷添加“浏览”按钮
⑸添加“修改”按钮
7添加“查询”按钮
2.购物表设计