/// <summary> /// 插入一条数据 /// </summary> /// <returns>"true"/"false"</returns> private string doInsert() { //return "<script>alert('" + "upload.Upload_PathName" + "')</script>)"; string uploadPath = ""; try { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); upload.Upload_DateTime = DateTime.Now; upload.Upload_UserId = 1; upload.Upload_PathName = IRequest.GetFormString("Upload_PathName").ToString(); //UpdateModelByForm(upload, Request.Form); uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + "\\" + upload.Upload_PathName; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //提交插入 session.Create(upload); } return("true"); } catch { return("false"); } }
/// <summary> /// 插入一条目录数据 /// </summary> /// <returns>"true"/"false"</returns> private string doInsertPath() { //return "<script>alert('" + "upload.Upload_PathName" + "')</script>)"; string uploadPath = ""; try { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); upload.Upload_DateTime = DateTime.Now; upload.Upload_UserId = 1; //upload.Upload_FileSize = "20kb"; upload.Upload_PathName = IRequest.GetFormString("Upload_PathName").ToString(); int parentId = IRequest.GetFormInt("Upload_ParentId", 0); if (parentId > 0) { SqlDb.Dcms_Upload upload1 = new SqlDb.Dcms_Upload(); IQuery query = session.GetQuery(upload1).Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(parentId)); List <SqlDb.Dcms_Upload> uploadList = query.GetList <SqlDb.Dcms_Upload>(); if (uploadList.Count > 0) { upload.Upload_IdPath = uploadList[0].Upload_IdPath + "\\" + upload.Upload_PathName; uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + upload.Upload_IdPath; //更新是否有子目录 if (uploadList[0].Upload_HasChild == 0) { session.simple("update [Dcms_Upload] set [Upload_HasChild]=1 where [Upload_Id]=" + parentId.ToString()); } } } else { //uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + "\\" + upload.Upload_PathName; upload.Upload_IdPath = "\\" + upload.Upload_PathName; uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + upload.Upload_IdPath; } upload.Upload_ParentId = parentId; //UpdateModelByForm(upload, Request.Form); if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //提交插入 session.Create(upload); } return("true"); } catch { return("false"); } }
///<summary> ///取目录路径 /// </summary> /// <return> /// 目录路径字符串 /// </return> private string getUploadPathByUploadId(int uploadId) { string pathstr = ""; using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); IQuery query = session.GetQuery(upload).Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(uploadId)); List <SqlDb.Dcms_Upload> uploadList = query.GetList <SqlDb.Dcms_Upload>(); if (uploadList.Count > 0) { pathstr = uploadList[0].Upload_IdPath; } return(pathstr); } }
/// <summary> /// 删除目录操作 /// </summary> /// <returns></returns> private string doDeletePath() { try { int id = Convert.ToInt32(IRequest.GetQueryString("id")); string path = HttpContext.Current.Server.MapPath(@"~/UploadFile"); //string[] files = Directory.GetFiles(path); //string delfiles = ""; //string delfile = "reflector.zip"; using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); IQuery uploadQuery = session.GetQuery(upload); List <SqlDb.Dcms_Upload> uploadSubList = uploadQuery.Where(SqlDb.Dcms_Upload._UPLOAD_PARENTID_.EqulesExp(id)).GetList <SqlDb.Dcms_Upload>(); if (uploadSubList.Count > 0)//当前目录还有子目录 { return("subpathexist"); } List <SqlDb.Dcms_Upload> uploadList = uploadQuery.Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(id)).GetList <SqlDb.Dcms_Upload>(); path = path + @uploadList[0].Upload_IdPath; string[] delfiles = Directory.GetFiles(path); if (delfiles.Length > 0) { foreach (string delfile in delfiles)//删除该目录下的所有文件 { File.Delete(delfile); } string delfilesql = "Delete from [Dcms_File] where [File_UploadId]='" + id + "'"; session.simple(delfilesql);//删除表里文件记录 } Directory.Delete(path); //删除硬盘上的目录 String delPathSql = "Delete from [Dcms_Upload] where [Upload_Id]='" + id + "'"; session.simple(delPathSql); //删除目录表里的记录 } return("true"); } catch { return("false"); } }
/// <summary> /// 取单条编辑数据 /// </summary> /// <returns>json</returns> private string doGetOne() { int id = IRequest.GetQueryInt("id", 0); string oneRecord = ""; if (id > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); IQuery query = session.GetQuery(upload).Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(id)); List <SqlDb.Dcms_Upload> uploadList = query.GetList <SqlDb.Dcms_Upload>(); if (uploadList.Count > 0) { //if(roleList[0] // oneRecord = "[{Role_Name:\"" + roleList[0].Role_Name + "\",Role_Order:\"" + roleList[0].Role_Order + "\",Role_Id:\"" + roleList[0].Role_Id.ToString() + "\"}]"; } } } return(oneRecord); }
///<summary> ///取目录路径 /// </summary> /// <return> /// 目录路径字符串 /// </return> private string getUploadPathByUploadId(int uploadId) { string pathstr = ""; using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); IQuery query = session.GetQuery(upload).Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(uploadId)); List<SqlDb.Dcms_Upload> uploadList = query.GetList<SqlDb.Dcms_Upload>(); if (uploadList.Count > 0) { pathstr = uploadList[0].Upload_IdPath; } return pathstr; } }
/// <summary> /// 插入一条目录数据 /// </summary> /// <returns>"true"/"false"</returns> private string doInsertPath() { //return "<script>alert('" + "upload.Upload_PathName" + "')</script>)"; string uploadPath = ""; try { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); upload.Upload_DateTime = DateTime.Now; upload.Upload_UserId = 1; //upload.Upload_FileSize = "20kb"; upload.Upload_PathName = IRequest.GetFormString("Upload_PathName").ToString(); int parentId = IRequest.GetFormInt("Upload_ParentId", 0); if (parentId > 0) { SqlDb.Dcms_Upload upload1 = new SqlDb.Dcms_Upload(); IQuery query = session.GetQuery(upload1).Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(parentId)); List<SqlDb.Dcms_Upload> uploadList = query.GetList<SqlDb.Dcms_Upload>(); if (uploadList.Count > 0) { upload.Upload_IdPath = uploadList[0].Upload_IdPath + "\\" + upload.Upload_PathName; uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + upload.Upload_IdPath; //更新是否有子目录 if (uploadList[0].Upload_HasChild == 0) { session.simple("update [Dcms_Upload] set [Upload_HasChild]=1 where [Upload_Id]=" + parentId.ToString()); } } } else { //uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + "\\" + upload.Upload_PathName; upload.Upload_IdPath = "\\" + upload.Upload_PathName; uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + upload.Upload_IdPath; } upload.Upload_ParentId = parentId; //UpdateModelByForm(upload, Request.Form); if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //提交插入 session.Create(upload); } return "true"; } catch { return "false"; } }
/// <summary> /// 插入一条数据 /// </summary> /// <returns>"true"/"false"</returns> private string doInsert() { //return "<script>alert('" + "upload.Upload_PathName" + "')</script>)"; string uploadPath = ""; try { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); upload.Upload_DateTime = DateTime.Now; upload.Upload_UserId = 1; upload.Upload_PathName = IRequest.GetFormString("Upload_PathName").ToString(); //UpdateModelByForm(upload, Request.Form); uploadPath = HttpContext.Current.Server.MapPath(@"~/UploadFile") + "\\" + upload.Upload_PathName; if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //提交插入 session.Create(upload); } return "true"; } catch { return "false"; } }
/// <summary> /// 取单条编辑数据 /// </summary> /// <returns>json</returns> private string doGetOne() { int id = IRequest.GetQueryInt("id", 0); string oneRecord = ""; if (id > 0) { using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); IQuery query = session.GetQuery(upload).Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(id)); List<SqlDb.Dcms_Upload> uploadList = query.GetList<SqlDb.Dcms_Upload>(); if (uploadList.Count > 0) { //if(roleList[0] // oneRecord = "[{Role_Name:\"" + roleList[0].Role_Name + "\",Role_Order:\"" + roleList[0].Role_Order + "\",Role_Id:\"" + roleList[0].Role_Id.ToString() + "\"}]"; } } } return oneRecord; }
/// <summary> /// 删除目录操作 /// </summary> /// <returns></returns> private string doDeletePath() { try { int id = Convert.ToInt32(IRequest.GetQueryString("id")); string path = HttpContext.Current.Server.MapPath(@"~/UploadFile"); //string[] files = Directory.GetFiles(path); //string delfiles = ""; //string delfile = "reflector.zip"; using (ISession session = dbContext.Current().GetContext("SqlDb").GetSession()) { SqlDb.Dcms_Upload upload = new SqlDb.Dcms_Upload(); IQuery uploadQuery = session.GetQuery(upload); List<SqlDb.Dcms_Upload> uploadSubList = uploadQuery.Where(SqlDb.Dcms_Upload._UPLOAD_PARENTID_.EqulesExp(id)).GetList<SqlDb.Dcms_Upload>(); if (uploadSubList.Count > 0)//当前目录还有子目录 { return "subpathexist"; } List<SqlDb.Dcms_Upload> uploadList = uploadQuery.Where(SqlDb.Dcms_Upload._UPLOAD_ID_.EqulesExp(id)).GetList<SqlDb.Dcms_Upload>(); path = path + @uploadList[0].Upload_IdPath; string[] delfiles = Directory.GetFiles(path); if (delfiles.Length > 0) { foreach (string delfile in delfiles)//删除该目录下的所有文件 { File.Delete(delfile); } string delfilesql = "Delete from [Dcms_File] where [File_UploadId]='" + id + "'"; session.simple(delfilesql);//删除表里文件记录 } Directory.Delete(path);//删除硬盘上的目录 String delPathSql = "Delete from [Dcms_Upload] where [Upload_Id]='" + id + "'"; session.simple(delPathSql);//删除目录表里的记录 } return "true"; } catch { return "false"; } }