private bool StoreAnnex(System.Guid contentId, string name, string address, string type) { bool IsSucess = false; try { if (contentId != System.Guid.Empty) { CY.CSTS.Core.Business.AnnexType annexType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(type); if (annexType == null) { annexType = new CY.CSTS.Core.Business.AnnexType(); annexType.TypeName = type; annexType.Save(); } CY.CSTS.Core.Business.Annex annex = new CY.CSTS.Core.Business.Annex(); annex.ContentID = contentId; annex.Name = name; annex.AnnexURI = address; annex.AnnexTypeID = annexType.Id; annex.Save(); IsSucess = true; } } catch (Exception ex) { throw ex; } finally { } return IsSucess; }
protected void SaveFiles(System.Guid contentId) { try { HttpFileCollection files = CY.Utility.Common.RequestUtility.GetHttpFiles(); if (files != null) { string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; string dirPath = appPath + CY.Utility.Common.AnnexUtility.UnitAnnexFileDir; DirectoryInfo di = new DirectoryInfo(dirPath); if (!di.Exists) { di.Create(); } string fileExtention = string.Empty; string fileName = string.Empty; string filesaveName = string.Empty; for (int i = 0; i < files.Count; i++) { if (files[i].ContentLength > 0) { fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(files[i].FileName); fileName = CY.Utility.Common.FileUtility.GetFileName(files[i].FileName); if (fileExtention != ".doc" && fileExtention != ".docx" && fileExtention != ".pdf" && fileExtention != ".txt" && fileExtention != ".text") { continue; } filesaveName = fileName + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString(); files[i].SaveAs(dirPath + filesaveName + fileExtention); CY.CSTS.Core.Business.Annex annex = new CY.CSTS.Core.Business.Annex(); CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.DocAnnexType); if (anneType == null) { anneType = new CY.CSTS.Core.Business.AnnexType(); anneType.TypeName = CY.Utility.Common.AnnexUtility.DocAnnexType; anneType.Save(); } annex.AnnexTypeID = anneType.Id; annex.ContentID = contentId; annex.Name = fileName; annex.AnnexURI = CY.Utility.Common.AnnexUtility.UnitAnnexFileDir + filesaveName + fileExtention; annex.Save(); } } } } catch (Exception ex) { throw ex; } finally { } }
protected void SaveImg(System.Guid contentId) { try { if (contentId == System.Guid.Empty) { return; } string[] strPaths = Request.Form.GetValues("imgpath"); string[] strNames = Request.Form.GetValues("imgname"); if (strPaths == null || strNames == null || strPaths.Length <= 0 || strNames.Length <= 0 || strPaths.Length != strNames.Length) { return; } string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; string dir = appPath + CY.Utility.Common.AnnexUtility.UnitAnneImgDir; DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { di.Create(); } CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (anneType == null) { anneType = new CY.CSTS.Core.Business.AnnexType(); anneType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; anneType.Save(); } string fileName = string.Empty; string fileExtention = string.Empty; CY.CSTS.Core.Business.Annex imgannex = null; for (int i = 0; i < strNames.Length; i++) { fileName = CY.Utility.Common.FileUtility.GetFileName(strNames[i]); //string fileSaveName = fileName + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString(); fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(strNames[i]); imgannex = new CY.CSTS.Core.Business.Annex(); imgannex.ContentID = contentId; imgannex.AnnexTypeID = anneType.Id; imgannex.Name = fileName; imgannex.AnnexURI = CY.Utility.Common.AnnexUtility.UnitAnneImgDir + fileName + fileExtention; imgannex.Save(); } } catch (Exception ex) { throw ex; } finally { } }
protected void SaveFiles(System.Guid contentId) { try { HttpFileCollection files = CY.Utility.Common.RequestUtility.GetHttpFiles(); if (files != null) { CY.CSTS.Core.Business.AnnexType docType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.DocAnnexType); if (docType == null) { docType.TypeName = CY.Utility.Common.AnnexUtility.DocAnnexType; docType.Save(); } CY.CSTS.Core.Business.Annex docAnnex = null; string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; string dir = appPath + CY.Utility.Common.AnnexUtility.SurveyAnnexFileDir; string fileName = string.Empty; string fileExtention = string.Empty; DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { di.Create(); } for (int i = 0; i < files.Count; i++) { fileName = CY.Utility.Common.FileUtility.GetFileName(files[i].FileName); fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(files[i].FileName); if (fileExtention != ".doc" && fileExtention != ".docx" && fileExtention != ".txt" && fileExtention != ".html" && fileExtention != ".htm") { continue; } files[i].SaveAs(dir + fileName + fileExtention); docAnnex = new CY.CSTS.Core.Business.Annex(); docAnnex.Name = fileName; docAnnex.ContentID = contentId; docAnnex.AnnexTypeID = docType.Id; docAnnex.AnnexURI = CY.Utility.Common.AnnexUtility.SurveyAnnexFileDir + fileName + fileExtention; docAnnex.Save(); } } } catch (Exception ex) { throw ex; } finally { } }
private void SaveImg(System.Guid contentId) { try { string[] imgNames = null; string[] imgPaths = null; if (string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString("imgpath")) || string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString("imgname"))) { return; } imgPaths = CY.Utility.Common.RequestUtility.GetFormString("imgpath").Split(','); imgNames = CY.Utility.Common.RequestUtility.GetFormString("imgName").Split(','); string appPath = string.Empty; string imgName = string.Empty; string imgExtention = string.Empty; string dirPath = string.Empty; if (imgPaths != null && imgNames != null && imgPaths.Length == imgNames.Length) { for (int i = 0; i < imgPaths.Length; i++) { CY.CSTS.Core.Business.AnnexType imgType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (imgType == null) { imgType = new CY.CSTS.Core.Business.AnnexType(); imgType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; imgType.Save(); } appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; imgName = CY.Utility.Common.FileUtility.GetFileName(imgNames[i]); imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgNames[i]); dirPath = CY.Utility.Common.SiteUtility.CurServer.MapPath(imgPaths[i]); if (File.Exists(dirPath)) { CY.CSTS.Core.Business.Annex imgAnnex = new CY.CSTS.Core.Business.Annex(); imgAnnex.Name = imgName; imgAnnex.AnnexTypeID = imgType.Id; imgAnnex.ContentID = contentId; imgAnnex.AnnexURI = CY.Utility.Common.AnnexUtility.InstrumentAnneImgDir + imgName + imgExtention; imgAnnex.Save(); } } } } catch (Exception ex) { throw ex; } finally { } }
protected void SaveFiles(System.Guid contentId) { HttpFileCollection hfc = Request.Files; string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; string dir = appPath + CY.Utility.Common.AnnexUtility.SubsidieAnneImgDir; string fileName = string.Empty; string fileExtention = string.Empty; string realFileName = string.Empty; DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { di.Create(); } CY.CSTS.Core.Business.AnnexType docType = null; for (int i = 0; i < hfc.Count; i++) { HttpPostedFile file = hfc[i]; realFileName = CY.Utility.Common.FileUtility.GetFileName(file.FileName); fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(file.FileName); fileName = Guid.NewGuid().ToString(); if (fileExtention == ".jpg" || fileExtention == ".jpeg" || fileExtention == ".gif" || fileExtention == ".png" || fileExtention == ".bmp") { docType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (docType == null) { docType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; docType.Save(); } } else if (fileExtention == ".csv" || fileExtention == ".doc" || fileExtention == ".docx" || fileExtention == ".pdf" || fileExtention == ".ppt" || fileExtention == ".txt" || fileExtention == ".rar" || fileExtention == ".zip") { docType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.DocAnnexType); if (docType == null) { docType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; docType.Save(); } } else { continue; } file.SaveAs(dir + fileName + fileExtention); CY.CSTS.Core.Business.Annex annex = new CY.CSTS.Core.Business.Annex(); annex.Name = realFileName; annex.ContentID = contentId; annex.AnnexTypeID = docType.Id; annex.AnnexURI = CY.Utility.Common.AnnexUtility.SubsidieAnneImgDir + fileName + fileExtention; annex.Save(); } }
public static void ImportInstrumentImg() { SqlServerUtility sql = new SqlServerUtility(); sql.ExecuteSql("delete from annex"); ImportSqlServerUtility isql = new ImportSqlServerUtility(); string strsql = "select * from instrpicture"; DataSet ds = isql.ExecuteSqlDataSet(strsql); CY.CSTS.Core.Business.AnnexType type = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Columns.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { CY.CSTS.Core.Business.Annex img = new CY.CSTS.Core.Business.Annex(); img.ContentID = TransferInstrumentId(ds.Tables[0].Rows[i][0].ToString()); img.ContentType = 2; if (ds.Tables[0].Rows[i][4].ToString().Length > 0) { if (ds.Tables[0].Rows[i][4].ToString().LastIndexOf("/") > 0) { img.Name = ds.Tables[0].Rows[i][4].ToString().Substring(ds.Tables[0].Rows[i][4].ToString().LastIndexOf("/") + 1, ds.Tables[0].Rows[i][4].ToString().LastIndexOf(".") - ds.Tables[0].Rows[i][4].ToString().LastIndexOf("/") - 1); if (ds.Tables[0].Rows[i][4].ToString().LastIndexOf('.') > 0) { img.AnnexURI = ds.Tables[0].Rows[i][4].ToString(); } else { img.AnnexURI = ds.Tables[0].Rows[i][4].ToString() + "." + ds.Tables[0].Rows[i][3].ToString(); } } else { if (ds.Tables[0].Rows[i][4].ToString().LastIndexOf(".") > 0) { img.Name = ds.Tables[0].Rows[i][4].ToString().Substring(0, ds.Tables[0].Rows[i][4].ToString().LastIndexOf(".")); } else { img.Name = ds.Tables[0].Rows[i][4].ToString(); } //if (img.AnnexURI.LastIndexOf('.') > 0) if(ds.Tables[0].Rows[i][4].ToString().LastIndexOf(".") > 0) { img.AnnexURI = "/upfiles/" + ds.Tables[0].Rows[i][4].ToString().ToLower(); } else { img.AnnexURI = "/upfiles/" + ds.Tables[0].Rows[i][4].ToString() + '.' + ds.Tables[0].Rows[i][3].ToString().ToLower(); } } img.AnnexTypeID = type.Id; img.Save(); } } } sql.ExecuteSql("update annex set annexuri=replace(annexuri,'//','/')"); }
protected void SaveImg(System.Guid contentId) { try { if (contentId == System.Guid.Empty) { return; } string[] strPaths = Request.Form.GetValues("imgpath"); string[] strNames = Request.Form.GetValues("imgname"); if (strPaths == null || strNames == null || strPaths.Length <= 0 || strNames.Length <= 0 || strPaths.Length != strNames.Length) { return; } #region Get AnnexType CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (anneType == null) { anneType = new CY.CSTS.Core.Business.AnnexType(); anneType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; anneType.Save(); } #endregion string fileName = string.Empty; string fileExtention = string.Empty; CY.CSTS.Core.Business.Annex imgannex = null; for (int i = 0; i < strNames.Length; i++) { fileName = CY.Utility.Common.FileUtility.GetFileName(strNames[i]); fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(strNames[i]); imgannex = new CY.CSTS.Core.Business.Annex(); imgannex.ContentID = contentId; imgannex.AnnexTypeID = anneType.Id; imgannex.Name = fileName; imgannex.AnnexURI = @"/Content/Instrument/Img/" + fileName + fileExtention; imgannex.Save(); } } catch (Exception ex) { throw ex; } finally { } }