/// <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) } ); }
/// <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)); }
/// <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)); }
/// <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()); }
/// <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()); }