统计数据,点击数字跳转详情列表(.net)

页面展示:

前台代码:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
function useraccesspage(obj) {
$("form:gt(0)").remove();
var v = $(obj).next().attr("value");
var diyForm = "<form action='../stat/user-access-page-stat.aspx' method='post' target='_blank'><input type='hidden' name='useraccesspageIds' value='" + v + "'></form>";
$("form:eq(0)").append(diyForm);
$("form:eq(1)").submit();
}
</script>
<style>
.tree table tr td {
border: none !important
}

.popup-text {
width: 400px !important;
height: 22px;
padding-left: 10px;
background: #FFFFFF;
border: 1px solid #e0e0e0;
text-align: left;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="Server">
<div class="message-container" id="divMessage" runat="server" enableviewstate="false">
</div>
<div class="list_container">
<div class="list-form">
<div class="list-tittle">
<div class="blue">
<asp:Label ID="lbl2015" runat="server">模块访问统计</asp:Label>
</div>
</div>
<table id="tbYear" runat="server" class="form-table">
<tr>
<td>选择模块</td>
<td>
<%--<div class="content" style=" width: 100%; overflow-y: scroll">--%>
<div class="td_margin">
<eafwc:PopupInput ID="piMenuResource" runat="server"></eafwc:PopupInput>
<%--</div>--%>
</div>
</td>
</tr>
<%--<tr>
<td style="width: 248px">模块名称</td>
<td>
<div class="td_margin">
<asp:TextBox ID="txtPage" runat="server"></asp:TextBox>
</div>
</td>
</tr>--%>
<tr>
<td>建设单位</td>
<td>
<div class="td_margin">
<asp:DropDownList ID="ddlUnit" runat="server"></asp:DropDownList>
</div>
</td>
</tr>
<tr>
<td>选择用户</td>
<td>
<div class="td_margin">
<eafwc:PopupInput ID="piUser" runat="server" CssClass="width-long"></eafwc:PopupInput>
</div>
</td>
</tr>
<tr>
<td>访问时间</td>
<td>
<div class="td_margin">
<asp:TextBox ID="tbBeginDate" placeholder="请输入开始时间" runat="server"></asp:TextBox>
<span style="display: block; float: left; margin: 0 10px;">-</span>
<asp:TextBox ID="tbEndDate" placeholder="请输入结束时间" runat="server"></asp:TextBox>&nbsp;&nbsp;
<span class="tooltip-icon" title="日期时间 例如:2019/5/15 00:00:00,选择当天的可直接输入开始时间即可查询"></span>
</div>
</td>
</tr>
</table>
<div class="td_btn_wapper">
<asp:Button ID="btnImport" runat="server" Text="统计" OnClientClick="AddRunningDiv()" OnClick="btnImport_Click" />
<asp:Button ID="btnToExcel" runat="server" Text="导出" OnClick="btnToExcel_Click" />
<asp:Button ID="btnToDetailExcel" runat="server" Text="导出详细" OnClick="btnToDetailExcel_Click" />
</div>
<table id="htblResult" runat="server" class="list-table table_con">
</table>
</div>

</div>
</asp:Content>

后台代码:

public IList<IList<string>> RowDatas
{
get
{
return (IList<IList<string>>)ViewState["RowDatas"];
}
set
{
ViewState["RowDatas"] = value;
}
}
private IList<int> MenuResourceIds
{
get { return (IList<int>)ViewState["MenuResourceIds"]; }
set { ViewState["MenuResourceIds"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//绑定建设单位
ddlUnit.DataBind(Enum<Region>.AsEnumerable().Select(s => new ListItem(s.GetText(), s.GetValue().ToString())), ControlDefine.LISTITEM_SELECT);
User user = Auth.GetUserReq();
if (user.Region != Region.省公司)
{
ddlUnit.SelectByValue(user.Region.GetValue().ToString());
ddlUnit.Enabled = false;
}
//设置日期控件
tbBeginDate.SetDatePicker();
tbEndDate.SetDatePicker();
//绑定数据
BindData();
//绑定用户控件
piUser.SetSelectUsers();
//选择菜单模块控件
piMenuResource.SetSelectMenuResource();
}
}

public void BindData()
{
#region 获取数据

DateTime? benginTime = tbBeginDate.Text.ToDateTime();
DateTime? endTime = tbEndDate.Text.ToDateTime();
if (endTime < benginTime)
{
divMessage.ShowMessageError("结束日期不能小于开始日期");
return;
}
Region? region = ddlUnit.SelectedValue.ToEnum<Region>();
//string page = txtPage.Text.Trim();
IList<int> user = piUser.Value.SplitInt(",");
IList<IList<string>> dataList = new List<IList<string>>();
IList<int> pageIds= piMenuResource.Value.SplitInt(",");
Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();//存储查询的数据
HtmlTableRow header = new HtmlTableRow();

#region 表题,表头
header.AddHeaderCell("建设单位");
header.AddHeaderCell("用户总数");
header.AddHeaderCell("访问次数");
header.AddHeaderCell("人均访问次数");
//dic.Add("建设单位", new List<string>() { "用户总数", "登录次数", "人均登陆次数" });
#endregion

dataList = GetValue(benginTime, endTime, pageIds, user, region, dic);
RowDatas = dataList;


htblResult.Rows.Add(header);
foreach (IList<string> list in dataList)
{
HtmlTableRow row = new HtmlTableRow();
foreach (string s in list)
{
row.AddCell(s);
}
htblResult.Rows.Add(row);
}
#endregion
}
protected void btnImport_Click(object sender, EventArgs e)
{
BindData();//统计查询
}

private IList<IList<string>> GetValue(DateTime? benginTime, DateTime? endTime, IList<int> pageIds, IList<int> user, Region? r, Dictionary<string, List<string>> dic)
{
IList<IList<string>> dataList = new List<IList<string>>();

IList<Region> regions = RegionExtensionMethod.GetSortedRegion(Enum<Region>.AsEnumerable().ToList());
User currentUser = Auth.GetUserReq();
if (!currentUser.IsAdmin() && !currentUser.IsProvince())
regions = regions.Where(s => s.GetValue().ToString() == currentUser.Region.GetValue().ToString()).ToList();

UserAccessPageCondition condition = new UserAccessPageCondition();
if (benginTime.HasValue)
condition.DateGEQ = benginTime.Value;
if (endTime.HasValue)
condition.DateLSS = endTime.Value;
if (pageIds.Count>0)
condition.PageIdIn = pageIds;
if (user.Count > 0)
{
condition.UserIdIn = user;
}
if (r.HasValue)
{
condition.Region = r.Value;
regions = regions.Where(s => s.GetValue().ToString() == r.GetValue().ToString()).ToList();
}
IList<UserAccessPage> userAccessPageList = IoCContainer.Get<IUserAccessPageDao>().Select(condition);
int userList = 0;
int loginList = 0;
int avgList = 0;
foreach (Region region in regions)
{
IList<string> data = new List<string>();
//用户总数
int allUserCount = 0;
//登录总数
int allLoginCount = 0;
//登录均数
int allLoginAvgCount = 0;

IList<int> userIds = userAccessPageList.Where(s => s.Region == region).Select(s => s.UserId).Distinct().ToList();
allUserCount = userIds.Count();

IList<int> loginIds = userAccessPageList.Where(s => s.Region == region).Select(s => s.Id).ToList();
allLoginCount = loginIds.Count();

if (allUserCount > 0 && allLoginCount > 0)
allLoginAvgCount = Convert.ToInt32(Convert.ToDecimal(allLoginCount) / Convert.ToDecimal(allUserCount));

data.Add(region.GetShortName());//地区
data.Add(GetUrluseraccesspage(loginIds, allUserCount));//用户总数
data.Add(GetUrluseraccesspage(loginIds, allLoginCount));//登录总数
data.Add(allLoginAvgCount.ToString());//登录均数
dataList.Add(data);

if (allUserCount > 0)
{
userList += allUserCount;
}
if (allLoginCount > 0)
{
loginList += allLoginCount;
}
if (allLoginAvgCount > 0)
{
avgList += allLoginAvgCount;
}
dic.Add(region.GetShortName(), new List<string>() { allUserCount.ToString(), allLoginCount.ToString(), allLoginAvgCount.ToString() });
}
IList<string> dataTotal = new List<string>();
dataTotal.Add("总计");
dataTotal.Add(GetUrluseraccesspage(userAccessPageList.Select(s => s.Id).ToList(), userList));
dataTotal.Add(GetUrluseraccesspage(userAccessPageList.Select(s => s.Id).ToList(), loginList));
dataTotal.Add(avgList.ToString());
dataList.Add(dataTotal);
dic.Add("总计", new List<string>() { userList.ToString(), loginList.ToString(), avgList.ToString() });
ViewState["Result"] = dic;
return dataList;
}

/// <summary>
/// 获取Id 传参 查询对应的数据详细
/// </summary>
/// <param name="Ids"></param>
/// <param name="count"></param>
/// <returns></returns>
private string GetUrluseraccesspage(IList<int> Ids, decimal count)
{
if (Ids.Count == 0)
{
return count.ToString();
}
string useraccesspageIds = Ids.JoinToString(",");
return "<a href=\"javascript:void(0)\" onclick=\"useraccesspage(this)\" >" + count + "</a><input type=\"hidden\" value=\"" + useraccesspageIds + "\"/>";

}

/// <summary>
/// 导出excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnToExcel_Click(object sender, EventArgs e)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "模块访问统计";
Cells cell = sheet.Cells;
cell.SetColumnWidth(0, 20);
cell.SetColumnWidth(1, 25);
cell.SetColumnWidth(2, 25);
cell.SetColumnWidth(3, 25);
cell[0, 0].PutValue("建设单位");
cell[0, 1].PutValue("用户总数");
cell[0, 2].PutValue("访问次数");
cell[0, 3].PutValue("人均访问次数");
Aspose.Cells.Style style = workbook.Styles[workbook.Styles.Add()];
style.HorizontalAlignment = TextAlignmentType.Center;
style.ForegroundColor = System.Drawing.Color.FromArgb(153, 204, 0);
style.Pattern = BackgroundType.Solid;
style.Font.IsBold = true;
cell.SetRowHeight(0, 30);
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线 
//cell.Merge(1,1,2,2);
for (int i = 0; i < 4; i++)
{
cell[0, i].SetStyle(style);
}
Dictionary<string, List<string>> dic = ViewState["Result"] as Dictionary<string, List<string>>;
int t = 0;
foreach (var temp in dic)
{
t = t + 1;
//sb.AppendLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\"", temp.Key, temp.Value[0], temp.Value[1], temp.Value[2]));
cell[t, 0].PutValue(temp.Key);
cell[t, 1].PutValue(temp.Value[0]);
cell[t, 2].PutValue(temp.Value[1]);
cell[t, 3].PutValue(temp.Value[2]);
Aspose.Cells.Style s = workbook.Styles[workbook.Styles.Add()];
s.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
s.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
s.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
s.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
s.IsTextWrapped = true;
cell.SetRowHeight(t, 20);
cell[t, 0].SetStyle(s);
cell[t, 1].SetStyle(s);
cell[t, 2].SetStyle(s);
cell[t, 3].SetStyle(s);
}
//for (int i = 0; i < list.Count; i++)
//{
// cell[i + 1, 0].PutValue(list[i].UserChineseName);
// cell[i + 1, 1].PutValue(list[i].Region.GetText());
// cell[i + 1, 2].PutValue(list[i].Page);
// cell[i + 1, 3].PutValue(list[i].Date.ToString());

// Aspose.Cells.Style s = workbook.Styles[workbook.Styles.Add()];
// s.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
// s.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
// s.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
// s.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
// s.IsTextWrapped = true;
// cell.SetRowHeight(i + 1, 20);
// cell[i + 1, 0].SetStyle(s);
// cell[i + 1, 1].SetStyle(s);
// cell[i + 1, 2].SetStyle(s);
// cell[i + 1, 3].SetStyle(s);
//}
Aspose.Cells.Style sty = workbook.Styles[workbook.Styles.Add()];
sty.HorizontalAlignment = TextAlignmentType.Center;
sty.ForegroundColor = System.Drawing.Color.AliceBlue;
sty.Pattern = BackgroundType.Solid;
sty.Font.IsBold = true;
sty.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
sty.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
sty.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
sty.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线 
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("模块访问统计.xls"));
workbook.Save(Response.OutputStream, SaveFormat.Excel97To2003);
Response.End();

}

