public PriceRuleCondition(PriceRule.ConditionType type, string formula, bool isException = false)
 {
     IsActive  = true;
     this.type = type;
     SetFormula(formula);
     this.isException = isException;
 }
 public PriceRuleCondition(PriceRule.ConditionType type, object [] values, bool isException = false)
 {
     IsActive  = true;
     this.type = type;
     SetValues(values);
     this.isException = isException;
 }
Beispiel #3
0
        private PriceRuleCondition ProcessGroupCondition <T> (PriceRule.ConditionType conditionType, bool isException, ChooseEditGroup <T> chooseEditGroup) where T : GroupBase <T>, new ()
        {
            if (!CheckNoDuplicateConditionType(conditionType, isException))
            {
                return(null);
            }

            using (chooseEditGroup)
                if (chooseEditGroup.Run() == ResponseType.Ok && chooseEditGroup.GetSelectedGroup() != null)
                {
                    return(priceRule.AddCondition(conditionType, isException, chooseEditGroup.GetSelectedGroup().Code));
                }

            return(null);
        }
Beispiel #4
0
        private bool CheckNoDuplicateConditionType(PriceRule.ConditionType conditionType, bool isException)
        {
            PriceRuleCondition existingCondition = priceRule.Conditions.Find(c => c.Type == conditionType &&
                                                                             c.IsException == !isException);

            if (existingCondition == null || !existingCondition.IsActive)
            {
                return(true);
            }

            MessageError.ShowDialog(isException ?
                                    Translator.GetString("There is already a condition of this type.") :
                                    Translator.GetString("There is already an exception of this type."), ErrorSeverity.Error);

            return(false);
        }
Beispiel #5
0
        private void MarkCondition(ToggledArgs e, TreeView treeView)
        {
            TreePath treePath = new TreePath(e.Path);
            TreeIter row;

            treeView.Model.GetIter(out row, treePath);

            PriceRule.ConditionType conditionType = (PriceRule.ConditionType)treeView.Model.GetValue(row, 4);
            bool isException             = treeView == treeViewExceptions;
            PriceRuleCondition condition = priceRule.Conditions
                                           .Find(c => c.Type == conditionType && c.IsException == isException);

            bool isChecked = (bool)treeView.Model.GetValue(row, 0);

            if (isChecked)
            {
                condition.IsActive = false;
                treeView.Model.SetValue(row, 0, false);
                RefreshPreview();
            }
            else
            {
                if (CheckNoDuplicateConditionType(conditionType, isException))
                {
                    if (condition == null)
                    {
                        ManageCondition(treeView, treePath);
                    }
                    else
                    {
                        condition.IsActive = true;
                        treeView.Model.SetValue(row, 0, true);
                        treeView.Model.SetValue(row, 2, condition.ToString());
                        RefreshPreview();
                    }
                }
            }
        }
Beispiel #6
0
        private PriceRuleCondition ProcessChoiceCondition <T, G> (ChooseEdit <T, G> chooseEdit, PriceRule.ConditionType conditionType, bool isException)
            where G : GroupBase <G>, new ()
            where T : class, IIdentifiableEntity
        {
            if (!CheckNoDuplicateConditionType(conditionType, isException))
            {
                return(null);
            }

            using (chooseEdit)
                if (chooseEdit.Run() == ResponseType.Ok && chooseEdit.SelectedItems.Length > 0)
                {
                    return(priceRule.AddCondition(conditionType, isException, chooseEdit.SelectedItems [0].Id));
                }

            return(null);
        }
