protected void Page_Load(object sender, EventArgs e) { int fileid = Int32.Parse(Request.QueryString["fileid"]);//获取文件的ID FileOfApplyInfo ffa = new FileOfApplyInfo(fileid); string fileName = ffa.FileOfName; DownLoads(fileName); }
protected void btnSave_Click(object sender, EventArgs e) { if (UpFile.HasFile) { this.UpFile.PostedFile.SaveAs(Server.MapPath("~/Files/File/" + UpFile.FileName)); FileOfApplyInfo ffa = new FileOfApplyInfo(); ffa.FileOfName = UpFile.FileName.ToString(); ffa.PhysicalName = UpFile.PostedFile.FileName.ToString(); ffa.Save(); FileApplyInfo fa = new FileApplyInfo(); fa.ApplyName = lblEm.Text.ToString(); fa.ApplyTime = txtTime.Text.ToString(); fa.DepartName = Session["DepartName"].ToString(); fa.DepartView = txtSectionView.Text.ToString(); fa.FileDes = txtFileDes.Text.ToString(); fa.FilesName = txtFileName.Text.ToString(); fa.FileType = txtFileType.Text.ToString(); fa.State = 0; fa.FileOfApplyId = ffa.FileOfApplyId; fa.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('新增成功,确认无误后需要您进一步提交!');</script>"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('请上传文件!');</script>"); } }
public FileOfApplyInfo GetFileOfApplyInfoById(int FileOfApplyId) { FileOfApplyInfo fileOfApplyInfo = null;// try { fileOfApplyInfo = new FileOfApplyInfo(FileOfApplyId); } catch (AppException) { return null; } return fileOfApplyInfo; }
protected void btnSave_Click(object sender, EventArgs e) { if (UpFile.HasFile) { FileApplyInfo fa = new FileApplyInfo(Convert.ToInt32(Request["FileApplyId"].ToString())); FileOfApplyInfo ffa = new FileOfApplyInfo(Convert.ToInt32(fa.FileOfApplyId)); ffa.FileOfName = UpFile.FileName.ToString(); ffa.PhysicalName = UpFile.PostedFile.FileName.ToString(); ffa.Save(); fa.ApplyTime = txtTime.Text.ToString(); fa.DepartView = txtSectionView.Text.ToString(); fa.FileDes = txtFileDes.Text.ToString(); fa.FilesName = txtFileName.Text.ToString(); fa.FileType = txtFileType.Text.ToString(); fa.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('保存成功,确认无误后需要您进一步提交!');</script>"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('请重新修改文件名并上传!');</script>"); } }
public object SaveFileOfApplyInfo(FileOfApplyInfo fileOfApplyInfo) { fileOfApplyInfo.Save(); return fileOfApplyInfo . FileOfApplyId; }
public void DeleteById(FileOfApplyInfo pFileOfApplyInfo) { FileOfApplyInfo fileOfApplyInfo = new FileOfApplyInfo(pFileOfApplyInfo.FileOfApplyId); fileOfApplyInfo.Delete(); }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List< FileOfApplyInfo> pList, FileOfApplyCollection pCollection) { foreach (FileOfApply fileOfApply in pCollection) { FileOfApplyInfo fileOfApplyInfo = new FileOfApplyInfo(); LoadFromDAL(fileOfApplyInfo, fileOfApply ); pList.Add(fileOfApplyInfo); } }
//数据持久化 internal static void SaveToDb(FileOfApplyInfo pFileOfApplyInfo, FileOfApply pFileOfApply,bool pIsNew) { pFileOfApply.FileOfApplyId = pFileOfApplyInfo.fileOfApplyId; pFileOfApply.FileOfName = pFileOfApplyInfo.fileOfName; pFileOfApply.PhysicalName = pFileOfApplyInfo.physicalName; pFileOfApply.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pFileOfApply.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(FileOfApplyInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pFileOfApplyInfo.fileOfApplyId = pFileOfApply.FileOfApplyId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(FileOfApplyInfo))) { ResetCache(); } }
//从后台获取数据 internal static void LoadFromDAL(FileOfApplyInfo pFileOfApplyInfo, FileOfApply pFileOfApply) { pFileOfApplyInfo.fileOfApplyId = pFileOfApply.FileOfApplyId; pFileOfApplyInfo.fileOfName = pFileOfApply.FileOfName; pFileOfApplyInfo.physicalName = pFileOfApply.PhysicalName; pFileOfApplyInfo.Loaded=true; }
/// <summary> /// 复制为另一个对象 /// </summary> /// <param name="pIndustryTypeInfoTo"></param> public void CopyTo(FileOfApplyInfo pFileOfApplyInfoTo) { Copy(this, pFileOfApplyInfoTo); }
/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List<FileOfApplyInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount) { if(pPageIndex<=1) pPageIndex=1; List< FileOfApplyInfo> list = new List< FileOfApplyInfo>(); Query q = FileOfApply .CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression,pOrderBy.ToString()); FileOfApplyCollection collection=new FileOfApplyCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (FileOfApply fileOfApply in collection) { FileOfApplyInfo fileOfApplyInfo = new FileOfApplyInfo(); LoadFromDAL(fileOfApplyInfo, fileOfApply); list.Add(fileOfApplyInfo); } pRecordCount=q.GetRecordCount(); return list; }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List<FileOfApplyInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(FileOfApplyInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return CachedEntityCommander.GetCache(cacheKey) as List< FileOfApplyInfo>; } else { List< FileOfApplyInfo> list =new List< FileOfApplyInfo>(); FileOfApplyCollection collection=new FileOfApplyCollection(); Query qry = new Query(FileOfApply.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach(FileOfApply fileOfApply in collection) { FileOfApplyInfo fileOfApplyInfo= new FileOfApplyInfo(); LoadFromDAL(fileOfApplyInfo,fileOfApply); list.Add(fileOfApplyInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(FileOfApplyInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return list; } }
/// <summary> /// 复制一个对象,采用硬编码的方式,避免反射的低效 /// </summary> /// <param name="pIndustryTypeInfoFrom"></param> /// <param name="pIndustryTypeInfoTo"></param> public static void Copy(FileOfApplyInfo pFileOfApplyInfoFrom, FileOfApplyInfo pFileOfApplyInfoTo) { pFileOfApplyInfoTo.FileOfApplyId = pFileOfApplyInfoFrom.fileOfApplyId; pFileOfApplyInfoTo.FileOfName = pFileOfApplyInfoFrom.fileOfName; pFileOfApplyInfoTo.PhysicalName = pFileOfApplyInfoFrom.physicalName; pFileOfApplyInfoTo.Loaded=pFileOfApplyInfoFrom.Loaded; }