Exemplo n.º 1
43
        public static string DatePart(DatePart part, string date, bool isStringDate = false)
        {
            if (isStringDate) {
                date = date.Enclose('\'');
            }

            return string.Format("DATEPART({0}, {1})", part, date);
        }
Exemplo n.º 2
0
        public static string DateAdd(DatePart part, int number, string date, bool isStringDate = false)
        {
            if (isStringDate) {
                date = date.Enclose('\'');
            }

            return string.Format("DATEADD({0}, {1}, {2})", part, number, date);
        }
Exemplo n.º 3
0
        public static string DateDiff(DatePart part, string startDate, string endDate, bool isStringStartDate = false, bool isStringEndDate = false)
        {
            if (isStringStartDate) {
                startDate = startDate.Enclose('\'');
            }
            if (isStringEndDate) {
                endDate = endDate.Enclose('\'');
            }

            return string.Format("DATEDIFF({0}, {1}, {2})", part, startDate, endDate);
        }
Exemplo n.º 4
0
 public GroupByColumnDatePart(string tableAlias, string fieldName, DatePart datePart)
     : base(tableAlias, fieldName)
 {
     DatePart = datePart;
 }
Exemplo n.º 5
0
 public static string ToSqlString(this DatePart value)
 {
     return(value.ToString().ToUpper());
 }
Exemplo n.º 6
0
        public static IEnumerable <TimeBucket <TCalendar> > GetBuckets(DateTime start, DateTime end, DatePart datePart,
                                                                       bool startingPartial = false, bool endingPartial = false)
        {
            var timeBuckets = new List <TimeBucket <TCalendar> >();
            var firstBucket = new TimeBucket <TCalendar>(start, datePart, partialStart: startingPartial);
            var lastBucket  = new TimeBucket <TCalendar>(end, datePart, partialEnd: endingPartial);
            TimeBucket <TCalendar> current;

            if (firstBucket.Given == firstBucket.StartPoint || startingPartial)
            {
                timeBuckets.Add(firstBucket);
                current = firstBucket.Clone();
            }
            else
            {
                current = firstBucket.AddDatePart(1).Clone();
            }

            if (lastBucket.Given != lastBucket.EndPoint && !endingPartial)
            {
                lastBucket.AddDatePart(-1);
            }

            while (current.EndPoint < lastBucket.StartPoint)
            {
                timeBuckets.Add(current.AddDatePart(1).Clone());
            }

            timeBuckets.Add(lastBucket);

            return(timeBuckets);
        }
