Esempio n. 1
0
 public static bool AddRegionRateToTax(int taxId, RegionalRate rate)
 {
     SQLDataAccess.ExecuteNonQuery("INSERT INTO [Catalog].[TaxRegionRate] ([TaxId], [RegionID], [RegionRate]) VALUES (@taxId, @regionId, @rate)",
                                     CommandType.Text,
                                     new SqlParameter("@taxId", taxId),
                                     new SqlParameter("@regionId", rate.RegionId),
                                     new SqlParameter("@rate", rate.Rate));
     return true;
 }
Esempio n. 2
0
    protected void grid_Command(object sender, GridViewCommandEventArgs e)
    {
        MsgErrRegions(true);
        switch (e.CommandName)
        {
        case "AddNewRegion":
        {
            var ddlRegionNew = (DropDownList)grid.FooterRow.FindControl("ddlRegionNew");
            if (ValidationHelper.IsValidPositiveIntNumber(ddlRegionNew.SelectedValue))
            {
                var rate = new RegionalRate
                {
                    RegionId = Int32.Parse(ddlRegionNew.SelectedValue)
                };
                if (!TaxServices.GetRegionalRatesForTax(CurrentTax.TaxId).Any(rr => rr.RegionId == rate.RegionId))
                {
                    decimal t;
                    rate.Rate = Decimal.TryParse(
                        ((TextBox)grid.FooterRow.FindControl("txtRegionRateNew")).Text,
                        out t)
                                            ? t
                                            : 0;
                    if (!TaxServices.AddRegionRateToTax(CurrentTax.TaxId, rate))
                    {
                        MsgErrRegions(Resources.Resource.Admin_Tax_RegionRateError);
                    }
                }
            }
            regionsPanel.Update();
            //grid.ShowFooter = false;
        }
        break;

        case "CancelAdd":
            grid.ShowFooter = false;
            regionsPanel.Update();
            break;

        case "Delete":
            TaxServices.RemoveRegionalRateFromTax(CurrentTax.TaxId, Int32.Parse((string)e.CommandArgument));
            break;

        case "Update":
        {
            var     regionId = Int32.Parse(((HiddenField)grid.Rows[Int32.Parse(((string)e.CommandArgument))].FindControl("hdRegionId")).Value);
            decimal rate     = 0;
            decimal t;
            if (Decimal.TryParse(((TextBox)grid.Rows[Int32.Parse(((string)e.CommandArgument))].FindControl("txtRegionRate")).Text, out t))
            {
                rate = t;
            }
            else
            {
                rate = 0;
            }
            TaxServices.UpdateRegionalRate(CurrentTax.TaxId, regionId, rate);
        }
        break;

        case "Sort":
        {
            _paging.Fields.Values.Where(x => x.Name != (string)e.CommandArgument).ToList().ForEach(x => x.Sorting = null);
            switch ((string)e.CommandArgument)
            {
            case "RegionName":
            {
                _paging.Fields["RegionName"].Sorting = !_paging.Fields["RegionName"].Sorting.HasValue ?
                                                       SortDirection.Ascending :
                                                       (_paging.Fields["RegionName"].Sorting == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending);
                grid.ChangeHeaderImageUrl("arrowName", _paging.Fields["RegionName"].Sorting == SortDirection.Ascending ? "images/arrowup.gif" : "images/arrowdown.gif");
            }
            break;

            case "RegionRate":
            {
                _paging.Fields["RegionRate"].Sorting = !_paging.Fields["RegionRate"].Sorting.HasValue ?
                                                       SortDirection.Ascending :
                                                       (_paging.Fields["RegionRate"].Sorting == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending);
                grid.ChangeHeaderImageUrl("arrowRate", _paging.Fields["RegionRate"].Sorting == SortDirection.Ascending ? "images/arrowup.gif" : "images/arrowdown.gif");
            }
            break;
            }
        }
        break;
        }
    }
