Ejemplo n.º 1
0
        public void SetData(DateTime from, DateTime to, DateRanges range = DateRanges.Custom)
        {
            fromDateString = BusinessDomain.GetFormattedDate(from);
            fromTimeString = BusinessDomain.GetFormattedTime(from);
            fromDate       = from.Date;
            fromTime       = from.TimeOfDay;

            toDateString = BusinessDomain.GetFormattedDate(to);
            toTimeString = BusinessDomain.GetFormattedTime(to);
            toDate       = to.Date;
            toTime       = to.TimeOfDay;

            timeRange = range;
        }
        public override string ToString()
        {
            string condition = formula;
            long   id;

            switch (type)
            {
            case PriceRule.ConditionType.Partner:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var partner = Partner.Cache.GetById(Convert.ToInt64(values [0]));
                condition = partner != null ? partner.Name : null;
                break;

            case PriceRule.ConditionType.PartnerGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var partnersGroup = Int64.TryParse((string)values [0], out id) ?
                                    PartnersGroup.Cache.GetById(id) :
                                    PartnersGroup.Cache.GetByCode((string)values [0]);

                condition = partnersGroup != null ? partnersGroup.Name : null;
                break;

            case PriceRule.ConditionType.Object:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var location = Location.Cache.GetById(Convert.ToInt64(values [0]));
                condition = location != null ? location.Name : null;
                break;

            case PriceRule.ConditionType.ObjectGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var locationsGroup = Int64.TryParse((string)values [0], out id) ?
                                     LocationsGroup.Cache.GetById(id) :
                                     LocationsGroup.Cache.GetByCode((string)values [0]);

                condition = locationsGroup != null ? locationsGroup.Name : null;
                break;

            case PriceRule.ConditionType.User:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var user = User.Cache.GetById(Convert.ToInt64(values [0]));
                condition = user != null ? user.Name : null;
                break;

            case PriceRule.ConditionType.UserGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var usersGroup = Int64.TryParse((string)values [0], out id) ?
                                 UsersGroup.Cache.GetById(id) :
                                 UsersGroup.Cache.GetByCode((string)values [0]);

                condition = usersGroup != null ? usersGroup.Name : null;
                break;

            case PriceRule.ConditionType.Good:
            case PriceRule.ConditionType.ContainsGood:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }
                var item = Item.Cache.GetById(Convert.ToInt64(values [0]));
                condition = item != null ? item.Name : null;
                break;

            case PriceRule.ConditionType.GoodGroup:
            case PriceRule.ConditionType.ContainsGGroup:
                if (values [0] == null)
                {
                    condition = null;
                    break;
                }

                var itemsGroup = Int64.TryParse((string)values [0], out id) ?
                                 ItemsGroup.Cache.GetById(id) :
                                 ItemsGroup.Cache.GetByCode((string)values [0]);

                condition = itemsGroup != null ? itemsGroup.Name : null;
                break;

            case PriceRule.ConditionType.Time:
                DateTime?timeFrom = (DateTime?)values [0];
                DateTime?timeTo   = (DateTime?)values [1];

                string timeFromString = timeFrom != null?
                                        String.Format("{0} {1}", Translator.GetString("from"), BusinessDomain.GetFormattedTime(timeFrom.Value)) :
                                            null;

                string timeToString = timeTo != null?
                                      String.Format("{0} {1}", Translator.GetString("to"), BusinessDomain.GetFormattedTime(timeTo.Value)) :
                                          null;

                if (timeFrom != null && timeTo != null)
                {
                    condition = String.Format("{0} {1}", timeFromString, timeToString);
                }
                else if (timeFrom != null)
                {
                    condition = timeFromString;
                }
                else if (timeTo != null)
                {
                    condition = timeToString;
                }
                else
                {
                    condition = null;
                }

                break;

            case PriceRule.ConditionType.Date:
                DateTime?dateFrom = (DateTime?)values [0];
                DateTime?dateTo   = (DateTime?)values [1];

                string dateFromString = dateFrom != null?
                                        String.Format("{0} {1}", Translator.GetString("from"), BusinessDomain.GetFormattedDate(dateFrom.Value)) :
                                            null;

                string dateToString = dateTo != null?
                                      String.Format("{0} {1}", Translator.GetString("to"), BusinessDomain.GetFormattedDate(dateTo.Value)) :
                                          null;

                if (dateFrom != null && dateTo != null)
                {
                    condition = String.Format("{0} {1}", dateFromString, dateToString);
                }
                else if (dateFrom != null)
                {
                    condition = dateFromString;
                }
                else if (dateTo != null)
                {
                    condition = dateToString;
                }
                else
                {
                    condition = null;
                }

                break;

            case PriceRule.ConditionType.DocumentSum:
            case PriceRule.ConditionType.TurnoverSum:
            case PriceRule.ConditionType.GoodQttySum:
            case PriceRule.ConditionType.PaymentSum:
            case PriceRule.ConditionType.UnpaidDocumentsSum:
                double?from = values [0] == null ? (double?)null : Convert.ToDouble(values [0]);
                double?to   = values [1] == null ? (double?)null : Convert.ToDouble(values [1]);
                string fromString;
                string toString;

                if (from != null)
                {
                    fromString = String.Format("{0} {1}", Translator.GetString("from"), type == PriceRule.ConditionType.GoodQttySum ?
                                               Quantity.ToString(from.Value) : Currency.ToString(from.Value, PriceType.Unknown));
                }
                else
                {
                    fromString = null;
                }

                if (to != null)
                {
                    toString = String.Format("{0} {1}", Translator.GetString("to"), type == PriceRule.ConditionType.GoodQttySum ?
                                             Quantity.ToString(to.Value) : Currency.ToString(to.Value, PriceType.Unknown));
                }
                else
                {
                    toString = null;
                }

                if (from != null && to != null)
                {
                    condition = String.Format("{0} {1}", fromString, toString);
                }
                else if (from != null)
                {
                    condition = fromString;
                }
                else if (to != null)
                {
                    condition = toString;
                }
                else
                {
                    condition = null;
                }

                break;

            case PriceRule.ConditionType.Weekdays:
                condition = String.Join(" ", ((IList <DayOfWeek>)values [0])
                                        .Select(DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName)
                                        .ToArray());
                break;

            case PriceRule.ConditionType.PaymentTypeUsed:
                condition = String.Join(" ", ((IList <BasePaymentType>)values [0])
                                        .Select(PaymentType.GetBasePaymentTypeName)
                                        .ToArray());
                break;

            case PriceRule.ConditionType.DatabaseUpdated:
                DateTime now = DateTime.Now;
                condition = String.Format(Translator.GetString("Sooner than {0}"), now.AddMinutes(-30).ToFriendlyTimeAgoString(now));
                break;
            }

            if (condition == null)
            {
                error = true;
            }

            return(String.Format("{0}: {1}", TypeToString(type),
                                 condition ?? AllMissingErrors [type]));
        }