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); } }
protected void ButtonMoveQuestion_Click1(object sender, EventArgs e) { try { #region Checks Throw_Exception_TextBox_Script(Textbox_QuestionKey_Move_Question_From); Throw_Exception_TextBox_Html(Textbox_QuestionKey_Move_Question_From); Throw_Exception_TextBox_Script(Textbox_IssueKey_Move_To); Throw_Exception_TextBox_Html(Textbox_IssueKey_Move_To); //if (db.Row_Optional(sql.Question(Textbox_QuestionKey_Move_Question_From.Text.Trim())) == null) if (Row_Question_Optional(Textbox_QuestionKey_Move_Question_From.Text.Trim()) == null) { throw new ApplicationException("The QuestionKey(" + Textbox_QuestionKey_Move_Question_From.Text.Trim() + ") does not exist"); } if (Row_Optional(Issue(Textbox_IssueKey_Move_To.Text.Trim())) == null) { throw new ApplicationException("The IssueKey(" + Textbox_IssueKey_Move_To.Text.Trim() + ") does not exist."); } #endregion #region Remove all Cached pages for IssueKey - Needs to be done first before old question is deleted #region Remove Issue.aspx cached pages //db.Cache_Remove_Issue_Pages(Textbox_IssueKey_Move_To.Text.Trim()); //db.Cache_Remove_Issue_Pages(db.Questions_IssueKey(Textbox_QuestionKey_Move_Question_From.Text.Trim())); #endregion #region Remove PoliticianIssue.aspx cached pages //db.Cache_Remove_PoliticianIssue_Issue(Textbox_IssueKey_Move_To.Text.Trim()); //db.Cache_Remove_PoliticianIssue_Issue(db.Questions_IssueKey(Textbox_QuestionKey_Move_Question_From.Text.Trim())); #endregion #endregion //Create a new QuestionKey for the new Issue var newQuestionKey = Textbox_IssueKey_Move_To.Text.Trim(); newQuestionKey += MakeUnique6Digits(); //if (db.Row_Optional(sql.Question(NewQuestionKey)) != null) if (Row_Question_Optional(newQuestionKey) != null) { throw new ApplicationException("The new QuestionKey (" + newQuestionKey + ") already exist"); } //Update Questions with new QuestionKey and IssueKey var sqlText = "UPDATE Questions"; sqlText += " SET QuestionKey = " + SqlLit(newQuestionKey); sqlText += " ,IssueKey = " + SqlLit(Textbox_IssueKey_Move_To.Text.Trim()); sqlText += " WHERE QuestionKey = " + SqlLit(Textbox_QuestionKey_Move_Question_From.Text.Trim()); G.ExecuteSql(sqlText); //Update all the Answers with the new QuestionKey sqlText = "UPDATE Answers"; sqlText += " SET QuestionKey = " + SqlLit(newQuestionKey); sqlText += " ,IssueKey = " + SqlLit(Textbox_IssueKey_Move_To.Text.Trim()); sqlText += " WHERE QuestionKey = " + SqlLit(Textbox_QuestionKey_Move_Question_From.Text.Trim()); G.ExecuteSql(sqlText); LogPoliticianAnswers.UpdateIssueKeyByQuestionKey( Textbox_IssueKey_Move_To.Text.Trim(), Textbox_QuestionKey_Move_Question_From.Text.Trim() ); LogPoliticianAnswers.UpdateQuestionKeyByQuestionKey( newQuestionKey, Textbox_QuestionKey_Move_Question_From.Text.Trim() ); Msg.Text = Ok("Question: (" + Questions_Str( newQuestionKey , "Question" ) + ") has been moved to Issue (" + Issues_Issue(Textbox_IssueKey_Move_To.Text.Trim()) + ")"); } catch (Exception ex) { Msg.Text = Fail(ex.Message); Log_Error_Admin(ex); } }