public JsonResult SaveTimeSheet(List<TaskHours> TaskHours,TimeSheet ID)
{
try
{
foreach (TaskHours item in TaskHours)
{
if (TaskHours != null)
{
string date = item.ID.Split(':')[1];
char[] arrDate = date.ToArray();
var dt = DateTime.Parse("" +
arrDate[0] + arrDate[1] + "/" +
arrDate[2] + arrDate[3] + "/" +
arrDate[4] + arrDate[5] + arrDate[6] + arrDate[7]);
//Save Timesheet
TimeSheet timeSheet = new TimeSheet();
var thisWeekStart = dt.AddDays(-(int)dt.DayOfWeek);
var thisWeekEnd =
thisWeekStart.AddDays(7).AddSeconds(-1);
timeSheet.StartDate = thisWeekStart;
timeSheet.EndDate = thisWeekEnd;
db.TimeSheets.Add(timeSheet);
db.SaveChanges();
//Save Timehsheet data
TimeSheetData timesheetdata = new TimeSheetData();
timesheetdata.Date = dt;
string Hours = item.Value;
timesheetdata.Hours = Convert.ToDouble(Hours);
timesheetdata.TimeSheet = timeSheet;
string TaskID = item.ID.Split(':')[0];
timesheetdata.TaskID = Guid.Parse(TaskID);
db.TimesheetData.Add(timesheetdata);
db.SaveChanges();
}
}
//Get Timesheet date
return Json(new { Result = "OK", Message = "Task Hours has been
saved successfully" });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
}
}
当我将数据传递到文本框中时,数据很容易保存但是我 希望保存的数据显示在文本框中。我想要检索 来自数据库的数据并将其显示在文本框中。
如何检查该周是否存在时间表? 如果它没有显示空白时间表。 如果它确实存在,则从时间表数据表中加载该周数据,并将其以json格式传递给视图,然后显示数据。
如何做到这一点?