Exemplo n.º 7
0
        //Calcuation Controller Action
        public void CalculateAction(List<CategoryViewModel> jCategory)
        {
            foreach (var group in jCategory)
            {
                foreach (var item in group.Functions)
                {
                    if (item.Function == "Input")
                    {
                        item.Output = InputFunctions.Output(item.Type, item.Output);
                        OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name });
                    }
                    else
                    {
                        //Logic check at Column Level
                        string colLogic = null;
                        bool colLogicParse = true;
                        if(group.Logic != null)
                        {
                            foreach (var bit in group.Logic)
                            {
                                var grouplastLogic = group.Logic.Last();
                                string grouplastLogicOperator = grouplastLogic.Operator;
                                Logic Logic = new Logic();
                                colLogic = Logic.Output(jCategory, bit, group.ID, 0);
                                Expression ex = new Expression(colLogic);
                                try
                                {
                                    colLogicParse = Convert.ToBoolean(ex.Evaluate());
                                }
                                catch (Exception exception)
                                {
                                    logger.Error(exception);
                                    throw new HttpException(exception.ToString());
                                }

                                if (grouplastLogicOperator == "AND" && colLogicParse == false)
                                {
                                    break;
                                }
                                else if (grouplastLogicOperator == "OR" && colLogicParse == true)
                                {
                                    colLogicParse = true;
                                    break;
                                }

                            }
                        }
                        if (item.Parameter.Count > 0)
                        {
                            string logic = null;
                            bool logicparse = true;
                            string MathString = null;
                            bool PowOpen = false;
                            //Logic check at column level
                            if (colLogicParse == true)
                            {
                                foreach (var bit in item.Logic)
                                {
                                    var lastLogic = item.Logic.Last();
                                    string lastLogicOperator = lastLogic.Operator;
                                    Logic Logic = new Logic();
                                    logic = Logic.Output(jCategory, bit, group.ID, item.ID);
                                    Expression ex = new Expression(logic);

                                    try
                                    {
                                        logicparse = Convert.ToBoolean(ex.Evaluate());
                                    }
                                    catch (Exception exception)
                                    {
                                        logger.Error(exception);
                                        throw new HttpException(exception.ToString());
                                    }

                                    if (lastLogicOperator == "AND" && logicparse == false)
                                    {
                                        break;
                                    }
                                    else if (lastLogicOperator == "OR" && logicparse == true)
                                    {
                                        logicparse = true;
                                        break;
                                    }

                                }
                            }
                            else
                            {
                                logicparse = false;
                            }
                            //Run code if logic if met at column and row level
                            if (logicparse == true)
                            {
                                int paramCount = 1;
                                foreach (var param in item.Parameter)
                                {
                                    string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param);
                                    logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID +") - " + item.Name);
                                    if (item.Function == "Maths")
                                    {
                                        Maths Maths = new Maths();
                                        Maths parameters = (Maths)javaScriptSerializ­er.Deserialize(jparameters, typeof(Maths));
                                        MathString = Maths.Output(jparameters,jCategory,group.ID,item.ID,MathString,PowOpen);
                                        PowOpen = Maths.PowOpen(jparameters, PowOpen);
                                        if (paramCount == item.Parameter.Count)
                                        {
                                            Expression e = new Expression(MathString);
                                            var Calculation = e.Evaluate();
                                            bool DeciParse;
                                            decimal CalculationDeci;
                                            string Rounding;
                                            DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci);
                                            Rounding = Convert.ToString(parameters.Rounding);

                                            if (Rounding == null || Rounding == "")
                                            {
                                                Rounding = "2";
                                            }
                                            if (DeciParse == true)
                                            {
                                                decimal Output = CalculationDeci;
                                                MathematicalFunctions MathematicalFunctions = new MathematicalFunctions();

                                                try
                                                {
                                                    Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output);
                                                }
                                                catch (Exception ex)
                                                {
                                                    logger.Error(ex);
                                                    throw new HttpException(ex.ToString());
                                                }

                                                item.Output = Convert.ToString(Output);
                                            }
                                            else
                                            {
                                                item.Output = "0";
                                            }
                                        }
                                        paramCount = paramCount + 1;
                                    }
                                    else if (item.Function == "ErrorsWarnings")
                                    {
                                        ErrorsWarnings Errors = new ErrorsWarnings();
                                        ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializ­er.Deserialize(jparameters, typeof(ErrorsWarnings));
                                        item.Name = parameters.Type;
                                        item.Output = parameters.String1;
                                    }
                                    else if (item.Function == "Comments")
                                    {
                                        Comments Errors = new Comments();
                                        Comments parameters = (Comments)javaScriptSerializ­er.Deserialize(jparameters, typeof(Comments));
                                        item.Output = parameters.String1;
                                    }
                                    else if (item.Function == "Period")
                                    {
                                        DateFunctions DateFunctions = new DateFunctions();
                                        Period Periods = new Period();
                                        try
                                        {
                                            item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }
                                    else if (item.Function == "Factors")
                                    {
                                        Factors Factors = new Factors();
                                        Factors parameters = (Factors)javaScriptSerializ­er.Deserialize(jparameters, typeof(Factors));
                                        try
                                        {
                                            item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }

                                        item.Type = parameters.OutputType;
                                    }
                                    else if (item.Function == "DateAdjustment")
                                    {
                                        Dates Dates = new Dates();
                                        try
                                        {
                                            item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }
                                    else if (item.Function == "DatePart")
                                    {
                                        DatePart DateParts = new DatePart();
                                        try
                                        {
                                            item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }

                                    else if (item.Function == "MathsFunctions")
                                    {
                                        MathsFunctions MathsFunctions = new MathsFunctions();
                                        try
                                        {
                                            item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }
                                    else if (item.Function == "ArrayFunctions")
                                    {
                                        ArrayFunctions ArrayFunctions = new ArrayFunctions();
                                        ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializ­er.Deserialize(jparameters, typeof(ArrayFunctions));
                                        try
                                        {
                                            item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }

                                        if(parameters.Function == "Count")
                                        {
                                            item.Type = "Decimal";
                                        }
                                        else
                                        {
                                            item.Type = parameters.LookupType;
                                        }

                                    }
                                    else if (item.Function == "StringFunctions")
                                    {
                                        StringFunctions StringFunctions = new StringFunctions();
                                        StringFunctions  parameters = (StringFunctions)javaScriptSerializ­er.Deserialize(jparameters, typeof(StringFunctions));
                                        try
                                        {
                                            item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }

                                        if(parameters.Type == "Len")
                                        {
                                            item.Type = "Decimal";
                                        }
                                        else
                                        {
                                            item.Type = "String";
                                        }
                                    }
                                }
                                //Expected results on the builder this sets the required ones
                                if (item.ExpectedResult == null || item.ExpectedResult == "")
                                {
                                    item.Pass = "******";
                                }
                                else if (item.ExpectedResult == item.Output)
                                {
                                    item.Pass = "******";
                                }
                                else
                                {
                                    item.Pass = "******";
                                }
                                OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name });
                            }
                            else
                            {
                                //Ignores the row if logic is not met
                                dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID);

                                if(Convert.ToString(LogicReplace) == Convert.ToString(item.Name))
                                {
                                    item.Output = null;
                                }
                                else
                                {
                                    item.Output = Convert.ToString(LogicReplace);
                                }
                                item.Pass = "******";

                                OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name });
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Alors la le parsing des parties de date suivant la langue c'est pas évident ....
        /// On peut considéré que seul des / et des - sont utilisé pour séparé les parties
        /// On peut considérer que l'année est toujours supérieur à 31 (pas de patrimoine en 31 après jesus christ :) )
        /// Si on as aucun séparateur  c'est une année , c'est sur
        /// Si on as un séparateur , l'anné c'est celui qui est supérieur à 31, le mois est l'autre
        /// Si on as deux séparateur, on tente un parsing de date normal avec CultureConfiguration.DateTimeFormat
        /// Du coup sa marche dans tout les cas :)
        /// Pour les test on prend pas 31 mais 1000 c'est plus lisible
        /// </summary>
        /// <param name="str"></param>
        /// <param name="message"></param>
        /// <param name="date"></param>
        /// <param name="datePart"></param>
        /// <returns></returns>
        public static bool ValidateDatePart(string str, out string message, out DateTime date, out DatePart datePart)
        {
            date = DateTime.Now;
            datePart = DatePart.None;
            message = null;
            if (!String.IsNullOrEmpty(str))
            {
                int countSeparator = str.Count(f => f == '/' || f == '-');
                if (countSeparator == 0)
                {
                    Int64 year = -1;
                    if (ValidateInt64(str, out message, out  year))
                    {
                        datePart = DatePart.Year;
                        date = new DateTime((int)year, 1, 1);
                        return true;
                    }
                }
                else if (countSeparator == 1)
                {
                    // on traite tous les séparateur ...
                    String[] itemsSplash = str.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    String[] itemsTiret = str.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    List<String> items = new List<string>();
                    items.AddRange(itemsSplash);
                    items.AddRange(itemsTiret);
                    Int64 value1 = -1;
                    Int64 value2 = -1;
                    Int64 valueMonth = -1;
                    Int64 valueYear = -1;
                    if (ValidateInt64(items[0], out message, out  value1) && ValidateInt64(items[1], out message, out  value2))
                    {
                        if (value1 > 1000 && value2 <= 12 && value2 > 0)
                        {
                            valueYear = value1;
                            valueMonth = value2;
                        }
                        else if (value2 > 1000 && value1 <= 12 && value2 > 0)
                        {
                            valueYear = value2;
                            valueMonth = value1;
                        }
                        datePart = DatePart.Month;
                        date = new DateTime((int)valueYear, (int)valueMonth, 1);
                        return true;

                    }
                }
                else if (countSeparator == 2)
                {
                    if (DateTime.TryParseExact(str, CultureConfiguration.DateFormatString, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out date))
                    {
                        datePart = DatePart.Day;
                        return true;
                    }
                }

            }

            return false;
        }
