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