我想从数据库中计算每个用户的总叶子。并希望在Asp.Net MVC-3 (Aspx)的 Telerik gridview 中显示它。
我有一个两列的gridview。第一列显示所有员工/用户的姓名,第二列将显示该用户的总休假。
我的数据库如下
leave_master
leave_id(主键) user_id(外键与表 user_master 的 user_id) leave_days
用户主
user_id(主键) user_real_name
我的模型文件如下
名称 - LeaveGridview.cs
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace ProjectManagementSystem.Models
{
public class LeaveGridview
{
public int user_id { get; set; }
public string user_name { get; set; }
public string user_real_name { get; set; }
public int leave_id { get; set; }
public decimal leave_days { get; set; }
}
}
</pre>
第二个文件
名称 - LeaveGridviewFetch.cs
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjectManagementSystem.Models
{
public class LeaveGridviewFetch
{
public static IList<LeaveGridview> all()
{
IList<LeaveGridview> result =
(IList<LeaveGridview>)HttpContext.Current.Session["leave1"];
if (result == null)
{
HttpContext.Current.Session["leave1"] = result =
(from l in new ProjectManagementSystemEntities3().leave_master
select new LeaveGridview
{
user_id = l.user_id,
leave_id = l.leave_id,
user_real_name = l.user_master.user_real_name,
}).ToList();
}
return result;
}
}
}
</pre>
我的控制器文件名LeaveController.cs
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjectManagementSystem.Models;
using Telerik.Web.Mvc;
namespace LeaveModule.Controllers
{
public class LeaveController : Controller
{
public ProjectManagementSystemEntities3 pb = new ProjectManagementSystemEntities3();
public ActionResult LeaveShow()
{
var leave_master = pb.leave_master.Include("user_master");
ViewBag.leave_id = new SelectList(pb.user_master, "user_id", "user_real_name");
return View(leave_master.ToList());
}
[GridAction]
public ActionResult _SelectBatchEditing()
{
return View(new GridModel(LeaveGridviewFetch.all()));
}
}
}
</pre>
我的看法是
名称LeaveShow.ascx
<pre>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
LeaveShow
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% Html.Telerik().Grid<ProjectManagementSystem.Models.LeaveGridview>()
.Name("grid")
.DataKeys(keys =>
{
keys.Add(l => l.leave_id);
})
.DataBinding(dataBinding =>
dataBinding.Ajax()
.Select("_SelectBatchEditing", "Leave") // Leave is controller name
)
.Columns(columns =>
{
columns.Bound(l => l.user_real_name).Width(200);
columns.Bound(l => l.leave_days).Width(150);
})
.Groupable()
.Pageable()
.Filterable()
.Render();
%>
</asp:Content>
</pre>
我想像这样输出
名字---------------total_叶
abc---------------- 10
xyz---------------- 12
pqr---------------- 06
那么我该怎么做呢?
提前致谢...