예제 #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)
            }
                                     );
        }
예제 #2
0
        void file_del()
        {
            var id = Request.QueryString["id"];

            SqlExec se = new SqlExec();

            se.update("up6_folders"
                      , new SqlParam[] { new SqlParam("f_deleted", true) }
                      , new SqlParam[] {
                new SqlParam("f_id", id)
                , new SqlParam("f_pid", id)
                , new SqlParam("f_pidRoot", id)
            }
                      , "or"
                      );
            se.update("up6_files"
                      , new SqlParam[] { new SqlParam("f_deleted", true) }
                      , new SqlParam[] {
                new SqlParam("f_id", id)
                , new SqlParam("f_pid", id)
                , new SqlParam("f_pidRoot", id)
            }
                      , "or"
                      );

            PageTool.to_content(new JObject {
                { "ret", 1 }
            });
        }
예제 #3
0
        public bool exist_same_folder(string name, string pid)
        {
            DBConfig      cfg = new DBConfig();
            SqlWhereMerge swm = new SqlWhereMerge();

            swm.equal("f_nameLoc", name.Trim());
            swm.equal("f_deleted", 0);
            if (cfg.m_isOracle)
            {
                if (string.IsNullOrEmpty(pid))
                {
                    pid = " ";
                }
                swm.equal("nvl(f_pid,' ')", pid);
            }
            else
            {
                swm.equal("LTRIM (f_pid)", pid.Trim());
            }

            string sql = string.Format("select f_id from up6_files where {0} " +
                                       " union select f_id from up6_folders where {0}", swm.to_sql());

            SqlExec se  = cfg.se();
            var     fid = (JArray)se.exec("up6_files", sql, "f_id", string.Empty);

            return(fid.Count > 0);
        }
예제 #4
0
        /// <summary>
        /// 取同名目录信息
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="nameLoc"></param>
        /// <returns></returns>
        public JObject read(string pid, string nameLoc)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            string   sql = string.Format(@"select f_id,f_pathRel from up6_files where f_pid='{0}' and f_nameLoc='{1}'", pid, nameLoc);

            if (string.IsNullOrEmpty(pid))
            {
                pid = " ";
            }
            if (cfg.m_isOracle)
            {
                sql = string.Format(@"select f_id,f_pathRel from up6_files where nvl(f_pid,' ')='{0}' and f_nameLoc='{1}'", pid, nameLoc);
            }

            var data = (JArray)se.exec("up6_files", sql, "f_id,f_pathRel");

            if (data.Count < 1)
            {
                return(null);
            }

            var o = JObject.FromObject(data[0]);

            return(o);
        }
예제 #5
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());
        }
예제 #6
0
        public void rename_folder(string name, string id, string pid)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();

            se.update("up6_folders"
                      , new SqlParam[] { new SqlParam("f_nameLoc", name) }
                      , new SqlParam[] { new SqlParam("f_id", id) });
        }
예제 #7
0
        /// <summary>
        /// 将所有目录转换成关联数组
        /// </summary>
        /// <param name="id">文件夹ID</param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public Dictionary <String, JToken> foldersToDic(string pidRoot)
        {
            //默认加载根目录
            string sql = string.Format("select f_id,f_nameLoc,f_pid,f_pidRoot from up6_folders where f_pidRoot='{0}'", pidRoot);

            DBConfig cfg     = new DBConfig();
            SqlExec  se      = cfg.se();
            var      folders = se.exec("up6_folders", sql, "f_id,f_nameLoc,f_pid,f_pidRoot");

            return(this.toDic(ref folders));
        }
예제 #8
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);
        }
예제 #9
0
        public bool exist_same_file(string name, string pid)
        {
            SqlWhereMerge swm = new SqlWhereMerge();

            swm.equal("f_nameLoc", name.Trim());
            swm.equal("f_pid", pid.Trim());
            swm.equal("f_deleted", 0);

            string sql = string.Format("select f_id from up6_files where {0} ", swm.to_sql());

            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            var      arr = (JArray)se.exec("up6_files", sql, "f_id", string.Empty);

            return(arr.Count > 0);
        }
