public string Create(ProjMeeting projMeeting) { try { dbContext.ProjMeetings.Add(projMeeting); dbContext.SaveChanges(); return Constants.AJAX_CREATE_SUCCESS_RETURN; } catch (Exception e1) { return "<p class='alert alert-danger'>出错了: " + e1.Message + "</p>"; } }
/// <summary> /// 需求会议导入 /// </summary> /// <param name="worksheet"></param> /// <param name="fileName"></param> /// <returns></returns> private string ProjMeetingExcel(ExcelWorksheet worksheet, string fileName) { int rowStart = worksheet.Dimension.Start.Row; //工作区开始行号 int rowEnd = worksheet.Dimension.End.Row; //工作区结束行号 var ls = this.GetProjList(); for (int row = rowStart + 1; row <= rowEnd; row++) { // 第一列为空则结束 if (worksheet.Cells[row, 1] == null) break; // 第1列,项目名称 string projName = worksheet.Cells[row, 1].GetValue<string>(); // 项目名称转ProjID var p = ls.Find(a => a.ProjName == projName); int projId = p == null ? 0 : p.ProjID; ProjMeeting r = new ProjMeeting(); r.ProjID = projId; r.MeetingTopic = worksheet.Cells[row, 2].GetValue<string>(); r.MeetingType = worksheet.Cells[row, 3].GetValue<string>(); r.HostDept = worksheet.Cells[row, 4].GetValue<string>(); r.HostPerson = worksheet.Cells[row, 5].GetValue<string>(); r.ReviewExpert = worksheet.Cells[row, 6].GetValue<string>(); r.Participants = worksheet.Cells[row, 7].GetValue<string>(); r.NoticeNo = worksheet.Cells[row, 9].GetValue<string>(); r.ReviewConclusion = worksheet.Cells[row, 10].GetValue<string>(); r.MeetingConclusion = worksheet.Cells[row, 11].GetValue<string>(); r.Remark = worksheet.Cells[row, 12].GetValue<string>(); string meetingDate = worksheet.Cells[row, 8].GetValue<string>(); if (!string.IsNullOrEmpty(meetingDate)) r.MeetingDate = DateTime.Parse(meetingDate); dbContext.ProjMeetings.Add(r); } // 保存 int realNum = dbContext.SaveChanges(); return string.Format("<p class='alert alert-success'>《{0}》处理成功!共{1}条数据,实际导入{2}条数据</p>", fileName, rowEnd - rowStart, realNum); }
public string Edit(ProjMeeting projMeeting) { try { dbContext.Entry(projMeeting).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); return Constants.AJAX_EDIT_SUCCESS_RETURN; } catch (Exception e1) { return "<p class='alert alert-danger'>出错了: " + e1.Message + "</p>"; } }