private void OptData() { /******** 可修改区域 Start ********/ Model.Attachment_Model model = GetNewDataModel(CurrentContext); /******** 可修改区域 End ********/ bool issuccess = false; string msg = string.Empty; try { if (IsAdd) { issuccess = bll.AddModel(model); msg = issuccess ? "添加成功。" : "添加失败!"; } else { issuccess = bll.UpdateModel(model); msg = issuccess ? "修改成功。" : "修改失败!"; } } catch (Exception ex) { issuccess = false; msg = string.Format("{0} {1}", msg, ex.Message); } ReturnMsg(issuccess, enumReturnTitle.OptData, msg); }
/******** 获取数据 可修改区域 Start ********/ private Model.Attachment_Model GetNewDataModel(HttpContext context) { Model.Attachment_Model model = new Model.Attachment_Model(); if (IsEdit) { model = bll.GetModelByKeyValue(_pKeyValue); if (null == model) { throw new HasNotRecordException(_pKeyValue); } } model.AttachID = string.IsNullOrWhiteSpace(_pKeyValue) ? 0 : int.Parse(_pKeyValue); model.AttachGUID = UrlHelper.ReqStrByGetOrPost(context, "AttachGUID"); model.BatchGUID = UrlHelper.ReqStrByGetOrPost(context, "BatchGUID"); model.FileName = UrlHelper.ReqStrByGetOrPost(context, "FileName"); model.Fix = UrlHelper.ReqStrByGetOrPost(context, "Fix"); model.FileType = UrlHelper.ReqStrByGetOrPost(context, "FileType"); model.HasThumbnail = UrlHelper.ReqBoolByGetOrPost(context, "HasThumbnail"); model.URI = UrlHelper.ReqStrByGetOrPost(context, "URI"); model.RelativeURL = UrlHelper.ReqStrByGetOrPost(context, "RelativeURL"); model.FileSize = UrlHelper.ReqFloatByGetOrPost(context, "FileSize"); model.OrderNum = UrlHelper.ReqFloatByGetOrPost(context, "OrderNum"); model.Description = UrlHelper.ReqStrByGetOrPost(context, "Description"); model.MemberUpLoader = UrlHelper.ReqStrByGetOrPost(context, "MemberUpLoader"); model.UserUploader = UrlHelper.ReqStrByGetOrPost(context, "UserUploader"); return(model); }
/// <summary> /// 文件保存至附件表 /// </summary> /// <param name="FileName"></param> /// <returns></returns> public bool SaveToAttachment(string newFileName, string oldFileName, string guid, string attachGUID, string relativeFolder) { bool isOK = false; FileInfo f = new FileInfo(newFileName); Model.Attachment_Model model = new Model.Attachment_Model(); model.AttachGUID = attachGUID; model.BatchGUID = guid; model.FileName = f.Name; model.Fix = f.Extension; model.URI = f.FullName; model.RelativeURL = relativeFolder + "/" + f.Name;// WEB.Config.WebConfig.AttachmentFileFoler + "/" + f.Name; model.FileSize = f.Length; model.OrderNum = 0; model.Description = oldFileName;//.Substring(0,oldFileName.LastIndexOf('.')); model.UserUploader = WEB.Module.LoginManage.LoginHelper.CurrentUser.BaseInfo.LoginID; model.CreateTime = DateTime.Now; isOK = bll.AddModel(model); return(isOK); }