Esempio n. 3
0
        public static ICollection<TaxElement> GetTaxesForProduct(int productId, CustomerContact sellerContact, CustomerContact billingContact, CustomerContact shippingContact)
        {
            using (var da = new SQLDataAccess())
            {
                da.cmd.CommandText = "SELECT [Catalog].[Tax].*, [Catalog].[TaxRegionRate].[RegionID], [Catalog].[TaxRegionRate].[RegionRate] " +
                                     "FROM [Catalog].[Tax] " +
                                     "LEFT JOIN [Catalog].[TaxRegionRate] ON [Tax].[TaxId] = [TaxRegionRate].[TaxId] " +
                                     "WHERE [Tax].TaxId in (select TaxId from [Catalog].[TaxMappingOnProduct] where [ProductID] = @ProductID) AND [Enabled] = 1 AND " +
                                     "([DependsOnAddress] = @default  AND [CountryID] = @sellerCountry   AND ([RegionID] = @sellerRegion OR [RegionID] is null)) OR " +
                                     "([DependsOnAddress] = @shipping AND [CountryID] = @shippingCountry AND ([RegionID] = @shippingRegion OR [RegionID] is null)) OR " +
                                     "([DependsOnAddress] = @billing  AND [CountryID] = @billingCountry  AND ([RegionID] = @billingRegion OR [RegionID] is null))";
                da.cmd.CommandType = CommandType.Text;
                da.cmd.Parameters.AddWithValue("@default", (int)TypeRateDepends.Default);
                da.cmd.Parameters.AddWithValue("@shipping", (int)TypeRateDepends.ByShippingAddress);
                da.cmd.Parameters.AddWithValue("@billing", (int)TypeRateDepends.ByBillingAddress);
                da.cmd.Parameters.AddWithValue("@sellerCountry", sellerContact.CountryId);
                da.cmd.Parameters.AddWithValue("@sellerRegion", sellerContact.RegionId.HasValue ? sellerContact.RegionId : (object)DBNull.Value);
                da.cmd.Parameters.AddWithValue("@shippingCountry", shippingContact.CountryId);
                da.cmd.Parameters.AddWithValue("@shippingRegion", shippingContact.RegionId.HasValue ? shippingContact.RegionId : (object)DBNull.Value);
                da.cmd.Parameters.AddWithValue("@billingCountry", billingContact.CountryId);
                da.cmd.Parameters.AddWithValue("@billingRegion", billingContact.RegionId.HasValue ? billingContact.RegionId : (object)DBNull.Value);
                da.cmd.Parameters.AddWithValue("@ProductID", productId);

                da.cnOpen();
                var result = new List<TaxElement>();
                using (SqlDataReader reader = da.cmd.ExecuteReader())
                    while (reader.Read())
                    {
                        var t = ReadTax(reader);

                        var regionalRateCollection = new List<RegionalRate>();
                        t.RegionalRates = regionalRateCollection;
                        if (!(reader["RegionID"] is DBNull))
                        {
                            var regionalRate = new RegionalRate
                            {
                                RegionId = SQLDataHelper.GetInt(reader, "RegionID"),
                                Rate = SQLDataHelper.GetFloat(reader, "RegionRate")
                            };
                            regionalRateCollection.Add(regionalRate);

                        }
                        result.Add(t);
                    }

                return result;
            }
        }
Esempio n. 4
0
        protected void grid_Command(object sender, GridViewCommandEventArgs e)
        {
            MsgErrRegions(true);
            switch (e.CommandName)
            {
                case "AddNewRegion":
                    {
                        var ddlRegionNew = (DropDownList) grid.FooterRow.FindControl("ddlRegionNew");
                        if (ValidationHelper.IsValidPositiveIntNumber(ddlRegionNew.SelectedValue))
                        {
                            var rate = new RegionalRate
                                {
                                    RegionId = Int32.Parse(ddlRegionNew.SelectedValue)
                                };
                            if (!TaxServices.GetRegionalRatesForTax(CurrentTax.TaxId).Any(rr => rr.RegionId == rate.RegionId))
                            {
                                float t;
                                rate.Rate = float.TryParse(
                                    ((TextBox) grid.FooterRow.FindControl("txtRegionRateNew")).Text,
                                    out t)
                                                ? t
                                                : 0;
                                if (!TaxServices.AddRegionRateToTax(CurrentTax.TaxId, rate))
                                {
                                    MsgErrRegions(Resources.Resource.Admin_Tax_RegionRateError);
                                }
                            }
                        }
                        regionsPanel.Update();
                        //grid.ShowFooter = false;

                    }
                    break;

                case "CancelAdd":
                    grid.ShowFooter = false;
                    regionsPanel.Update();
                    break;

                case "Delete":
                    TaxServices.RemoveRegionalRateFromTax(CurrentTax.TaxId, Int32.Parse((string)e.CommandArgument));
                    break;

                case "Update":
                    {
                        var regionId = Int32.Parse(((HiddenField)grid.Rows[Int32.Parse(((string)e.CommandArgument))].FindControl("hdRegionId")).Value);
                        float rate = 0;
                        float t;
                        if (float.TryParse(((TextBox)grid.Rows[Int32.Parse(((string)e.CommandArgument))].FindControl("txtRegionRate")).Text, out t))
                        {
                            rate = t;
                        }
                        else
                        {
                            rate = 0;
                        }
                        TaxServices.UpdateRegionalRate(CurrentTax.TaxId, regionId, rate);
                    }
                    break;

                case "Sort":
                    {
                        _paging.Fields.Values.Where(x => x.Name != (string)e.CommandArgument).ToList().ForEach(x => x.Sorting = null);
                        switch ((string)e.CommandArgument)
                        {
                            case "RegionName":
                                {
                                    _paging.Fields["RegionName"].Sorting = !_paging.Fields["RegionName"].Sorting.HasValue ?
                                                                               SortDirection.Ascending :
                                                                               (_paging.Fields["RegionName"].Sorting == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending);
                                    grid.ChangeHeaderImageUrl("arrowName", _paging.Fields["RegionName"].Sorting == SortDirection.Ascending ? "images/arrowup.gif" : "images/arrowdown.gif");
                                }
                                break;
                            case "RegionRate":
                                {
                                    _paging.Fields["RegionRate"].Sorting = !_paging.Fields["RegionRate"].Sorting.HasValue ?
                                                                               SortDirection.Ascending :
                                                                               (_paging.Fields["RegionRate"].Sorting == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending);
                                    grid.ChangeHeaderImageUrl("arrowRate", _paging.Fields["RegionRate"].Sorting == SortDirection.Ascending ? "images/arrowup.gif" : "images/arrowdown.gif");
                                }
                                break;
                        }
                    }
                    break;
            }
        }