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); }
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(); } } } }
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); } }