我有七个地点和14个状态。我已经对很多东西进行了硬编码,我想让它干涸。我把所有东西都变成了一个int数组。我试图对调查员进行一些研究,但我不确定它究竟是什么样的。
目前,我需要显示每个位置以计算每种状态的单位数。
"SELECT
SUM(CASE WHEN status = 'A' THEN 1 ELSE 0 END) AS A
,SUM(CASE WHEN status = 'B' THEN 1 ELSE 0 END) AS B
,SUM(CASE WHEN status = 'C' THEN 1 ELSE 0 END) AS C
,SUM(CASE WHEN status = 'D' THEN 1 ELSE 0 END) AS D
,SUM(CASE WHEN status = 'E' THEN 1 ELSE 0 END) AS E
,SUM(CASE WHEN status = 'F' THEN 1 ELSE 0 END) AS F
,SUM(CASE WHEN status = 'G' THEN 1 ELSE 0 END) AS G...
FROM TABLE WHERE location1 = @location"
//..
int[] result = new int[15];
//..
DataSet ds = new DataSet();
da.Fill(ds);
foreach (DataRow dRow in ds.Tables[0].Rows)
{
result[0] = (int)dRow["A"];
result[1] = (int)dRow["B"];
result[2] = (int)dRow["C"];
result[3] = (int)dRow["D"];
result[4] = (int)dRow["E"];
//..
}
return result;
我的控制器
private IEquipmentDapper dapper = new EquipmentDapper();
public ActionResult Index()
{
int[] AllLocationStatuses = dapper.CountAllStatuses();
ViewBag.TotalA = AllLocationStatuses[0];
ViewBag.TotalB = AllLocationStatuses[1];
ViewBag.TotalC = AllLocationStatuses[2];
ViewBag.TotalD = AllLocationStatuses[3];
ViewBag.TotalE = AllLocationStatuses[4];
//..
int[] Location1Statuses = dapper.CountStatusesByLocation();
ViewBag.Location1A = Location1Statuses[0];
ViewBag.Location1B = Location1Statuses[1];
ViewBag.Location1C = Location1Statuses[2];
//..
我的观点
<td>Total</td>
<td><span class="A"></span>@ViewBag.A A</td>
<td><span class="B"></span>@ViewBag.B B</td>
<td><span class="C"></span>@ViewBag.C C</td>
<td><span class="D"></span>@ViewBag.D D</td>