private bool InsertFile(HttpPostedFile file, int projectID, int ticketID, bool isPublicFeedback, int feedbacksID) { string tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; string folderName = string.Empty; folderName = projectID.ToString(); string fileName = file.FileName; string savePath = Server.MapPath(tempPath) + folderName; string sExtension = Path.GetExtension(fileName); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string sNewFileName = string.Format("{0}_{1}{2}", feedbacksID, DateTime.Now.ToString("yyMMddssmm"), sExtension);; file.SaveAs(savePath + @"\" + sNewFileName); FilesEntity fileEntity = new FilesEntity(); fileEntity.ContentType = sExtension.ToLower(); fileEntity.CreatedBy = UserInfo.UserID; fileEntity.FilePath = tempPath.Substring(2) + folderName + @"/" + sNewFileName; fileEntity.FileSize = Convert.ToDecimal(file.ContentLength); fileEntity.FileTitle = fileName.Substring(0, fileName.LastIndexOf('.')); fileEntity.IsPublic = isPublicFeedback; fileEntity.FeedbackId = feedbacksID; fileEntity.TicketId = ticketID; fileEntity.ProjectId = projectID; fileEntity.SourceType = (int)FileSourceType.FeedBack; fileEntity.ThumbPath = ""; fileEntity.CreatedOn = DateTime.Now.Date; fileEntity.CompanyID = ticketsApp.GetCompanyIdByTicketId(ticketID); return(new FileApplication().AddFile(fileEntity) > 0); }
protected void btnSave_Click(object sender, EventArgs e) { string msg = string.Empty; if (!CheckInput(out msg)) { ShowMessageToClient(msg, 2, false, false); return; } if (rbtnNewDirectory.Checked) { DirectoryEntity model = GetDirectory(); int id = fileApp.UpdateDirectory(model); if (id > 0) { this.ShowSuccessMessageToClient(); } else { this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } } else if (rbtnNewFile.Checked) { FilesEntity model = GetFile(); if (fileApp.UpdateFile(model)) { ShowSuccessMessageToClient(true, true); } else { ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } } }
/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(FilesEntity entity) { if (entity.ID <= 0) { entity.ID = GetNewID(); } Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into Files (" + "ID," + "Name," + "Size," + "Path," + "UserName," + "FileType) " + "values(" + "@ID," + "@Name," + "@Size," + "@Path," + "@UserName," + "@FileType)"; if (await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))) { return(DataConverter.CLng(entity.ID)); } return(-1); }
public FilesEntity Create(int Uid) { FilesEntity model = new FilesEntity(); model.FileID = 1; model.FilePath = "aa"; model.FileSize = 11; if (Uid == 1) { model.FileTitle = "aaaa1111.docssss"; } else { model.FileTitle = "aaaa1111.doc"; } model.IsPublic = true; model.ID = 1; model.IsDelete = false; model.ModifiedBy = Uid; model.ModifiedOn = DateTime.Now; model.SourceID = 1; model.SourceType = 1; model.ThumbPath = "111"; return(model); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual bool Add(FilesEntity entity) { if (entity.ID <= 0) { entity.ID = GetNewID(); } Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into Files (" + "ID," + "Name," + "Size," + "Path," + "UserName," + "FileType) " + "values(" + "@ID," + "@Name," + "@Size," + "@Path," + "@UserName," + "@FileType)"; return(_DB.ExeSQLResult(strSQL, dict)); }
protected void BindDataModel(FilesEntity entity) { txtFileTitle.Text = entity.FileTitle; txtTags.Text = entity.Tags; lblFile.Visible = true; lblFile.Text = string.Format("<a href='/Do/DoDownloadFileHandler.ashx?FileID={0}&size={1}' target='_blank'>{2}</a>", entity.FileID, entity.FileSize, entity.FileTitle); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string strFileID = context.Request.QueryString["FileID"]; string strSize = context.Request.QueryString["size"]; string tableType = context.Request.QueryString["tableType"]; int fileId = 0; if (!int.TryParse(strFileID, out fileId)) { context.Response.Write("File not found."); return; } string filename = ""; string fileurl = ""; int tableTypeValue = 0; int.TryParse(tableType, out tableTypeValue); if (tableTypeValue == 2) { OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient(); string str = client.GetFileInfo(fileId); filename = str.Substring(str.IndexOf("|") + 1); fileurl = str.Substring(0, str.IndexOf("|")); } else { FilesEntity fileEntity = fileApp.Get(fileId); filename = fileEntity.FileTitle; fileurl = fileEntity.FilePath; } if (fileurl == "") { context.Response.Write("File not found."); return; } string filePath = HttpContext.Current.Server.MapPath(string.Format("/{0}", fileurl)); if (System.IO.File.Exists(filePath)) { if (filename.IndexOf(".") < 0) { filename += Path.GetExtension(filePath); } filename = filename.Replace(" ", "_"); context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename.NoHTML())); context.Response.TransmitFile(filePath); return; } else { context.Response.Write("File not found."); return; } }
public int AddFile(FilesEntity file) { this.ClearBrokenRuleMessages(); int result = mgr.AddFile(file); this.AddBrokenRuleMessages(mgr.BrokenRuleMessages); return(result); }
/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(FilesEntity entity, Dictionary <string, object> dict) { dict.Add("ID", entity.ID); dict.Add("Name", entity.Name); dict.Add("Size", entity.Size); dict.Add("Path", entity.Path); dict.Add("UserName", entity.UserName); dict.Add("FileType", entity.FileType); }
/// <summary> /// Update a record /// </summary> public bool Update(FilesEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Files set "); strSql.Append("CompanyID=@CompanyID,"); strSql.Append("TicketId=@TicketId,"); strSql.Append("ProjectId=@ProjectId,"); strSql.Append("FeedbackId=@FeedbackId,"); strSql.Append("SourceType=@SourceType,"); strSql.Append("FileTitle=@FileTitle,"); strSql.Append("ContentType=@ContentType,"); strSql.Append("FileSize=@FileSize,"); strSql.Append("FilePath=@FilePath,"); strSql.Append("ThumbPath=@ThumbPath,"); strSql.Append("CreatedOn=@CreatedOn,"); strSql.Append("CreatedBy=@CreatedBy,"); strSql.Append("IsDelete=@IsDelete,"); strSql.Append("IsPublic=@IsPublic,"); strSql.Append("Tags=@Tags,"); strSql.Append("SourceID=@SourceID"); strSql.Append(" where FileID=@FileID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { db.AddInParameter(dbCommand, "FileID", DbType.Int32, model.FileID); db.AddInParameter(dbCommand, "CompanyID", DbType.Int32, model.CompanyID); db.AddInParameter(dbCommand, "TicketId", DbType.Int32, model.TicketId); db.AddInParameter(dbCommand, "ProjectId", DbType.Int32, model.ProjectId); db.AddInParameter(dbCommand, "FeedbackId", DbType.Int32, model.FeedbackId); db.AddInParameter(dbCommand, "SourceType", DbType.Int32, model.SourceType); db.AddInParameter(dbCommand, "FileTitle", DbType.String, model.FileTitle); db.AddInParameter(dbCommand, "ContentType", DbType.String, model.ContentType); db.AddInParameter(dbCommand, "FileSize", DbType.Int32, model.FileSize); db.AddInParameter(dbCommand, "FilePath", DbType.String, model.FilePath); db.AddInParameter(dbCommand, "ThumbPath", DbType.String, model.ThumbPath); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, model.CreatedOn); db.AddInParameter(dbCommand, "CreatedBy", DbType.Int32, model.CreatedBy); db.AddInParameter(dbCommand, "IsDelete", DbType.Boolean, model.IsDelete); db.AddInParameter(dbCommand, "IsPublic", DbType.Boolean, model.IsPublic); db.AddInParameter(dbCommand, "Tags", DbType.String, model.Tags); db.AddInParameter(dbCommand, "WorkRequestId", DbType.Int32, model.ProposalTrackerId); db.AddInParameter(dbCommand, "SourceID", DbType.Int32, model.SourceID); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = QS("id", 0); if (id > 0) { FilesEntity entity = fileApp.Get(id); BindDataModel(entity); } } }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static FilesEntity GetEntityFromrdr(NullableDataReader rdr) { FilesEntity info = new FilesEntity(); info.ID = rdr.GetInt32("ID"); info.Name = rdr.GetString("Name"); info.Size = rdr.GetInt32("Size"); info.Path = rdr.GetString("Path"); info.UserName = rdr.GetString("UserName"); info.FileType = rdr.GetString("FileType"); return(info); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (string.IsNullOrEmpty(Request.QueryString["id"]) || string.IsNullOrEmpty(Request.QueryString["type"]) || (QS("id", 0) == 0)) { ShowArgumentErrorMessageToClient(); return; } int id = int.Parse(Request.QueryString["id"]); string type = Request.QueryString["type"]; if (type == DirectoryObjectType.Directory.ToString()) { rbtnNewDirectory.Checked = true; rbtnNewFile.Checked = false; DirectoryEntity model = fileApp.GetDirectory(int.Parse(Request.Params["id"])); DirectoryEntity parent = fileApp.GetDirectory(model.ParentID); List <DirectoryEntity> list = fileApp.GetDirectories(parent.ParentID); list.BindDropdown <DirectoryEntity>(ddlCurrent, "Title", "ID", "Please Select", "0"); ddlCurrent.SelectedValue = model.ParentID.ToString(); txtTitle.Text = model.Title; txtDesc.Text = model.Description; } else if (type == DirectoryObjectType.File.ToString()) { int direid = 0; if (!string.IsNullOrEmpty(Request.Params["direid"]) && int.TryParse(Request.Params["direid"], out direid)) { DirectoryObjectsEntity objects = fileApp.GetObjects(direid); if (!ISReadOnlyRole || UserInfo.ID == objects.CreatedBy) { DirectoryEntity parent = fileApp.GetDirectory(objects.DirectoryID); ddlCurrent.Items.Add(new ListItem(parent.Title, parent.ID.ToString(), true)); FilesEntity file = fileApp.Get(objects.ObjectID); txtDesc.Text = file.ThumbPath; } else { ShowArgumentErrorMessageToClient(); return; } } rbtnNewDirectory.Checked = false; rbtnNewFile.Checked = true; } } }
protected void btnSave_Click(object sender, EventArgs e) { int id = QS("id", 0); int workRequestId = QS("wid", 0); if (fileProject.HasFile || lblFile.Visible == true) { FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("WorkRequest", workRequestId, fileProject.PostedFile);; model.WorkRequestId = workRequestId; model.ContentType = fileProject.PostedFile.ContentType; model.FileID = 0; model.FileSize = fileProject.PostedFile.ContentLength; if (string.IsNullOrEmpty(txtFileTitle.Text)) { model.FileTitle = Path.GetFileName(fileProject.FileName); model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf(".")); } else { model.FileTitle = txtFileTitle.Text; } model.IsDelete = false; model.IsPublic = UserInfo.Role == RolesEnum.CLIENT; model.SourceType = (int)FileSourceType.WorkRequest; model.ThumbPath = Path.GetFileName(fileProject.PostedFile.FileName); model.IsDelete = false; model.Tags = txtTags.Text.Trim(); bool result = true; if (id > 0) { model.FileID = id; result = fileApp.UpdateFile(model); } else { result = fileApp.AddFile(model) > 0 ? true : false; } if (!result) { this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } else { this.ShowSuccessMessageToClient(); } } else { this.ShowFailMessageToClient("Please select a file"); } }
/// <summary> /// Add a record /// </summary> public int Insert(FilesEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Files("); strSql.Append(@"TicketId,CompanyID,ProjectId,FeedbackId,SourceType,FileTitle,ContentType,FileSize,FilePath,ThumbPath, CreatedOn,CreatedBy,IsDelete,IsPublic,Tags,WorkRequestId,SourceID)"); strSql.Append(" values ("); strSql.Append(@"@TicketId,@CompanyID,@ProjectId,@FeedbackId,@SourceType,@FileTitle,@ContentType,@FileSize,@FilePath,@ThumbPath, @CreatedOn,@CreatedBy,@IsDelete,@IsPublic,@Tags,@WorkRequestId,@SourceID)"); strSql.Append(";select ISNULL( SCOPE_IDENTITY(),0);"); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "TicketId", DbType.Int32, model.TicketId); db.AddInParameter(dbCommand, "CompanyID", DbType.Int32, model.CompanyID); db.AddInParameter(dbCommand, "ProjectId", DbType.Int32, model.ProjectId); db.AddInParameter(dbCommand, "FeedbackId", DbType.Int32, model.FeedbackId); db.AddInParameter(dbCommand, "SourceType", DbType.Int32, model.SourceType); db.AddInParameter(dbCommand, "FileTitle", DbType.String, model.FileTitle); db.AddInParameter(dbCommand, "ContentType", DbType.String, model.ContentType); db.AddInParameter(dbCommand, "FileSize", DbType.Int32, model.FileSize); db.AddInParameter(dbCommand, "FilePath", DbType.String, model.FilePath); db.AddInParameter(dbCommand, "ThumbPath", DbType.String, model.ThumbPath); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, model.CreatedOn); db.AddInParameter(dbCommand, "CreatedBy", DbType.Int32, model.CreatedBy); db.AddInParameter(dbCommand, "IsDelete", DbType.Boolean, model.IsDelete); db.AddInParameter(dbCommand, "IsPublic", DbType.Boolean, model.IsPublic); db.AddInParameter(dbCommand, "Tags", DbType.String, model.Tags); db.AddInParameter(dbCommand, "WorkRequestId", DbType.String, model.ProposalTrackerId); db.AddInParameter(dbCommand, "SourceID", DbType.String, model.SourceID); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(0); } } }
/// <summary> /// 获取实体 /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual FilesEntity GetEntity(string strWhere, Dictionary <string, object> dict = null) { FilesEntity obj = null; string strSQL = "select top 1 * from Files where 1=1 " + strWhere; using (NullableDataReader reader = _DB.GetDataReader(strSQL, dict)) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <FilesEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { FilesEntity obj = null; string strSQL = "select top 1 * from Files where 1=1 " + strWhere; using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict))) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
public List <FilesEntity> GetFileListBySourceId(int Sid, FileSourceType type) { List <FilesEntity> list = new List <FilesEntity>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Files "); switch (type) { case FileSourceType.Ticket: strSql.Append(" where TicketId=@Sid "); break; case FileSourceType.Project: strSql.Append(" where ProjectId=@Sid "); break; case FileSourceType.FeedBack: strSql.Append(" where FeedbackId=@Sid "); break; case FileSourceType.WorkRequest: strSql.Append(" where WorkRequestId=@Sid "); break; case FileSourceType.KnowledgeShare: strSql.Append(" where SourceID=@Sid "); break; default: break; } strSql.Append(" and SourceType=@SourceType and Isdelete =0"); strSql.Append(" order by CreatedOn desc"); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { db.AddInParameter(dbCommand, "Sid", DbType.Int32, Sid); db.AddInParameter(dbCommand, "SourceType", DbType.Int32, (int)type); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { list.Add(FilesEntity.ReaderBind(dataReader)); } } } return(list); }
protected void btnSaveFiles_Click(object sender, EventArgs e) { int id = QS("id", 0); int companyid = QS("companyid", 0); if (fileProject.HasFile) { FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Project", id, fileProject.PostedFile);; model.CompanyID = companyid; model.ContentType = fileProject.PostedFile.ContentType; model.FileID = 0; model.FileSize = fileProject.PostedFile.ContentLength; if (string.IsNullOrEmpty(txtFileTitle.Text)) { model.FileTitle = Path.GetFileName(fileProject.FileName); model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf(".")); } else { model.FileTitle = txtFileTitle.Text; } model.IsDelete = false; model.IsPublic = UserInfo.Role == RolesEnum.CLIENT; model.SourceType = (int)FileSourceType.Project; model.ProjectId = id; model.ThumbPath = Path.GetFileName(fileProject.PostedFile.FileName); model.IsDelete = false; FileApplication fileApp = new FileApplication(); int result = fileApp.AddFile(model); OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient(); List <FilesEntity> clientFiles = new List <FilesEntity>(); clientFiles.Add(model); client.AddDocManagement(Newtonsoft.Json.JsonConvert.SerializeObject(clientFiles)); if (result <= 0) { this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } else { InitFiles(); this.ShowSuccessMessageToClient(false, false); txtFileTitle.Text = ""; } } }
protected void btnSave_Click(object sender, EventArgs e) { string msg = string.Empty; if (!CheckInput(out msg)) { ShowMessageToClient(msg, 2, false, false); return; } if (rbtnNewDirectory.Checked) { DirectoryEntity model = GetDirectory(); int id = fileApp.UpdateDirectory(model); if (id > 0) { Session["CreatedDirectory"] = string.Format("{0}-{1}", ddlCurrent.SelectedValue, id.ToString()); this.ShowSuccessMessageToClient(); } else { this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } } else if (rbtnNewFile.Checked) { FilesEntity model = GetFile(); FileApplication fileApp = new FileApplication(); int result = fileApp.AddFile(model); if (result <= 0) { ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); return; } else { DirectoryObjectsEntity objecttoadd = GetObject(result); int id = fileApp.PushObjectToDirectory(objecttoadd); if (id > 0) { ShowSuccessMessageToClient(true, true); } else { ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); return; } } } }
private FilesEntity GetFile() { int id = int.Parse(Request.Params["id"]); FilesEntity model = fileApp.Get(id); if (fileCompany.HasFile) { model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Company", UserInfo.CompanyID, fileCompany.PostedFile); model.ContentType = Path.GetExtension(fileCompany.FileName); model.FileTitle = Path.GetFileName(fileCompany.FileName); model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf(".")); model.FileSize = fileCompany.PostedFile.ContentLength; } model.ThumbPath = txtDesc.Text; return(model); }
private int InsertFile(string file, int shareID) { var realFileName = file.Replace(string.Format("{0}_", UserInfo.ID), ""); string tempPath = Config.UploadPath; string tmpFile = Server.MapPath(Config.UploadPath + "/" + file); if (!File.Exists(tmpFile)) { return(0); } string folderName = UserInfo.CompanyID.ToString(); string savePath = Path.Combine(Server.MapPath(tempPath), folderName); string sExtension = Path.GetExtension(file); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string sNewFileName = string.Format("{0}_{1}{2}", shareID, DateTime.Now.ToString("yyMMddssmm"), sExtension);; FilesEntity fileEntity = new FilesEntity(); fileEntity.ContentType = sExtension.ToLower(); fileEntity.CreatedBy = UserInfo.UserID; fileEntity.FilePath = string.Format("{0}{1}/{2}", tempPath.Substring(1), folderName, sNewFileName); fileEntity.FileSize = Convert.ToDecimal(new FileInfo(tmpFile).Length); fileEntity.FileTitle = realFileName.Substring(0, realFileName.LastIndexOf('.')); fileEntity.IsPublic = true; fileEntity.FeedbackId = 0; fileEntity.TicketId = 0; fileEntity.ProjectId = 0; fileEntity.SourceID = shareID; fileEntity.SourceType = (int)FileSourceType.KnowledgeShare; fileEntity.ThumbPath = ""; fileEntity.CreatedOn = DateTime.Now.Date; fileEntity.CompanyID = UserInfo.CompanyID; if (FileHelper.Move(file, Server.MapPath(fileEntity.FilePath))) { return(_fileApp.AddFile(fileEntity)); } return(0); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(FilesEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update Files SET " + "Name = @Name," + "Size = @Size," + "Path = @Path," + "UserName = @UserName," + "FileType = @FileType" + " WHERE " + "ID = @ID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
protected void btnSave_Click(object sender, EventArgs e) { if (!fileUpload.HasFile) { ShowFailMessageToClient("Please upload file"); return; } ProposalTrackerEntity proposaltrackerEntity = new App.ProposalTrackerApplication().Get(QS("ID", 0)); if (proposaltrackerEntity == null) { ShowFailMessageToClient("unauthorized access."); return; } FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("ProposalTracker", proposaltrackerEntity.ProjectID, fileUpload.PostedFile);; model.ProposalTrackerId = proposaltrackerEntity.ProposalTrackerID; model.ContentType = fileUpload.PostedFile.ContentType; model.FileID = 0; model.FileSize = fileUpload.PostedFile.ContentLength; model.FileTitle = Path.GetFileName(fileUpload.PostedFile.FileName); model.IsDelete = false; model.IsPublic = UserInfo.Role == RolesEnum.CLIENT; model.SourceType = (int)FileSourceType.WorkRequest; model.ThumbPath = txtFileTitle.Text; model.IsDelete = false; model.Tags = txtTags.Text.Trim(); bool result = true; result = fileApp.AddFile(model) > 0; if (!result) { ShowFailMessageToClient(fileApp.BrokenRuleMessages); } else { Redirect(EmptyPopPageUrl, false, true); } }
private FilesEntity GetFile() { int companyID = UserInfo.CompanyID; FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Company", companyID, fileCompany.PostedFile); model.CompanyID = companyID; model.ContentType = Path.GetExtension(fileCompany.FileName); model.FileID = 0; model.FileSize = fileCompany.PostedFile.ContentLength; model.FileTitle = Path.GetFileName(fileCompany.FileName); model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf(".")); model.IsDelete = false; model.IsPublic = false; model.SourceType = (int)FileSourceType.Company; model.ThumbPath = txtDesc.Text; model.IsDelete = false; return(model); }
protected void btnSaveFiles_Click(object sender, EventArgs e) { if (fileProject.HasFile) { FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Company", CompanyID, fileProject.PostedFile);; model.CompanyID = CompanyID; model.ContentType = Path.GetExtension(fileProject.FileName); model.FileID = 0; model.FileSize = fileProject.PostedFile.ContentLength; if (string.IsNullOrEmpty(txtFileTitle.Text)) { model.FileTitle = Path.GetFileName(fileProject.FileName); model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf(".")); } else { model.FileTitle = txtFileTitle.Text; } model.IsDelete = false; model.IsPublic = BaseWebsitePage.UserInfo.Role == RolesEnum.CLIENT; model.SourceType = (int)FileSourceType.Company; model.ThumbPath = Path.GetFileName(fileProject.PostedFile.FileName); model.IsDelete = false; FileApplication fileApp = new FileApplication(); int result = fileApp.AddFile(model); if (result <= 0) { BaseWebsitePage.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } else { BaseWebsitePage.ShowSuccessMessageToClient(false, false); InitFiles(); txtFileTitle.Text = ""; } } }
/// <summary> /// Get an object entity /// </summary> public FilesEntity Get(int FileID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Files "); strSql.Append(" where FileID=@FileID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { db.AddInParameter(dbCommand, "FileID", DbType.Int32, FileID); FilesEntity model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = FilesEntity.ReaderBind(dataReader); } } return(model); } }
private void InsertFile(string file, int projectID, int ticketID, int companyID) { string realFileName = file.Replace(string.Format("{0}_", UserInfo.UserID), ""); var fileLength = (int)SunNet.PMNew.PM2014.Codes.FileHelper.GetFileLength(file); string tempPath = Config.UploadPath; string folderName = projectID.ToString(); string fileName = file; string savePath = Path.Combine(Server.MapPath(tempPath), folderName); string sExtension = Path.GetExtension(fileName); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string sNewFileName = string.Format("{0}_{1}_{2}{3}", ticketID, Path.GetFileNameWithoutExtension(file), DateTime.Now.ToString("ssmmfff"), sExtension); FilesEntity fileEntity = new FilesEntity(); fileEntity.ContentType = sExtension.ToLower(); fileEntity.CreatedBy = UserInfo.UserID; fileEntity.FilePath = string.Format("{0}{1}/{2}", tempPath.Substring(1), folderName, sNewFileName); fileEntity.FileSize = Convert.ToDecimal(fileLength); fileEntity.FileTitle = realFileName.Substring(0, realFileName.LastIndexOf('.')); fileEntity.IsPublic = true; fileEntity.FeedbackId = 0; fileEntity.TicketId = ticketID; fileEntity.ProjectId = projectID; fileEntity.SourceType = (int)FileSourceType.Ticket; fileEntity.ThumbPath = ""; fileEntity.CreatedOn = DateTime.Now.Date; fileEntity.CompanyID = companyID; if (SunNet.PMNew.PM2014.Codes.FileHelper.Move(file, Server.MapPath(fileEntity.FilePath))) { new FileApplication().AddFile(fileEntity); } }
private int InsertFile(string file, int projectID, int ticketID, bool isPublicFeedback, int feedbacksID, HttpServerUtility Server, out string realFileName) { realFileName = file.Replace(string.Format("{0}_", UserID), ""); var fileLength = (int)FileHelper.GetFileLength(file); string tempPath = Config.UploadPath; string folderName = projectID.ToString(); string fileName = file; string savePath = Path.Combine(Server.MapPath(tempPath), folderName); string sExtension = Path.GetExtension(fileName); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string sNewFileName = string.Format("{0}_{1}_{2}{3}", ticketID, Path.GetFileNameWithoutExtension(file), DateTime.Now.ToString("ssmmfff"), sExtension); FilesEntity fileEntity = new FilesEntity(); fileEntity.ContentType = sExtension.ToLower(); fileEntity.CreatedBy = UserInfo.UserID; fileEntity.FilePath = string.Format("{0}{1}/{2}", tempPath.Substring(1), folderName, sNewFileName); fileEntity.FileSize = Convert.ToDecimal(fileLength); fileEntity.FileTitle = realFileName.Substring(0, realFileName.LastIndexOf('.')); fileEntity.IsPublic = isPublicFeedback; fileEntity.FeedbackId = feedbacksID; fileEntity.TicketId = ticketID; fileEntity.ProjectId = projectID; fileEntity.SourceType = (int)FileSourceType.FeedBack; fileEntity.ThumbPath = ""; fileEntity.CreatedOn = DateTime.Now.Date; fileEntity.CompanyID = ticketApp.GetCompanyIdByTicketId(ticketID); if (FileHelper.Move(file, Server.MapPath(fileEntity.FilePath))) { return(fileApp.AddFile(fileEntity)); } return(0); }
public FilesEntity Get(int fileId, decimal size) { StringBuilder strSql = new StringBuilder(); strSql.Append("select FileID,CompanyID,ProjectId,TicketId,FeedbackId,SourceType,FileTitle,ContentType,FileSize,FilePath,ThumbPath,CreatedOn,CreatedBy,IsDelete,IsPublic from Files "); strSql.Append(" where FileID=@FileID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { db.AddInParameter(dbCommand, "FileID", DbType.Int32, fileId); db.AddInParameter(dbCommand, "FileSize", DbType.Int32, size); FilesEntity model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = FilesEntity.ReaderBind(dataReader); } } return(model); } }