Esempio n. 1
0
 protected void Matches_ItemCommand(object sender, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "New")
     {
         PackageMatchList matches = GetMatches();
         PackageMatch     match   = new PackageMatch();
         matches.Insert(e.Item.ItemIndex + 1, match);
         DataSource = matches;
         DataBindChildren();
     }
     else if (e.CommandName == "Delete")
     {
         PackageMatchList matches = GetMatches();
         matches.RemoveAt(e.Item.ItemIndex);
         DataSource = matches;
         DataBindChildren();
     }
 }
Esempio n. 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);
            PackageRule rule  = new PackageRule();
            rule.Matches.Add(new PackageMatch());
            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)
            {
                PackageRule 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))
            {
                PackageRule 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)
                {
                    DropDownList packagePropertyList = (DropDownList)row.FindControl("ValuePackagePropertyField");

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

                    if (packageProperty == PackageProperties.Distance)
                    {
                        if (PostalCode.IsPostalDataInstalled())
                        {
                            Manager.AddScriptForClientSideEval(
                                "alert('No postal code data has been installed. The Distance property will always return -1.');");
                        }
                    }
                    else
                    {
                        PackageMatchList matches =
                            ((BVModules_Shipping_Package_Rules_PackageMatchEditor)row.FindControl("PackageMatchEditor"))
                            .GetMatches();
                        foreach (PackageMatch match in matches)
                        {
                            if (match.PackageProperty == PackageProperties.Distance)
                            {
                                if (PostalCode.IsPostalDataInstalled())
                                {
                                    Manager.AddScriptForClientSideEval(
                                        "alert('No postal code data has been installed. The Distance property will always return -1.');");
                                    break;
                                }
                            }
                        }
                    }

                    Page.Items["matches"] =
                        ((BVModules_Shipping_Package_Rules_PackageMatchEditor)row.FindControl("PackageMatchEditor")).
                        GetMatches();
                }
            }
        }
        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["SampleShippingCostsData"] = GetSampleOrders(row, out count);
                        grid.DataSource = Session["SampleShippingCostsData"];
                        grid.DataBind();
                        if (count > grid.PageSize * 5)
                        {
                            grid.Caption = string.Format("{0}+ matching packages", grid.PageSize * 5);
                        }
                        else
                        {
                            grid.Caption = string.Format("{0} matching package", count);
                            if (count == 0 || count > 1)
                            {
                                grid.Caption += "s";
                            }
                        }
                    }
                }
            }
        }
    }
    protected void PackagingRules_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "MoveDown")
        {
            String        id            = e.CommandArgument.ToString();
            Int32         index         = Settings.PackagingRules.IndexOf(id);
            PackagingRule packagingRule = Settings.PackagingRules[index];
            Settings.PackagingRules.RemoveAt(index);
            Settings.PackagingRules.Insert(index + 1, packagingRule);
            Settings.PackagingRules.Save();
            PackagingRules.DataBind();
        }
        else if (e.CommandName == "MoveUp")
        {
            String        id            = e.CommandArgument.ToString();
            Int32         index         = Settings.PackagingRules.IndexOf(id);
            PackagingRule packagingRule = Settings.PackagingRules[index];
            Settings.PackagingRules.RemoveAt(index);
            Settings.PackagingRules.Insert(index - 1, packagingRule);
            Settings.PackagingRules.Save();
            PackagingRules.DataBind();
        }
        else if (e.CommandName == "New")
        {
            // Create the default packaging rule
            PackagingRule packagingRule = new PackagingRule();
            packagingRule.Limits.Add(new PackageMatch());

            // Add or insert the settings into the list
            String id    = e.CommandArgument.ToString();
            Int32  index = Settings.PackagingRules.IndexOf(id);
            Settings.PackagingRules.Insert(index + 1, packagingRule);
            Settings.PackagingRules.Save();
            PackagingRules.DataBind();
            PackagingRules.EditIndex = index + 1;

            Page.Items["PackagingRules"] = packagingRule;
        }
        else if (e.CommandName == "Update")
        {
            if (Page.IsValid)
            {
                GridViewRow row = PackagingRules.Rows[PackagingRules.EditIndex];
                if (Page.IsValid)
                {
                    if (row != null)
                    {
                        PackageMatchList matches = ((BVModules_Shipping_Package_Rules_PackageMatchEditor)row.FindControl("PackageMatchEditor")).GetMatches();
                        foreach (PackageMatch match in matches)
                        {
                            if (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["Limits"] = matches;
                    }
                }
            }
        }
        else if (e.CommandName == "View")
        {
            if (Page.IsValid)
            {
                GridViewRow row = PackagingRules.Rows[PackagingRules.EditIndex];
                if (row != null)
                {
                    GridView grid = row.FindControl("SamplePackages") as GridView;
                    if (grid != null)
                    {
                        Int32 count;
                        grid.Visible = true;
                        Session["SamplePackagesData"] = GetSamplePackages(row, out count);
                        grid.DataSource = Session["SamplePackagesData"];
                        grid.DataBind();
                        if (count > grid.PageSize * 5)
                        {
                            grid.Caption = string.Format("This rule would create {0}+ packages", grid.PageSize * 5);
                        }
                        else
                        {
                            grid.Caption = string.Format("This rule would create {0} package", count);
                            if (count == 0 || count > 1)
                            {
                                grid.Caption += "s";
                            }
                        }
                        grid.Caption += " from your existing orders";
                    }
                }
            }
        }
    }
Esempio n. 4
0
    protected void Matches_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            PackageMatchList matches = (PackageMatchList)DataSource;
            PackageMatch     match   = matches[e.Item.ItemIndex];

            DropDownList packagePropertyList      = (DropDownList)e.Item.FindControl("MatchPackagePropertyField");
            DropDownList itemPropertyList         = (DropDownList)e.Item.FindControl("MatchItemPropertyField");
            DropDownList customPropertyList       = (DropDownList)e.Item.FindControl("MatchCustomPropertyField");
            DropDownList comparisonList           = (DropDownList)e.Item.FindControl("MatchComparisonTypeField");
            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");

            packagePropertyList.Items.Clear();
            packagePropertyList.Items.AddRange(GetMatchPackageProperties());

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

            customPropertyList.Visible = false;

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

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

            limitPackagePropertyList.Items.Clear();
            limitPackagePropertyList.Items.AddRange(GetLimitPackageProperties());

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

            limitCustomPropertyList.Visible = false;

            multiplierLabel.Visible = match.LimitPackageProperty != PackageProperties.FixedAmountOne;

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

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