⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recent.cpp

📁 个人电子图书管理系统.提供电子书的书名和其他信息.检查电子书信息的合法性(E-1) .为这本电子书生成 id.使用分类id
💻 CPP
字号:
// 静态模型
#include "Recent.h"
#include <iostream>
#include <sstream>
namespace Library
{
    
    /// <summary>默认构造函数</summary>
    /// <remarks>只有Book和BookClass需要GUID, 因此调用基类构造函数的BookObject( int )版</remarks>
    RecentItem::RecentItem()
        :BookObject( 0 )
    {
        this->count = -1;
    }

    /// <summary>拷贝构造函数</summary>
    /// <remarks>只有Book和BookClass需要GUID, 因此调用基类构造函数的BookObject( int )版</remarks>
    RecentItem::RecentItem(const Library::RecentItem &copy)
        :BookObject( 0 )
    {
        this->id    = copy.id;
        this->lastTime = copy.lastTime;
        this->count = copy.count;
    }

    
    /// <summary>从以一个XML节点加载数据</summary>
    int RecentItem::LoadFromXml(TiXmlElement *elem)
    {
        if(elem == NULL)
            return 1;

        const char*   pAttu = NULL;
        pAttu = elem->Attribute("id");
        if(NULL != pAttu)
        {
            this->id = pAttu;
        }
        else
        {
            throw KException("没有找到图书的id.缺乏必须的信息.");
        }
        pAttu = elem->Attribute("lasttime");
        if(NULL != pAttu)
        {
            this->lastTime = pAttu;
        }
        else
        {
            throw KException("没有找到打开时间.缺乏必须的信息.");
        }
        pAttu = elem->Attribute("count");
        if(NULL != pAttu)
        {
            std::stringstream ss;
            ss<< pAttu;
            ss>> this->count;
        }
        else
        {
            throw KException("没有找到打开次数.缺乏必须的信息.");
        }

        return 0;
    }

    
    /// <summary>将最近浏览的数据保存到一个XML节点</summary>
    /// <param name="elem">zml节点指针</param>
    /// <returns>成功返回i0; 失败返回其他值</returns>
    /// <remarks></remarks>
    int RecentItem::SaveToXml(TiXmlElement *elem)
    {
        if(elem == NULL)
            return 1;
        elem->Clear();

        // 节点名
        elem->SetValue("BookItem");

        // 属性
        elem->SetAttribute("id", this->id);
        elem->SetAttribute("lasttime", this->lastTime);

        std::stringstream ss;
        std::string strCount;
        ss<< this->count;
        ss>> strCount;

        elem->SetAttribute("count", strCount);

        return 0;
    }
} // Library

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -