/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, NosaworkresultEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
public string SaveForm() { string templatePath = ""; string templateName = ""; int count = HttpContext.Request.Files.Count; if (count > 0) { var file = Request.Files[0]; templateName = file.FileName; if (!string.IsNullOrWhiteSpace(templateName)) { string sufx = System.IO.Path.GetExtension(file.FileName); templatePath = string.Format("~/Resource/NosaWorkResult/{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), sufx); string filename = Server.MapPath(templatePath); var path = System.IO.Path.GetDirectoryName(filename); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } file.SaveAs(filename); } } var keyValue = Request["ID"]; var workId = Request["WorkId"]; NosaworkresultEntity entity = null; if (!string.IsNullOrWhiteSpace(keyValue)) { entity = nosaworkresultbll.GetEntity(keyValue); if (!string.IsNullOrWhiteSpace(templateName)) { string filename = Server.MapPath(entity.TemplatePath); if (System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } } } if (entity == null) { entity = new NosaworkresultEntity() { ID = keyValue }; } entity.WorkId = workId; entity.Name = Request["Name"]; entity.TemplatePath = !string.IsNullOrWhiteSpace(templatePath) ? templatePath : entity.TemplatePath; entity.TemplateName = !string.IsNullOrWhiteSpace(templateName) ? templateName : entity.TemplateName; nosaworkresultbll.SaveForm(keyValue, entity); return("保存成功。"); }