博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用户界面与业务逻辑的分离
阅读量:5101 次
发布时间:2019-06-13

本文共 4187 字,大约阅读时间需要 13 分钟。

摘自《Visual C++视频技术方案宝典》1.1.1

1 class CStuff   2 {
3 public: 4 CStuff(); 5 virtual ~CStuff(); 6 private: 7 int ID; //工号 8 CString Name; //名称 9 CString Sex; //性别 10 CString Knowledge; //学历 11 float Wage; //工资 12 public: 13 int GetID() const 14 {
15 return ID; 16 } 17 CString GetName() const 18 {
19 return Name; 20 } 21 CString GetSex() const 22 {
23 return Sex; 24 } 25 CString GetKnowledge() const 26 {
27 return Knowledge; 28 } 29 float GetWage() const 30 {
31 return Wage; 32 } 33 34 void SetID(int uID) 35 {
36 ID = uID; 37 } 38 void SetName(CString strName) 39 {
40 Name = strName; 41 } 42 void SetSex(CString strSex) 43 {
44 Sex = strSex; 45 } 46 void SetKnowledge(CString strKnowledge) 47 {
48 Knowledge = strKnowledge; 49 } 50 void SetWage(float fWage) 51 {
52 Wage = fWage; 53 } 54 55 };
 
1 class CStuffManage   2 {
3 public: 4 void SelectStuff(_RecordsetPtr pRecord); 5 BOOL DeleteStuff(CStuff& stuff); 6 BOOL UpdateStuff(CStuff& stuff,CStuff &oldstuff); 7 void IniStuff(CStuff& stuff); 8 BOOL AddStuff(CStuff& stuff); 9 BOOL ValidCheck(CStuff& stuff); 10 CStuffManage(); 11 virtual ~CStuffManage(); 12 }; 13 14 15 //合法性检查 16 BOOL CStuffManage::ValidCheck(CStuff &stuff) 17 {
18 if (stuff.GetKnowledge().IsEmpty() || stuff.GetSex().IsEmpty() 19 || stuff.GetName().IsEmpty()||stuff.GetWage()<0) 20 return FALSE; 21 else 22 return TRUE; 23 } 24 25 //添加员工信息 26 BOOL CStuffManage::AddStuff(CStuff &stuff) 27 {
28 CString sql; 29 sql.Format("insert into tb_StuffInfo values (%i, '%s','%s','%s',%f)",stuff.GetID(),stuff.GetName(), 30 stuff.GetSex(),stuff.GetKnowledge(),stuff.GetWage()); 31 try 32 {
33 m_DataManage.ExecOpt(sql); 34 return TRUE; 35 } 36 catch(...) 37 {
38 return FALSE; 39 } 40 } 41 //初始化员工信息 42 void CStuffManage::IniStuff(CStuff &stuff) 43 {
44 stuff.SetID(0); 45 stuff.SetName(""); 46 stuff.SetKnowledge(""); 47 stuff.SetSex(""); 48 stuff.SetWage(0.0); 49 } 50 51 //修改员工信息 52 BOOL CStuffManage::UpdateStuff(CStuff &stuff,CStuff &oldstuff) 53 {
54 CString sql; 55 sql.Format("update tb_StuffInfo set id = %i, name = '%s',sex = '%s', knowledge = '%s',wage = %f where id = '%s'",stuff.GetID(),stuff.GetName(), 56 stuff.GetSex(),stuff.GetKnowledge(),stuff.GetWage(),oldstuff.GetID()); 57 try 58 {
59 m_DataManage.ExecOpt(sql); 60 return TRUE; 61 } 62 catch(...) 63 {
64 return FALSE; 65 } 66 } 67 68 //删除员工信息 69 BOOL CStuffManage::DeleteStuff(CStuff &stuff) 70 {
71 CString sql; 72 sql.Format("delete tb_StuffInfo where id = '%s'",stuff.GetID()); 73 try 74 {
75 m_DataManage.ExecOpt(sql); 76 return TRUE; 77 } 78 catch(...) 79 {
80 return FALSE; 81 } 82 } 83 84 //查询员工信息 85 void CStuffManage::SelectStuff(_RecordsetPtr pRecord) 86 {
87 pRecord = m_DataManage.ExecSelect("select * from tb_StuffInfo"); 88 }
 
1 void CStuffSysDlg::OnSavefinfo()  2 {
3 //提供员工信息 4 UpdateData(); 5 6 m_Stuff.SetID(m_StuffID); 7 8 m_Stuff.SetName(m_StuffName); 9 10 CString sex; 11 m_StuffSex.GetWindowText(sex); 12 m_Stuff.SetSex(sex); 13 14 CString knowledge; 15 m_StuffKnowledge.GetWindowText(knowledge); 16 17 m_Stuff.SetKnowledge(knowledge); 18 19 m_Stuff.SetWage(m_StuffWage); 20 21 //检查员工信息的合法性 22 if (m_StuffManage.ValidCheck(m_Stuff)) 23 {
24 //添加员工信息 25 if (m_StuffManage.AddStuff(m_Stuff)) 26 MessageBox("员工信息添加成功"); 27 else 28 MessageBox("员工信息添加失败"); 29 OnClearinfo() ; 30 } 31 else 32 MessageBox("员工信息非法!"); 33 }
 

  

 

 

 

转载于:https://www.cnblogs.com/lzihua/archive/2012/03/07/2382801.html

你可能感兴趣的文章
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
IOS-图片操作集合
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
Codeforces 719B Anatoly and Cockroaches
查看>>
ActiveMQ与spring整合
查看>>
EOS生产区块:解析插件producer_plugin
查看>>
格式化输出数字和时间
查看>>
关于TFS2010使用常见问题
查看>>
URL编码与解码
查看>>
Eclipse 安装SVN插件
查看>>
阿里云服务器CentOS6.9安装Mysql
查看>>
剑指offer系列6:数值的整数次方
查看>>
js 过滤敏感词
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
软件开发和软件测试,我该如何选择?(蜗牛学院)
查看>>
基本封装方法
查看>>
Illustrated C#学习笔记(一)
查看>>
理解oracle中连接和会话
查看>>