private void ProcessData(IEnumerable <Category> rootCategories) { foreach (var rc in rootCategories) { TaxLasyLoad.ProcessCategoryRow(rc, 0, -1, DataTable, false, Convert.ToInt32(Request["taxid"])); } }
protected void saveClick(object sender, EventArgs e) { MsgErr(false); CurrentTax.Name = txtName.Text; var cid = Int32.Parse(ddlCountry.SelectedValue); if (CurrentTax.CountryID != cid) { CurrentTax.RegionalRates.Clear(); } CurrentTax.Enabled = chkEnabled.Checked; CurrentTax.CountryID = cid; int priority = 0; if (int.TryParse(txtPriority.Text, out priority)) { CurrentTax.Priority = priority; } else { CurrentTax.Priority = 1; txtPriority.Text = "1"; } decimal fedRate = 0; if (Decimal.TryParse(txtFederalRate.Text, out fedRate)) { CurrentTax.FederalRate = fedRate; } else { CurrentTax.FederalRate = 0; txtFederalRate.Text = @"0.00"; } CurrentTax.DependsOnAddress = ((TypeRateDepends)(Int32.Parse(ddlDependsOnAddress.SelectedValue))); CurrentTax.RegNumber = txtRegNumber.Text; CurrentTax.ShowInPrice = chkShowInPrice.Checked; CurrentTax.Type = (RateType)(Int32.Parse(ddlRateType.SelectedValue)); try { TaxServices.UpdateTax(CurrentTax); Msg(Resources.Resource.Admin_Tax_Saved); formPanel.Update(); } catch (Exception ex) { MsgErr(ex.Message); return; } // Mapping on product ---------------------------------------------------- var sc = CatalogDataTreeViewForTaxes.SelectedCategories; if (sc.Count == 0) { TaxLasyLoad.SetCategorySelectionState("0", CurrentTax.TaxId, false, true); } foreach (var selectedCategory in sc) { int categoryID = selectedCategory.Category.CategoryId; var hasSelectedSubCats = sc.Where(cat => cat.Category.CategoryId != selectedCategory.Category.CategoryId).Any(c => c.Category.ParentCategoryId == categoryID); var hasSelectedProducts = false; foreach (Product product1 in CatalogDataTreeViewForTaxes.SelectedProducts.Where(product1 => CategoryService.GetProductsByCategoryId(categoryID).Where(p => p.ProductId == product1.ProductId).Count() > 0)) { hasSelectedProducts = true; } if (selectedCategory.Full) { //sp.AddRange(selectedCategory.Category.Products); TaxLasyLoad.SetCategorySelectionState(selectedCategory.Category.CategoryId.ToString(CultureInfo.InvariantCulture), CurrentTax.TaxId, true, true); } else { if (hasSelectedSubCats) { //Выполняется очистка выбранных категорий и продуктов для текущей категории TaxLasyLoad.SetCategorySelectionState(selectedCategory.Category.CategoryId.ToString(CultureInfo.InvariantCulture), CurrentTax.TaxId, false, true); //а затем сохранение состояния только для текущей категории TaxLasyLoad.SetCategorySelectionState(selectedCategory.Category.CategoryId.ToString(CultureInfo.InvariantCulture), CurrentTax.TaxId, true, false); //остальные выбранные категории будут сохранены на следующих итерация, а продукты в следующем цикле } else if (hasSelectedProducts) { TaxLasyLoad.SetCategorySelectionState(selectedCategory.Category.CategoryId.ToString(CultureInfo.InvariantCulture), CurrentTax.TaxId, true, false); } } } foreach (Product selectedProduct in CatalogDataTreeViewForTaxes.SelectedProducts) { TaxLasyLoad.SetProductSelectionState(selectedProduct.ProductId, CurrentTax.TaxId); } }