1、初始化:void CCompanyView: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.Set
2、ColumnWidth(2,100); m_list.SetColumnWidth(3,100); CString sql=select * from 表1; m_set.Open(AFX_DB_USE_DEFAULT_TYPE,sql); int i=0; while(!m_set.IsEOF() m_list.InsertItem(i,m_set.m_num); m_list.SetItemText(i,1,m_set.m_sex); CString str; str.Format(%d,m_set.m_age); m_list.SetItemText(i,2,str); m_list.S
3、etItemText(i,3,m_set.m_name); m_set.MoveNext(); i+; m_set.Close();“添加”调出新对话框(IDD_DIALOG1) 创建一个新类Cadd dlg,并添加头文件” #include c1set.h” 及成员变量(CString m_num; int m_sex; CString m_wage; int m_age;)Onadd() cadd dlg; if(dlg.DoModal()=IDOK) m_set.Open(AFX_DB_USE_DEFAULT_TYPE,NULL); m_set.AddNew(); m_set.m_num
4、=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(); “删除”void CMy1View:Ondel() int i=m_list.GetSelectionMark(); if(iMessageBox(先选取记录 else CString xnum1; char xnum10; int x=m_list.GetItemText(i,0,xnum,10); xnum1.Format(%
5、s,xnum); CString sql=select * from 表1 where num = + xnum1 + / select * from stud where num=10001 m_set.Open(AFX_DB_USE_DEFAULT_TYPE,sql); m_set.Delete(); “浏览”OnScan() m_list.DeleteAllItems();select * from comp m_list.SetItemText(i,3,m_set.m_wage);“修改”Onedit() return; cadd dlg; CString xnum1,xnum0; c
6、har xnum10; 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(
7、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.SetI
8、temText(0,1,m_set.m_sex); m_list.SetItemText(0,2,str); m_list.SetItemText(0,3,m_set.m_name);购物表设计添加了一个新类struct GoodsTypechar * type;char * name;int price;goods=日常用品,牙刷,2,牙膏,3,毛巾,5,脸盆香皂,4,文具铅笔,1,圆珠笔钢笔,12,水彩笔,6,签字笔球类篮球,22,足球,25,羽毛球,62,网球,82,乒乓球,50;添加的变量:int total;int count;CListBox m_isSelGoods; CList
9、Box m_isName; CComboBox m_cmbType; CString m_Type; CString m_Name; CString m_singleprice; CString m_totalprice; int m_count; CString m_SelGoods;1 初始化BOOL CShoppingDlg:OnInitDialog() m_singleprice=单价 m_totalprice=共计: total=0; count=0; m_cmbType.AddString ( m_Type= for(int i=0;i5;i+) m_isName.AddStrin
10、g(goodsi.name); UpdateData(0);2 左侧列表框void CShoppingDlg:OnSelchangeSaleList1() UpdateData();15; if(m_Name=goodsi.name ) char x100; sprintf(x,单价:%d元,goodsi.price );/int型转换成字符串型 m_singleprice=x; UpdateData(0); break; 3 组合框 void CShoppingDlg:OnSelchangeSaleType() int start; int x=m_cmbType.GetCurSel();/
11、组合框中选取当前商品类型 m_cmbType.GetLBText(x,m_Type);/传到列表框中 if(m_Type= start=0; else if(m_Type= start=5; start=10; m_isName.ResetContent();/重置列表框1的内容 for(int i=start;start+5;/追加商品名称4 确定OnShop() UpdateData(); if(m_Name=goodsi.name) total=total+goodsi.price*m_count; break; m_isSelGoods.AddString(m_Name); char x100; sprintf(x, %d元,total); m_totalprice=x;5 取消选择OnCansel() if(m_Name=goodsi.name) total-=goodsi.price*m_count; int s=m_isSelGoods.GetCurSel(); m_isSelGoods.DeleteString(s);6 取消OnCancel() CDialog:OnCancel();四、 运行结果1.数据库添加listcontrol控件添加“添加”按钮添加“删除”按钮添加“浏览”按钮添加“修改”按钮7 添加“查询”按钮2.购物表设计
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1