예제 #10
0
        /// <summary>
        /// 根据pid查询
        /// </summary>
        /// <param name="fdCur"></param>
        public JToken build_path_by_id(JObject fdCur)
        {
            var id      = fdCur["f_id"].ToString().Trim();      //
            var pidRoot = fdCur["f_pidRoot"].ToString().Trim(); //

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

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

                return(JToken.FromObject(psort));
            }

            //当前目录是子目录
            DBConfig cfg  = new DBConfig();
            SqlExec  se   = cfg.se();
            var      data = (JArray)se.selectUnion(new string[] { "up6_files", "up6_folders" }, "f_pidRoot"
                                                   , new SqlParam[] { new SqlParam("f_id", id) });

            if (data.Count > 0)
            {
                pidRoot = data[0]["f_pidRoot"].ToString().Trim();
            }

            //构建目录映射表(id,folder)
            Dictionary <string, JToken> dt = this.foldersToDic(pidRoot);

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

            //是子目录->添加根目录
            if (!string.IsNullOrEmpty(pidRoot))
            {
                var cur = se.read("up6_files", "f_id,f_nameLoc,f_pid,f_pidRoot", new SqlParam[] { new SqlParam("f_id", pidRoot) });
                psort.Insert(0, cur);
            }//是根目录->添加根目录
            else if (!string.IsNullOrEmpty(id) && string.IsNullOrEmpty(pidRoot))
            {
                var root = se.read("up6_files", "f_id,f_nameLoc,f_pid,f_pidRoot", new SqlParam[] { new SqlParam("f_id", id) });
                psort.Insert(0, root);
            }
            psort.Insert(0, this.root);

            return(JToken.FromObject(psort));
        }
예제 #11
0
        /// <summary>
        /// 获取根目录或子目录信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FileInf read(string id)
        {
            DBConfig cfg  = new DBConfig();
            SqlExec  se   = cfg.se();
            string   sql  = string.Format("select f_pid,f_pidRoot,f_pathSvr,f_pathRel from up6_files where f_id='{0}' union select f_pid,f_pidRoot,f_pathSvr,f_pathRel from up6_folders where f_id='{0}'", id);
            var      data = (JArray)se.exec("up6_files", sql, "f_pid,f_pidRoot,f_pathSvr,f_pathRel");
            var      o    = JObject.FromObject(data[0]);

            FileInf file = new FileInf();

            file.id      = id;
            file.pid     = o["f_pid"].ToString().Trim();
            file.pidRoot = o["f_pidRoot"].ToString().Trim();
            file.pathSvr = o["f_pathSvr"].ToString().Trim();
            file.pathRel = o["f_pathRel"].ToString().Trim();
            return(file);
        }
예제 #12
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());
        }
예제 #13
0
        /// <summary>
        /// 取同名目录信息
        /// </summary>
        /// <param name="pathRel"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public FileInf read(string pathRel, string pid, string id)
        {
            DBConfig cfg = new DBConfig();
            SqlExec  se  = cfg.se();
            string   sql = string.Format(@"select f_id,f_pid,f_pidRoot,f_pathSvr,f_pathRel 
from up6_files 
where f_pid='{0}' and f_pathRel='{1}' and f_deleted=0 and f_id!='{2}'
union select f_id,f_pid,f_pidRoot,f_pathSvr,f_pathRel 
    from up6_folders where f_pid='{0}' and f_pathRel='{1}' and f_deleted=0 and f_id!='{2}'", pid, pathRel, id);

            if (string.IsNullOrEmpty(pid))
            {
                pid = " ";
            }
            if (cfg.m_isOracle)
            {
                sql = string.Format(@"select f_id,f_pid,f_pidRoot,f_pathSvr,f_pathRel 
from up6_files 
where nvl(f_pid,' ')='{0}' and f_pathRel='{1}' and f_deleted=0 and f_id!='{2}'
union select f_id,f_pid,f_pidRoot,f_pathSvr,f_pathRel 
    from up6_folders where nvl(f_pid,' ')='{0}' and f_pathRel='{1}' and f_deleted=0 and f_id!='{2}'", pid, pathRel, id);
            }

            var data = (JArray)se.exec("up6_files", sql, "f_id,f_pid,f_pidRoot,f_pathSvr,f_pathRel");

            if (data.Count < 1)
            {
                return(null);
            }

            var o = JObject.FromObject(data[0]);

            FileInf file = new FileInf();

            file.id      = o["f_id"].ToString().Trim();
            file.pid     = o["f_pid"].ToString().Trim();
            file.pidRoot = o["f_pidRoot"].ToString().Trim();
            file.pathSvr = o["f_pathSvr"].ToString().Trim();
            file.pathRel = o["f_pathRel"].ToString().Trim();
            return(file);
        }
예제 #14
0
        void folder_complete()
        {
            string id  = Request.QueryString["id"];
            string uid = Request.QueryString["uid"];
            string cak = Request.QueryString["callback"];
            int    ret = 0;

            if (string.IsNullOrEmpty(id) ||
                uid.Length < 1)
            {
            }
            else
            {
                FileInf inf = new FileInf();
                DBFile  db  = new DBFile();
                db.read(id, ref inf);
                string root = inf.pathSvr;

                //上传完毕
                DBFile.fd_complete(id, uid);

                //扫描文件夹结构,
                fd_scan sa = new fd_scan();
                sa.root = inf;//
                sa.scan(inf, root);

                //更新扫描状态
                SqlExec se = new SqlExec();
                se.update("up6_folders", new SqlParam[] {
                    new SqlParam("f_scan", true)
                }, new SqlParam[] {
                    new SqlParam("f_id", id)
                    , new SqlParam("f_uid", uid)
                });

                up6_biz_event.folder_post_complete(id);

                ret = 1;
            }
            PageTool.to_content(cak + "(" + ret + ")");
        }
예제 #15
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));
        }
