Пример #1
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;
        }
    }