예제 #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="organization"></param>
        /// <param name="subOrganization"></param>
        public RuleEntity(PackageRule rule, SplitPackageConfig organization, Organization subOrganization)
        {
            if ((rule == null) || (organization == null) || (subOrganization == null))
            {
                throw new ArgumentNullException("非法参数");
            }
            this.Rule       = rule;
            this.RuleId     = rule.Id;
            this.RuleName   = rule.SubBusinessName;
            this.HasMixRule = (rule.MixRule.Count > 0);

            this.Organization  = organization;
            this.LogisticsId   = Organization.OrganizationId;
            this.LogisticsName = Organization.OrganizationName;

            this.SubOrganization     = subOrganization;
            this.SubOrganizationName = SubOrganization.GradeName;

            this.Key = string.Format("{0}${1}${2}", this.LogisticsId, this.SubOrganizationName, this.RuleId);

            this.InitSplitRule();
        }
예제 #2
0
    private List <SampleOrderResult> GetSampleOrders(GridViewRow row, out int count)
    {
        GridView grid = (GridView)row.FindControl("SampleShippingCosts");

        PackageRule rule = new PackageRule(Rules.DataKeys[row.RowIndex].Value.ToString());

        rule.Matches.AddRange(
            ((BVModules_Shipping_Package_Rules_PackageMatchEditor)row.FindControl("PackageMatchEditor")).GetMatches());
        rule.Value = Decimal.Parse(((TextBox)row.FindControl("ValueField")).Text);
        rule.ValueCustomProperty       = ((DropDownList)row.FindControl("ValueCustomPropertyField")).SelectedValue;
        rule.ValueItemPropertyAsString = ((DropDownList)row.FindControl("ValueItemPropertyField")).SelectedValue;
        rule.ValuePropertyAsString     = ((DropDownList)row.FindControl("ValuePackagePropertyField")).SelectedValue;

        count = 0;

        // Scan all placed orders
        List <SampleOrderResult> results = new List <SampleOrderResult>();

        foreach (Order order in Order.FindByCriteria(new OrderSearchCriteria()))
        {
            Order heavyOrder = Order.FindByBvin(order.Bvin);

            // "Unship" all of the items so that the samples look like they
            // were just placed. Skip any orders with deleted items.
            bool skipOrder = false;
            foreach (LineItem lineitem in heavyOrder.Items)
            {
                if (lineitem.AssociatedProduct == null || lineitem.AssociatedProduct.ShippingMode == ShippingMode.None)
                {
                    skipOrder = true;
                }
                else
                {
                    lineitem.QuantityShipped = 0;
                }
            }
            if (skipOrder)
            {
                break;
            }

            int groupNumber = 0;
            foreach (ExtendedShippingGroup group in Settings.PackagingRules.Apply(heavyOrder.GetShippingGroups()))
            {
                groupNumber += 1;
                if (rule.IsMatch(group))
                {
                    count += 1;
                    if (count > grid.PageSize * 5)
                    {
                        break;
                    }
                    SampleOrderResult result = new SampleOrderResult();
                    result.OrderNumber  = order.OrderNumber;
                    result.OrderDisplay = string.Format("<a href=\"{0}\" target=\"order\">{1}</a> / {2}",
                                                        Page.ResolveUrl(
                                                            string.Format("~/BVAdmin/Orders/ViewOrder.aspx?id={0}",
                                                                          order.Bvin)),
                                                        order.OrderNumber,
                                                        string.IsNullOrEmpty(group.Name) ? "(default)" : group.Name);
                    List <string> matchValues = new List <string>();
                    List <string> limitValues = new List <string>();
                    if (rule.IsDefaultRule)
                    {
                        matchValues.Add("n/a");
                        limitValues.Add("n/a");
                    }
                    else
                    {
                        for (int index = 0; index < rule.Matches.Count; index++)
                        {
                            PackageMatch match      = rule.Matches[index];
                            string       matchValue =
                                PackagePropertiesHelper.GetPackagePropertyValue(group, match.PackageProperty,
                                                                                match.ItemProperty,
                                                                                match.CustomProperty, "1").ToString();
                            if (string.IsNullOrEmpty(matchValue))
                            {
                                matchValue = "(empty)";
                            }
                            matchValues.Add(matchValue);
                            string limitValue =
                                PackagePropertiesHelper.GetPackagePropertyValue(group, match.LimitPackageProperty,
                                                                                match.LimitItemProperty,
                                                                                match.LimitCustomProperty, match.Limit).
                                ToString();
                            if (string.IsNullOrEmpty(limitValue))
                            {
                                limitValue = "(empty)";
                            }
                            limitValues.Add(limitValue);
                        }
                    }
                    result.MatchValues = string.Join(", ", matchValues.ToArray());
                    result.LimitValues = string.Join(", ", limitValues.ToArray());
                    object value =
                        PackagePropertiesHelper.GetPackagePropertyValue(group, rule.ValuePackageProperty,
                                                                        rule.ValueItemProperty,
                                                                        rule.ValueCustomProperty, "1");
                    result.Value = value == null ? "n/a" : value.ToString();
                    if (String.IsNullOrEmpty(result.Value))
                    {
                        result.Value = "(empty)";
                    }
                    ShippingRate rate =
                        new ShippingRate(((PackageRulesEditor)NamingContainer).NameFieldText, string.Empty,
                                         string.Empty, 0, string.Empty);
                    decimal?cost = rule.GetCost(group);
                    if (cost.HasValue)
                    {
                        rate.Rate          = cost.Value;
                        result.RateDisplay = rate.RateAndNameForDisplay;
                    }
                    else
                    {
                        result.RateDisplay = "Hidden";
                    }
                    results.Add(result);
                }
            }
        }
        results.Sort();
        return(results);
    }
