public ObjectDirectory(string name) { this.id = 0; this.name = name; this.objectDirectories = new ObjectDirectories(); this.mapObjects = new MapObjects(); }
/// <summary> /// Deletes from the database any Object Directory that is no longer in this list, then calls insertupdate on each object /// </summary> /// <param name="os">The list of object directories to have in the database</param> /// <param name="parent">The parent of the object directories</param> private static void InsertUpdateObjectDirectories(ObjectDirectories os, long parent) { ObjectDirectories curr = GetObjectDirectories(parent); if (curr != null && curr.Count > 0 && os != null) { foreach (ObjectDirectory o in curr) { if (os.FindByID(o.ID) == null) { DeleteObjectDirectory(o.ID); } } } foreach (ObjectDirectory o in os) { InsertUpdateObjectDirectory(o, parent); } }
/// <summary> /// Gets all object directores with the given parent /// </summary> /// <param name="parent">The parent id of the object directories to get</param> /// <returns>All object directories with the given parent</returns> public static ObjectDirectories GetObjectDirectories(long parent) { ObjectDirectories toReturn = new ObjectDirectories(); SqlCommand cmd = new SqlCommand(); ObjectDirectory temp = null; DataTable dt = null; string query = "SELECT * FROM [ObjectDirectory] WHERE Parent = @Parent"; cmd.CommandType = CommandType.Text; cmd.CommandText = query; cmd.Parameters.Add(new SqlParameter("@Parent", SqlDbType.BigInt)).Value = parent; dt = DatabaseHelper.ExecuteQuery(GetConnectionString(), cmd); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { temp = new ObjectDirectory(); temp.ID = DatabaseHelper.GetValidValueFromObject(dr["ID"], (long)0); temp.Name = DatabaseHelper.GetValidValueFromObject(dr["Name"], string.Empty); toReturn.Add(temp); } } return toReturn; }