/// <summary> /// 删除文件 /// </summary> /// <param name="UserId"></param> /// <param name="FileId"></param> /// <returns></returns> public string DelFileData(string UserId, string FileId, string path) { NetFileManager fileBll = new NetFileManager(); if (fileBll.Delete(UserId, FileId)) { string fullpath = HttpContext.Current.Server.MapPath(path); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } log4net.Config.BasicConfigurator.Configure(new log4net.Appender.FileAppender(new log4net.Layout.PatternLayout("%d;%m;%p%n"), "log\\" + HttpContext.Current.Session["realName"].ToString() + "的日志记录.log")); log.Info(HttpContext.Current.Session["realName"].ToString() + "(" + HttpContext.Current.Session["uname"].ToString() + ")" + "删除文档文件" + HttpContext.Current.Request.UserHostAddress); log4net.LogManager.ResetConfiguration(); return("1"); } else { return("0"); } }
/// <summary> /// 获取列表信息 /// </summary> /// <param name="IsSearch">是否为搜索</param> public void GetFileList(bool IsSearch) { NetFileManager fileBll = new NetFileManager(); FileManager fileInfo = new FileManager(); #region 分页处理 if (this.beginTime.Value.Trim() == "" || this.endTime.Value.Trim() == "") { this.endTime.Value = System.DateTime.Now.ToString("yyyy-MM-dd"); this.beginTime.Value = System.DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd"); beginSearchDate = this.beginTime.Value; endSearchDate = this.endTime.Value; DocType = this.drop_DocType.SelectedItem.Text; } if (IsSearch) { beginSearchDate = Convert.ToDateTime(this.beginTime.Value).ToString("yyyy-MM-dd"); endSearchDate = Convert.ToDateTime(this.endTime.Value).ToString("yyyy-MM-dd"); DocType = this.drop_DocType.SelectedItem.Text; KeyWord = this.txt_KeyWord.Value.Trim(); } else { if (Request.QueryString["bd"] != null && Request.QueryString["ed"] != null) { try { beginSearchDate = Convert.ToDateTime(Request.QueryString["bd"]).ToString("yyyy-MM-dd"); endSearchDate = Convert.ToDateTime(Request.QueryString["ed"]).ToString("yyyy-MM-dd"); } catch { beginSearchDate = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); endSearchDate = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); } } else { beginSearchDate = Convert.ToDateTime(this.beginTime.Value).ToString("yyyy-MM-dd"); endSearchDate = Convert.ToDateTime(this.endTime.Value).ToString("yyyy-MM-dd"); DocType = this.drop_DocType.SelectedItem.Text; } } this.beginTime.Value = beginSearchDate; this.endTime.Value = endSearchDate; int userCount = fileBll.GetFileFYCount(DocType, beginSearchDate, endSearchDate, KeyWord);//获取分页总数 int currentPage = 1; try { currentPage = Convert.ToInt32(Request.QueryString["page"]); if (currentPage > (userCount + PageSize - 1) / PageSize) { currentPage = (userCount + PageSize - 1) / PageSize; } if (currentPage <= 0) { currentPage = 1; } } catch { currentPage = 1; } #endregion DataSet ds = fileBll.GetFileDataSet(DocType, beginSearchDate, endSearchDate, PageSize, currentPage, KeyWord); if (ds != null) { HtmlTableRow hrow = null; int count = ds.Tables[0].Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { hrow = new HtmlTableRow(); int tempBH = (currentPage - 1) * PageSize + i + 1; string tempOpreator = string.Empty; tempOpreator = "<div><a href='" + ds.Tables[0].Rows[i]["FilePath"].ToString() + "' target='_blank'>下载</a> | <a href='javascript:void(0);' onclick=\"del('" + ds.Tables[0].Rows[i]["FileId"].ToString() + "','" + ds.Tables[0].Rows[i]["UserId"].ToString() + "','" + ds.Tables[0].Rows[i]["FilePath"].ToString() + "')\">删除</a></div>"; hrow.Cells.Add(GetHCell(tempOpreator, false));//操作 hrow.Cells.Add(GetHCell(ds.Tables[0].Rows[i]["FileTitle"].ToString(), false)); hrow.Cells.Add(GetHCell(ds.Tables[0].Rows[i]["FileType"].ToString(), false)); hrow.Cells.Add(GetHCell(ds.Tables[0].Rows[i]["realName"].ToString(), false)); hrow.Cells.Add(GetHCell(Convert.ToDateTime(ds.Tables[0].Rows[i]["WriteDate"].ToString()).ToString("MM/dd H:mm"), false)); tbl_list.Rows.Add(hrow); } div_noInfo.Style.Add("display", "none"); } else { div_noInfo.Attributes.Add("display", "block"); } } else { div_noInfo.Attributes.Add("display", "none"); } string parms = "&bd=" + beginSearchDate + "&ed=" + endSearchDate + "&tl=" + Server.UrlEncode(KeyWord) + "&dty=" + Server.UrlEncode(DocType); GetPage(userCount, PageSize, currentPage, parms);//获取分页文字 }
private string _msg = "上传成功!"; //返回信息 public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; if (context.Session["userId"] != null) { string user = context.Request.UrlReferrer.ToString(); int iTotal = context.Request.Files.Count; string title = context.Request.Params["txt_title"].ToString(); //string Type = context.Request.Params["txt_Type"].ToString(); string desc = context.Request.Params["txt_Desc"].ToString(); string userid = context.Session["userId"].ToString(); string typeId = context.Request.Params["typeId"].ToString(); if (iTotal == 0) { _msg = "没有数据"; } else { int iCount = 0; for (int i = 0; i < iTotal; i++) { HttpPostedFile file = context.Request.Files[i]; if (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName)) { //保存文件 string FileDir = HttpContext.Current.Server.MapPath(commonFun.uploadFile + typeId + "/" + System.DateTime.Now.ToString("yyyyMMdd")); if (!Directory.Exists(FileDir)) { Directory.CreateDirectory(FileDir); } string filePath = commonFun.uploadFile + typeId + "/" + System.DateTime.Now.ToString("yyyyMMdd") + "/" + Path.GetFileName(file.FileName); string fullPath = System.Web.HttpContext.Current.Server.MapPath(filePath); file.SaveAs(fullPath); //这里可以根据实际设置其他限制 if (++iCount > UploadFileLimit) { _msg = "超过上传限制:" + UploadFileLimit; break; } NetFileManager fbll = new NetFileManager(); FileManager fInfo = new FileManager(); fInfo.UserId = Convert.ToInt32(userid); fInfo.FileTitle = title; fInfo.FilePath = filePath; fInfo.FileDesc = desc; fInfo.FileType = typeId; try { if (!fbll.Insert(fInfo)) { _msg = "插入数据失败"; System.IO.File.Delete(fullPath); break; } } catch { _msg = "插入数据失败"; System.IO.File.Delete(fullPath); break; } } } } context.Response.Write("<script>window.parent.Finish('" + _msg + "');</script>"); } }