Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my controller
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Configuration;
- using System.Text;
- using System.Data.Common;
- using System.Data.SqlClient;
- using System.DirectoryServices;
- using System.Globalization;
- using NLG_STUB.Constant.UserCheck;
- using NLG_STUB.DataAccess;
- using NLG_STUB.Models;
- using System.Data;
- using System.IO;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using PagedList;
- //using ClosedXML;
- //using ClosedXML.Excel;
- namespace NLG_STUB.Controllers
- {
- public class UsererrorcountController : Controller
- {
- string ADContainer = string.Empty;
- string ADLDAPUrl = string.Empty;
- string ADDomain = string.Empty;
- string ADDomainServer = string.Empty;
- string ADGlobalCatalog = string.Empty;
- static string ADCommonName = string.Empty;
- public ActionResult Usererrorcount()
- {
- return View();
- }
- [NonAction]
- private void SetADEnvironmentParams(string environment)
- {
- switch (environment)
- {
- case "DEV":
- ADLDAPUrl = "LDAP://" + ConfigurationManager.AppSettings["DEV-Container"].ToString();
- ADDomain = ConfigurationManager.AppSettings["DEV-DomainServer"].ToString().ToUpper();
- break;
- case "UAT":
- ADLDAPUrl = "LDAP://" + ConfigurationManager.AppSettings["UAT-Container"].ToString();
- ADDomain = ConfigurationManager.AppSettings["UAT-DomainServer"].ToString().ToUpper();
- break;
- case "PROD":
- ADLDAPUrl = "LDAP://" + ConfigurationManager.AppSettings["PROD-Container"].ToString();
- ADDomain = ConfigurationManager.AppSettings["PROD-DomainServer"].ToString().ToUpper();
- break;
- }
- }
- public ActionResult ErrorCount(string startDate, string endDate, string environment, int? pageNumber)
- {
- Session["environment"] = environment;
- Session["StartDate"] = startDate;
- Session["EndDate"] = endDate;
- List<ErrorCountList> viewModel = new List<ErrorCountList>();
- List<ErrorCountList> empInfo = TempData["ErrorDetails"] as List<ErrorCountList>;
- TempData.Keep("ErrorDetails");
- viewModel = empInfo;
- viewModel = PoplulData(startDate, endDate, environment);
- TempData["ErrorDetails"] = viewModel;
- return View("_Error", viewModel.ToPagedList(pageNumber ?? 1, 10));
- }
- public ActionResult error(int? pageNumber)
- {
- List<ErrorCountList> viewModel = new List<ErrorCountList>();
- List<ErrorCountList> empInfo = TempData["ErrorDetails"] as List<ErrorCountList>;
- TempData.Keep("ErrorDetails");
- viewModel = empInfo;
- TempData["ErrorDetails"] = viewModel;
- return View("_Error", viewModel.ToPagedList(pageNumber ?? 1, 10));
- }
- [NonAction]
- private List<ErrorCountList> PoplulData(string startDate, string endDate, string environment)
- {
- List<ErrorDetailsList> errorDetails = new List<ErrorDetailsList>();
- string sqlCommand = string.Empty;
- string connectionString = string.Empty;
- if(environment.Contains("DEV"))
- connectionString=ConfigurationManager.ConnectionStrings["NLG_Excerption_Details_"+environment].ConnectionString;
- else if(environment.Contains("UAT"))
- connectionString = ConfigurationManager.ConnectionStrings["NLG_Excerption_Details_"+environment].ConnectionString;
- else if(environment.Contains("PROD"))
- connectionString = ConfigurationManager.ConnectionStrings["NLG_Excerption_Details_"+environment].ConnectionString;
- DateTime sDate = !string.IsNullOrEmpty(startDate) ? Convert.ToDateTime(startDate) : DateTime.Now;
- DateTime eDate = !string.IsNullOrEmpty(endDate) ? Convert.ToDateTime(endDate) : DateTime.Now;
- StringBuilder sb = new StringBuilder();
- sb.Append("select ExceptionMessage,UserId ");
- //sb.Append(" SELECT distinct ',' + (UserId)FROM [NLG_ExceptionLogging].[dbo].[srcExceptionLog] ");
- //sb.Append(" WHERE ExceptionMessage = A.ExceptionMessage and ");
- //sb.Append(" cast(Convert(varchar,Timestamp,100) as Date) >= cast(convert(varchar,'" + sDate + "',100) as date) and");
- //sb.Append("(cast(convert(varchar,timestamp,100)as date) <= cast(convert(varchar,'" + eDate + "',100) as date) )");
- //sb.Append("FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') ");
- sb.Append("FROM [NLG_ExceptionLogging].[dbo].[srcExceptionLog] A ");
- sb.Append("where cast(Convert(varchar,Timestamp,100) as Date) >= cast(convert(varchar,'" + sDate + "',100) as date) and");
- sb.Append("(cast(convert(varchar,timestamp,100)as date) <= cast(convert(varchar,'" + eDate + "',100) as date) )");
- sqlCommand = sb.ToString();
- DataSet da = new DataSet();
- using (SqlDataAdapter a = new SqlDataAdapter(sqlCommand, new SqlConnection(connectionString)))
- {
- a.Fill(da);
- }
- if (da != null)
- {
- if (da.Tables[0].Rows.Count > 0)
- {
- for (int i = 0; i <= da.Tables[0].Rows.Count - 1; i++)
- {
- ErrorDetailsList errorDetail = new ErrorDetailsList();
- errorDetail.ExceptionMessage = da.Tables[0].Rows[i][0].ToString();
- errorDetail.UserId = da.Tables[0].Rows[i][1].ToString();
- errorDetails.Add(errorDetail);
- }
- }
- }
- List<ErrorCountList> errorCountList = new List<ErrorCountList>();
- List<string> distinctErromessage = errorDetails.Select(x => x.ExceptionMessage).ToList();
- distinctErromessage = distinctErromessage.Distinct().Select(x => x).ToList();
- foreach (string exceptionMesage in distinctErromessage)
- {
- ErrorCountList item = new ErrorCountList();
- item.ExceptionMessage = exceptionMesage;
- item.count = errorDetails.Count(x => x.ExceptionMessage == exceptionMesage);
- List<string> distinctusers = errorDetails.Where(x => x.ExceptionMessage == exceptionMesage).Select(x => x.UserId).ToList();
- item.UserId = string.Join(",", distinctusers.Distinct().Select(x => x));
- errorCountList.Add(item);
- }
- //return View(errorCountList.ToPagedList(page ?? 1, 10));
- return errorCountList.OrderByDescending(x => x.count).ToList();
- }
- }
- }
- my view:
- 1
- @{
- ViewBag.Title = "Usererrorcount";
- }
- <h2>Usererrorcount</h2>
- <div id="SelectDateRange" >
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <link rel="stylesheet" type="text/css" href="../../Content/themes/base/jquery.ui.datepicker.css" />
- <script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
- <script type="text/javascript">
- var AJAX_URL = '@Url.Action("Usererrorcount", "Usererrorcount")';
- function CheckErrorCount() {
- var reg = $("#Environment option:selected").val();
- var Startdate = $('input[id*=Startdate]').val();
- var Enddate = $('input[id*=Enddate]').val();
- location.href = '@Url.Action("ErrorCount", "Usererrorcount")?startDate=' + Startdate + '&endDate=' + Enddate + '&environment=' + reg;
- }
- </script>
- <script src="../../Scripts/UserCheck.js" type="text/javascript"></script>
- </head>
- <body>
- <center>
- <label style="font-family: 'Tw Cen MT Condensed Extra Bold'; font-weight: bolder;
- font-size: x-large; font-variant: normal; text-transform: capitalize; color: #008000;
- background-color: #CCFFCC; text-align: center; text-align: center; width: 90pc;">
- Error Count</label>
- </center>
- <br />
- <center><p>Please provide date in mm/dd/yyyy format</p></center>
- <table align="center" cellspacing="5" cellpadding="2" style="outline-style: solid;
- outline-color: Black; outline-width: medium">
- <tr>
- <td>
- Select Environment
- </td>
- <td>
- @Html.DropDownList("Environment", new List<SelectListItem>
- {
- new SelectListItem(){ Text= "DEV", Value = "DEV"},
- new SelectListItem(){ Text= "UAT", Value = "UAT"},
- }, "Select Environment", new { id="Environment" })
- </td>
- </tr>
- <tr>
- <td>
- StartDate
- </td>
- <td>
- <input type="text" id= "Startdate" Value = @DateTime.Now.ToShortDateString() />
- </td>
- </tr>
- <tr>
- <td>
- EndDate
- </td>
- <td>
- <input type="text" id="Enddate" Value = @DateTime.Now.ToShortDateString() />
- </td>
- </tr>
- <tr>
- <td colspan="2" align="center">
- <input type="button" id="btnCheckErrorCount" value="Check User Error Count" onclick="CheckErrorCount()" />
- </td>
- </tr>
- </table>
- </body>
- </html>
- view 2
- @using PagedList;
- @model PagedList.IPagedList<NLG_STUB.Models.ErrorCountList>
- <style>
- .linkEnlight
- {
- font-weight: bold;
- text-decoration: none;
- color: #569B42;
- }
- .linkEnlight:hover
- {
- text-decoration: underline;
- }
- .table
- {
- width: 50%;
- height: auto;
- }
- .td
- {
- width: 50%;
- height: 50%;
- }
- </style>
- <style type="text/css">
- #groupInfo
- {
- font-family: Sans-Serif;
- border: 1px solid gray;
- border-left-style: none;
- border-right-style: none;
- font-size: 14px;
- }
- #groupInfo tr th
- {
- border-bottom: 1px solid gray;
- border-right: 1px solid gray;
- vertical-align: bottom;
- font-weight: bold;
- }
- #groupInfo tr th, td
- {
- border-right: 1px solid gray;
- font-size: 14px;
- }
- </style>
- <style type="text/css">
- table td
- {
- word-wrap: break-word;
- }
- </style>
- <div id="ErrorDetails" style="width: 100%; padding-top: 25px; padding-left: 5px;
- font-family: Sans-Serif;">
- @if (Model != null && Model.Count > 0)
- {
- <table cellpadding="0" cellspacing="0" style="border: 1px solid black; border-collapse: collapse;
- width: 100%; table-layout: fixed;">
- <tr>
- <th>
- @Html.LabelFor(a => a[0].ExceptionMessage)
- </th>
- <th style="text-align: Left; width: 10%;">
- @Html.LabelFor(a => a[0].count)
- </th>
- <th style="text-align: Left; width: 20%;">
- @Html.LabelFor(a => a[0].UserId)
- </th>
- </tr>
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.ActionLink(@item.ExceptionMessage, "ErrorDetails", "Usererrorsearcher", new { ExceptionMessage = @item.ExceptionMessage }, new { @class = "linkEnlight" })
- </td>
- <td>@item.count
- </td>
- <td>@item.UserId
- </td>
- </tr>
- }
- </table>
- }
- <br />
- <br />
- <div>
- <br />
- <table id="paging" cellpadding="2" cellspacing="5">
- <tr>
- <td class="DisplayText" style="width: 100%;" colspan="6">
- <p>
- You are now viewing records @((Model.PageNumber - 1) * 10 + 1)
- through @(Model.PageNumber * 10)
- of @(Model.PageCount * 10)
- Error Details records.</p>
- </td>
- </tr>
- <tr>
- @if (Model.PageNumber != 1)
- {
- <td style="width: 15%;">
- <input type="button" style="background-color: Green; color: White;" value="FIRST PAGE"
- onclick="getModifiedData(1)" />
- </td>
- }
- else
- {
- <td style="width: 15%;">
- <input type="button" style="background-image: none; background-color: rgb(176,176,176);"
- disabled="disabled" value="FIRST PAGE" onclick="getModifiedData(1)" />
- </td>
- }
- @if (Model.HasPreviousPage)
- {
- <td style="width: 20%;">
- <input type="button" style="background-color:Green;color:White;" value="PREVIOUS PAGE" onclick="getModifiedData(@Model.PageNumber-1)" />
- </td>
- }
- else
- {
- <td style="width: 20%;">
- <input type="button" style="background-image:none;background-color:rgb(176,176,176);" disabled="disabled" value="PREVIOUS PAGE" onclick="getModifiedData(@Model.PageNumber-1)" />
- </td>
- }
- @if (Model.HasNextPage)
- {
- <td style="width: 15%;">
- <input type="button" style="background-color:Green;color:White;" value="NEXT PAGE" onclick="getModifiedData(@Model.PageNumber+1)" />
- </td>
- }
- else
- {
- <td style="width: 15%;">
- <input type="button" style="background-image:none;background-color:rgb(176,176,176);" disabled="disabled" value="NEXT PAGE" onclick="getModifiedData(@Model.PageNumber+1)" />
- </td>
- }
- @if (Model.PageCount != Model.PageNumber)
- {
- <td style="width: 15%;">
- <input type="button" style="background-color:Green;color:White;" value="LAST PAGE" onclick="getModifiedData(@Model.PageCount)" />
- </td>
- }
- else
- {
- <td style="width: 15%;">
- <input type="button" style="background-image:none;background-color:rgb(176,176,176);" disabled="disabled" value="LAST PAGE" onclick="getModifiedData(@Model.PageCount)" />
- </td>
- }
- <td style="width: 15%;">
- <a href="#" style="text-decoration: none;"><span class="DisplayLabel" style="color: Green;
- font-weight: bold;">Go To Top </span></a>
- </td>
- <td style="width: 25%;">
- <p class="DisplayLabel" style="font-weight: normal;">
- Page @Model.PageNumber of @Model.PageCount</p>
- </td>
- </tr>
- </table>
- </div>
- @if (@Model.Count == 0)
- {
- <p>
- <span class="DisplayText" style="color: Red;">No Records found </span>
- </p>
- }
- </div>
- <div id="divErrorDetailsNew" style="width: 100%; padding-top: 25px; padding-left: 5px;
- font-family: Sans-Serif;">
- <script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>
- <script type="text/javascript">
- function getModifiedData(pageNo) {
- SerachData = { "pageNumber": pageNo }
- var MyAppUrlSettings = {
- RedirectUrl: '@Url.Action("error", "Usererrorcount")'
- }
- $.ajax({
- url: MyAppUrlSettings.RedirectUrl,
- contentType: 'application/json; charset=utf-8',
- type: "GET",
- data: SerachData,
- dataType: "html",
- success: function (data) {
- //var result = data.replace('<div id="ErrorDetails" style="width: 100%; padding-top: 25px; padding-left: 5px;font-family: Sans-Serif;">', '<div id="ErrorDetails" style="visibility: hidden; display:inline; width: 100%; padding-top: 25px; padding-left: 5px;font-family: Sans-Serif;">');
- $('#divErrorDetailsNew').html(data);
- }
- });
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement