Exemplo n.º 1
0
    /// <summary>
    /// Deletes state. Called when the "Delete state" button is pressed.
    /// Expects the CreateState method to be run first.
    /// </summary>
    private bool DeleteState()
    {
        // Get the state
        StateInfo deleteState = StateInfoProvider.GetStateInfo("MyNewState");

        // Delete the state
        StateInfoProvider.DeleteStateInfo(deleteState);

        return(deleteState != null);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            int countryId = ValidationHelper.GetInteger(actionArgument, 0);

            bool dependent = false;

            // Get country states
            DataSet ds = StateInfoProvider.GetCountryStates(countryId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                // Check dependency of all state at first
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int stateId = ValidationHelper.GetInteger(dr["StateID"], 0);
                    if (StateInfoProvider.CheckDependencies(stateId))
                    {
                        dependent = true;
                        break;
                    }
                }
            }

            // Get country dependency without states
            DataSet dsCountryDependency = CountryInfoProvider.GetCountries(String.Format("(CountryID IN (SELECT AddressCountryID FROM COM_Address WHERE AddressCountryID={0}) OR CountryID IN (SELECT CustomerCountryID FROM COM_Customer WHERE CustomerCountryID={0}) OR CountryID IN (SELECT CountryID FROM COM_TaxClassCountry WHERE CountryID={0}))", countryId), null, 1, "CountryID");

            // Check dependency of country itself
            dependent |= (!DataHelper.DataSourceIsEmpty(dsCountryDependency));

            if (dependent)
            {
                ShowError(GetString("ecommerce.deletedisabledwithoutenable"));
            }
            else
            {
                // Delete all states
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int stateId = ValidationHelper.GetInteger(dr["StateID"], 0);
                    StateInfoProvider.DeleteStateInfo(stateId);
                }

                // Delete CountryInfo object from database
                CountryInfoProvider.DeleteCountryInfo(countryId);
            }
        }
    }