Пример #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();
     }
 }
Пример #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
    private List <SamplePackageResult> GetSamplePackages(Control row, out int count)
    {
        GridView grid = (GridView)row.FindControl("SamplePackages");

        PackagingRule rule = new PackagingRule();

        rule.BoxHeight = decimal.Parse(((TextBox)row.FindControl("HeightField")).Text);
        rule.BoxLength = decimal.Parse(((TextBox)row.FindControl("LengthField")).Text);
        rule.BoxWidth  = decimal.Parse(((TextBox)row.FindControl("WidthField")).Text);
        rule.Limits.AddRange(
            ((BVModules_Shipping_Package_Rules_PackageMatchEditor)row.FindControl("PackageMatchEditor")).GetMatches());
        rule.Name       = ((TextBox)row.FindControl("NameField")).Text.Trim();
        rule.TareWeight = decimal.Parse(((TextBox)row.FindControl("TareWeightField")).Text);
        Packager packager = new Packager(rule);

        count = 0;

        // Scan all placed orders
        List <SamplePackageResult> results = new List <SamplePackageResult>();
        int rowCount = 0;

        foreach (Order order in Order.FindByCriteria(new OrderSearchCriteria(), -1, grid.PageSize * 5, ref rowCount))
        {
            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;
            }

            ExtendedShippingGroupList groups = new ExtendedShippingGroupList();
            foreach (ShippingGroup group in heavyOrder.GetShippingGroups())
            {
                groups.Add(new ExtendedShippingGroup(0, group, group.Items));
            }

            foreach (ExtendedShippingGroup group in groups)
            {
                ExtendedShippingGroupList splitGroups    = packager.Split(group);
                List <String>             remainingItems = new List <string>();
                SamplePackageResult       result;

                Boolean matchingPackage = false;

                foreach (ExtendedShippingGroup splitGroup in splitGroups)
                {
                    if (splitGroup.Name.Equals(rule.Name))
                    {
                        matchingPackage = true;
                        count          += 1;

                        result              = new SamplePackageResult();
                        result.OrderNumber  = order.OrderNumber;
                        result.OrderDisplay = string.Format("<a href=\"{0}\" target=\"order\">{1}</a>",
                                                            Page.ResolveUrl(
                                                                string.Format("~/BVAdmin/Orders/ViewOrder.aspx?id={0}",
                                                                              order.Bvin)),
                                                            order.OrderNumber);
                        List <string> matchValues = new List <string>();
                        List <string> limitValues = new List <string>();
                        for (int index = 0; index < rule.Limits.Count; index++)
                        {
                            PackageMatch match      = rule.Limits[index];
                            string       matchValue =
                                PackagePropertiesHelper.GetPackagePropertyValue(splitGroup, match.PackageProperty, match.ItemProperty,
                                                                                match.CustomProperty, "1").ToString();
                            if (string.IsNullOrEmpty(matchValue))
                            {
                                matchValue = "(empty)";
                            }
                            matchValues.Add(matchValue);
                            string limitValue =
                                PackagePropertiesHelper.GetPackagePropertyValue(splitGroup, 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());
                        result.Volume      = splitGroup.GetShippingVolume().ToString("0.000");
                        result.Weight      = splitGroup.GetShippingWeight().ToString("0.000");
                        if (splitGroup.HasBoxDimensions)
                        {
                            decimal boxVolume = splitGroup.BoxHeight * splitGroup.BoxLength * splitGroup.BoxWidth;
                            result.FillFactor = string.Format("{0:0.000}%", splitGroup.GetShippingVolume() * 100M / boxVolume);
                        }
                        else
                        {
                            result.FillFactor = "n/a";
                        }
                        List <string> lineitems = new List <string>();
                        foreach (LineItem lineitem in splitGroup.Items)
                        {
                            lineitems.Add(string.Format("{0:0} &times; {1}", lineitem.Quantity, lineitem.ProductSku));
                        }
                        result.Items = string.Join(", ", lineitems.ToArray());
                        results.Add(result);
                    }
                    else
                    {
                        foreach (LineItem lineitem in splitGroup.Items)
                        {
                            remainingItems.Add(string.Format("{0:0} &times; {1}", lineitem.Quantity, lineitem.ProductSku));
                        }
                    }

                    if (count > grid.PageSize * 5)
                    {
                        break;
                    }
                }

                // If there was at least one matching package, then list the unmatched items
                if (matchingPackage && (remainingItems.Count > 0))
                {
                    result              = new SamplePackageResult();
                    result.OrderNumber  = order.OrderNumber;
                    result.OrderDisplay = string.Format("<a href=\"{0}\" target=\"order\">{1}</a>",
                                                        Page.ResolveUrl(
                                                            string.Format("~/BVAdmin/Orders/ViewOrder.aspx?id={0}",
                                                                          order.Bvin)),
                                                        order.OrderNumber);
                    result.MatchValues = "unpackaged items";
                    result.Items       = string.Join(", ", remainingItems.ToArray());
                    results.Add(result);
                }
            }
            if (count > grid.PageSize * 5)
            {
                break;
            }
        }
        results.Sort();
        return(results);
    }
Пример #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;
            }
        }
    }
 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();
     }
 }