TaxRates.ascx.cs :  » Web-Frameworks » nopCommerce » NopSolutions » NopCommerce » Web » Administration » Tax » GeneralTaxConfigure » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Web Frameworks » nopCommerce 
nopCommerce » NopSolutions » NopCommerce » Web » Administration » Tax » GeneralTaxConfigure » TaxRates.ascx.cs
//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using NopSolutions.NopCommerce.BusinessLogic.Directory;
using NopSolutions.NopCommerce.BusinessLogic.Tax;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.Web.Templates.Shipping;
using NopSolutions.NopCommerce.Web.Templates.Tax;

namespace NopSolutions.NopCommerce.Web.Administration.Tax.GeneralTaxConfigure{
    public partial class TaxRatesControl : BaseNopAdministrationUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ToggleGrid(true);
                BindGrid();
            }
        }

        protected void FillTaxCategoryDropDown()
        {
            this.ddlTaxCategory.Items.Clear();
            TaxCategoryCollection taxCategories = TaxCategoryManager.GetAllTaxCategories();
            foreach (TaxCategory taxCategory in taxCategories)
            {
                ListItem ddlTaxCategoryItem2 = new ListItem(taxCategory.Name, taxCategory.TaxCategoryId.ToString());
                this.ddlTaxCategory.Items.Add(ddlTaxCategoryItem2);
            }
        }

        protected void FillCountryDropDowns()
        {
            this.ddlCountry.Items.Clear();
            CountryCollection countryCollection = CountryManager.GetAllCountries();
            foreach (Country country in countryCollection)
            {
                ListItem ddlCountryItem2 = new ListItem(country.Name, country.CountryId.ToString());
                this.ddlCountry.Items.Add(ddlCountryItem2);
            }
        }

        protected void FillStateProvinceDropDowns()
        {
            this.ddlStateProvince.Items.Clear();
            int countryId = int.Parse(this.ddlCountry.SelectedItem.Value);

            StateProvinceCollection stateProvinceCollection = StateProvinceManager.GetStateProvincesByCountryId(countryId);
            ListItem ddlStateProvinceItem = new ListItem("*", "0");
            this.ddlStateProvince.Items.Add(ddlStateProvinceItem);
            foreach (StateProvince stateProvince in stateProvinceCollection)
            {
                ListItem ddlStateProviceItem2 = new ListItem(stateProvince.Name, stateProvince.StateProvinceId.ToString());
                this.ddlStateProvince.Items.Add(ddlStateProviceItem2);
            }
        }

        protected void BindGrid()
        {
            TaxRateCollection taxRates = TaxRateManager.GetAllTaxRates();
            gvTaxRates.DataSource = taxRates;
            gvTaxRates.DataBind();
            if (taxRates.Count > 10)
            {
                btnAddNew1.Visible = true;
                btnAddNew2.Visible = true;
            }
            else
            {
                btnAddNew1.Visible = true;
                btnAddNew2.Visible = false;
            }
        }

        protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillStateProvinceDropDowns();
        }

        protected void gvTaxRates_RowEditing(object source, GridViewEditEventArgs e)
        {
            HiddenField hfTaxRateId = gvTaxRates.Rows[e.NewEditIndex].Cells[0].FindControl("hfTaxRateId") as HiddenField;
            int taxRateId = int.Parse(hfTaxRateId.Value);            
            LoadEditor(taxRateId);
            ToggleGrid(false);
        }
        
        protected void gvTaxRates_RowDeleting(object source, GridViewDeleteEventArgs e)
        {
            HiddenField hfTaxRateId = gvTaxRates.Rows[e.RowIndex].Cells[0].FindControl("hfTaxRateId") as HiddenField;
            int taxRateId = int.Parse(hfTaxRateId.Value);
            TaxRateManager.DeleteTaxRate(taxRateId);
            BindGrid();
        }
        
        protected string GetStateProvinceInfo(int stateProvinceId)
        {
            StateProvince stateProvince = StateProvinceManager.GetStateProvinceById(stateProvinceId);
            if (stateProvince != null)
                return stateProvince.Name;
            else
                return "*";
        }

        protected string GetZipInfo(string Zip)
        {
            if (string.IsNullOrEmpty(Zip))
                return "*";
            else
                return Zip;
        }

        protected void ToggleGrid(bool show)
        {
            pnlGrid.Visible = show;
            pnlEdit.Visible = !show;
        }

        protected void LoadEditor(int taxRateId)
        {
            ToggleGrid(false);
            
            TaxRate taxRate = TaxRateManager.GetTaxRateById(taxRateId);
            if (taxRate != null)
            {
                lblTaxRateId.Text = taxRate.TaxRateId.ToString();

                FillTaxCategoryDropDown();
                CommonHelper.SelectListItem(this.ddlTaxCategory, taxRate.TaxCategoryId);
                FillCountryDropDowns();
                CommonHelper.SelectListItem(this.ddlCountry, taxRate.CountryId);
                FillStateProvinceDropDowns();
                CommonHelper.SelectListItem(this.ddlStateProvince, taxRate.StateProvinceId);
                this.txtZip.Text = taxRate.Zip;
                this.txtPercentage.Value = taxRate.Percentage;
            }
            else
            {
                lblTaxRateId.Text = "0";

                FillTaxCategoryDropDown();
                FillCountryDropDowns();
                FillStateProvinceDropDowns();

                txtZip.Text = string.Empty;
                txtPercentage.Value = decimal.Zero;
            }
        }

        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                LoadEditor(0);
                ToggleGrid(false);
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    int taxRateId = 0;
                    int.TryParse(lblTaxRateId.Text, out taxRateId);
                    int taxCategoryId = int.Parse(this.ddlTaxCategory.SelectedItem.Value);
                    int countryId = int.Parse(this.ddlCountry.SelectedItem.Value);
                    int stateProvinceId = int.Parse(this.ddlStateProvince.SelectedItem.Value);
                    string zipPostalCode = txtZip.Text;
                    decimal percentage = txtPercentage.Value;

                    TaxRate taxRate = TaxRateManager.GetTaxRateById(taxRateId);

                    if (taxRate != null)
                    {
                        taxRate = TaxRateManager.UpdateTaxRate(taxRate.TaxRateId, taxCategoryId,
                            countryId, stateProvinceId, zipPostalCode, percentage);
                    }
                    else
                    {
                        taxRate = TaxRateManager.InsertTaxRate(taxCategoryId,
                            countryId, stateProvinceId, zipPostalCode, percentage);
                    }

                    BindGrid();
                    ToggleGrid(true);
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void CancelButton_Click(object sender, EventArgs e)
        {
            ToggleGrid(true);
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.