Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.31 KB | None | 0 0
  1. my controller
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using System.Configuration;
  9. using System.Text;
  10. using System.Data.Common;
  11. using System.Data.SqlClient;
  12. using System.DirectoryServices;
  13. using System.Globalization;
  14.  
  15. using NLG_STUB.Constant.UserCheck;
  16. using NLG_STUB.DataAccess;
  17. using NLG_STUB.Models;
  18. using System.Data;
  19. using System.IO;
  20. using System.Web.UI;
  21. using System.Web.UI.WebControls;
  22. using PagedList;
  23.  
  24. //using ClosedXML;
  25. //using ClosedXML.Excel;
  26.  
  27. namespace NLG_STUB.Controllers
  28. {
  29. public class UsererrorcountController : Controller
  30. {
  31. string ADContainer = string.Empty;
  32. string ADLDAPUrl = string.Empty;
  33. string ADDomain = string.Empty;
  34. string ADDomainServer = string.Empty;
  35. string ADGlobalCatalog = string.Empty;
  36. static string ADCommonName = string.Empty;
  37.  
  38. public ActionResult Usererrorcount()
  39. {
  40. return View();
  41. }
  42. [NonAction]
  43. private void SetADEnvironmentParams(string environment)
  44. {
  45. switch (environment)
  46. {
  47. case "DEV":
  48. ADLDAPUrl = "LDAP://" + ConfigurationManager.AppSettings["DEV-Container"].ToString();
  49. ADDomain = ConfigurationManager.AppSettings["DEV-DomainServer"].ToString().ToUpper();
  50. break;
  51.  
  52. case "UAT":
  53. ADLDAPUrl = "LDAP://" + ConfigurationManager.AppSettings["UAT-Container"].ToString();
  54. ADDomain = ConfigurationManager.AppSettings["UAT-DomainServer"].ToString().ToUpper();
  55. break;
  56.  
  57. case "PROD":
  58. ADLDAPUrl = "LDAP://" + ConfigurationManager.AppSettings["PROD-Container"].ToString();
  59. ADDomain = ConfigurationManager.AppSettings["PROD-DomainServer"].ToString().ToUpper();
  60. break;
  61. }
  62. }
  63.  
  64. public ActionResult ErrorCount(string startDate, string endDate, string environment, int? pageNumber)
  65. {
  66.  
  67. Session["environment"] = environment;
  68. Session["StartDate"] = startDate;
  69. Session["EndDate"] = endDate;
  70. List<ErrorCountList> viewModel = new List<ErrorCountList>();
  71. List<ErrorCountList> empInfo = TempData["ErrorDetails"] as List<ErrorCountList>;
  72. TempData.Keep("ErrorDetails");
  73. viewModel = empInfo;
  74. viewModel = PoplulData(startDate, endDate, environment);
  75. TempData["ErrorDetails"] = viewModel;
  76. return View("_Error", viewModel.ToPagedList(pageNumber ?? 1, 10));
  77.  
  78.  
  79. }
  80. public ActionResult error(int? pageNumber)
  81. {
  82. List<ErrorCountList> viewModel = new List<ErrorCountList>();
  83. List<ErrorCountList> empInfo = TempData["ErrorDetails"] as List<ErrorCountList>;
  84. TempData.Keep("ErrorDetails");
  85. viewModel = empInfo;
  86. TempData["ErrorDetails"] = viewModel;
  87. return View("_Error", viewModel.ToPagedList(pageNumber ?? 1, 10));
  88.  
  89. }
  90.  
  91. [NonAction]
  92.  
  93. private List<ErrorCountList> PoplulData(string startDate, string endDate, string environment)
  94. {
  95. List<ErrorDetailsList> errorDetails = new List<ErrorDetailsList>();
  96.  
  97. string sqlCommand = string.Empty;
  98. string connectionString = string.Empty;
  99. if(environment.Contains("DEV"))
  100. connectionString=ConfigurationManager.ConnectionStrings["NLG_Excerption_Details_"+environment].ConnectionString;
  101. else if(environment.Contains("UAT"))
  102. connectionString = ConfigurationManager.ConnectionStrings["NLG_Excerption_Details_"+environment].ConnectionString;
  103. else if(environment.Contains("PROD"))
  104. connectionString = ConfigurationManager.ConnectionStrings["NLG_Excerption_Details_"+environment].ConnectionString;
  105. DateTime sDate = !string.IsNullOrEmpty(startDate) ? Convert.ToDateTime(startDate) : DateTime.Now;
  106. DateTime eDate = !string.IsNullOrEmpty(endDate) ? Convert.ToDateTime(endDate) : DateTime.Now;
  107. StringBuilder sb = new StringBuilder();
  108. sb.Append("select ExceptionMessage,UserId ");
  109. //sb.Append(" SELECT distinct ',' + (UserId)FROM [NLG_ExceptionLogging].[dbo].[srcExceptionLog] ");
  110. //sb.Append(" WHERE ExceptionMessage = A.ExceptionMessage and ");
  111. //sb.Append(" cast(Convert(varchar,Timestamp,100) as Date) >= cast(convert(varchar,'" + sDate + "',100) as date) and");
  112. //sb.Append("(cast(convert(varchar,timestamp,100)as date) <= cast(convert(varchar,'" + eDate + "',100) as date) )");
  113. //sb.Append("FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') ");
  114. sb.Append("FROM [NLG_ExceptionLogging].[dbo].[srcExceptionLog] A ");
  115. sb.Append("where cast(Convert(varchar,Timestamp,100) as Date) >= cast(convert(varchar,'" + sDate + "',100) as date) and");
  116. sb.Append("(cast(convert(varchar,timestamp,100)as date) <= cast(convert(varchar,'" + eDate + "',100) as date) )");
  117.  
  118.  
  119. sqlCommand = sb.ToString();
  120.  
  121. DataSet da = new DataSet();
  122.  
  123. using (SqlDataAdapter a = new SqlDataAdapter(sqlCommand, new SqlConnection(connectionString)))
  124. {
  125. a.Fill(da);
  126. }
  127.  
  128. if (da != null)
  129. {
  130. if (da.Tables[0].Rows.Count > 0)
  131. {
  132. for (int i = 0; i <= da.Tables[0].Rows.Count - 1; i++)
  133. {
  134. ErrorDetailsList errorDetail = new ErrorDetailsList();
  135. errorDetail.ExceptionMessage = da.Tables[0].Rows[i][0].ToString();
  136. errorDetail.UserId = da.Tables[0].Rows[i][1].ToString();
  137. errorDetails.Add(errorDetail);
  138. }
  139. }
  140. }
  141.  
  142.  
  143. List<ErrorCountList> errorCountList = new List<ErrorCountList>();
  144.  
  145. List<string> distinctErromessage = errorDetails.Select(x => x.ExceptionMessage).ToList();
  146. distinctErromessage = distinctErromessage.Distinct().Select(x => x).ToList();
  147. foreach (string exceptionMesage in distinctErromessage)
  148. {
  149. ErrorCountList item = new ErrorCountList();
  150. item.ExceptionMessage = exceptionMesage;
  151. item.count = errorDetails.Count(x => x.ExceptionMessage == exceptionMesage);
  152. List<string> distinctusers = errorDetails.Where(x => x.ExceptionMessage == exceptionMesage).Select(x => x.UserId).ToList();
  153. item.UserId = string.Join(",", distinctusers.Distinct().Select(x => x));
  154. errorCountList.Add(item);
  155. }
  156.  
  157.  
  158.  
  159.  
  160. //return View(errorCountList.ToPagedList(page ?? 1, 10));
  161. return errorCountList.OrderByDescending(x => x.count).ToList();
  162. }
  163. }
  164. }
  165.  
  166. my view:
  167.  
  168. 1
  169. @{
  170. ViewBag.Title = "Usererrorcount";
  171. }
  172.  
  173. <h2>Usererrorcount</h2>
  174.  
  175. <div id="SelectDateRange" >
  176. <html xmlns="http://www.w3.org/1999/xhtml">
  177. <head runat="server">
  178. <link rel="stylesheet" type="text/css" href="../../Content/themes/base/jquery.ui.datepicker.css" />
  179. <script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
  180. <script type="text/javascript">
  181. var AJAX_URL = '@Url.Action("Usererrorcount", "Usererrorcount")';
  182. function CheckErrorCount() {
  183.  
  184. var reg = $("#Environment option:selected").val();
  185. var Startdate = $('input[id*=Startdate]').val();
  186. var Enddate = $('input[id*=Enddate]').val();
  187.  
  188. location.href = '@Url.Action("ErrorCount", "Usererrorcount")?startDate=' + Startdate + '&endDate=' + Enddate + '&environment=' + reg;
  189. }
  190.  
  191. </script>
  192. <script src="../../Scripts/UserCheck.js" type="text/javascript"></script>
  193.  
  194.  
  195. </head>
  196. <body>
  197. <center>
  198. <label style="font-family: 'Tw Cen MT Condensed Extra Bold'; font-weight: bolder;
  199. font-size: x-large; font-variant: normal; text-transform: capitalize; color: #008000;
  200. background-color: #CCFFCC; text-align: center; text-align: center; width: 90pc;">
  201. Error Count</label>
  202. </center>
  203. <br />
  204. <center><p>Please provide date in mm/dd/yyyy format</p></center>
  205.  
  206. <table align="center" cellspacing="5" cellpadding="2" style="outline-style: solid;
  207. outline-color: Black; outline-width: medium">
  208. <tr>
  209. <td>
  210. Select Environment
  211. </td>
  212. <td>
  213. @Html.DropDownList("Environment", new List<SelectListItem>
  214. {
  215. new SelectListItem(){ Text= "DEV", Value = "DEV"},
  216.      new SelectListItem(){ Text= "UAT", Value = "UAT"},
  217.     
  218. }, "Select Environment", new { id="Environment" })
  219.  
  220.  
  221. </td>
  222. </tr>
  223. <tr>
  224.  
  225. <td>
  226. StartDate
  227. </td>
  228. <td>
  229. <input type="text" id= "Startdate" Value = @DateTime.Now.ToShortDateString() />
  230. </td>
  231. </tr>
  232. <tr>
  233. <td>
  234. EndDate
  235. </td>
  236. <td>
  237. <input type="text" id="Enddate" Value = @DateTime.Now.ToShortDateString() />
  238. </td>
  239. </tr>
  240.  
  241. <tr>
  242. <td colspan="2" align="center">
  243. <input type="button" id="btnCheckErrorCount" value="Check User Error Count" onclick="CheckErrorCount()" />
  244. </td>
  245. </tr>
  246.  
  247. </table>
  248. </body>
  249. </html>
  250.  
  251.  
  252.  
  253. view 2
  254. @using PagedList;
  255. @model PagedList.IPagedList<NLG_STUB.Models.ErrorCountList>
  256. <style>
  257. .linkEnlight
  258. {
  259. font-weight: bold;
  260. text-decoration: none;
  261. color: #569B42;
  262. }
  263. .linkEnlight:hover
  264. {
  265. text-decoration: underline;
  266. }
  267. .table
  268. {
  269. width: 50%;
  270. height: auto;
  271. }
  272.  
  273. .td
  274. {
  275. width: 50%;
  276. height: 50%;
  277. }
  278. </style>
  279. <style type="text/css">
  280. #groupInfo
  281. {
  282. font-family: Sans-Serif;
  283. border: 1px solid gray;
  284. border-left-style: none;
  285. border-right-style: none;
  286. font-size: 14px;
  287. }
  288. #groupInfo tr th
  289. {
  290. border-bottom: 1px solid gray;
  291. border-right: 1px solid gray;
  292. vertical-align: bottom;
  293. font-weight: bold;
  294. }
  295. #groupInfo tr th, td
  296. {
  297. border-right: 1px solid gray;
  298. font-size: 14px;
  299. }
  300. </style>
  301. <style type="text/css">
  302. table td
  303. {
  304. word-wrap: break-word;
  305. }
  306. </style>
  307.  
  308. <div id="ErrorDetails" style="width: 100%; padding-top: 25px; padding-left: 5px;
  309. font-family: Sans-Serif;">
  310. @if (Model != null && Model.Count > 0)
  311. {
  312.  
  313. <table cellpadding="0" cellspacing="0" style="border: 1px solid black; border-collapse: collapse;
  314. width: 100%; table-layout: fixed;">
  315. <tr>
  316. <th>
  317. @Html.LabelFor(a => a[0].ExceptionMessage)
  318. </th>
  319. <th style="text-align: Left; width: 10%;">
  320. @Html.LabelFor(a => a[0].count)
  321. </th>
  322. <th style="text-align: Left; width: 20%;">
  323. @Html.LabelFor(a => a[0].UserId)
  324. </th>
  325. </tr>
  326. @foreach (var item in Model)
  327. {
  328. <tr>
  329. <td>
  330. @Html.ActionLink(@item.ExceptionMessage, "ErrorDetails", "Usererrorsearcher", new { ExceptionMessage = @item.ExceptionMessage }, new { @class = "linkEnlight" })
  331. </td>
  332. <td>@item.count
  333. </td>
  334. <td>@item.UserId
  335. </td>
  336. </tr>
  337. }
  338. </table>
  339. }
  340. <br />
  341. <br />
  342. <div>
  343. <br />
  344. <table id="paging" cellpadding="2" cellspacing="5">
  345. <tr>
  346. <td class="DisplayText" style="width: 100%;" colspan="6">
  347. <p>
  348. You are now viewing records @((Model.PageNumber - 1) * 10 + 1)
  349. through @(Model.PageNumber * 10)
  350. of @(Model.PageCount * 10)
  351. Error Details records.</p>
  352. </td>
  353. </tr>
  354. <tr>
  355. @if (Model.PageNumber != 1)
  356. {
  357. <td style="width: 15%;">
  358. <input type="button" style="background-color: Green; color: White;" value="FIRST PAGE"
  359. onclick="getModifiedData(1)" />
  360. </td>
  361. }
  362. else
  363. {
  364. <td style="width: 15%;">
  365. <input type="button" style="background-image: none; background-color: rgb(176,176,176);"
  366. disabled="disabled" value="FIRST PAGE" onclick="getModifiedData(1)" />
  367. </td>
  368. }
  369. @if (Model.HasPreviousPage)
  370. {
  371. <td style="width: 20%;">
  372. <input type="button" style="background-color:Green;color:White;" value="PREVIOUS PAGE" onclick="getModifiedData(@Model.PageNumber-1)" />
  373. </td>
  374. }
  375. else
  376. {
  377. <td style="width: 20%;">
  378. <input type="button" style="background-image:none;background-color:rgb(176,176,176);" disabled="disabled" value="PREVIOUS PAGE" onclick="getModifiedData(@Model.PageNumber-1)" />
  379. </td>
  380. }
  381. @if (Model.HasNextPage)
  382. {
  383. <td style="width: 15%;">
  384. <input type="button" style="background-color:Green;color:White;" value="NEXT PAGE" onclick="getModifiedData(@Model.PageNumber+1)" />
  385. </td>
  386. }
  387. else
  388. {
  389. <td style="width: 15%;">
  390. <input type="button" style="background-image:none;background-color:rgb(176,176,176);" disabled="disabled" value="NEXT PAGE" onclick="getModifiedData(@Model.PageNumber+1)" />
  391. </td>
  392. }
  393. @if (Model.PageCount != Model.PageNumber)
  394. {
  395. <td style="width: 15%;">
  396. <input type="button" style="background-color:Green;color:White;" value="LAST PAGE" onclick="getModifiedData(@Model.PageCount)" />
  397. </td>
  398. }
  399. else
  400. {
  401. <td style="width: 15%;">
  402. <input type="button" style="background-image:none;background-color:rgb(176,176,176);" disabled="disabled" value="LAST PAGE" onclick="getModifiedData(@Model.PageCount)" />
  403. </td>
  404. }
  405. <td style="width: 15%;">
  406. <a href="#" style="text-decoration: none;"><span class="DisplayLabel" style="color: Green;
  407. font-weight: bold;">Go To Top </span></a>
  408. </td>
  409. <td style="width: 25%;">
  410. <p class="DisplayLabel" style="font-weight: normal;">
  411. Page @Model.PageNumber of @Model.PageCount</p>
  412. </td>
  413. </tr>
  414. </table>
  415. </div>
  416. @if (@Model.Count == 0)
  417. {
  418.  
  419. <p>
  420. <span class="DisplayText" style="color: Red;">No Records found </span>
  421. </p>
  422.  
  423. }
  424. </div>
  425. <div id="divErrorDetailsNew" style="width: 100%; padding-top: 25px; padding-left: 5px;
  426. font-family: Sans-Serif;">
  427. <script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>
  428. <script type="text/javascript">
  429.  
  430.  
  431. function getModifiedData(pageNo) {
  432. SerachData = { "pageNumber": pageNo }
  433. var MyAppUrlSettings = {
  434. RedirectUrl: '@Url.Action("error", "Usererrorcount")'
  435. }
  436.  
  437. $.ajax({
  438. url: MyAppUrlSettings.RedirectUrl,
  439. contentType: 'application/json; charset=utf-8',
  440. type: "GET",
  441. data: SerachData,
  442. dataType: "html",
  443. success: function (data) {
  444. //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;">');
  445.  
  446. $('#divErrorDetailsNew').html(data);
  447. }
  448. });
  449.  
  450.  
  451.  
  452. }
  453. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement