public ActionResult Create([Bind(Include = "Id,BillTypeNumber,BillTypeName,BillNumber,ContractNumber,FirstParty,SecondParty,SignDate,DueDate,Amount,ContractObject,ContractAttachmentType,ContractAttachmentName,ContractAttachmentUrl,Remark")] Contract contract, HttpPostedFileBase file) { if (ModelState.IsValid) { //{if (file != null) // contract.ContractAttachmentType = file.ContentType;//获取图片类型 // contract.ContractAttachment = new byte[file.ContentLength];//新建一个长度等于图片大小的二进制地址 // file.InputStream.Read(contract.ContractAttachment, 0, file.ContentLength);//将image读取到Logo中 //} if (!HasFiles.HasFile(file)) { ModelState.AddModelError("", "文件不能为空!"); return(View(contract)); } string miniType = file.ContentType; Stream fileStream = file.InputStream; string path = AppDomain.CurrentDomain.BaseDirectory + "files\\"; string filename = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(path, filename)); contract.ContractAttachmentType = miniType; contract.ContractAttachmentName = filename; contract.ContractAttachmentUrl = Path.Combine(path, filename); db.Contracts.Add(contract);//存储到数据库 db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contract)); }
public ActionResult Create(Contract contract1, HttpPostedFileBase file) { if (ModelState.IsValid) { if (HasFiles.HasFile(file)) { string miniType = file.ContentType; Stream fileStream = file.InputStream; string path = AppDomain.CurrentDomain.BaseDirectory + "files\\"; string filename = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(path, filename)); contract1.ContractAttachmentType = miniType; contract1.ContractAttachmentName = filename; contract1.ContractAttachmentUrl = Path.Combine(path, filename); } contract1.RecordTime = DateTime.Now; contract1.RecordPerson = base.Name; byte status = AuditApplicationContract(contract1); //需要对原表做出的修改 contract1.AuditStatus = status; db.Contracts.Add(contract1);//存储到数据库 db.SaveChanges(); //没有找到该单据的审批模板 if (status == 7) { ViewBag.alertMessage = true; ContractViewModel contract = new ContractViewModel(); contract.BillTypeNumber = contract1.BillTypeNumber; contract.BillNumber = contract1.BillNumber; contract.Department = Request["Department"]; contract.ContractNumber = contract1.ContractNumber; contract.SecondParty = contract1.SecondParty; contract.SignDate = contract1.SignDate; contract.DueDate = contract1.DueDate; contract.Amount = contract1.Amount; contract.ContractObject = contract1.ContractObject; contract.Remark = contract1.Remark; ViewBag.company = this.CompanyFullName; var fieldList1 = (from p in db.ReserveFields join q in db.TableNameContrasts on p.TableNameId equals q.Id where q.TableName == "Contracts" && p.Status == true select p).ToList(); ViewBag.fieldList = fieldList1; return(View(contract)); } var fieldList = (from p in db.ReserveFields join q in db.TableNameContrasts on p.TableNameId equals q.Id where q.TableName == "Contracts" && p.Status == true select p).ToList(); ViewBag.fieldList = fieldList; /*遍历,保存员工基本信息预留字段*/ foreach (var temp in fieldList) { ContractReserve cr = new ContractReserve(); cr.Number = contract1.Id; cr.FieldId = temp.Id; cr.Value = Request[temp.FieldName]; /*占位,为了在Index中显示整齐的格式*/ if (cr.Value == null) { cr.Value = " "; } db.ContractReserves.Add(cr); db.SaveChanges(); } return(RedirectToAction("Index")); } else { ViewBag.company = this.CompanyFullName; var fieldList = (from p in db.ReserveFields join q in db.TableNameContrasts on p.TableNameId equals q.Id where q.TableName == "Contracts" && p.Status == true select p).ToList(); ViewBag.fieldList = fieldList; ContractViewModel contract = new ContractViewModel(); contract.BillTypeNumber = contract1.BillTypeNumber; contract.BillNumber = contract1.BillNumber; contract.Department = Request["Department"]; contract.ContractNumber = contract1.ContractNumber; contract.SecondParty = contract1.SecondParty; contract.SignDate = contract1.SignDate; contract.DueDate = contract1.DueDate; contract.Amount = contract1.Amount; contract.ContractObject = contract1.ContractObject; contract.Remark = contract1.Remark; //contract.AuditPerson = contract1.AuditPerson; //contract.AuditStatusName = contract1.AuditStatusName; //contract.AuditStatus = contract1.AuditStatus; return(View(contract)); } }