Exemplo n.º 1
0
        public static OfficeKeyInfo GetPreviousOfficeKeyInfoByRunningMateKey(
            string runningMateKey, int commandTimeout = -1)
        {
            var cmdText =
                "SELECT ElectionsPoliticians.ElectionKey,ElectionsPoliticians.OfficeKey" +
                " FROM ElectionsPoliticians,Elections" +
                " WHERE ElectionsPoliticians.RunningMateKey=@RunningMateKey" +
                "  AND ElectionsPoliticians.ElectionKey = Elections.ElectionKey" +
                "  AND Elections.ElectionDate<@Today" +
                " ORDER BY Elections.ElectionDate DESC";

            cmdText = VoteDb.InjectSqlLimit(cmdText, 1);
            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "RunningMateKey", runningMateKey);
            VoteDb.AddCommandParameter(cmd, "Today", DateTime.Today);
            var table = FillTable(cmd, ElectionsPoliticiansTable.ColumnSet.OfficeKey);

            if (table.Count == 0)
            {
                return(OfficeKeyInfo.Empty);
            }
            return(new OfficeKeyInfo
            {
                ElectionKey = table[0].ElectionKey,
                OfficeKey = table[0].OfficeKey
            });
        }
Exemplo n.º 2
0
        public static OfficeKeyInfo GetFutureOfficeKeyInfoByRunningMateKey(
            string runningMateKey, bool isViewable, int commandTimeout = -1)
        {
            var cmdText =
                "SELECT ElectionsPoliticians.ElectionKey,ElectionsPoliticians.OfficeKey" +
                " FROM ElectionsPoliticians,Elections" +
                " WHERE ElectionsPoliticians.RunningMateKey=@RunningMateKey" +
                "  AND ElectionsPoliticians.ElectionKey = Elections.ElectionKey" +
                "  AND Elections.ElectionDate>=@Today" +
                "  AND Elections.IsViewable=@IsViewable" +
                " ORDER BY Elections.ElectionDate";

            cmdText = VoteDb.InjectSqlLimit(cmdText, 1);
            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "RunningMateKey", runningMateKey);
            VoteDb.AddCommandParameter(cmd, "Today",
                                       DateTime.Today.AddDays(-DaysAfterElectionToShowAsUpcoming));
            VoteDb.AddCommandParameter(cmd, "IsViewable", isViewable);
            var table = FillTable(cmd, ElectionsPoliticiansTable.ColumnSet.OfficeKey);

            if (table.Count == 0)
            {
                return(OfficeKeyInfo.Empty);
            }
            return(new OfficeKeyInfo
            {
                ElectionKey = table[0].ElectionKey,
                OfficeKey = table[0].OfficeKey
            });
        }
Exemplo n.º 3
0
        public static int GetNextOrderOnBallot(string electionKey)
        {
            var cmdText =
                "SELECT OrderOnBallot FROM Referendums WHERE ElectionKey=@ElectionKey" +
                " ORDER BY OrderOnBallot DESC";

            cmdText = VoteDb.InjectSqlLimit(cmdText, 1);
            var cmd = VoteDb.GetCommand(cmdText);

            VoteDb.AddCommandParameter(cmd, "ElectionKey", electionKey);
            var result = VoteDb.ExecuteScalar(cmd);

            return(result == null ? 10 : Convert.ToInt32(result) + 10);
        }
Exemplo n.º 4
0
        public static string GetIncumbentOfficeKeyByRunningMateKey(
            string runningMateKey, int commandTimeout = -1)
        {
            var cmdText = "SELECT OfficesOfficials.OfficeKey" +
                          " FROM OfficesOfficials,Offices" +
                          " WHERE OfficesOfficials.RunningMateKey=@RunningMateKey" +
                          "  AND OfficesOfficials.OfficeKey = Offices.OfficeKey" +
                          " ORDER BY OfficesOfficials.DataLastUpdated DESC";

            cmdText = VoteDb.InjectSqlLimit(cmdText, 1);
            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "RunningMateKey", runningMateKey);
            var table = FillTable(cmd, OfficesOfficialsTable.ColumnSet.OfficeKey);

            return(table.Count == 0 ? null : table[0].OfficeKey);
        }
Exemplo n.º 5
0
        public static string GetLatestViewableElectionKeyStateByOfficeKey(
            string officeKey, string defaultValue = null)
        {
            var cmdText = "SELECT ElectionsOffices.ElectionKeyState" +
                          " FROM Elections,ElectionsOffices" +
                          " WHERE ElectionsOffices.OfficeKey=@OfficeKey" +
                          "  AND Elections.IsViewable='1'" +
                          " ORDER BY ElectionsOffices.ElectionKeyState DESC";

            cmdText = VoteDb.InjectSqlLimit(cmdText, 1);
            var cmd = VoteDb.GetCommand(cmdText, -1);

            VoteDb.AddCommandParameter(cmd, "OfficeKey", officeKey);
            var result = VoteDb.ExecuteScalar(cmd);

            if ((result == null) || (result == DBNull.Value))
            {
                return(defaultValue);
            }
            return(result as string);
        }