コード例 #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();
                }
            }
        }
コード例 #2
0
        public static string TypeToString(PriceRule.ActionType actionType)
        {
            switch (actionType)
            {
            case PriceRule.ActionType.Stop:
                return(Translator.GetString("Stop operation"));

            case PriceRule.ActionType.Exit:
                return(Translator.GetString("Stop price rules"));

            case PriceRule.ActionType.Message:
                return(Translator.GetString("Message"));

            case PriceRule.ActionType.Email:
                return(Translator.GetString("Send e-mail"));

            case PriceRule.ActionType.AddGood:
                return(Translator.GetString("Add promotional item to the operation"));

            case PriceRule.ActionType.AddGlobalGood:
                return(Translator.GetString("Add promotional item once for the operation"));

            case PriceRule.ActionType.Price:
                return(Translator.GetString("Change price"));

            case PriceRule.ActionType.Discount:
                return(Translator.GetString("Change discount"));

            case PriceRule.ActionType.ServiceCharge:
                return(Translator.GetString("Service charge"));

            case PriceRule.ActionType.Payment:
                return(Translator.GetString("Add advance"));

            case PriceRule.ActionType.AskAdvancePayment:
                return(Translator.GetString("Ask for advance deposit"));
            }
            return(String.Empty);
        }
コード例 #3
0
 public PriceRuleAction(PriceRule.ActionType type, params object [] values)
 {
     IsActive  = true;
     this.type = type;
     SetValues(values);
 }
コード例 #4
0
 private PriceRuleAction(PriceRule.ActionType type, string formula)
 {
     IsActive  = true;
     this.type = type;
     SetFormula(formula);
 }
コード例 #5
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;
            }
        }