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

📄 introduction.cs

📁 一个简单的Demo
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using Db4objects.Db4o;
using System.IO;
using System.Xml.Serialization;

namespace Surance.DB4ODAL
{
    [Serializable]
    public  class Introduction
    {
        #region Field
        private string title;
        private string content;
        private DateTime createTime;
        private int hit;
        private string category;

        private IObjectContainer db;
        #endregion

        #region Property
        public string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }
        public string Content
        {
            get 
            {
                return content;
            }
            set
            {
                content = value;
            }
        }
        public DateTime CreateTime
        {
            get
            {
                return createTime;
            }
            set
            {
                createTime = value;
            }
        }
        public int Hit
        {
            get
            {
                return hit;
            }
            set
            {
                hit = value;
            }
        }
        public string Category
        {
            get
            {
                return category;
            }
            set
            {
                category = value;
            }
        }
        #endregion

        #region Constructor
        public Introduction(IObjectContainer db)
        {
            this.db = db;
        }
        public Introduction() { }
        #endregion

        #region Public Method
        public void Add(Introduction intro)
        {
            db.Set(intro);
        }

        public void Update(Introduction intro)
        {
            db.Set(intro);
        }

        public void Del(Introduction intro)
        {
            db.Delete(intro);
        }

        public IList<Introduction> GetAll()
        {
            IList<Introduction> list = new List<Introduction>();
            list = db.Query<Introduction>(typeof(Introduction));
            return list;
        }

        public Introduction GetOne(string title)
        {
            IList<Introduction> list = db.Query<Introduction> (delegate(Introduction tmpIntro)
            {
                return tmpIntro.title == title;
            });
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }
        }


        #endregion

        public bool BackupToXml(string path)
        {
            FileStream fs = null;
            try
            {

                if (!File.Exists(path))
                    fs = File.Create(path);
                else
                    fs = File.OpenWrite(path);

                IList<Introduction> allData = this.GetAll();
                XmlSerializer xsl = new XmlSerializer(this.GetType());

                foreach (Introduction o in allData)
                {
                    xsl.Serialize(fs, o);
                }
                return true;
            }
            finally
            {
                fs.Flush();
                fs.Close();
                fs.Dispose();

            }

        }

    }
}

⌨️ 快捷键说明

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