我在数据库中有两个表,分别是ProjectList和TaskList。TaskList表列是任务名称,描述,开始日期,结束日期,状态,项目。项目列存储项目名称。每个项目都有任务号。我有两个视图,分别是ProjectDetails,TaskDetails。我将根据项目名称动态获取ProjectDetails页面,它将重定向到TaskDetails页面。现在,我需要基于Tasks(已完成任务总数/总任务总数)计算每个任务的项目百分比。
如何实现这一目标,请帮助我。
ProjectDetails页面的代码如下
@foreach (var item in Model)
{
@if (item.ProjectStatus == "OnGoing")
{
<div class="col-lg-4 col-md-12 cur-pointer">
<div class="card">
<div class="card-header">
<h5 class="card-title">@Html.DisplayFor(modelItem => item.ProjectName)</h5>
<div class="card-options">
<a asp-action="EditProject" asp-route-id="@item.ProjectID">
<i class="fa fa-edit icon-size icon-align"></i>
</a>
<a href="#" class="card-options-collapse" data-toggle="card-collapse"></a>
</div>
</div>
<a asp-action="AllTask" asp-route-id="@item.ProjectName" style="color:#000 !important">
<div class="card-body cur-pointer">
<p class="tag tag-blue mb-3">@Html.DisplayFor(modelItem => item.ProjectStatus)</p>
<p>@Html.DisplayFor(modelItem => item.ProjectDescription)</p>
<div class="row">
<div class="col-5 py-1"><strong>Scope:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.ProjectScope)</div>
<div class="col-5 py-1"><strong>Family:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.ProjectFamily)</div>
<div class="col-5 py-1"><strong>Bucket:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.ProjectBucket)</div>
<div class="col-5 py-1"><strong>Manager:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.Manager)</div>
<div class="col-5 py-1"><strong>Start Date:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.StartDate)</div>
<div class="col-5 py-1"><strong>End Date:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.EndDate)</div>
<div class="col-5 py-1"><strong>Cost:</strong></div>
<div class="col-7 py-1">@Html.DisplayFor(modelItem => item.Budget)</div>
</div>
</div>
<div class="float-left"><strong>**TaskPErcentage**%</strong></div>
<div class="float-right"><small class="text-muted">Progress</small>'
</div>
</a>
</div>
</div>
}
}
我的控制器是:
public IActionResult AllProject()
{
List<Project> lstProject = new List<Project>();
lstProject = objproject.GetAllProject().ToList();
return View(lstProject);
}
答案 0 :(得分:0)
在TaskDetails页面中:可能是您正在从ProjectDetails获取与各个ProjectName相关的所有任务。 因此,只需根据任务状态在foreach内部进行操作即可:
before foreach : $completed = $totalTask = 0;
$totalTask++;
@if(item.ProjectStatus == "completed")
{
$completed++;
}
$percentage = ((int)$completed / (int) $totalTask ) * 100