Statistical data, click on the number to jump Details List (.net)

Page impressions:

Front Code:

<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"> Access Module Statistics </ ASP: the Label> <TR><Table ID = "tbYear" the runat = "Server" class = "Table-form"></ div>
</ div>



<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>  
<span class = "tooltip-icon" title = " datetime example: 2019/5/15 00:00:00, the day can be selected directly input start time to the query"> </ span> <div class = "td_btn_wapper"></ Table></ TR></ TD >
</ div>




<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>

 

Background Code:

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 Province Company)
{
ddlUnit.SelectByValue (user.Region.GetValue () ToString ().);
ddlUnit.Enabled = false;
}
// Set the date control
tbBeginDate.SetDatePicker ();
tbEndDate. SetDatePicker ();
// bind data
BindData ();
// bind user controls
piUser.SetSelectUsers ();
// select menu control module
piMenuResource.SetSelectMenuResource ();
}
}

void BindData public ()
{
#region data acquisition

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 table title, header
header.AddHeaderCell ( "construction unit");
header.AddHeaderCell ( "Total number of users");
header.AddHeaderCell ( "visits");
header.AddHeaderCell ( "visits per capita");
// dic.Add ( "construction unit", new List <string> ( ) { " The total number of users," "logins", "the number of times per landing"});
#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;
the foreach (Region Region in Regions)
{
the IList <String> = new new Data List <String> ();
// Number of users
int allUserCount = 0;
// Number of log
int allLoginCount = 0;
// log mean
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 ()); // area
data.Add (GetUrluseraccesspage (loginIds, allUserCount) ); // total number of users
data.Add (GetUrluseraccesspage (loginIds, allLoginCount) ); // login total
data.Add ( allLoginAvgCount.ToString ()); // Login mean
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>
/// Export Excel
/// </ Summary>
/// <param name = "SENDER"> </ param>
/// <param name = "E"> </ param>
protected void btnToExcel_Click (SENDER Object, EventArgs E)
{
the Workbook Workbook the Workbook new new = ();
the Worksheet Sheet workbook.Worksheets = [0];
sheet.Name = "access module statistics";
Cells Cell = sheet.Cells;
cell.SetColumnWidth (0, 20 is);
cell.SetColumnWidth (. 1, 25);
cell.SetColumnWidth (2, 25);
cell.SetColumnWidth (. 3, 25);
Cell [0, 0] .PutValue ( "building unit");
Cell [0,. 1 ] .PutValue ( "total number of users");
Cell [0, 2] .PutValue ( "visits");
Cell [0,. 3] .PutValue ( "visits per");
Aspose.Cells.Style style = workbook.Styles[workbook.Styles.Add()];
= TextAlignmentType.Center style.HorizontalAlignment;
style.ForegroundColor the System.Drawing.Color.FromArgb = (153, 204, 0);
style.Pattern = BackgroundType.Solid;
style.Font.IsBold = to true;
cell.SetRowHeight (0, 30 );
style.Borders [BorderType.LeftBorder] .LineStyle = CellBorderType.Thin; // left boundary line using the boundary line  
style.Borders [BorderType.RightBorder] .LineStyle = CellBorderType.Thin; // right boundary line using the boundary line  
style.Borders [ BorderType.TopBorder] .LineStyle = CellBorderType.Thin; // use the boundary line of the boundary line  
style.Borders [BorderType.BottomBorder] .LineStyle = CellBorderType.Thin; // application boundary lower boundary 
//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;// application boundary line right boundary line  
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 workbook.Styles = S // [workbook.Styles.Add ()];
// s.Borders [BorderType.LeftBorder] .LineStyle = CellBorderType.Thin; // left boundary line using the boundary line  
// s. Borders [BorderType.RightBorder] .LineStyle = CellBorderType.Thin; // right boundary line using the boundary line  
// s.Borders [BorderType.TopBorder] .LineStyle = CellBorderType.Thin ; // application boundary upper boundary  
// s.Borders [BorderType.BottomBorder] .LineStyle = CellBorderType.Thin; // lower boundary line using the boundary
// = s.IsTextWrapped to true;
// cell.SetRowHeight (I +. 1, 20 is);
// 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 ()];
= TextAlignmentType.Center sty.HorizontalAlignment;
sty.ForegroundColor = System.Drawing.Color.AliceBlue;
sty.Pattern = BackgroundType.Solid;
sty.Font.IsBold = to true;
sty.Borders [BorderType.LeftBorder] = CellBorderType.Thin .LineStyle ; // left boundary line using the boundary line  
sty.Borders [BorderType.RightBorder] .LineStyle = CellBorderType.Thin; // right boundary line using the boundary line  
sty.Borders [BorderType.TopBorder] .LineStyle = CellBorderType.Thin; // use the boundary line upper boundary line  
sty.Borders [BorderType.BottomBorder] .LineStyle = CellBorderType.Thin; // lower boundary line using the boundary 
Response.ContentType = "file application / vnd.ms-Excel";
Response.AppendHeader ( "the Content-Disposition", " attachment; filename = "+ HttpUtility.UrlEncode ( " access module statistics .xls "));
workbook.Save(Response.OutputStream, SaveFormat.Excel97To2003);
Response.End();

}

/// <Summary>
/// derived Detail List
/// </ Summary>
/// <param name = "SENDER"> </ param>
/// <param name = "E"> </ param>
protected btnToDetailExcel_Click void (SENDER Object, EventArgs E)
{
the Workbook Workbook the Workbook new new = ();
the Worksheet Sheet workbook.Worksheets = [0];
sheet.Name = "access module detail list";
Cells Cell = sheet.Cells;
cell.SetColumnWidth ( 0, 20 is);
cell.SetColumnWidth (. 1, 25);
cell.SetColumnWidth (2, 25);
cell.SetColumnWidth (. 3, 25);
Cell [0, 0] .PutValue ( "user");
Cell [0, 1] .PutValue ( "City place");
Cell [0, 2] .PutValue ( "module name");
Cell [0,. 3] .PutValue ( "access time");
Aspose.Cells.Style style = workbook.Styles[workbook.Styles.Add()];
= TextAlignmentType.Center style.HorizontalAlignment;
style.ForegroundColor the System.Drawing.Color.FromArgb = (153, 204, 0);
style.Pattern = BackgroundType.Solid;
style.Font.IsBold = to true;
cell.SetRowHeight (0, 30 );
style.Borders [BorderType.LeftBorder] .LineStyle = CellBorderType.Thin; // left boundary line using the boundary line  
style.Borders [BorderType.RightBorder] .LineStyle = CellBorderType.Thin; // right boundary line using the boundary line  
style.Borders [ BorderType.TopBorder] .LineStyle = CellBorderType.Thin; // use the boundary line of the boundary line  
style.Borders [BorderType.BottomBorder] .LineStyle = CellBorderType.Thin; // application boundary lower boundary 
for (int i = 0; i < . 4; I ++)
{
Cell [0, I] .setStyle (style);
}

Cond = new new UserAccessPageCondition UserAccessPageCondition ();
? = TbBeginDate.Text.ToDateTime the DateTime Start ();
? = TbEndDate.Text.ToDateTime the DateTime End ();
IF (start.HasValue && end.HasValue)
{
IF (end.Value <Start .Value)
{
divMessage.ShowMessageError ( "end time must be less than the start time, reselect!");
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());

S = workbook.Styles Aspose.Cells.Style [workbook.Styles.Add ()];
s.Borders [BorderType.LeftBorder] .LineStyle = CellBorderType.Thin; // left boundary line using the boundary line  
s.Borders [BorderType.RightBorder] .LineStyle = CellBorderType.Thin; // right boundary line using the boundary line  
s.Borders [BorderType.TopBorder] .LineStyle = CellBorderType.Thin; // application boundary upper boundary  
s.Borders [BorderType.BottomBorder] .LineStyle = CellBorderType. Thin; // application boundary lower boundary
s.IsTextWrapped = to true;
cell.SetRowHeight (I +. 1, 20 is);
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;
= System.Drawing.Color.AliceBlue sty.ForegroundColor;
sty.Pattern = BackgroundType.Solid;
sty.Font.IsBold = to true;
sty.Borders [BorderType.LeftBorder] .LineStyle = CellBorderType.Thin; // left boundary line using the boundary line  
sty.Borders [BorderType.RightBorder] .LineStyle = CellBorderType.Thin; // right boundary line using the boundary line  
sty.Borders [BorderType.TopBorder] .LineStyle = CellBorderType.Thin; // application boundary upper boundary  
sty.Borders [BorderType .BottomBorder] .LineStyle = CellBorderType.Thin; // lower boundary line using the boundary 
Response.ContentType = "file application / vnd.ms-Excel";
Response.AppendHeader ( "the Content-Disposition", "Attachment; filename =" + HttpUtility. UrlEncode ( "module to access detailed list .xls"));
workbook.Save (Response.OutputStream, SaveFormat.Excel97To2003);
Response.End ();

}

 

Select the menu controls, do a new pop page

<%@ 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>

Backstage

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);
}

Guess you like

Origin www.cnblogs.com/suqq/p/11130610.html