Esempio n. 1
0
        /// <summary>
        /// 查询目录和文件列表
        /// 只加载已完成且未删除的
        /// </summary>
        /// <param name="id"></param>
        void query(string id, string pidRoot)
        {
            //查询目录
            var se      = new SqlExec();
            var folders = se.select("up6_folders"
                                    , "f_id,f_nameLoc,f_pid,f_pidRoot"
                                    , new SqlParam[] { new SqlParam("f_deleted", 0) }
                                    , string.Empty);

            //取所有子目录
            this.m_folders = folders.Children <JObject>().ToDictionary(x => x["f_id"].ToString(), x => JToken.FromObject(x));

            //是根节点
            if (id == pidRoot)
            {
                var root = se.read("up6_files", "f_nameLoc", new SqlParam[] { new SqlParam("f_id", id) });
                this.m_folders.Add(id, new JObject {
                    { "f_id", id }, { "f_pid", string.Empty }, { "f_pidRoot", string.Empty }, { "f_nameLoc", root["f_nameLoc"].ToString() }
                });
            }

            //查询pidRoot全部文件
            this.m_files = se.select("up6_files"
                                     , "f_id,f_pid,f_nameLoc,f_pathSvr,f_pathRel,f_lenSvr,f_sizeLoc"
                                     , new SqlParam[] {
                new SqlParam("f_pidRoot", pidRoot)
                , new SqlParam("f_deleted", false)
                , new SqlParam("f_complete", true)
            }
                                     );
        }
Esempio n. 2
0
        /// <summary>
        /// 获取所有子目录
        /// </summary>
        /// <param name="id"></param>
        public static string[] all_childs(string id)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();

            var folders = se.select("up6_folders", "f_id,f_pid", string.Empty);

            var dt = new Dictionary <string, HashSet <string> >();

            foreach (var f in folders)
            {
                var fid  = f["f_id"].ToString().Trim();
                var fpid = f["f_pid"].ToString().Trim();

                if (fpid == string.Empty)
                {
                    fpid = "0";
                }

                if (dt.ContainsKey(fpid))
                {
                    dt[fpid].Add(fid);
                }
                else
                {
                    dt[fpid] = new HashSet <string>();
                    dt[fpid].Add(fid);
                }
            }

            if (id.Trim() == "")
            {
                id = "0";
            }
            var pids = new List <string>();

            pids.Add(id);

            //子目录ID列表
            var childs = new List <string>();
            var pidCur = id;

            while (pids.Count > 0)
            {
                //不存在此pid的数据
                if (!dt.ContainsKey(pidCur))
                {
                    break;
                }

                childs.AddRange(dt[pidCur]);
                pids.AddRange(dt[pidCur]); //将所有子ID添加成pid
                pids.Remove(pidCur);       //移除此PID
                pidCur = dt[pidCur].First();
            }

            return(childs.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// 重命名目录检查
        /// </summary>
        /// <param name="newName"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public bool rename_folder_check(string newName, string pid)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            var      res = (JArray)se.select("up6_folders"
                                             , "f_id"
                                             , new SqlParam[] {
                new SqlParam("f_nameLoc", newName)
                , new SqlParam("f_pid", pid)
            });

            return(res.Count > 0);
        }
Esempio n. 4
0
        /// <summary>
        /// 构建路径
        /// </summary>
        /// <param name="fd"></param>
        /// <returns></returns>
        public JToken build_path(JObject fdCur)
        {
            //查询文件表目录数据
            DBConfig cfg   = new DBConfig();
            SqlExec  se    = cfg.se();
            var      files = se.select("up6_files", "f_id,f_pid,f_nameLoc,f_pathRel",
                                       new SqlParam[] { new SqlParam("f_fdTask", true) });
            var folders = se.select("up6_folders", "f_id,f_pid,f_nameLoc,f_pathRel", new SqlParam[] { });
            var id      = fdCur["f_id"].ToString().Trim();//

            //根目录
            List <JToken> psort = new List <JToken>();

            if (string.IsNullOrEmpty(id))
            {
                psort.Insert(0, this.root);

                return(JToken.FromObject(psort));
            }

            //构建目录映射表(id,folder)
            Dictionary <string, JToken> dtFiles   = this.toDic(ref files);
            Dictionary <string, JToken> dtFolders = this.toDic(ref folders);

            foreach (var fd in dtFolders)
            {
                if (!dtFiles.ContainsKey(fd.Key))
                {
                    dtFiles.Add(fd.Key, fd.Value);
                }
            }

            //按层级顺序排列目录
            this.sortByPid(ref dtFiles, id, ref psort);

            psort.Insert(0, this.root);

            return(JToken.FromObject(psort));
        }