예제 #3
0
    protected String GetRuleAsString(String id)
    {
        PackageRule rule = Settings.CostingRules[id];

        return(rule.ToString());
    }
예제 #4
0
    protected void Rules_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            String      id       = Rules.DataKeys[e.Row.RowIndex].Value.ToString();
            PackageRule rule     = Settings.CostingRules[id];
            Int32       rowIndex = (Rules.PageIndex * Rules.PageSize) + e.Row.RowIndex;

            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                if (rowIndex == Settings.CostingRules.Count - 1)
                {
                    e.Row.FindControl("DeleteRow").Visible    = false;
                    e.Row.FindControl("MoveRuleUp").Visible   = false;
                    e.Row.FindControl("MoveRuleDown").Visible = false;
                }
                if (rowIndex == Settings.CostingRules.Count - 2)
                {
                    e.Row.FindControl("MoveRuleDown").Visible = false;
                }
                if (rowIndex == 0)
                {
                    e.Row.FindControl("MoveRuleUp").Visible = false;
                }
            }
            else if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
            {
                DropDownList packagePropertyList = (DropDownList)e.Row.FindControl("ValuePackagePropertyField");
                DropDownList itemPropertyList    = (DropDownList)e.Row.FindControl("ValueItemPropertyField");
                DropDownList customPropertyList  = (DropDownList)e.Row.FindControl("ValueCustomPropertyField");
                HelpLabel    customPropertyLabel = (HelpLabel)e.Row.FindControl("ValueCustomPropertyLabel");

                Label         multiplierLabel = (Label)e.Row.FindControl("ValueMultiplierLabel");
                HelpLabel     valueLabel      = (HelpLabel)e.Row.FindControl("ValueLabel");
                TextBox       valueField      = (TextBox)e.Row.FindControl("ValueField");
                BaseValidator valueRequired   = (BaseValidator)e.Row.FindControl("ValueRequired");
                BaseValidator valueNumeric    = (BaseValidator)e.Row.FindControl("ValueNumeric");

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

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

                if (rule.ValuePackageProperty == PackageProperties.ItemProperty)
                {
                    itemPropertyList.Visible = true;
                    PrepareCustomPropertyField(customPropertyLabel, customPropertyList, rule.ValueItemProperty);
                    PrepareValueField(multiplierLabel, valueLabel, valueField, valueRequired, valueNumeric,
                                      rule.ValueItemProperty);
                }
                else
                {
                    PrepareCustomPropertyField(customPropertyLabel, customPropertyList, rule.ValuePackageProperty);
                    PrepareValueField(multiplierLabel, valueLabel, valueField, valueRequired, valueNumeric,
                                      rule.ValuePackageProperty);
                }

                if (customPropertyList.Items.Count == 0)
                {
                    customPropertyList.Items.Add(new ListItem("", rule.ValueCustomProperty));
                }
                if (customPropertyList.Items.FindByValue(rule.ValueCustomProperty) == null)
                {
                    rule.ValueCustomProperty = customPropertyList.Items[0].Value;
                }
            }
        }
    }
예제 #5
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";
                            }
                        }
                    }
                }
            }
        }
    }