/// <summary> /// 文件保存 /// Created:20170329(ChengMengjia) /// </summary> /// <param name="entity"></param> /// <returns></returns> public JsonResult SaveFile(DeliverablesFiles entity, bool ReUpload) { JsonResult jsonreslut = new JsonResult(); try { string _id; entity.NodeID = entity.NodeID.Substring(0, 36); if (string.IsNullOrEmpty(entity.ID)) { new Repository <DeliverablesFiles>().Insert(entity, true, out _id); } else { DeliverablesFiles old = new Repository <DeliverablesFiles>().Get(entity.ID); old.Name = entity.Name; old.Desc = entity.Desc; old.Path = ReUpload ? entity.Path : old.Path; new Repository <DeliverablesFiles>().Update(old, true, out _id); } jsonreslut.data = _id; jsonreslut.result = true; jsonreslut.msg = "保存成功!"; } catch (Exception ex) { LogHelper.WriteException(ex, LogType.BussinessDLL); jsonreslut.result = false; jsonreslut.msg = ex.Message; } return(jsonreslut); }
/// <summary> /// 文件-编辑保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveFile_Click(object sender, EventArgs e) { DeliverablesFiles entity = new DeliverablesFiles(); entity.ID = txtFileName.Tag == null ? "" : txtFileName.Tag.ToString(); entity.NodeID = CurrentNode.ID; entity.Path = txtFilePath.Text; entity.Name = txtFileName.Text; entity.Desc = txtFileDesc.Text; #region 检查 if (string.IsNullOrEmpty(entity.Path)) { MessageHelper.ShowMsg(MessageID.W000000002, MessageType.Alert, "附件"); return; } if (string.IsNullOrEmpty(entity.Name)) { MessageHelper.ShowMsg(MessageID.W000000002, MessageType.Alert, "附件名称"); return; } #endregion #region 文件上传 //判断是否有选择文件上传 bool ReUpload = txtFilePath.Tag != null && txtFilePath.Tag.Equals(1); if (ReUpload) { entity.Path = FileHelper.UploadFile(entity.Path, UploadType.WBS, ProjectId, CurrentNode.ID); } #endregion if (string.IsNullOrEmpty(entity.Path)) { MessageHelper.ShowRstMsg(false); } else { JsonResult result = bll.SaveFile(entity, ReUpload); MessageHelper.ShowRstMsg(result.result); if (result.result) { btnClearFile_Click(sender, e); LoadFile(false); entity.Path = FileHelper.GetFilePath(UploadType.WBS, ProjectId, CurrentNode.ID, "") + entity.Path; EmailFiles.Add(entity); LoadEmailFile(); } } }
/// <summary> /// 邮件-添加附件 /// Created:20170411(ChengMengjia) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPAdd_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Multiselect = false; if (dialog.ShowDialog() == DialogResult.OK) { DeliverablesFiles entity = new DeliverablesFiles(); entity.ID = Guid.NewGuid().ToString(); entity.Path = dialog.FileName; string[] temp = dialog.SafeFileName.Split('.'); entity.Name = temp[0]; EmailFiles.Add(entity); LoadEmailFile(); } } }