Esempio n. 5
0
        /// <summary>
        /// 获取文件夹中所有子项(文件和目录)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        string[] all_files(string id)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            var      obj = se.read("up6_folders", "f_id,f_pid,f_pidRoot", new SqlParam[] {
                new SqlParam("f_id", id)
            });

            var list = se.select("up6_files", "f_id", new SqlParam[] {
                new SqlParam("f_pidRoot", obj["f_pidRoot"].ToString())
            });

            var ids = from f in list
                      select f["f_id"].ToString();

            return(ids.ToArray());
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">文件夹ID</param>
        /// <returns></returns>
        public JToken build(string id)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            var      o   = se.read("up6_files", "*", new SqlParam[] { new SqlParam("f_id", id) });

            //子目录
            if (o == null)
            {
                o = se.read("up6_folders", "*", new SqlParam[] { new SqlParam("f_id", id) });
            }

            string pathRoot = o["f_pathRel"].ToString();
            var    index    = pathRoot.Length;

            JArray fs = new JArray();

            //查询文件
            string where = string.Format("CHARINDEX('{0}',f_pathRel)>0 and f_fdTask=0 and f_deleted=0", pathRoot + "/");
            if (cfg.m_isOracle)
            {
                where = string.Format("instr(f_pathRel,'{0}')>0 and f_fdTask=0 and f_deleted=0", pathRoot + "/");
            }
            var files = (JArray)se.select("up6_files", "*", where);
            int count = files.Count();//获取数组的长度

            for (int i = 0; i < count; i++)
            {
                var pathRel = files[i]["f_pathRel"].ToString();
                var fo      = new JObject {
                    { "f_id", files[i]["f_id"] },
                    { "nameLoc", files[i]["f_nameLoc"] },
                    { "pathSvr", files[i]["f_pathSvr"] },
                    { "pathRel", pathRel.Substring(index) },
                    { "lenSvr", files[i]["f_lenSvr"] },
                    { "sizeSvr", files[i]["f_sizeLoc"] }
                };
                fs.Add(fo);
            }
            return(JToken.FromObject(fs));
        }
Esempio n. 7
0
        /// <summary>
        /// 查询所有文件夹,包含子文件夹
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        string[] all_folders(string id)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            var      obj = se.read("up6_folders", "f_id,f_pid,f_pidRoot", new SqlParam[] {
                new SqlParam("f_id", id)
            });

            var list = se.select("up6_folders", "f_id,f_pid", new SqlParam[] {
                new SqlParam("f_pidRoot", obj["f_pidRoot"].ToString())
            });

            var dt = list.Children <JObject>()
                     .ToDictionary(x => x["f_pid"].ToString(), x => x["f_id"].ToString().Trim());

            var dt_sel = new Dictionary <string, string>();

            var    folders = list.ToArray();
            string pid_cur = id;

            foreach (var i in list)
            {
                if (!dt_sel.ContainsKey(pid_cur))
                {
                    continue;
                }

                if (i["f_pid"].ToString().Trim() == pid_cur)
                {
                    dt_sel.Add(i["f_id"].ToString(), i["f_pid"].ToString());
                    pid_cur = i["f_id"].ToString();
                }
            }

            var ids = from f in list
                      select f["f_id"].ToString();

            return(ids.ToArray());
        }