Пример #1
0
    /// <summary>
    /// Gets and bulk updates states. Called when the "Get and bulk update states" button is pressed.
    /// Expects the CreateState method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateStates()
    {
        // Get the country
        CountryInfo country = CountryInfoProvider.GetCountryInfo("MyNewCountry");

        if (country != null)
        {
            // Get the data
            DataSet states = StateInfoProvider.GetCountryStates(country.CountryID);
            if (!DataHelper.DataSourceIsEmpty(states))
            {
                // Loop through the individual items
                foreach (DataRow stateDr in states.Tables[0].Rows)
                {
                    // Create object from DataRow
                    StateInfo modifyState = new StateInfo(stateDr);

                    // Update the property
                    modifyState.StateDisplayName = modifyState.StateDisplayName.ToUpper();

                    // Update the state
                    StateInfoProvider.SetStateInfo(modifyState);
                }

                return(true);
            }
        }

        return(false);
    }
Пример #2
0
    /// <summary>
    /// Validates data
    /// </summary>
    protected override void ValidateStepData(object sender, StepEventArgs e)
    {
        base.ValidateStepData(sender, e);

        if (!StopProcessing)
        {
            if (!addressForm.ValidateData())
            {
                e.CancelEvent = true;
                return;
            }
            // Just set current filed values into EditableObject, saving was canceled in OnBeforeSave
            addressForm.SaveData(null, false);

            AddressInfo ai = addressForm.EditedObject as AddressInfo;
            if (ai != null)
            {
                // Validate state
                if (!DataHelper.DataSourceIsEmpty(StateInfoProvider.GetCountryStates(ai.AddressCountryID)))
                {
                    if (ai.AddressStateID < 1)
                    {
                        e.CancelEvent = true;
                        addressForm.DisplayErrorLabel("AddressCountryID", ResHelper.GetString("com.address.nostate"));
                    }
                }
            }
        }
    }
Пример #3
0
        public JsonResult CountryStates(int countryId)
        {
            // Gets the display names of the country's states
            var responseModel = StateInfoProvider.GetCountryStates(countryId)
                                .Select(s => new
            {
                id   = s.StateID,
                name = HTMLHelper.HTMLEncode(s.StateDisplayName)
            });

            // Returns serialized display names of the states
            return(Json(responseModel));
        }
    /// <summary>
    /// Validates data
    /// </summary>
    protected override void ValidateStepData(object sender, StepEventArgs e)
    {
        base.ValidateStepData(sender, e);

        if (!StopProcessing)
        {
            if (!addressForm.ValidateData())
            {
                e.CancelEvent = true;
                return;
            }
            // Just set current filed values into EditableObject, saving was canceled in OnBeforeSave
            addressForm.SaveData(null, false);

            AddressInfo address = addressForm.EditedObject as AddressInfo;
            if (address != null)
            {
                // Validate state
                if (!DataHelper.DataSourceIsEmpty(StateInfoProvider.GetCountryStates(address.AddressCountryID)))
                {
                    if (address.AddressStateID < 1)
                    {
                        e.CancelEvent = true;
                        addressForm.DisplayErrorLabel("AddressCountryID", ResHelper.GetString("com.address.nostate"));
                        return;
                    }
                }


                // Clear AddressName and AddressPersonalName to force their update (only if not present on the address form)
                if (!addressForm.FieldControls.Contains("AddressName"))
                {
                    address.AddressName = null;
                }
                if (!addressForm.FieldControls.Contains("AddressPersonalName"))
                {
                    address.AddressPersonalName = null;
                }

                // Assign validated new address to the current shopping cart
                // Address will be saved by customer detail web part (existing customer object is needed for the address)
                CurrentCartAddress = address;
            }
        }

        // Clear shipping address (StopProcessing is true when chkShowAddress is cleared)
        ClearShippingAddress();
    }
Пример #5
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);
            }
        }
    }
Пример #6
0
 /// <summary>
 /// Returns all states in country with given ID.
 /// </summary>
 /// <param name="countryId">Country identifier</param>
 /// <returns>Collection of all states in county.</returns>
 public IEnumerable <StateInfo> GetCountryStates(int countryId)
 {
     return(StateInfoProvider.GetCountryStates(countryId));
 }