예제 #1
0
파일: Dir.cs 프로젝트: dkostenko/2safe
        public static List<Dir> All(long parent_id)
        {
            List<Dir> result = new List<Dir>();
            Dir temp;

            SQLiteConnection connection = new SQLiteConnection(dbName);
            connection.Open();
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM dirs WHERE parent_id='" + parent_id.ToString() + "'", connection);
            SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                temp = new Dir(reader.GetInt64(0), reader.GetInt64(1), reader.GetString(2));
                temp.SetPath();
                result.Add(temp);
            }

            reader.Close();
            connection.Close();

            return result;
        }
예제 #2
0
파일: Dir.cs 프로젝트: dkostenko/2safe
        /// <summary>
        /// Находит папку в базе данных по названию и ID родительской папки
        /// </summary>
        /// <param name="name">Имя папки</param>
        /// <param name="parent_id">ID родительской папки</param>
        /// <returns>Возвращает объект папки</returns>
        public static Dir FindByNameAndParentId(string name, long parent_id)
        {
            Dir result = null;

            SQLiteConnection connection = new SQLiteConnection(dbName);
            connection.Open();
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM dirs WHERE name='" + name + "' AND parent_id='" + parent_id.ToString() + "'", connection);
            SQLiteDataReader reader = command.ExecuteReader();
            try
            {
                reader.Read();
                result = new Dir(reader.GetInt64(0), reader.GetInt64(1), reader.GetString(2));
            }
            catch
            {
            }

            reader.Close();
            connection.Close();

            //result = new Dir(Properties.Settings.Default.RootId, 0, "root");
            return result;
        }
예제 #3
0
파일: Dir.cs 프로젝트: dkostenko/2safe
        /// <summary>
        /// Находит родительскую папку по полному пути
        /// </summary>
        /// <param name="path">Полный путь до папки (включая саму папку)</param>
        /// <returns></returns>
        public static Dir FindParentByPath(String path)
        {
            Dir result;
            string[] parts = path.Substring(Properties.Settings.Default.UserFolderPath.Length + 1).Split('\\');

            if (parts.Length == 1)
            {
                result = new Dir(Properties.Settings.Default.RootId, 0, "root");
            }
            else
            {
                result = FindByNameAndParentId(parts[0], Properties.Settings.Default.RootId);
                for (int i = 1; i < parts.Length - 1; ++i)
                {
                    result = FindByNameAndParentId(parts[i], result.Id);
                }
            }

            return result;
        }
예제 #4
0
파일: Dir.cs 프로젝트: dkostenko/2safe
        /// <summary>
        /// Находит папку в базе данных по ID
        /// </summary>
        /// <param name="id">ID папки на сайте 2safe</param>
        /// <returns>Возвращает объект папки</returns>
        public static Dir FindById(long id)
        {
            Model.Dir dir = null;
            if (id != Properties.Settings.Default.RootId)
            {
                SQLiteConnection connection = new SQLiteConnection(dbName);
                connection.Open();
                SQLiteCommand command = new SQLiteCommand("SELECT * FROM dirs WHERE id='" + id.ToString() + "'", connection);
                SQLiteDataReader reader = command.ExecuteReader();
                reader.Read();

                dir = new Model.Dir(reader.GetInt64(0), reader.GetInt64(1), reader.GetString(2));
                //dir.SetPath();

                reader.Close();
                connection.Close();
            }
            else
            {
                dir = new Dir(Properties.Settings.Default.RootId, 0, "root");
            }

            return dir;
        }