//[ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "FileDataDetailId,FileDataId,FilePath,Status,UploadTime")] FileDataDetail fileDataDetail, FileDataDetail fDD, HttpPostedFileBase fileupload) { if (fileupload.ContentLength > 0) { string _FileName = Path.GetFileName(fileupload.FileName); string extension = Path.GetExtension(fileupload.FileName); _FileName = fDD.FileDataId + "-" + fDD.Status + extension; string _path = Path.Combine(Server.MapPath("~/App_Data/uploads"), _FileName); fDD.FilePath = _path; fDD.UploadTime = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"); fileupload.SaveAs(fDD.FilePath); } try { if (ModelState.IsValid) { db.FileDataDetails.Add(fDD); db.SaveChanges(); return(RedirectToAction("Index", new { filedataid = fDD.FileDataId })); } } catch (Exception ex) { TempData["Error"] = ex.Message; } return(View()); }
public ActionResult DeleteConfirmed(int id) { FileDataDetail fileDataDetail = db.FileDataDetails.Find(id); db.FileDataDetails.Remove(fileDataDetail); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "FileDataDetailId,FileDataId,FilePath,Status,UploadTime")] FileDataDetail fileDataDetail) { if (ModelState.IsValid) { db.Entry(fileDataDetail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FileDataId = new SelectList(db.FileDatas, "FileDataId", "Date", fileDataDetail.FileDataId); return(View(fileDataDetail)); }
// GET: FileDataDetail/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FileDataDetail fileDataDetail = db.FileDataDetails.Find(id); if (fileDataDetail == null) { return(HttpNotFound()); } return(View(fileDataDetail)); }
// GET: FileDataDetail/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FileDataDetail fileDataDetail = db.FileDataDetails.Find(id); if (fileDataDetail == null) { return(HttpNotFound()); } ViewBag.FileDataId = new SelectList(db.FileDatas, "FileDataId", "Date", fileDataDetail.FileDataId); return(View(fileDataDetail)); }
/// <summary> /// 读取文本文件的内容 /// </summary> /// <param name="path"></param> /// <returns></returns> private static List <FileDataDetail> GetFileDataDetailList(string sourcePath) { // 结果数据 List <FileDataDetail> fileDataDetailList = new List <FileDataDetail>(); bool isNewNode = true; // 是否为一个新的 <> 的开始 FileDataDetail fileDataDetail = null; // 一个<> 开始跟结束段,为一个数据详细信息 SerialPortConfigInfo serialPortConfigInfo = null; //串品配置信息 EquipmentInfo equipmentInfo = null; //设备信息 using (StreamReader sr = new StreamReader(sourcePath, Encoding.Default)) { string line = string.Empty; while (!string.IsNullOrEmpty(line = sr.ReadLine())) { #region 处理节点配置 <> 信息 if (line.StartsWith("<")) { //1、去掉 "<>" 截取字符串 本行主要内容 //记录带<>行的数据内容 string lineContent = line.Substring(1, line.Length - 2); // 2、读取形如:<02 zm Desc> if (lineContent.Contains(NameSplit)) { //设备信息 equipmentInfo = new EquipmentInfo(); equipmentInfo.Name = lineContent; fileDataDetail.EquipmentList.Add(equipmentInfo); continue; } // 2、读取形如:<串口配置> //第一次加载时,直接实例化一个FileDataDetail if (isNewNode) { fileDataDetail = new FileDataDetail(); fileDataDetail.Name = lineContent; fileDataDetailList.Add(fileDataDetail); isNewNode = false; continue; } // 3、读取形如:<串口配置结束> if (lineContent == (fileDataDetail.Name + "结束")) { isNewNode = true; continue; } } #endregion #region 读取数据段的内容 // 拆分行内容 string[] contents = line.Split(DataSplit); // 串口配置信息 if (fileDataDetail.Name == "串口配置") { serialPortConfigInfo = new SerialPortConfigInfo(); serialPortConfigInfo.DDC_ID = Convert.ToInt32(contents[0]); serialPortConfigInfo.Comm = Convert.ToInt32(contents[1]); serialPortConfigInfo.Baud = Convert.ToInt32(contents[2]); serialPortConfigInfo.DataBit = Convert.ToInt32(contents[3]); serialPortConfigInfo.StopBit = Convert.ToInt32(contents[4]); serialPortConfigInfo.Parity = contents[5]; serialPortConfigInfo.CNT_Resend = Convert.ToInt32(contents[6]); fileDataDetail.SerialPortList.Add(serialPortConfigInfo); } else // 如:大厅照明 的详细信息 { EquipmentConfigInfo equipmentConfigInfo = new EquipmentConfigInfo(); equipmentConfigInfo.DDC_ID = Convert.ToInt32(contents[0]); equipmentConfigInfo.VarType = contents[1]; equipmentConfigInfo.Func = contents[2]; equipmentConfigInfo.Offset = contents[3]; equipmentConfigInfo.Desc = contents[4]; equipmentConfigInfo.Unit = contents[5]; equipmentConfigInfo.Point = contents[6]; equipmentConfigInfo.Param1 = contents[7]; equipmentConfigInfo.Param2 = contents[8]; equipmentInfo.EquipmentConfigList.Add(equipmentConfigInfo); } #endregion } } return(fileDataDetailList); }
//[ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "Id,Date,Filename,Filenumber,Subject,Type,Givennumber,Pages,Addressee,Sectionoforigin,Receivedby,Status,Pdfdirectory")] FileData fileData, FileData FD, HttpPostedFileBase file, FileDataDetail filedatadetail) { FD.Receivedby = User.Identity.Name.ToString(); if (file.ContentLength > 0) { string _FileName = Path.GetFileName(file.FileName); string extension = Path.GetExtension(file.FileName); _FileName = FD.FileDataId + "-" + FD.Filename + FD.Status + extension; string _path = Path.Combine(Server.MapPath("~/App_Data/uploads"), _FileName); string uploadedfilename; uploadedfilename = _path; FD.Pdfdirectory = _FileName; // setting values for filedatadetails values filedatadetail.FileDataId = FD.FileDataId; filedatadetail.FilePath = _path; filedatadetail.Status = FD.Status; filedatadetail.UploadTime = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"); file.SaveAs(uploadedfilename); } try { if (ModelState.IsValid) { db.FileDatas.Add(FD); db.FileDataDetails.Add(filedatadetail); db.SaveChanges(); TempData["Msg"] = "Data Successfully Added"; return(RedirectToAction("Create")); } } catch (Exception ex) { TempData["mess"] = ex.Message; } return(View()); }