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

📄 sqlgroup.cs

📁 Gibphone is CSharp Program, it can tell you how to design p2p chat.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using FirebirdSql.Data.FirebirdClient;

namespace GPCore
{
    public struct SqlGroup : IIdable
    {
        private int id;
        public int ID
        {
            get
            {
                return id;
            }
        }
        public int ParentGroup
        {
            get
            {
                object o = Sql.ExecuteScalar("select ParentGroup from Groups where GroupID = ?", id);
                return (o is int ? (int)o : -1);
            }
            set
            {
                Sql.ExecuteNonQuery("update Groups set ParentGroup = ? where GroupID = ?", value, id);
            }
        }
        private string name;
        public string Alias
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
                Sql.ExecuteNonQuery("update Groups set Alias = ? where GroupID = ?", value, id);
            }
        }
        public static readonly SqlGroup Zero = new SqlGroup(-1);
        public SqlGroup(int id)
        {
            object o = Sql.ExecuteScalar("select Alias from Groups where GroupID = ?", id);
            string s = o as string;
            if (string.IsNullOrEmpty(s) && id != -1)
                throw new ArgumentException("The given ID is not in the table", "id");
            this.id = id;
            this.name = s;
        }
        public SqlGroup(string alias)
        {
            object o = Sql.ExecuteScalar("select groupId from groups where Alias = ?", alias);
            if (o == null)
            {
                Sql.ExecuteNonQuery("insert into groups (alias) values (?)", alias);
                o = Sql.ExecuteScalar("select groupId from groups where Alias = ?", alias);
            }
            this.name = alias;
            this.id = (int)o;
        }


        #region IEnumerable<IIdable> Members

        public IEnumerator<IIdable> GetEnumerator()
        {
            FbCommand com = Sql.SqlDatabase.CreateCommand();
            com.CommandText = "Select Alias from Groups Where ParentGroup = ? Order by GroupID ASC";
            com.Parameters.AddWithValue("", ID);
            FbDataReader reader = com.ExecuteReader();
            while (reader.Read())
            {
                SqlGroup g = new SqlGroup(reader.GetString(0).Trim());
                yield return g;
            }
            reader.Close();
            com = Sql.SqlDatabase.CreateCommand();
            com.CommandText = "Select Alias from Gibs Where GroupID = ? Order by GibID ASC";
            com.Parameters.AddWithValue("", ID);
            reader = com.ExecuteReader();
            while (reader.Read())
            {
                SqlGib g = new SqlGib(reader.GetString(0).Trim());
                yield return g;
            }
            reader.Close();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        #region IIdable Members


        public IIdable Parent
        {
            get { return new SqlGroup(ParentGroup); }
        }
        public int Count
        {
            get
            {
                List<IIdable> items = new List<IIdable>(this);
                return items.Count;
            }
        }
        #endregion
        public override string ToString()
        {
            return Alias;
        }
        public static IEnumerable<SqlGroup> Groups
        {
            get
            {
                FbCommand com = Sql.SqlDatabase.CreateCommand();
                com.CommandText = "Select Alias from Groups Order by GroupID ASC";
                FbDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    SqlGroup g = new SqlGroup(reader.GetString(0).Trim());
                    yield return g;
                }
                reader.Close();
            }
        }
    }
}

⌨️ 快捷键说明

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