Beispiel #7
0
        private void ManageCondition(object o, TreePath treePath)
        {
            ListStore listStore = (ListStore)((TreeView)o).Model;
            TreeIter  row;

            listStore.GetIter(out row, treePath);

            PriceRule.ConditionType conditionType = (PriceRule.ConditionType)listStore.GetValue(row, 4);
            bool               isException        = o == treeViewExceptions;
            object             entityId           = null;
            PriceRuleCondition existingCondition  =
                priceRule.Conditions.Find(c => c.Type == conditionType && c.IsException == isException);

            if (existingCondition != null && existingCondition.Values [0] != null)
            {
                entityId = existingCondition.Values [0];
            }

            long?groupId = null;
            PriceRuleCondition newCondition = null;

            switch (conditionType)
            {
            case PriceRule.ConditionType.Partner:
                newCondition = ProcessChoiceCondition(new ChooseEditPartner(true, entityId as int?), conditionType, isException);
                break;

            case PriceRule.ConditionType.PartnerGroup:
                if (entityId != null)
                {
                    long id;
                    var  g = PartnersGroup.Cache.GetByCode((string)entityId);
                    if (g == null && long.TryParse((string)entityId, out id))
                    {
                        g = PartnersGroup.Cache.GetById(id);
                    }

                    if (g != null)
                    {
                        groupId = g.Id;
                    }
                }
                newCondition = ProcessGroupCondition(conditionType, isException, new ChooseEditPartnersGroup(groupId));
                break;

            case PriceRule.ConditionType.Object:
                newCondition = ProcessChoiceCondition(new ChooseEditLocation(true, entityId as int?), conditionType, isException);
                break;

            case PriceRule.ConditionType.ObjectGroup:
                if (entityId != null)
                {
                    long id;
                    var  g = LocationsGroup.Cache.GetByCode((string)entityId);
                    if (g == null && long.TryParse((string)entityId, out id))
                    {
                        g = LocationsGroup.Cache.GetById(id);
                    }

                    if (g != null)
                    {
                        groupId = g.Id;
                    }
                }
                newCondition = ProcessGroupCondition(conditionType, isException, new ChooseEditLocationsGroup(groupId));
                break;

            case PriceRule.ConditionType.User:
                newCondition = ProcessChoiceCondition(new ChooseEditUser(true, entityId as int?), conditionType, isException);
                break;

            case PriceRule.ConditionType.UserGroup:
                if (entityId != null)
                {
                    long id;
                    var  g = UsersGroup.Cache.GetByCode((string)entityId);
                    if (g == null && long.TryParse((string)entityId, out id))
                    {
                        g = UsersGroup.Cache.GetById(id);
                    }

                    if (g != null)
                    {
                        groupId = g.Id;
                    }
                }
                newCondition = ProcessGroupCondition(conditionType, isException, new ChooseEditUsersGroup(groupId));
                break;

            case PriceRule.ConditionType.Good:
            case PriceRule.ConditionType.ContainsGood:
                newCondition = ProcessChoiceCondition(new ChooseEditItem(true, entityId as int?), conditionType, isException);
                break;

            case PriceRule.ConditionType.GoodGroup:
            case PriceRule.ConditionType.ContainsGGroup:
                if (entityId != null)
                {
                    long id;
                    var  g = ItemsGroup.Cache.GetByCode((string)entityId);
                    if (g == null && long.TryParse((string)entityId, out id))
                    {
                        g = ItemsGroup.Cache.GetById(id);
                    }

                    if (g != null)
                    {
                        groupId = g.Id;
                    }
                }
                newCondition = ProcessGroupCondition(conditionType, isException, new ChooseEditItemsGroup(groupId));
                break;

            case PriceRule.ConditionType.Time:
                ChooseTimeInterval chooseTimeInterval;
                if (existingCondition != null && existingCondition.Values.Length >= 2 &&
                    (existingCondition.Values [0] != null || existingCondition.Values [1] != null))
                {
                    DateTime?timeFrom = (DateTime?)existingCondition.Values [0];
                    DateTime?timeTo   = (DateTime?)existingCondition.Values [1];
                    chooseTimeInterval = new ChooseTimeInterval(timeFrom, timeTo);
                }
                else
                {
                    chooseTimeInterval = new ChooseTimeInterval();
                }

                using (chooseTimeInterval)
                    if (chooseTimeInterval.Run() == ResponseType.Ok)
                    {
                        newCondition = priceRule.AddCondition(conditionType, isException, chooseTimeInterval.TimeFrom,
                                                              chooseTimeInterval.TimeTo);
                    }
                break;

            case PriceRule.ConditionType.Date:
                ChooseDateInterval chooseDateInterval;
                if (existingCondition != null && existingCondition.Values.Length >= 2 &&
                    (existingCondition.Values [0] != null || existingCondition.Values [1] != null))
                {
                    DateTime?dateFrom = (DateTime?)existingCondition.Values [0];
                    DateTime?dateTo   = (DateTime?)existingCondition.Values [1];
                    chooseDateInterval = new ChooseDateInterval(dateFrom, dateTo);
                }
                else
                {
                    chooseDateInterval = new ChooseDateInterval();
                }

                using (chooseDateInterval)
                    if (chooseDateInterval.Run() == ResponseType.Ok)
                    {
                        newCondition = priceRule.AddCondition(conditionType, isException,
                                                              chooseDateInterval.DateFrom, chooseDateInterval.DateTo);
                    }
                break;

            case PriceRule.ConditionType.DocumentSum:
            case PriceRule.ConditionType.TurnoverSum:
            case PriceRule.ConditionType.GoodQttySum:
            case PriceRule.ConditionType.PaymentSum:
            case PriceRule.ConditionType.UnpaidDocumentsSum:
                ChooseNumericInterval chooseNumericInterval;
                if (existingCondition != null && existingCondition.Values.Length >= 2 &&
                    (existingCondition.Values [0] != null || existingCondition.Values [1] != null))
                {
                    double?valueFrom = (double?)existingCondition.Values [0];
                    double?valueTo   = (double?)existingCondition.Values [1];
                    chooseNumericInterval = new ChooseNumericInterval(valueFrom, valueTo);
                }
                else
                {
                    chooseNumericInterval = new ChooseNumericInterval();
                }

                chooseNumericInterval.DialogControl.Title = PriceRuleCondition.TypeToString(conditionType);

                using (chooseNumericInterval)
                    if (chooseNumericInterval.Run() == ResponseType.Ok)
                    {
                        newCondition = priceRule.AddCondition(conditionType, isException,
                                                              chooseNumericInterval.ValueFrom, chooseNumericInterval.ValueTo);
                    }
                break;

            case PriceRule.ConditionType.Weekdays:
                ChooseWeekDays chooseWeekDays;
                if (existingCondition != null && existingCondition.Values.Length >= 2 &&
                    existingCondition.Values [0] != null)
                {
                    chooseWeekDays = new ChooseWeekDays((IEnumerable <DayOfWeek>)existingCondition.Values [0]);
                }
                else
                {
                    chooseWeekDays = new ChooseWeekDays();
                }

                using (chooseWeekDays)
                    if (chooseWeekDays.Run() == ResponseType.Ok && chooseWeekDays.SelectedWeekDays.Count > 0)
                    {
                        newCondition = priceRule.AddCondition(conditionType, isException, chooseWeekDays.SelectedWeekDays);
                    }
                break;

            case PriceRule.ConditionType.PaymentTypeUsed:
                ChoosePaymentTypes choosePaymentTypes;
                if (existingCondition != null && existingCondition.Values.Length >= 2 &&
                    existingCondition.Values [0] != null)
                {
                    choosePaymentTypes = new ChoosePaymentTypes((IEnumerable <BasePaymentType>)existingCondition.Values [0]);
                }
                else
                {
                    choosePaymentTypes = new ChoosePaymentTypes();
                }

                using (choosePaymentTypes)
                    if (choosePaymentTypes.Run() == ResponseType.Ok && choosePaymentTypes.Selected.Count > 0)
                    {
                        newCondition = priceRule.AddCondition(conditionType, isException, choosePaymentTypes.Selected);
                    }
                break;

            case PriceRule.ConditionType.DatabaseUpdated:
                if (existingCondition != null &&
                    existingCondition.Values.Length > 0 &&
                    existingCondition.Values [0] != null)
                {
                    newCondition = existingCondition;
                }
                else
                {
                    newCondition = priceRule.AddCondition(conditionType, isException, 30);
                }
                break;
            }

            if (newCondition != null)
            {
                DisplayIndication(listStore, row, newCondition);
            }
        }
        public static string TypeToString(PriceRule.ConditionType conditionType)
        {
            switch (conditionType)
            {
            case PriceRule.ConditionType.Partner:
                return(Translator.GetString("Partner"));

            case PriceRule.ConditionType.PartnerGroup:
                return(Translator.GetString("Partner group"));

            case PriceRule.ConditionType.Object:
                return(Translator.GetString("Location"));

            case PriceRule.ConditionType.ObjectGroup:
                return(Translator.GetString("Location group"));

            case PriceRule.ConditionType.User:
                return(Translator.GetString("User"));

            case PriceRule.ConditionType.UserGroup:
                return(Translator.GetString("User group"));

            case PriceRule.ConditionType.Good:
                return(Translator.GetString("Item"));

            case PriceRule.ConditionType.GoodGroup:
                return(Translator.GetString("Item group"));

            case PriceRule.ConditionType.Time:
                return(Translator.GetString("Hour"));

            case PriceRule.ConditionType.Date:
                return(Translator.GetString("Date"));

            case PriceRule.ConditionType.DocumentSum:
                return(Translator.GetString("Document amount"));

            case PriceRule.ConditionType.TurnoverSum:
                return(Translator.GetString("Turnover"));

            case PriceRule.ConditionType.GoodQttySum:
                return(Translator.GetString("Item quantity in operation"));

            case PriceRule.ConditionType.PaymentSum:
                return(Translator.GetString("Amount due by partner"));

            case PriceRule.ConditionType.Weekdays:
                return(Translator.GetString("Days of week"));

            case PriceRule.ConditionType.UnpaidDocumentsSum:
                return(Translator.GetString("Unpaid amount with expired due date"));

            case PriceRule.ConditionType.ContainsGood:
                return(Translator.GetString("Presence of item in the operation"));

            case PriceRule.ConditionType.ContainsGGroup:
                return(Translator.GetString("Presence of item of group in the operation"));

            case PriceRule.ConditionType.PaymentTypeUsed:
                return(Translator.GetString("Payment type used"));

            case PriceRule.ConditionType.DatabaseUpdated:
                return(Translator.GetString("The database is updated"));
            }
            return(String.Empty);
        }