public ActionResult Create(Tender_TongZhi custf, HttpPostedFileBase[] fileToUpload,int id=0) { //if (ModelState.IsValid) //{ // tender_tongzhi.CreateDateT = DateTime.Now; // db.Tender_TongZhi.Add(tender_tongzhi); // db.SaveChanges(); // return RedirectToAction("Index"); //} //return View(tender_tongzhi); if (id == 3) return Content(""); HttpPostedFileBase file = null; if (fileToUpload != null) file = fileToUpload[0]; if (file != null && !String.IsNullOrEmpty(file.FileName)) { custf.CustFile = DateTime.Now.ToString("yyyyMMdd") + Guid.NewGuid().ToString("N"); Directory.CreateDirectory(Path.Combine(System.Web.Configuration.WebConfigurationManager.AppSettings["AttachmentRootPath"], (custf.CustFile.Substring(0, 4) + @"\" + custf.CustFile.Substring(4, 4) + @"\"))); file.SaveAs(Path.Combine(System.Web.Configuration.WebConfigurationManager.AppSettings["AttachmentRootPath"], (custf.CustFile.Substring(0, 4) + @"\" + custf.CustFile.Substring(4, 4) + @"\" + custf.CustFile.Substring(8)))); GenericDataAccess.UpdateBySql("Insert into YZAppAttachment(FileID,Name,Ext,Size,OwnerAccount) values(@FileID,@Name,@Ext,@Size,@OwnerAccount)", new string[,] { { "@FileID",custf.CustFile,"DbType.String",null }, { "@Name",Path.GetFileName(file.FileName),"DbType.String",null }, { "@Ext",Path.GetExtension(file.FileName),"DbType.String",null }, { "@Size",file.ContentLength.ToString(),"DbType.Int32",null }, { "@OwnerAccount","0","DbType.String",null } }); custf.CustName = Path.GetFileName(file.FileName); } custf.CreateDateT = System.DateTime.Now; db.Tender_TongZhi.Add(custf); db.SaveChanges(); //string fPath = @"D://myupload/" + file.FileName; //file.SaveAs(fPath); //string custT="nul"; //if(custf!=null) //{ // custT = custf.CustText; //} return Content("保存成功"); }
public ActionResult Edit(Tender_TongZhi tender_tongzhi) { if (ModelState.IsValid) { Tender_TongZhi ttz = db.Tender_TongZhi.Find(tender_tongzhi.TZID); //tender_tongzhi.CreateDateT = ttz.CreateDateT; //tender_tongzhi.CustFile = ttz.CustFile; //tender_tongzhi.CustName = ttz.CustName; ttz.TitleT = tender_tongzhi.TitleT; ttz.ContentT = tender_tongzhi.ContentT; db.Entry(ttz).State = EntityState.Modified; db.SaveChanges(); return Content("修改成功!"); } return Content("修改失败!"); }