public static DateTime GetMaxDate(string ip)
        {
            // Connection to the data source
            SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Private;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");

            // Open connection
            conn.Open();

            // Retrieve Messages data tables
            SqlCommand sqlcmd = new SqlCommand("[dbo].[UptoDate]", conn);

            sqlcmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader sdr = sqlcmd.ExecuteReader();

            SqlDateTime sdtmax = SqlDateTime.MinValue.Value;

            if (!sdr.HasRows)
            {
                sdr.Close();
                return(sdtmax.Value);
            }

            while (sdr.Read())
            {
                SqlDateTime sdt = sdr.GetSqlDateTime(1).Value;

                if (sdr.GetTextReader(0).ReadLine().Contains(ip) && SqlDateTime.GreaterThan(sdt, sdtmax).Value)
                {
                    sdtmax = sdt;
                }
            }

            sdr.Close();
            return(sdtmax.Value);
        }
Exemple #2
0
        public void Greaters()
        {
            // GreateThan ()
            Assert.True(!SqlDateTime.GreaterThan(_test1, _test2).Value);
            Assert.True(SqlDateTime.GreaterThan(_test2, _test1).Value);
            Assert.True(!SqlDateTime.GreaterThan(_test2, _test3).Value);

            // GreaterTharOrEqual ()
            Assert.True(!SqlDateTime.GreaterThanOrEqual(_test1, _test2).Value);
            Assert.True(SqlDateTime.GreaterThanOrEqual(_test2, _test1).Value);
            Assert.True(SqlDateTime.GreaterThanOrEqual(_test2, _test3).Value);
        }
        public void Greaters()
        {
            // GreateThan ()
            Assert.IsTrue(!SqlDateTime.GreaterThan(Test1, Test2).Value, "#H01");
            Assert.IsTrue(SqlDateTime.GreaterThan(Test2, Test1).Value, "#H02");
            Assert.IsTrue(!SqlDateTime.GreaterThan(Test2, Test3).Value, "#H03");

            // GreaterTharOrEqual ()
            Assert.IsTrue(!SqlDateTime.GreaterThanOrEqual(Test1, Test2).Value, "#H04");
            Assert.IsTrue(SqlDateTime.GreaterThanOrEqual(Test2, Test1).Value, "#H05");
            Assert.IsTrue(SqlDateTime.GreaterThanOrEqual(Test2, Test3).Value, "#H06");
        }
Exemple #4
0
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool hasData = false;

            try
            {
                switch (kind)
                {
                case AggregateType.Min:
                    SqlDateTime min = SqlDateTime.MaxValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlDateTime.LessThan(_values[record], min)).IsTrue)
                        {
                            min = _values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(min);
                    }
                    return(_nullValue);

                case AggregateType.Max:
                    SqlDateTime max = SqlDateTime.MinValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlDateTime.GreaterThan(_values[record], max)).IsTrue)
                        {
                            max = _values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(max);
                    }
                    return(_nullValue);

                case AggregateType.First:     // Does not seem to be implemented
                    if (records.Length > 0)
                    {
                        return(_values[records[0]]);
                    }
                    return(null !);   // no data => null

                case AggregateType.Count:
                    int count = 0;
                    for (int i = 0; i < records.Length; i++)
                    {
                        if (!IsNull(records[i]))
                        {
                            count++;
                        }
                    }
                    return(count);
                }
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlDateTime));
            }
            throw ExceptionBuilder.AggregateException(kind, _dataType);
        }
Exemple #5
0
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool flag = false;

            try
            {
                int         num;
                int         num2;
                int         num3;
                int         num4;
                int         num5;
                SqlDateTime minValue;
                int         num6;
                SqlDateTime maxValue;
                switch (kind)
                {
                case AggregateType.Min:
                    maxValue = SqlDateTime.MaxValue;
                    num3     = 0;
                    goto Label_007D;

                case AggregateType.Max:
                    minValue = SqlDateTime.MinValue;
                    num2     = 0;
                    goto Label_00F9;

                case AggregateType.First:
                    if (records.Length <= 0)
                    {
                        return(null);
                    }
                    return(this.values[records[0]]);

                case AggregateType.Count:
                    num4 = 0;
                    num  = 0;
                    goto Label_015A;

                default:
                    goto Label_017F;
                }
Label_002F:
                num6 = records[num3];
                if (!this.IsNull(num6))
                {
                    if (SqlDateTime.LessThan(this.values[num6], maxValue).IsTrue)
                    {
                        maxValue = this.values[num6];
                    }
                    flag = true;
                }
                num3++;
Label_007D:
                if (num3 < records.Length)
                {
                    goto Label_002F;
                }
                if (flag)
                {
                    return(maxValue);
                }
                return(base.NullValue);

Label_00AB:
                num5 = records[num2];
                if (!this.IsNull(num5))
                {
                    if (SqlDateTime.GreaterThan(this.values[num5], minValue).IsTrue)
                    {
                        minValue = this.values[num5];
                    }
                    flag = true;
                }
                num2++;
Label_00F9:
                if (num2 < records.Length)
                {
                    goto Label_00AB;
                }
                if (flag)
                {
                    return(minValue);
                }
                return(base.NullValue);

Label_0145:
                if (!this.IsNull(records[num]))
                {
                    num4++;
                }
                num++;
Label_015A:
                if (num < records.Length)
                {
                    goto Label_0145;
                }
                return(num4);
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlDateTime));
            }
Label_017F:
            throw ExceptionBuilder.AggregateException(kind, base.DataType);
        }