public void DeleteAppendix(HttpContext context, OleDbConnection conn) { OleDbTransaction trans = conn.BeginTransaction(); int iUploadFileID = Convert.ToInt32(context.Request["UploadFileID"]); int iOwnerID = Convert.ToInt32(context.Request["OwnerID"]); int iCorrelationID = Convert.ToInt32(context.Request["CorrelationID"]); int iID = Convert.ToInt32(context.Request["ID"]); Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(iUploadFileID, conn, trans); string strFileUrl = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + dUploadFileInfo.URL; if (dUploadFileInfo != null) { try { if (File.Exists(strFileUrl)) { File.Delete(strFileUrl); } BLL.UploadFileInfo.DeleteUploadFile(iUploadFileID, conn, trans); // dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(iOwnerID, iCorrelationID, "DeclarationAppendix", conn, trans); string strFileName = "暂未上传文件!"; context.Response.Write(JsonConvert.SerializeObject(strFileName)); trans.Commit(); conn.Close(); } catch (Exception ex) { context.Response.Write(JsonConvert.SerializeObject(ex.Message)); trans.Rollback(); } } }
public void DeleteDeployFile(HttpContext context, OleDbConnection conn) { OleDbTransaction trans = conn.BeginTransaction(); int iUploadFileID = Convert.ToInt32(context.Request["UploadFileID"]); Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(iUploadFileID, conn, trans); string strFileType = dUploadFileInfo.TypeCode; string strFileUrl = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + dUploadFileInfo.URL; if (dUploadFileInfo != null) { try { if (File.Exists(strFileUrl)) { File.Delete(strFileUrl); } BLL.UploadFileInfo.DeleteUploadFile(iUploadFileID, conn, trans); context.Response.Write(JsonConvert.SerializeObject(strFileType)); trans.Commit(); conn.Close(); } catch (Exception ex) { context.Response.Write(JsonConvert.SerializeObject(ex.Message)); trans.Rollback(); } } }
public void UploadDeployFile(HttpContext context, OleDbConnection conn) { if (context.Request.Files.Count > 0) { string strFileType = context.Request["FileType"]; string fileName = ""; HttpFileCollection files = context.Request.Files; OleDbTransaction trans = conn.BeginTransaction(); try { for (int i = 0; i < files.Count; i++) { // 存入文件夹 HttpPostedFile file = files[i]; string strRootDirectory = System.Web.HttpContext.Current.Request.PhysicalApplicationPath; string strFilePath = strRootDirectory + "Content\\Temp\\Deploy"; if (!Directory.Exists(strFilePath)) { Directory.CreateDirectory(strFilePath); } Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(0, 0, "UpdateContent", conn, trans); if (dUploadFileInfo != null) { int Index = dUploadFileInfo.URL.IndexOf("Content"); string Pathe = dUploadFileInfo.URL.Substring(Index); string MapPath = strRootDirectory + Pathe; if (File.Exists(MapPath)) { File.Delete(MapPath); } } string strPath = "Deploy\\" + file.FileName.Replace(" ", "_"); fileName = context.Server.MapPath("~\\Content\\Temp\\" + strPath); file.SaveAs(fileName); // 存入数据库 Dal.Models.UploadFileInfo dataFile = new Dal.Models.UploadFileInfo(); dataFile.Type = (Dal.Models.FileType)Enum.Parse(typeof(Dal.Models.FileType), strFileType, true); dataFile.OwnerID = 0; dataFile.CorrelationID = 0; dataFile.FileName = file.FileName.Replace(" ", "_"); dataFile.URL = "Content\\Temp\\" + strPath; BLL.UploadFileInfo.SaveFile(dataFile, conn, trans); } trans.Commit(); context.Response.Write(JsonConvert.SerializeObject(strFileType)); } catch (Exception ex) { trans.Rollback(); context.Response.Write(JsonConvert.SerializeObject(ex.Message)); } } }
public void PrepLoadFile(HttpContext context, OleDbConnection conn) { string strUploadFileID = context.Request["UploadFileID"]; Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(Convert.ToInt32(strUploadFileID), conn); if (dUploadFileInfo != null) { Dal.Models.UploadFileInfo file = new Dal.Models.UploadFileInfo(); file.UploadFileID = dUploadFileInfo.UploadFileID; if (!File.Exists(context.Request.PhysicalApplicationPath + dUploadFileInfo.URL)) { BLL.UploadFileInfo.LoadFile(file, conn); } context.Response.Write(JsonConvert.SerializeObject(file)); } }
public void GetDeployFile(HttpContext context, OleDbConnection conn) { string strFileType = context.Request["FileType"]; try { Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(0, 0, strFileType, conn); StringBuilder sbFileName = new StringBuilder(); sbFileName.AppendFormat("<a onclick='LoadFile({0})'>{1}</a>", dUploadFileInfo.UploadFileID, dUploadFileInfo.FileName); sbFileName.Append("<br />"); sbFileName.AppendFormat("<a onclick='DeleteAppendix({0},{1},{2});return false;' title='删除' href=''>" , dUploadFileInfo.UploadFileID, dUploadFileInfo.OwnerID, dUploadFileInfo.CorrelationID); sbFileName.Append("<i class='fa fa-trash-o'></i></a>"); sbFileName.AppendFormat(" <a onclick=\'DownloadAppendix({0});return false;\' title='下载' href=''>", dUploadFileInfo.UploadFileID); sbFileName.Append("<i class='fa fa-download'></i></a>"); context.Response.Write(JsonConvert.SerializeObject(sbFileName.ToString())); } catch (Exception ex) { context.Response.Write(JsonConvert.SerializeObject(ex.Message)); } }
public void DeleteImg(HttpContext context, OleDbConnection conn) { OleDbTransaction trans = conn.BeginTransaction(); int iUploadFileID = Convert.ToInt32(context.Request["UploadFileID"]); int iOwnerID = Convert.ToInt32(context.Request["OwnerID"]); int iCorrelationID = Convert.ToInt32(context.Request["CorrelationID"]); int iID = Convert.ToInt32(context.Request["ID"]); Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(iUploadFileID, conn, trans); if (dUploadFileInfo != null) { try { if (File.Exists(dUploadFileInfo.URL)) { File.Delete(dUploadFileInfo.URL); } BLL.UploadFileInfo.DeleteUploadFile(iUploadFileID, conn, trans); List <Dal.Models.UploadFileInfo> lstUploadFileInfo = BLL.UploadFileInfo.GetFileList(iOwnerID, iCorrelationID, "DeclarationAtlas", conn, trans); StringBuilder sbAtlasHTML = new StringBuilder(); if (lstUploadFileInfo.Count != 0) { for (int i = 0; i < lstUploadFileInfo.Count; i++) { int Index = lstUploadFileInfo[i].URL.IndexOf("Content"); int Index2 = lstUploadFileInfo[i].URL.IndexOf(lstUploadFileInfo[i].FileName); string Path = lstUploadFileInfo[i].URL.Substring(Index); string PathMax = lstUploadFileInfo[i].URL; Path = Path.Insert(Index2, "(mini)"); Path = Path.Replace("\\", "/"); sbAtlasHTML.Append("<br />"); sbAtlasHTML.AppendFormat("<a id='Atlas" + i + "' class='dowebok'\">"); sbAtlasHTML.AppendFormat("<img src='../../{0}' data-original='../../{1}' width='150px' height='150px' title='查看详情'/>", Path, PathMax); sbAtlasHTML.Append("</a>"); sbAtlasHTML.Append("<br />"); sbAtlasHTML.Append(lstUploadFileInfo[i].FileName); sbAtlasHTML.Append("<br />"); sbAtlasHTML.AppendFormat("<a onclick='DeleteImg({0},{1},{2},{3});return false;' title='删除' href=''>" , lstUploadFileInfo[i].UploadFileID, lstUploadFileInfo[i].OwnerID, lstUploadFileInfo[i].CorrelationID, iID); sbAtlasHTML.Append("<i class='fa fa-trash-o'></i></a>"); sbAtlasHTML.AppendFormat("<a id='DownloadImg{0}' onclick=\"DownloadImg({1});return false;\" title='下载' href=''>" , i, lstUploadFileInfo[i].UploadFileID); sbAtlasHTML.Append("<i class='fa fa-download'></i>"); sbAtlasHTML.Append("</a>"); } context.Response.Write(JsonConvert.SerializeObject(sbAtlasHTML.ToString())); } else { string strAtlas = "该专业下暂无图集!"; context.Response.Write(JsonConvert.SerializeObject(strAtlas)); } trans.Commit(); conn.Close(); } catch (Exception ex) { context.Response.Write(JsonConvert.SerializeObject(ex.Message)); trans.Rollback(); } } }
public void ImportAtlasFile(HttpContext context, OleDbConnection conn) { int a = context.Request.Files.Count; if (a == 0) { context.Response.Write(JsonConvert.SerializeObject("2")); } if (context.Request.Files.Count > 0) { string strDeclarationCode = context.Request["DeclarationCodeBackups"]; string strDeclarationID = context.Request["DeclarationID"]; string strAtlasID = context.Request["AtlasID"]; string strID = context.Request["ID"]; string fileName = ""; string minfileName = ""; HttpFileCollection files = context.Request.Files; OleDbTransaction trans = conn.BeginTransaction(); Dal.Models.Atlas AtlasInfo = BLL.Atlas.GetAtlas(Convert.ToInt32(strAtlasID), conn, trans); string strRootDirectory = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "Content\\"; string strFilePath = strRootDirectory + "Temp\\" + strDeclarationCode + "\\图集\\" + strAtlasID; if (!Directory.Exists(strFilePath)) { Directory.CreateDirectory(strFilePath); } try { for (int i = 0; i < files.Count; i++) { List <Dal.Models.UploadFileInfo> lstUploadFileInfo = BLL.UploadFileInfo.GetFileList( Convert.ToInt32(strDeclarationID), Convert.ToInt32(strAtlasID), "DeclarationAtlas", conn, trans); if (lstUploadFileInfo.Count < AtlasInfo.UploadLimitMax || AtlasInfo.UploadLimitMax == 0) { // 存入本地文件夹 HttpPostedFile file = files[i]; fileName = context.Server.MapPath("~/Content/Temp/" + strDeclarationCode + "/图集/" + strAtlasID + "/" + files[i].FileName.Replace(" ", "_")); file.SaveAs(fileName); minfileName = context.Server.MapPath("~/Content/Temp/" + strDeclarationCode + "/图集/" + strAtlasID + "/(mini)" + files[i].FileName.Replace(" ", "_")); BLL.PictureHelper.MakeThumbnail(fileName, minfileName, 100, 100, true); // 存入数据库 Dal.Models.UploadFileInfo dataFile = new Dal.Models.UploadFileInfo(); dataFile.Type = FileType.DeclarationAtlas; dataFile.OwnerID = Convert.ToInt32(strDeclarationID); dataFile.CorrelationID = Convert.ToInt32(strAtlasID); dataFile.FileName = files[i].FileName.Replace(" ", "_"); dataFile.URL = "Content\\Temp\\" + strDeclarationCode + "\\图集\\" + strAtlasID + "\\" + files[i].FileName.Replace(" ", "_"); BLL.UploadFileInfo.SaveFile(dataFile, conn, trans); context.Response.Write(JsonConvert.SerializeObject(strDeclarationID + "," + strAtlasID + "," + strID)); } else { context.Response.Write(JsonConvert.SerializeObject("1")); } } trans.Commit(); } catch (Exception ex) { trans.Rollback(); context.Response.Write(ex.Message); } } }