/// <summary>
/// 导出明细列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnToDetailExcel_Click(object sender, EventArgs e)
{
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "模块访问明细列表";
Cells cell = sheet.Cells;
cell.SetColumnWidth(0, 20);
cell.SetColumnWidth(1, 25);
cell.SetColumnWidth(2, 25);
cell.SetColumnWidth(3, 25);
cell[0, 0].PutValue("用户");
cell[0, 1].PutValue("所属地市");
cell[0, 2].PutValue("模块名称");
cell[0, 3].PutValue("访问时间");
Aspose.Cells.Style style = workbook.Styles[workbook.Styles.Add()];
style.HorizontalAlignment = TextAlignmentType.Center;
style.ForegroundColor = System.Drawing.Color.FromArgb(153, 204, 0);
style.Pattern = BackgroundType.Solid;
style.Font.IsBold = true;
cell.SetRowHeight(0, 30);
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线 
for (int i = 0; i < 4; i++)
{
cell[0, i].SetStyle(style);
}

UserAccessPageCondition cond = new UserAccessPageCondition();
DateTime? start = tbBeginDate.Text.ToDateTime();
DateTime? end = tbEndDate.Text.ToDateTime();
if (start.HasValue && end.HasValue)
{
if (end.Value < start.Value)
{
divMessage.ShowMessageError("结束时间不能小于开始时间,请重新选择!");
return;
}
}
if (start.HasValue)
cond.DateGEQ = start.Value;
if (end.HasValue)
cond.DateLSS = end.Value;

IList<int> pageIds = piMenuResource.Value.SplitInt(",");
if (pageIds.Count > 0)
cond.PageIdIn = pageIds;
Region? region = ddlUnit.SelectedValue.ToEnum<Region>();
if (region.HasValue)
{
cond.Region = region.Value;
}
IList<UserAccessPage> list = IoCContainer.Get<IUserAccessPageDao>().Select(cond).OrderByDescending(s => s.Date).ToList();
for (int i = 0; i < list.Count; i++)
{
cell[i + 1, 0].PutValue(list[i].UserChineseName);
cell[i + 1, 1].PutValue(list[i].Region.GetText());
cell[i + 1, 2].PutValue(list[i].Page);
cell[i + 1, 3].PutValue(list[i].Date.ToString());

Aspose.Cells.Style s = workbook.Styles[workbook.Styles.Add()];
s.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
s.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
s.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
s.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
s.IsTextWrapped = true;
cell.SetRowHeight(i + 1, 20);
cell[i + 1, 0].SetStyle(s);
cell[i + 1, 1].SetStyle(s);
cell[i + 1, 2].SetStyle(s);
cell[i + 1, 3].SetStyle(s);
}
Aspose.Cells.Style sty = workbook.Styles[workbook.Styles.Add()];
sty.HorizontalAlignment = TextAlignmentType.Center;
sty.ForegroundColor = System.Drawing.Color.AliceBlue;
sty.Pattern = BackgroundType.Solid;
sty.Font.IsBold = true;
sty.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线  
sty.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
sty.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线  
sty.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线 
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("模块访问明细列表.xls"));
workbook.Save(Response.OutputStream, SaveFormat.Excel97To2003);
Response.End();

}

