Exemple #1
0
        protected void ButtonUploadPictureProfile_ServerClick(object sender,
                                                              EventArgs e)
        {
            try
            {
                var postedFile    = Request.Files[ImageFileProfile.Name];
                var politicianKey = LabelPoliticianKey.Text;
                var uploadTime    = DateTime.UtcNow;

                if ((postedFile == null) || (postedFile.ContentLength == 0))
                {
                    return;
                }
                Size originalSize;
                ImageManager.UpdatePoliticianProfileImages(politicianKey,
                                                           postedFile.InputStream, uploadTime, out originalSize);
                CommonCacheInvalidation.ScheduleInvalidation("politicianimage",
                                                             politicianKey);

                // We only want to propagate the profile to the headshot if there
                // is no current Headshot -- we check Headshot100
                if (PoliticiansImagesBlobs.GetHeadshot100(politicianKey) == null)
                {
                    ImageManager.UpdateResizedPoliticianHeadshotImages(politicianKey,
                                                                       postedFile.InputStream, uploadTime, out originalSize);
                }

                var memoryStream = new MemoryStream();
                postedFile.InputStream.Position = 0;
                postedFile.InputStream.CopyTo(memoryStream);
                postedFile.InputStream.Position = 0;
                var imageBlob = memoryStream.ToArray();
                LogPoliticiansImagesOriginal.Insert(politicianKey, imageBlob, uploadTime,
                                                    UserSecurityClass, UserName, 0);

                UpdateRowCountAfterChange();

                Msg.Text =
                    Ok("The profile image for ID " + politicianKey + " was uploaded.");
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
        internal static byte[] GetLoggedImageByDate(string politicianKey, DateTime date)
        {
            byte[] blob          = null;
            var    originalTable = LogPoliticiansImagesOriginal
                                   .GetDataByPoliticianKeyProfileOriginalDate(politicianKey, date);

            if (originalTable.Count == 1)
            {
                blob = originalTable[0].ProfileOriginal;
            }
            else
            {
                var newOriginalsTable = LogDataChange
                                        .GetDataByTableNameColumnNameKeyValuesDateStamp("PoliticiansImagesBlobs",
                                                                                        "ProfileOriginal", politicianKey, date);
                if (newOriginalsTable.Count == 1)
                {
                    blob = Convert.FromBase64String(newOriginalsTable[0].NewValue);
                }
            }
            return(blob);
        }
Exemple #3
0
        protected void ButtonRevertToLog_ServerClick(object sender, EventArgs e)
        {
            try
            {
                var    politicianKey = LabelPoliticianKey.Text;
                string user;
                var    latestLogDate =
                    LogDataChange.GetSecondLatestProfileImageDate(politicianKey, out user);

                var logTime    = new DateTime(latestLogDate.Ticks);
                var loggedBlob = LatestLoggedImagePage.GetLoggedImageByDate(
                    politicianKey, logTime);
                if ((latestLogDate == DefaultDbDate) || (loggedBlob == null) ||
                    (loggedBlob.Length == 0))
                {
                    Msg.Text =
                        Fail("No log profile image for ID " + politicianKey + " was found.");
                }
                else
                {
                    var  now = DateTime.UtcNow;
                    Size originalSize;
                    ImageManager.UpdatePoliticianProfileImages(politicianKey,
                                                               new MemoryStream(loggedBlob), now, out originalSize);
                    CommonCacheInvalidation.ScheduleInvalidation("politicianimage",
                                                                 politicianKey);
                    LogPoliticiansImagesOriginal.Insert(politicianKey, loggedBlob, now,
                                                        UserSecurityClass, UserName, 0);
                    Msg.Text =
                        Ok("The profile image for ID " + politicianKey +
                           " was reverted to the most recent logged version.");
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Exemple #4
0
        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);
            }
        }