• 用户界面与业务逻辑的分离


    摘自《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 }
    
    

      






  • 相关阅读:
    hadoop之 解析HDFS的写文件流程
    Linux之 手动释放内存
    Heka 的编译
    go get 下载需要的相关工具
    峰值计算的方法
    thrift简介
    Bazaar 版本控制工具
    Homebrew
    虚拟机下centos时间不正确的方便解决方法
    golang 应用的部署相关技术
  • 原文地址:https://www.cnblogs.com/lzihua/p/2382801.html
Copyright © 2020-2023  润新知