选择菜单控件,新做的一个弹窗页面

<%@ Import Namespace="EAF.Utility.Web" %>
<asp:Content ContentPlaceHolderID="head" runat="Server">
<style>
table.pageTable {
border-collapse: collapse;
width: 100%;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border: 1px solid #a8aeb2;
}
</style>
</asp:Content>
<asp:Content ContentPlaceHolderID="content" runat="Server">
<div class="list-form">
<div class="list-tittle">
<div class="no-blue">
<asp:Label ID="lblTitle" runat="server" Text=""></asp:Label>
</div>
</div>
<table runat="server" class="pageTable">
<tr style="border: 1px solid #a8aeb2">
<td>选择模块:</td>
<td>
<div class="td_margin">
<asp:TreeView ID="tvMenuResource" CssClass="tree" BorderStyle="None" runat="server" ShowCheckBoxes="All"></asp:TreeView>
</div>
</td>
</tr>
</table>
<div class="button-container-popup">
<asp:Button ID="btSave" runat="server" Text="确定" OnClick="btSave_OnClick" />
<asp:Button ID="btnClear" runat="server" Text="清除" OnClick="btnClear_OnClick" />
</div>
</div>
</asp:Content>

后台

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
tvMenuResource.Attributes.Add("onclick", "CheckEvent(event)");
tvMenuResource.CollapseAll();
IList<MenuResource> list = IoCContainer.Get<IMenuResourceDao>().SelectUserMenu();
BindTree(list);
}
}

