private static void LogSignIn() { LogLogins.Insert(DateTime.UtcNow, UserName, UserSecurityClass, UserStateCode, UserCountyCode, UserLocalCode, UserDesignCode, UserOrganizationCode, UserIssuesCode, UserPartyKey, UserPoliticianKey); }
public void GetData(string userName, DateTime startDate, DateTime endDate) { DataTable = LogLogins.GetDataByUserNameDateStampRange(userName, startDate, endDate); }
private static void LogSignIn() { LogLogins.Insert(DateTime.UtcNow, UserName, UserSecurityClass, UserStateCode, UserCountyCode, UserLocalKey, Empty, Empty, Empty, UserPartyKey, UserPoliticianKey); }
public static void Report() { // Get yesterday's activity var placeholder = new PlaceHolder(); var date = DateTime.UtcNow.Date.AddDays(-1); var logins = LogLogins.GetPoliticianLoginsByDateStampRange(date).Rows.OfType <DataRow>() .ToList(); var message = new HtmlP(); message.AddTo(placeholder); message.Style.Add(HtmlTextWriterStyle.FontFamily, "arial"); message.Style.Add(HtmlTextWriterStyle.FontSize, "8pt"); if (logins.Count == 0) { message.InnerText = $"There were no politician sign-ins on {date:d}"; } else { message.InnerText = $"These politicians signed in on {date:d}"; var lines = logins.Select(r => { var tr = new TableRow { TableSection = TableRowSection.TableBody }; new TableCell { Text = r.StateCode() }.AddTo(tr); new TableCell { Text = r.PoliticianKey() }.AddTo(tr); new TableCell { Text = Politicians.FormatName(r) }.AddTo(tr); new TableCell { Text = Offices.FormatOfficeName(r) }.AddTo(tr); new TableCell { Text = r.ElectionDescription() }.AddTo(tr); new TableCell { Text = r.LiveOfficeStatus() }.AddTo(tr); foreach (var td in tr.Controls.OfType <TableCell>()) { td.Style.Add(HtmlTextWriterStyle.BorderWidth, "1px"); td.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid"); td.Style.Add(HtmlTextWriterStyle.BorderColor, "#cccccc"); td.Style.Add(HtmlTextWriterStyle.Padding, "3px"); } return(tr); }); var table = new Table(); table.AddTo(placeholder); table.Style.Add(HtmlTextWriterStyle.BorderCollapse, "collapse"); table.Style.Add(HtmlTextWriterStyle.FontFamily, "arial"); table.Style.Add(HtmlTextWriterStyle.FontSize, "8pt"); table.Style.Add(HtmlTextWriterStyle.MarginTop, "20px"); // Add the heading row var thr = new TableHeaderRow(); thr.AddTo(table); thr.TableSection = TableRowSection.TableHeader; thr.Style.Add(HtmlTextWriterStyle.FontWeight, "bold"); thr.Style.Add(HtmlTextWriterStyle.Color, "#ffffff"); thr.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#666666"); new TableHeaderCell { Text = "State" }.AddTo(thr); new TableHeaderCell { Text = "Politician Key" }.AddTo(thr); new TableHeaderCell { Text = "Name" }.AddTo(thr); new TableHeaderCell { Text = "Office" }.AddTo(thr); new TableHeaderCell { Text = "Election" }.AddTo(thr); new TableHeaderCell { Text = "Status" }.AddTo(thr); foreach (var th in thr.Controls.OfType <TableHeaderCell>()) { th.Style.Add(HtmlTextWriterStyle.BorderWidth, "1px"); th.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid"); th.Style.Add(HtmlTextWriterStyle.BorderColor, "#666666"); th.Style.Add(HtmlTextWriterStyle.Padding, "3px"); th.Style.Add(HtmlTextWriterStyle.TextAlign, "left"); } foreach (var line in lines) { line.AddTo(table); } } SendEmails(placeholder, date); }
protected void ButtonRunReport_Click(object sender, EventArgs e) { try { #region Textbox Checks if (TextBoxLoginUser.Text.Trim() == string.Empty) { throw new ApplicationException("The Login Username is empty."); } if (!Is_Valid_Date(TextBoxFrom.Text.Trim())) { throw new ApplicationException("The From Date is not valid."); } if (!Is_Valid_Date(TextBoxTo.Text.Trim())) { throw new ApplicationException("The To Date is not valid."); } #endregion #region Login Username LabelUserName.Text = "Login User Name: " + TextBoxLoginUser.Text.Trim() + " From:" + TextBoxFrom.Text.Trim() + " To: " + TextBoxTo.Text.Trim(); #endregion var userName = TextBoxLoginUser.Text.Trim(); if (CheckBoxListLogs.Items[0].Selected) //LogLogins { TableLogins.Visible = true; #region LogLogins var htmlTable = new HtmlTable(); var tr = new HtmlTableRow().AddTo(htmlTable, "trReportDetail"); new HtmlTableCell { Align = "center", InnerHtml = "First Login" }.AddTo( tr, "tdReportDetailHeading"); new HtmlTableCell { Align = "center", InnerHtml = "Last Login" }.AddTo( tr, "tdReportDetailHeading"); new HtmlTableCell { Align = "center", InnerHtml = "Hours" }.AddTo( tr, "tdReportDetailHeading"); var date = Convert.ToDateTime(TextBoxFrom.Text.Trim()); var dateEnd = Convert.ToDateTime(TextBoxTo.Text.Trim()); var totalDuration = TimeSpan.MinValue; var days = 0; var totalHours = 0; while (dateEnd >= date) { var lowDate = date; var highDate = date.AddDays(1); var loginTable = LogLogins.GetDataByUserNameDateStampRange(userName, lowDate, highDate); if (loginTable.Count > 0) { var firstLogin = loginTable[0].DateStamp; var lastLogin = loginTable[loginTable.Count - 1].DateStamp; var duration = lastLogin - firstLogin; var hours = duration.Hours; tr = new HtmlTableRow().AddTo(htmlTable, "trReportDetail"); Add_Td_To_Tr(tr, firstLogin.ToString(CultureInfo.InvariantCulture), "tdReportDetail"); Add_Td_To_Tr(tr, lastLogin.ToString(CultureInfo.InvariantCulture), "tdReportDetail"); Add_Td_To_Tr(tr, duration.Hours.ToString(CultureInfo.InvariantCulture), "tdReportDetail"); totalDuration = totalDuration + duration; days++; totalHours += hours; } date = date.AddDays(1); } tr = Add_Tr_To_Table_Return_Tr(htmlTable, "trReportDetail"); Add_Td_To_Tr(tr, "Total", "tdReportDetail"); Add_Td_To_Tr(tr, "Days: " + days, "tdReportDetail"); Add_Td_To_Tr(tr, totalHours.ToString(CultureInfo.InvariantCulture), "tdReportDetail"); LabelLogins.Text = htmlTable.RenderToString(); #endregion } var beginDate = Convert.ToDateTime(TextBoxFrom.Text.Trim()); var endDate = Convert.ToDateTime(TextBoxTo.Text.Trim()); endDate = endDate.AddDays(1); if (CheckBoxListLogs.Items[1].Selected) //LogPoliticianAnswers { var table1 = LogPoliticianAnswers.GetBillingDataByUserNameDateStampRange(userName, beginDate, endDate); var table2 = LogDataChange.GetBillingDataByUserNameTableNameDateStampRange( userName, "Answers", beginDate, endDate); var dateList = table1.Select(row => row.DateStamp.Date) .Concat(table2.Select(row => row.DateStamp.Date)) .GroupBy(date => date) .Select(g => new DateCount { DateStamp = g.Key, Count = g.Count() }); TablePoliticianAnswers.Visible = true; //Control report = Report(dateList, "Answers", 40); Control report = Report(dateList, "Answers", 30); LabelPoliticianAnswers.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[2].Selected) //LogPoliticianAdds { var table = LogPoliticianAdds.GetBillingDataByUserNameDateStampRange(userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TablePoliticianAdds.Visible = true; Control report = Report(dateList, "Politician Adds", 20); LabelPoliticianAdds.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[3].Selected) //LogPoliticianChanges { var table1 = LogPoliticianChanges.GetBillingDataByUserNameDateStampRange(userName, beginDate, endDate); var table2 = LogDataChange.GetBillingDataByUserNameTableNameDateStampRange( userName, "Politicians", beginDate, endDate); var dateList = table1.Select(row => row.DateStamp.Date) .Concat(table2.Select(row => row.DateStamp.Date)) .GroupBy(date => date) .Select(g => new DateCount { DateStamp = g.Key, Count = g.Count() }); TablePoliticianChanges.Visible = true; //Control report = Report(dateList, "Politician Changes", 8); Control report = Report(dateList, "Politician Changes", 10); LabelPoliticianChanges.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[4].Selected) //LogElectionPoliticianAddsDeletes { var table = LogElectionPoliticianAddsDeletes.GetBillingDataByUserNameDateStampRange (userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TableElectionPoliticianAddsDeletes.Visible = true; Control report = Report(dateList, "Election Politician Adds Deletes", 15); LabelElectionPoliticianAddsDeletes.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[6].Selected) //LogElectionOfficeChanges { var table = LogElectionOfficeChanges.GetBillingDataByUserNameDateStampRange( userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TableElectionOfficeChanges.Visible = true; Control report = Report(dateList, "Election Office Changes", 15); LabelElectionOfficeChanges.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[7].Selected) //LogOfficeChanges { var table = LogOfficeChanges.GetBillingDataByUserNameDateStampRange(userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TableOfficeChanges.Visible = true; //Control report = Report(dateList, "Office Changes", 8); Control report = Report(dateList, "Office Changes", 10); LabelOfficeChanges.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[8].Selected) //LogOfficeOfficialAddsDeletes { var table = LogOfficeOfficialAddsDeletes.GetBillingDataByUserNameDateStampRange( userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TableOfficeOfficialsAdds.Visible = true; Control report = Report(dateList, "Office Official Adds Deletes", 15); LabelOfficeOfficialsAdds.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[9].Selected) //LogOfficeOfficialChanges { var table = LogOfficeOfficialChanges.GetBillingDataByUserNameDateStampRange( userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TableOfficeOfficialsChanges.Visible = true; Control report = Report(dateList, "Office Official Changes", 15); LabelOfficeOfficialsChanges.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[10].Selected) //LogPoliticiansImagesOriginal { var table1 = LogPoliticiansImagesOriginal.GetBillingDataByUserNameDateStampRange( userName, beginDate, endDate); var table2 = LogDataChange.GetBillingDataByUserNameTableNameDateStampRange( userName, "PoliticiansImagesBlobs", beginDate, endDate); var dateList = table1.Select(row => row.ProfileOriginalDate.Date) .Concat(table2.Select(row => row.DateStamp.Date)) .GroupBy(date => date) .Select(g => new DateCount { DateStamp = g.Key, Count = g.Count() }); TablePictureUploads.Visible = true; Control report = Report(dateList, "Picture Uploads", 60); LabelPictureUploads.Text = report.RenderToString(); } if (CheckBoxListLogs.Items[11].Selected) //LogAdminData { var table = LogAdminData.GetBillingDataByUserNameDateStampRange( userName, beginDate, endDate); var dateList = table.GroupBy(row => row.DateStamp.Date) .Select( group => new DateCount { DateStamp = group.Key, Count = group.Count() }); TableAdminDataUpdates.Visible = true; Control report = Report(dateList, "Admin Data Updates", 20); LabelAdminDataUpdates.Text = report.RenderToString(); } } catch (Exception ex) { Msg.Text = Fail(ex.Message); Log_Error_Admin(ex); } }