Exemplo n.º 9
0
 public static string ToSortString(this DatePart datePart)
 {
     return(string.Join("", datePart.Year.ToString().PadLeft(4, '0'), datePart.Month.ToString().PadLeft(2, '0'), datePart.Day.ToString().PadLeft(2, '0')));
 }
Exemplo n.º 10
0
 /// <summary>
 /// DateDiff
 /// </summary>
 /// <param name="time"></param>
 /// <param name="format"></param>
 /// <param name="compareTime"></param>
 /// <returns></returns>
 public static int DateDiff(this Nullable <DateTime> time, DatePart format, DateTime compareTime)
 {
     return(1);
 }
Exemplo n.º 11
0
 internal DateAddFunction(DatePart datePart)
 {
     this.DatePart = datePart;
 }
Exemplo n.º 12
0
 /// <summary>
 /// DateDiff
 /// </summary>
 /// <param name="time"></param>
 /// <param name="format"></param>
 /// <param name="compareTime"></param>
 /// <returns></returns>
 public static double DateDiff(this DateTime?time, DatePart format, DateTime compareTime)
 {
     return(DateDiff(time.Value, format, compareTime));
 }
Exemplo n.º 13
0
 internal bool this[DatePart index]
 {
     get { return (_bits & (1 << (int)index)) != 0; }
     set
     {
         if (value)
         {
             _bits |= (1 << (int)index);
         }
         else
         {
             _bits &= ~(1 << (int)index);
         }
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// 时间转时间戳
        /// </summary>
        /// <param name="source">源时间</param>
        /// <param name="sourceTimeZoneId">源时区,空或者 Local 表示本地时间(常用 UTC,Local,Pacific Standard Time)</param>
        /// <param name="dayPart">时间戳单位(秒/毫秒/计时周期)</param>
        /// <returns></returns>
        public static long ConvertToTimestamp(DateTime source, string sourceTimeZoneId = null, DatePart dayPart = DatePart.Millisecond)
        {
            // 转至UTC时区
            if (sourceTimeZoneId != "UTC")
            {
                source = Common.ConvertDateTime(source, sourceTimeZoneId, "UTC");
            }
            switch (dayPart)
            {
            case DatePart.Second:
                return((source.Ticks - 621355968000000000L) / 10000000);

            case DatePart.Millisecond:
                return((source.Ticks - 621355968000000000L) / 10000);

            case DatePart.Tick:
                return(source.Ticks - 621355968000000000L);

            default:
                throw new NotSupportedException(dayPart + " is not a support type.");
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// 対象日より指定日までの日付範囲を返す。
 /// </summary>
 /// <param name="dt">this 日付</param>
 /// <param name="toDate">指定日</param>
 /// <param name="step">ステップ数</param>
 /// <param name="stepUnit"ステップ単位></param>
 /// <returns>対象日より指定日までの日付範囲</returns>
 public static DateRange To(this DateTime dt, DateTime toDate, int step = 1, DatePart stepUnit = DatePart.Day)
 => new DateRange(dt, toDate, step, stepUnit);
Exemplo n.º 16
0
 /// <summary>
 /// DateDiff
 /// </summary>
 /// <param name="time"></param>
 /// <param name="format">DatePart</param>
 /// <param name="compareTime">比较的时间</param>
 /// <returns></returns>
 public static int DateDiff(this DateTime time, DatePart format, DateTime compareTime)
 {
     return(1);
 }
Exemplo n.º 17
0
        /// <summary>
        /// 対象日より指定日までの日付範囲を返す。
        /// </summary>
        /// <param name="dt">this 日付</param>
        /// <param name="span">加算値</param>
        /// <param name="spanUnit">加算単位</param>
        /// <param name="step">ステップ数</param>
        /// <param name="stepUnit">ステップ単位</param>
        /// <returns>対象日より指定した単位で加算した日付までの日付範囲</returns>
        public static DateRange To(this DateTime dt, int span, DatePart spanUnit, int step = 1, DatePart stepUnit = DatePart.Day)
        {
            var toDate = dt.Add(span, spanUnit);

            return(new DateRange(dt, toDate, step, stepUnit));
        }
Exemplo n.º 18
0
 public SqlDateFunctionAttribute(string name, DbType dbType, DatePart datePartSpecifier = DatePart.None) : base(name, dbType)
 {
     _datePartSpecifier = datePartSpecifier;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatePartSpan"/> struct.
 /// </summary>
 /// <param name="part">The part.</param>
 /// <param name="value">The value.</param>
 public DatePartSpan(string part, int value)
 {
     this.part  = datePartMap[part];
     this.value = value;
 }
Exemplo n.º 20
0
        public static void ToSql(DatePart expression, StringBuilder builder)
        {
            if (null == expression) throw new ArgumentNullException("expression");
            if (null == builder) throw new ArgumentNullException("builder");

            if (expression.Operands.Count > 0)
            {
                DatePartToken operand1 = expression.Operands
                                                   .OfType<DatePartToken>()
                                                   .FirstOrDefault();
                IToken operand2 = expression.Operands
                                            .ElementAtOrDefault(1);
                if (null != operand1 && null != operand2)
                {
                    if (operand1.DatePart == DatePartToken.DatePartEnum.None)
                        operand2.ToSql(builder);
                    else
                    {
                        string spart = operand1.DatePart.ToString().ToLowerInvariant();
                        if (operand1.DatePart == DatePartToken.DatePartEnum.DayOfWeek)
                            spart = "weekday";

                        builder.Append("DATEPART(");
                        builder.AppendFormat("{0}, ", spart);
                        operand2.ToSql(builder);
                        builder.Append(")");
                    }
                }
                else
                    builder.Append("''''");
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatePartSpan"/> struct.
 /// </summary>
 /// <param name="part">The part.</param>
 /// <param name="value">The value.</param>
 public DatePartSpan(DatePart part, int value)
 {
     this.part  = part;
     this.value = value;
 }
		public SqlDateFunctionAttribute(string name, DbType dbType, DatePart datePartSpecifier = DatePart.None) : base(name, dbType)
		{
			_datePartSpecifier = datePartSpecifier;
		}
Exemplo n.º 23
0
 private int GetDatePart(DatePart Part)
 {
     return(this.GetDateParts()[(int)Part]);
 }
Exemplo n.º 24
0
 /// <summary>
 /// дcookieֵ
 /// </summary>
 /// <param name="strName">����</param>
 /// <param name="strValue">ֵ</param>
 /// <param name="expires">����ʱ��(����)</param>
 /// <param name="datepart">����ʱ��(����ʱ�䲿��)</param>
 public static void WriteCookie(string strName, string strValue, int expires,DatePart datepart)
 {
     HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
     if (cookie == null)
     {
         cookie = new HttpCookie(strName);
     }
     cookie.Value = strValue;
     switch (datepart)
     {
         case DatePart.Seconds:
             cookie.Expires = DateTime.Now.AddSeconds(expires);
             break;
         case DatePart.Minutes:
             cookie.Expires = DateTime.Now.AddMinutes(expires);
             break;
         case DatePart.Hours:
             cookie.Expires = DateTime.Now.AddHours(expires);
             break;
         case DatePart.Days:
             cookie.Expires = DateTime.Now.AddDays(expires);
             break;
         case DatePart.Months:
             cookie.Expires = DateTime.Now.AddMonths(expires);
             break;
         case DatePart.Years:
             cookie.Expires = DateTime.Now.AddYears(expires);
             break;
         case DatePart.ForEver:
             cookie.Expires = DateTime.Now.AddYears(99);
             break;
         default:
             break;
     }
     HttpContext.Current.Response.AppendCookie(cookie);
 }
		internal LightDatePartDataFieldInfo (DataFieldInfo info, DatePart part)
			: base (info.TableMapping)
		{
			_baseFieldInfo = info;
			_part = part;
		}