예제 #16
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));
        }
예제 #17
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());
        }
예제 #18
0
        void folder_init()
        {
            string id       = Request.QueryString["id"];
            string pid      = Request.QueryString["pid"];
            string pidRoot  = Request.QueryString["pidRoot"];
            string uid      = Request.QueryString["uid"];
            string lenLoc   = Request.QueryString["lenLoc"];
            string sizeLoc  = Request.QueryString["sizeLoc"];
            string pathLoc  = HttpUtility.UrlDecode(Request.QueryString["pathLoc"]);
            string callback = Request.QueryString["callback"];//jsonp参数

            if (string.IsNullOrEmpty(id) ||
                string.IsNullOrEmpty(uid) ||
                string.IsNullOrEmpty(pathLoc)
                )
            {
                Response.Write(callback + "({\"value\":null})");
                return;
            }

            FileInf fileSvr = new FileInf();

            fileSvr.id      = id;
            fileSvr.pid     = pid;
            fileSvr.pidRoot = pidRoot;
            fileSvr.fdChild = false;
            fileSvr.fdTask  = true;
            fileSvr.uid     = int.Parse(uid);//将当前文件UID设置为当前用户UID
            fileSvr.nameLoc = Path.GetFileName(pathLoc);
            fileSvr.pathLoc = pathLoc;
            fileSvr.lenLoc  = Convert.ToInt64(lenLoc);
            fileSvr.sizeLoc = sizeLoc;
            fileSvr.deleted = false;
            fileSvr.nameSvr = fileSvr.nameLoc;

            //生成存储路径
            PathBuilderUuid pb = new PathBuilderUuid();

            fileSvr.pathSvr = pb.genFolder(ref fileSvr);
            fileSvr.pathSvr = fileSvr.pathSvr.Replace("\\", "/");
            if (!Directory.Exists(fileSvr.pathSvr))
            {
                Directory.CreateDirectory(fileSvr.pathSvr);
            }

            //添加到文件表
            DBFile db = new DBFile();

            db.Add(ref fileSvr);
            //添加到目录表
            SqlExec se = new SqlExec();

            se.insert("up6_folders", new SqlParam[] {
                new SqlParam("f_id", id)
                , new SqlParam("f_pathLoc", fileSvr.pathLoc)
                , new SqlParam("f_size", fileSvr.sizeLoc)
                , new SqlParam("f_nameLoc", fileSvr.nameLoc)
                , new SqlParam("f_pid", pid)
                , new SqlParam("f_pidRoot", pidRoot)
            });
            up6_biz_event.folder_create(fileSvr);

            string json = JsonConvert.SerializeObject(fileSvr);

            json = HttpUtility.UrlEncode(json);
            json = json.Replace("+", "%20");
            var jo = new JObject {
                { "value", json }
            };

            json = callback + string.Format("({0})", JsonConvert.SerializeObject(jo));
            PageTool.to_content(json);
        }