コード例 #1
0
 protected void Matches_ItemCommand(object sender, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "New")
     {
         OrderMatchList matches = GetMatches();
         OrderMatch     match   = new OrderMatch();
         matches.Insert(e.Item.ItemIndex + 1, match);
         DataSource = matches;
         DataBindChildren();
     }
     else if (e.CommandName == "Delete")
     {
         OrderMatchList matches = GetMatches();
         matches.RemoveAt(e.Item.ItemIndex);
         DataSource = matches;
         DataBindChildren();
     }
 }
コード例 #2
0
    protected void Rules_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "New")
        {
            String    id    = e.CommandArgument.ToString();
            Int32     index = Settings.CostingRules.IndexOf(id);
            OrderRule rule  = new OrderRule();
            rule.Matches.Add(new OrderMatch());
            Settings.CostingRules.Insert(index, rule);
            Settings.CostingRules.Save();
            Rules.DataBind();
            Rules.EditIndex = index;
        }
        else if (e.CommandName == "MoveUp")
        {
            String id    = e.CommandArgument.ToString();
            Int32  index = Settings.CostingRules.IndexOf(id);
            if (index > 0)
            {
                OrderRule rule = Settings.CostingRules[index];
                Settings.CostingRules.RemoveAt(index);
                Settings.CostingRules.Insert(index - 1, rule);
                Settings.CostingRules.Save();
                Rules.DataBind();
            }
        }
        else if (e.CommandName == "MoveDown")
        {
            String id    = e.CommandArgument.ToString();
            Int32  index = Settings.CostingRules.IndexOf(id);
            if (index < (Settings.CostingRules.Count - 2))
            {
                OrderRule rule = Settings.CostingRules[index];
                Settings.CostingRules.RemoveAt(index);
                Settings.CostingRules.Insert(index + 1, rule);
                Settings.CostingRules.Save();
                Rules.DataBind();
            }
        }
        else if (e.CommandName == "Update")
        {
            if (Page.IsValid)
            {
                GridViewRow row = Rules.Rows[Rules.EditIndex];
                if (row != null)
                {
                    OrderMatchList matches = ((BVModules_Shipping_Order_Rules_OrderMatchEditor)row.FindControl("OrderMatchEditor")).GetMatches();

                    DropDownList orderPropertyList   = (DropDownList)row.FindControl("ValueOrderPropertyField");
                    DropDownList packagePropertyList = (DropDownList)row.FindControl("ValuePackagePropertyField");

                    OrderProperties   orderProperty   = (OrderProperties)Enum.Parse(typeof(OrderProperties), orderPropertyList.SelectedValue);
                    PackageProperties packageProperty = (PackageProperties)Enum.Parse(typeof(PackageProperties), packagePropertyList.SelectedValue);

                    if (orderProperty == OrderProperties.PackageProperty && packageProperty == PackageProperties.Distance)
                    {
                        if (PostalCode.IsPostalDataInstalled())
                        {
                            Anthem.Manager.AddScriptForClientSideEval("alert('No postal code data has been installed. The Distance property will always return -1.');");
                        }
                    }
                    else
                    {
                        foreach (OrderMatch match in matches)
                        {
                            if (match.OrderProperty == OrderProperties.PackageProperty && match.PackageProperty == PackageProperties.Distance)
                            {
                                if (PostalCode.IsPostalDataInstalled())
                                {
                                    Anthem.Manager.AddScriptForClientSideEval("alert('No postal code data has been installed. The Distance property will always return -1.');");
                                    break;
                                }
                            }
                        }
                    }

                    Page.Items["matches"] = matches;
                }
            }
        }
        else if (e.CommandName == "View")
        {
            if (Page.IsValid)
            {
                GridViewRow row = Rules.Rows[Rules.EditIndex];
                if (row != null)
                {
                    GridView grid = row.FindControl("SampleShippingCosts") as GridView;
                    if (grid != null)
                    {
                        Int32 count;
                        grid.Visible          = true;
                        Session["SampleData"] = GetSampleOrders(row, out count);
                        grid.DataSource       = Session["SampleData"];
                        grid.DataBind();
                        if (count > grid.PageSize * 5)
                        {
                            grid.Caption = string.Format("{0}+ matching orders", grid.PageSize * 5);
                        }
                        else
                        {
                            grid.Caption = string.Format("{0} matching order", count);
                            if (count == 0 || count > 1)
                            {
                                grid.Caption += "s";
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #3
0
    protected void Matches_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            OrderMatchList matches = (OrderMatchList)DataSource;
            OrderMatch     match   = matches[e.Item.ItemIndex];

            DropDownList orderPropertyList        = (DropDownList)e.Item.FindControl("MatchOrderPropertyField");
            DropDownList itemPropertyList         = (DropDownList)e.Item.FindControl("MatchItemPropertyField");
            DropDownList packagePropertyList      = (DropDownList)e.Item.FindControl("MatchPackagePropertyField");
            DropDownList customPropertyList       = (DropDownList)e.Item.FindControl("MatchCustomPropertyField");
            DropDownList comparisonList           = (DropDownList)e.Item.FindControl("MatchComparisonTypeField");
            DropDownList limitOrderPropertyList   = (DropDownList)e.Item.FindControl("LimitOrderPropertyField");
            DropDownList limitPackagePropertyList = (DropDownList)e.Item.FindControl("LimitPackagePropertyField");
            DropDownList limitItemPropertyList    = (DropDownList)e.Item.FindControl("LimitItemPropertyField");
            DropDownList limitCustomPropertyList  = (DropDownList)e.Item.FindControl("LimitCustomPropertyField");

            HelpLabel customPropertyLabel      = (HelpLabel)e.Item.FindControl("MatchCustomPropertyLabel");
            HelpLabel limitCustomPropertyLabel = (HelpLabel)e.Item.FindControl("LimitCustomPropertyLabel");

            Label         multiplierLabel = (Label)e.Item.FindControl("LimitMultiplierLabel");
            HelpLabel     limitLabel      = (HelpLabel)e.Item.FindControl("LimitLabel");
            TextBox       limitField      = (TextBox)e.Item.FindControl("LimitField");
            BaseValidator limitRequired   = (BaseValidator)e.Item.FindControl("LimitRequired");
            BaseValidator limitNumeric    = (BaseValidator)e.Item.FindControl("LimitNumeric");

            orderPropertyList.Items.Clear();
            orderPropertyList.Items.AddRange(GetMatchOrderProperties());

            itemPropertyList.Items.Clear();
            itemPropertyList.Items.AddRange(GetItemProperties());
            itemPropertyList.Visible = false;

            packagePropertyList.Items.Clear();
            packagePropertyList.Items.AddRange(GetPackageProperties());
            packagePropertyList.Visible = false;

            customPropertyList.Visible = false;

            if (match.OrderProperty == OrderProperties.ItemProperty)
            {
                itemPropertyList.Visible = true;
                PrepareCustomPropertyField(customPropertyLabel, customPropertyList, match.ItemProperty);
            }
            else if (match.OrderProperty == OrderProperties.PackageProperty)
            {
                packagePropertyList.Visible = true;
                PrepareCustomPropertyField(customPropertyLabel, customPropertyList, match.PackageProperty);
            }
            else
            {
                PrepareCustomPropertyField(customPropertyLabel, customPropertyList, match.OrderProperty);
            }

            if (customPropertyList.Items.Count == 0)
            {
                customPropertyList.Items.Add(new ListItem("", match.CustomProperty));
            }
            if (customPropertyList.Items.FindByValue(match.CustomProperty) == null)
            {
                match.CustomProperty = customPropertyList.Items[0].Value;
            }

            comparisonList.Items.Clear();
            comparisonList.Items.AddRange(GetComparisons());

            limitOrderPropertyList.Items.Clear();
            limitOrderPropertyList.Items.AddRange(GetLimitOrderProperties());

            limitItemPropertyList.Items.Clear();
            limitItemPropertyList.Items.AddRange(GetItemProperties());
            limitItemPropertyList.Visible = false;

            limitPackagePropertyList.Items.Clear();
            limitPackagePropertyList.Items.AddRange(GetPackageProperties());
            limitPackagePropertyList.Visible = false;

            limitCustomPropertyList.Visible = false;

            multiplierLabel.Visible = match.LimitOrderProperty != OrderProperties.FixedAmountOne;

            if (match.LimitOrderProperty == OrderProperties.ItemProperty)
            {
                limitItemPropertyList.Visible = true;
                PrepareCustomPropertyField(limitCustomPropertyLabel, limitCustomPropertyList, match.LimitItemProperty);
                PrepareLimitField(multiplierLabel, limitLabel, limitField, limitRequired, limitNumeric,
                                  match.LimitItemProperty);
            }
            else if (match.LimitOrderProperty == OrderProperties.PackageProperty)
            {
                limitPackagePropertyList.Visible = true;
                PrepareCustomPropertyField(limitCustomPropertyLabel, limitCustomPropertyList, match.LimitPackageProperty);
                PrepareLimitField(multiplierLabel, limitLabel, limitField, limitRequired, limitNumeric,
                                  match.LimitPackageProperty);
            }
            else
            {
                PrepareCustomPropertyField(limitCustomPropertyLabel, limitCustomPropertyList, match.LimitOrderProperty);
                PrepareLimitField(multiplierLabel, limitLabel, limitField, limitRequired, limitNumeric,
                                  match.LimitOrderProperty);
            }

            if (limitCustomPropertyList.Items.Count == 0)
            {
                limitCustomPropertyList.Items.Add(new ListItem("", match.LimitCustomProperty));
            }
            if (limitCustomPropertyList.Items.FindByValue(match.LimitCustomProperty) == null)
            {
                match.LimitCustomProperty = limitCustomPropertyList.Items[0].Value;
            }
        }
    }