/// <summary> /// 得到一个对象实体 /// </summary> public static EtNet_Models.InformationFile GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, informationid, fileload, filename, filesize, downloadnum, createtime "); strSql.Append(" from InformationFile "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; EtNet_Models.InformationFile model = new EtNet_Models.InformationFile(); DataTable tbl = EtNet_DAL.DBHelper.GetDataSet(strSql.ToString(), parameters); if (tbl.Rows.Count > 0) { model.id = int.Parse(tbl.Rows[0]["id"].ToString()); model.informationid = int.Parse(tbl.Rows[0]["informationid"].ToString()); model.fileload = tbl.Rows[0]["fileload"].ToString(); model.filename = tbl.Rows[0]["filename"].ToString(); model.filesize = int.Parse(tbl.Rows[0]["filesize"].ToString()); model.downloadnum = int.Parse(tbl.Rows[0]["downloadnum"].ToString()); model.createtime = DateTime.Parse(tbl.Rows[0]["createtime"].ToString()); return(model); } else { return(null); } }
private void DownloadFile() { if (Request.Params["id"] != null) { int id = int.Parse(Request.Params["id"]); EtNet_Models.InformationFile model = EtNet_BLL.InformationFileManager.GetModel(id); if (model != null) { string path = model.fileload; Response.Clear(); Response.Buffer = false; Response.ContentEncoding = System.Text.Encoding.UTF8; //注意编码 //string filename = Server.UrlEncode(tbl.Rows[0]["cname"].ToString()) + path.Substring(path.LastIndexOf('.')); string filename = ""; if (model.filename.IndexOf('.') != -1) { filename = model.filename; } else { filename = model.filename + path.Substring(path.LastIndexOf('.')); } if (Request.Browser.Browser == "IE") { filename = Server.UrlEncode(filename); } Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename); //设置输出流HttpMiME类型(导出文件格式) Response.ContentType = "application/octet-stream;"; //image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword Response.WriteFile(Server.MapPath(model.fileload)); } } }
/// <summary> /// 保存附件的路径 /// </summary> /// <param name="filelist">附件的路径的列表</param> /// <param name="jobflowid">工作流的id值</param> private void CreateDocumentFile(string[] filelist, int informationid) { EtNet_Models.InformationFile model = null; for (int i = 1; i < 6; i++) { if (filelist[i] != "") { model = new EtNet_Models.InformationFile(); model.downloadnum = 0; model.fileload = filelist[i].Substring(0, filelist[i].IndexOf("|")); model.createtime = DateTime.Now; model.filename = filelist[i].Substring(filelist[i].LastIndexOf("|") + 1); model.filesize = int.Parse(filelist[i].Split('|')[1]); model.informationid = informationid; EtNet_BLL.InformationFileManager.Add(model); } } }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(EtNet_Models.InformationFile model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update InformationFile set "); strSql.Append(" informationid = @informationid , "); strSql.Append(" fileload = @fileload , "); strSql.Append(" filename = @filename , "); strSql.Append(" filesize = @filesize , "); strSql.Append(" downloadnum = @downloadnum , "); strSql.Append(" createtime = @createtime "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@informationid", SqlDbType.Int, 4), new SqlParameter("@fileload", SqlDbType.VarChar, 200), new SqlParameter("@filename", SqlDbType.VarChar, 100), new SqlParameter("@filesize", SqlDbType.Int, 4), new SqlParameter("@downloadnum", SqlDbType.Int, 4), new SqlParameter("@createtime", SqlDbType.SmallDateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.informationid; parameters[2].Value = model.fileload; parameters[3].Value = model.filename; parameters[4].Value = model.filesize; parameters[5].Value = model.downloadnum; parameters[6].Value = model.createtime; int result = EtNet_DAL.DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (result >= 1) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public static bool Add(EtNet_Models.InformationFile model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into InformationFile("); strSql.Append("informationid,fileload,filename,filesize,downloadnum,createtime"); strSql.Append(") values ("); strSql.Append("@informationid,@fileload,@filename,@filesize,@downloadnum,@createtime"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@informationid", SqlDbType.Int, 4), new SqlParameter("@fileload", SqlDbType.VarChar, 200), new SqlParameter("@filename", SqlDbType.VarChar, 100), new SqlParameter("@filesize", SqlDbType.Int, 4), new SqlParameter("@downloadnum", SqlDbType.Int, 4), new SqlParameter("@createtime", SqlDbType.SmallDateTime) }; parameters[0].Value = model.informationid; parameters[1].Value = model.fileload; parameters[2].Value = model.filename; parameters[3].Value = model.filesize; parameters[4].Value = model.downloadnum; parameters[5].Value = model.createtime; int result = EtNet_DAL.DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (result >= 1) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(EtNet_Models.InformationFile model) { return(EtNet_DAL.InformationFileService.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public static bool Add(EtNet_Models.InformationFile model) { return(EtNet_DAL.InformationFileService.Add(model)); }