private void BindTree(IList<MenuResource> list)
{
IList<MenuResource> listRoots = list.Where(s => s.No.Length < 5).OrderBy(s => s.Index).ToList();

tvMenuResource.Nodes.Clear();

foreach (var item in listRoots)
{
TreeNode tnParent = new TreeNode();
tnParent.Text = item.NodeName;
tnParent.Value = item.Id.ToString();
tnParent.SelectAction = TreeNodeSelectAction.Expand;
tnParent.ShowCheckBox = false;
tvMenuResource.Nodes.Add(tnParent);
BindNode(tnParent, list.Where(s => s.No.StartsWith(item.No) && s.Id != item.Id).ToList());
}
tvMenuResource.CollapseAll();
}
private void BindNode(TreeNode parentNode, IList<MenuResource> list)
{
List<MenuResource> childMenus = list.Where(s => s.ParentId == parentNode.Value.ToInt32Req()).OrderBy(s => s.Index).ToList();
foreach (var item in childMenus)
{
TreeNode childNode = new TreeNode();
childNode.Value = item.Id.ToString();
childNode.Text = item.NodeName;
List<MenuResource> child = list.Where(s => s.ParentId == item.Id).OrderBy(s => s.Index).ToList();
if (child.Count==0)
{
childNode.ShowCheckBox = true;
}
else
childNode.ShowCheckBox = false;
childNode.SelectAction = TreeNodeSelectAction.None;
parentNode.ChildNodes.Add(childNode);
BindNode(childNode, list);
}
}


protected void btSave_OnClick(object sender, EventArgs e)
{
IList<int> ids = new List<int>();
foreach (TreeNode item in tvMenuResource.CheckedNodes)
{
int i = item.Value.ToInt32Req();
ids.Add(i);
}
IList<MenuResource> mList = IoCContainer.Get<IMenuResourceDao>().SelectByIds(ids);
PopupInput.Return(mList.Select(s=>s.NodeName).JoinToString(","), mList.Select(s=>s.Id).Count() > 0 ? mList.Select(s=>s.Id).JoinToString(",") : string.Empty);
}

protected void btnClear_OnClick(object sender, EventArgs e)
{
PopupInput.Return(string.Empty, string.Empty);
}

猜你喜欢

转载自www.cnblogs.com/suqq/p/11130610.html