/// <summary> /// 添加通知和办事流程附件 /// </summary> /// <param name="attachment">附件实体</param> /// <returns>附件实体</returns> public Attachments AddAdminNotifyAttachment(Attachments attachment) { using (SqlCommand cmd = new SqlCommand("spAttachmentsAdd", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; conn.Open(); cmd.Parameters.Add(new SqlParameter("@attachmentTitle", attachment.attachmentTitle)); cmd.Parameters.Add(new SqlParameter("@attachmentUrl", attachment.attachmentUrl)); cmd.Parameters.Add(new SqlParameter("@attachmentId", 0)); cmd.Parameters["@attachmentId"].Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); attachment.attachmentId = int.Parse(cmd.Parameters["@attachmentId"].Value.ToString()); conn.Close(); } return attachment; }
/// <summary> /// 查询附件 /// </summary> /// <param name="attachmentId">附件编号</param> /// <returns>附件实体</returns> public Attachments FindAttachmentByAttachmentId(int attachmentId) { string cmdstring = "SELECT attachmentId,attachmentTitle,attachmentUrl,updateTime FROM [USTA].[dbo].[usta_Attachments] WHERE attachmentId=@attachmentId"; SqlParameter[] parameters = new SqlParameter[1]{ new SqlParameter("@attachmentId",attachmentId) }; SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, cmdstring, parameters); Attachments attachment = null; while (dr.Read()) { attachment = new Attachments(); attachment.attachmentId = int.Parse(dr["attachmentId"].ToString().Trim()); attachment.attachmentUrl = dr["attachmentUrl"].ToString().Trim(); attachment.attachmentTitle = dr["attachmentTitle"].ToString().Trim(); attachment.updateTime = DateTime.Parse(dr["updateTime"].ToString().Trim()); } dr.Close(); conn.Close(); return attachment; }
/// <summary> /// 文件上传 /// </summary> /// <param name="file">要上传的文件</param> /// <param name="fileFolderType">要上传的文件目录</param> /// <param name="userCookiesInfo">用户Cookies实体类</param> /// <returns>返回附件实体类</returns> public static Attachments doUpload(HttpPostedFile file, int fileFolderType, UserCookiesInfo userCookiesInfo) { //上传文件子目录,根据传入的枚举值进行获取 string fileFolderName = GetFileFolderName(fileFolderType); string fileFolderNameOnDate = GetSaveFilePath(); Attachments attachments = null; if (!Directory.Exists(uploadFileServerPath + fileFolderName + fileFolderNameOnDate)) { Directory.CreateDirectory(uploadFileServerPath + fileFolderName + fileFolderNameOnDate); } string strNewPath = string.Empty; string strFileName = file.FileName; strNewPath = fileFolderName + fileFolderNameOnDate + GetCorrectFileName(file.FileName).Replace(GetExtension(file.FileName), "") +"_"+ DateTimeString() + GetExtension(file.FileName); ////为作业或实验上传文件重命名文件名称 //if (fileFolderType == (int)FileFolderType.experiments || fileFolderType == (int)FileFolderType.schoolWorks) //{ // strNewPath = fileFolderName + fileFolderNameOnDate + UploadFileRename.RenameExperimentsOrSchoolWorks(userCookiesInfo) + GetExtension(file.FileName); //} ////为批改后的作业或实验上传文件重命名文件名称 //if (fileFolderType == (int)FileFolderType.remarkExperimentsAndSchoolWorks) //{ // strNewPath = fileFolderName + fileFolderNameOnDate + UploadFileRename.RenameRemarkExperimentsAndSchoolWorks(userCookiesInfo) + GetExtension(file.FileName); //} ////为作业或实验上传文件重命名附件名称 //if (fileFolderType == (int)FileFolderType.experiments || fileFolderType == (int)FileFolderType.schoolWorks) //{ // attachments.attachmentTitle = UploadFileRename.RenameExperimentsOrSchoolWorks(userCookiesInfo) + GetExtension(file.FileName); //} file.SaveAs(uploadFileServerPath + strNewPath); attachments = new Attachments { attachmentUrl = uploadFileFolderName + strNewPath, attachmentTitle = GetCorrectFileName(file.FileName) }; return attachments; }
/// <summary> ///查询单个通知和办事流程附件 /// </summary> /// <param name="attachmentId">附件编号</param> /// <returns></returns> public Attachments FindAdminNotifyAttachmentById(int attachmentId) { Attachments attachment = null; SqlParameter[] parameters = { new SqlParameter("@attachmentId", SqlDbType.Int,4) }; parameters[0].Value = attachmentId; SqlDataReader dr = SqlHelper.ExecuteReader(conn, "spAttachmentsGetModel", parameters); while (dr.Read()) { attachment = new Attachments { attachmentId = int.Parse(dr["attachmentId"].ToString()), attachmentTitle = dr["attachmentTitle"].ToString().Trim(), attachmentUrl = dr["attachmentUrl"].ToString().Trim(), updateTime = DateTime.Parse(dr["updateTime"].ToString().Trim()) }; } dr.Close(); conn.Close(); return attachment; }
/// <summary> /// 修改通知和办事流程附件, 暂不使用,因为项目采用的方案是删除后再上传,不再进行直接更新 /// </summary> /// <param name="attachment">附件实体</param> public void UpdateAdminNotifyAttachment(Attachments attachment) { try { SqlParameter[] parameters = { new SqlParameter("@attachmentTitle", SqlDbType.NChar,50), new SqlParameter("@attachmentId", SqlDbType.Int,4), new SqlParameter("@updateTime", SqlDbType.DateTime)}; parameters[0].Value = attachment.attachmentTitle; parameters[1].Value = attachment.attachmentId; parameters[2].Value = DateTime.Now; SqlHelper.ExecuteNonQuery(conn, "spAttachmentsUpdate", parameters); } catch (Exception ex) { MongoDBLog.LogRecord(ex); CommonUtility.RedirectUrl(); } finally { conn.Close(); } }