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

📄 sqlgib.cs

📁 Gibphone is CSharp Program, it can tell you how to design p2p chat.
💻 CS
📖 第 1 页 / 共 2 页
字号:
            g.Accounts.Clear();
            Sql.ExecuteNonQuery("Delete from Gibs where GibID = ?", ID);
            
        }
        /// <summary>
        /// Removes the given Gib.
        /// </summary>
        /// <param name="gib">The Gib to remove</param>
        public static void Remove(SqlGib gib)
        {
            RemoveAt(gib.ID);
        }
        #endregion

        #region ICollection<SqlGib> Members

        /// <summary>
        /// Creates a new SqlGib with the given Alias and GroupKey and adds it
        /// to the Database.
        /// </summary>
        /// <param name="Alias">The Alias of the Gib.</param>
        /// <param name="GroupKey">The Groupkey of the Gib.</param>
        /// <returns>The new Gib.</returns>
        public static SqlGib Add(String Alias, String GroupKey)
        {
            return new SqlGib(Alias, GroupKey);
        }

        
        /// <summary>
        /// Copys the contents of the GibLIst into array.
        /// </summary>
        /// <param name="array">A non-null array to hold all of the Gibs.</param>
        public static void CopyTo(SqlGib[] array)
        {
            CopyTo(array, 0);   
        }
        /// <summary>
        /// Copys the contents of the GibLIst into array.
        /// </summary>
        /// <param name="array">A non-null array to hold all of the Gibs.</param>
        /// <param name="arrayindex">The place to start in the array.</param>
        public static void CopyTo(SqlGib[] array, int arrayindex)
        {
            List<SqlGib> gl = new List<SqlGib>();
            foreach (SqlGib g in Gibs)
            {
                gl.Add(g);
            }
            Array.Copy(gl.ToArray(),0, array,arrayindex, gl.Count);
        }
        /// <summary>
        /// Removes all gibs from the list.
        /// </summary>
        public static void Clear()
        {
            Sql.ExecuteNonQuery("delete from Gibs where GibID > -1");
        }

        /// <summary>
        /// Checks if the given Gib is in the list.
        /// </summary>
        /// <param name="item">The gib to search for.</param>
        /// <returns>True if the Gib is in the list otherwise false.</returns>
        public static bool Contains(SqlGib item)
        {
            object o = Sql.ExecuteScalar("select Count(GibID) from Gibs where GibID = ?", item.ID);
            int i = (o == null ? 0 : (int)o);
            return i > 0;
        }

        /// <summary>
        /// Gets the number of Gibs in the list.
        /// </summary>
        public static int Count
        {
            get
            {
                object o = Sql.ExecuteScalar("select Count(GibID) from Gibs");
                return (o == null ? 0 : (int)o);
                
            }
        }

        /// <summary>
        /// Checks if there is a Gib that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>True if there is a gib like it, otherwise false.</returns>
        public static bool Exists(Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Gibs)
            {
                if (match(g))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Finds the first Gib that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>The First Gib for which <paramref name="match"/> returns true.</returns>
        public static SqlGib Find(Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Gibs)
            {
                if (match(g))
                    return g;
            }
            return new SqlGib();
        }

        /// <summary>
        /// Finds All of the Gibs that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>A list of Gibs for which <paramref name="match"/> returns true.</returns>
        public static List<SqlGib> FindAll(Predicate<SqlGib> match)
        {
            List<SqlGib> gl = new List<SqlGib>();
            foreach (SqlGib g in Gibs)
            {
                if (match(g))
                    gl.Add(g);
            }
            return gl;
        }
        
        /// <summary>
        /// Finds the ID of the First Gib that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>The ID of the First Gib.</returns>
        public static int FindIndex(Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Gibs)
            {
                if (match(g))
                    return g.ID;
            }
            return -1;
        }

        /// <summary>
        /// Finds the ID of the First Gib after startindex that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <param name="startindex">The ID of the Gib to start the search from.</param>
        /// <returns>The ID of the First Gib after startindex.</returns>
        public static int FindIndex(int startindex, Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Gibs)
            {
                if (g.ID >= startindex && match(g))
                    return g.ID;
            }
            return -1;
        }

        /// <summary>
        /// Finds the Last Gib that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>The Last Gib that matches.</returns>
        public static SqlGib FindLast(Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Reverse)
            {
                if (match(g))
                    return g;
            }
            return new SqlGib();
        }
        /// <summary>
        /// Finds the ID of the Last Gib that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>The ID of the Last Gib that matches.</returns>
        public static int FindLastIndex(Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Reverse)
            {
                if (match(g))
                    return g.ID;
            }
            return -1;
        }

        /// <summary>
        /// Finds the ID of the Last Gib from startindex that matches the given predicate.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <param name="startindex">The ID to start the search from.</param>
        /// <returns>The ID of the Last Gib after startindex that matches.</returns>
        public static int FindLastIndex(int startindex, Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Reverse)
            {
                if (g.ID <= startindex && match(g) )
                    return g.ID;
            }
            return -1;
        }

        /// <summary>
        /// Performs action for each element in the Giblist.
        /// </summary>
        /// <param name="action">The action to Perform.</param>
        public static void ForEach(Action<SqlGib> action)
        {
            foreach (SqlGib g in Gibs)
            {
                action(g);
            }
        }

        /// <summary>
        /// Converts the Giblist to an array.
        /// </summary>
        /// <returns>A new array with elements of the Giblist.</returns>
        public static SqlGib[] ToArray()
        {
            List<SqlGib> gl = new List<SqlGib>();
            foreach (SqlGib g in Gibs)
            {
                gl.Add(g);
            }
            return gl.ToArray();
        }
        /// <summary>
        /// Checks if the given predicate is true for all Gibs in the list.
        /// </summary>
        /// <param name="match">The condition to search for.</param>
        /// <returns>True if <paramref name="match"/> is true for all the elements, otherwise false.</returns>
        public static bool TrueForAll(Predicate<SqlGib> match)
        {
            foreach (SqlGib g in Gibs)
            {
                if (!match(g))
                    return false;
            }
            return true;
        }

        #endregion

        #region IEnumerable<SqlGib> Members


        /// <summary>
        /// Gets an Enumerable object to iterate through the gibs in the collection.
        /// </summary>
        public static  IEnumerable<SqlGib> Gibs
        {
            get
            {
                FbCommand com = Sql.SqlDatabase.CreateCommand();
                com.CommandText = "Select Alias from Gibs Order by GibID ASC";
                FbDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    SqlGib g = new SqlGib(reader.GetString(0).Trim());
                    yield return g;
                }
                reader.Close();

            }
        }

        /// <summary>
        /// Gets an Enumerable object to iterate through the gibs in the collection in reverse order.
        /// </summary>
        public static IEnumerable<SqlGib> Reverse
        {
            get
            {
                FbCommand com = Sql.SqlDatabase.CreateCommand();
                com.CommandText = "Select Alias from Gibs order by GibID DESC";
                FbDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    SqlGib g = new SqlGib(reader.GetString(0).Trim());
                    yield return g;
                }
                reader.Close();

            }
        }
        #endregion
    }
 }

⌨️ 快捷键说明

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