Example #1
0
        private void MarkAction(ToggledArgs e)
        {
            TreePath treePath = new TreePath(e.Path);
            TreeIter row;

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

            PriceRule.ActionType actionType = (PriceRule.ActionType)treeViewActions.Model.GetValue(row, 4);
            PriceRuleAction      action     = priceRule.Actions.Find(a => a.Type == actionType);

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

            if (isChecked)
            {
                action.IsActive = false;
                treeViewActions.Model.SetValue(row, 0, false);
                RefreshPreview();
            }
            else
            {
                if (action == null)
                {
                    ManageAction(treeViewActions, treePath);
                }
                else
                {
                    action.IsActive = true;
                    treeViewActions.Model.SetValue(row, 0, true);
                    treeViewActions.Model.SetValue(row, 2, action.ToString());
                    RefreshPreview();
                }
            }
        }
Example #2
0
 private void DisplayAction(TreeModel listStore, TreeIter row, PriceRuleAction action)
 {
     listStore.Foreach((model, path, iter) =>
     {
         model.SetValue(iter, 0, false);
         model.SetValue(iter, 2, string.Empty);
         return(false);
     });
     DisplayIndication(listStore, row, action);
 }
Example #3
0
        private void ManageAction(object o, TreePath treePath)
        {
            ListStore listStore = (ListStore)((TreeView)o).Model;
            TreeIter  row;

            listStore.GetIter(out row, treePath);

            PriceRule.ActionType actionType     = (PriceRule.ActionType)listStore.GetValue(row, 4);
            PriceRuleAction      existingAction = priceRule.Actions.Find(a => a.Type == actionType);
            string          message;
            PriceRuleAction action;

            switch (actionType)
            {
            case PriceRule.ActionType.Stop:
            case PriceRule.ActionType.Exit:
            case PriceRule.ActionType.Message:
                message = existingAction != null && existingAction.Values != null && existingAction.Values.Length > 0 ?
                          (string)existingAction.Values [0] : string.Empty;
                using (ChooseMessage chooseMessage = new ChooseMessage(message))
                    if (chooseMessage.Run() == ResponseType.Ok)
                    {
                        action = priceRule.AddAction(actionType, chooseMessage.Message);
                        DisplayAction(listStore, row, action);
                    }
                break;

            case PriceRule.ActionType.Email:
                string email = string.Empty;
                message = string.Empty;
                if (existingAction != null && existingAction.Values != null)
                {
                    if (existingAction.Values.Length > 0)
                    {
                        email = (string)existingAction.Values [0];
                    }

                    if (existingAction.Values.Length > 1)
                    {
                        message = (string)existingAction.Values [1];
                    }
                }

                using (ChooseMessage chooseMessage = new ChooseMessage(email, message))
                    if (chooseMessage.Run() == ResponseType.Ok)
                    {
                        action = priceRule.AddAction(actionType, chooseMessage.Message, chooseMessage.Email);
                        DisplayAction(listStore, row, action);
                    }
                break;

            case PriceRule.ActionType.AddGood:
            case PriceRule.ActionType.AddGlobalGood:
                IEnumerable promotions = existingAction != null ? existingAction.Values : null;
                using (ChooseItemsForPromotion chooseGoodsForPromotions = new ChooseItemsForPromotion(promotions))
                    if (chooseGoodsForPromotions.Run() == ResponseType.Ok)
                    {
                        List <SaleDetail> nonEmptyDetails = chooseGoodsForPromotions.SelectedDetails.FindAll(d => d.ItemId > 0);
                        if (nonEmptyDetails.Count > 0)
                        {
                            action = priceRule.AddAction(actionType, nonEmptyDetails.Cast <object> ().ToArray());
                            DisplayAction(listStore, row, action);
                        }
                    }
                break;

            case PriceRule.ActionType.Price:
                ChoosePrice choosePrice;
                if (existingAction != null && existingAction.Values != null)
                {
                    if (existingAction.Values.Length > 2)
                    {
                        PriceGroup   priceGroup   = (PriceGroup)existingAction.Values [0];
                        OperatorType operatorType = (OperatorType)existingAction.Values [1];
                        double       value        = (double)existingAction.Values [2];
                        choosePrice = new ChoosePrice(priceGroup, operatorType, value);
                    }
                    else
                    {
                        choosePrice = new ChoosePrice((double)existingAction.Values [0]);
                    }
                }
                else
                {
                    choosePrice = new ChoosePrice();
                }

                using (choosePrice)
                    if (choosePrice.Run() == ResponseType.Ok)
                    {
                        object [] values = choosePrice.IsPriceGroupSelected ?
                                           new object [] { choosePrice.PriceGroup, choosePrice.ArithmeticOperation, choosePrice.PriceGroupValue } :
                        new object [] { choosePrice.Value };
                        action = priceRule.AddAction(actionType, values);
                        DisplayAction(listStore, row, action);
                    }
                break;

            case PriceRule.ActionType.Discount:
                double initialDiscount = existingAction != null && existingAction.Values != null && existingAction.Values.Length > 0 ?
                                         (double)existingAction.Values [0] : 0d;
                using (AddDiscount addDiscount = new AddDiscount(true, initialDiscount))
                    if (addDiscount.Run() == ResponseType.Ok)
                    {
                        action = priceRule.AddAction(actionType, addDiscount.PercentDiscount);
                        DisplayAction(listStore, row, action);
                    }
                break;

            case PriceRule.ActionType.ServiceCharge:
                Item   serviceChargeItem;
                double initialServiceCharge;
                if (existingAction != null && existingAction.Values != null && existingAction.Values.Length > 1)
                {
                    serviceChargeItem    = (Item)existingAction.Values [0];
                    initialServiceCharge = (double)existingAction.Values [1];
                }
                else
                {
                    serviceChargeItem    = null;
                    initialServiceCharge = 0d;
                }

                using (AddServiceCharge addServiceCharge = new AddServiceCharge(serviceChargeItem, initialServiceCharge)) {
                    if (addServiceCharge.Run() == ResponseType.Ok)
                    {
                        action = priceRule.AddAction(actionType, addServiceCharge.Item, addServiceCharge.Amount);
                        DisplayAction(listStore, row, action);
                    }
                }
                break;

            case PriceRule.ActionType.Payment:
            case PriceRule.ActionType.AskAdvancePayment:
                double advancePercentage = existingAction != null && existingAction.Values != null && existingAction.Values.Length > 0 ?
                                           (double)existingAction.Values [0] : 0d;
                using (AddAdvancePercentage addDiscount = new AddAdvancePercentage(advancePercentage))
                    if (addDiscount.Run() == ResponseType.Ok)
                    {
                        action = priceRule.AddAction(actionType, addDiscount.PercentDiscount);
                        DisplayAction(listStore, row, action);
                    }
                break;
            }
        }