Example #1
0
        /// <summary>
        /// Initializes the stores collection and determines the default store filter
        /// </summary>
        private void InitializeStores()
        {
            Stores = Store.GetStoreList();

            if (!IsPostBack || Stores.Count == 1)
            {
                int qStoreId = Request.QueryStringNativeInt("StoreId");
                if (Stores.Any(store => store.StoreID == qStoreId))
                {
                    StoreFilter = qStoreId;
                }
                else
                {
                    // default to All
                    //StoreFilter = Shipping.DONT_FILTER_PER_STORE;
                    var defStore = Stores.FirstOrDefault(store => store.IsDefault);
                    StoreFilter = defStore.StoreID;
                }
            }
            else
            {
                StoreFilter = Request.Form["StoreFilter"].ToNativeInt();
            }
        }
Example #2
0
        protected void gMain_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = gMain.Rows[e.RowIndex];

            if (row != null)
            {
                string        iden     = row.Cells[2].Text.ToString(); // the StringResourceId column
                TextBox       txtName  = (TextBox)row.FindControl("txtName");
                TextBox       txtValue = (TextBox)row.FindControl("txtValue");
                DropDownList  ddLocale = (DropDownList)row.FindControl("ddLocale");
                StringBuilder sql      = new StringBuilder(2500);

                int    stringResourceId = iden.ToNativeInt();
                string name             = txtName.Text;
                string selectedLocale   = ddLocale.SelectedValue;
                string value            = txtValue.Text;
                int    prevStoreId      = row.FindControl <HiddenField>("hdfPrevStoreId").Value.ToNativeInt();

                var defaultStore = Stores.FirstOrDefault(store => store.IsDefault);
                int storeId      = 1; // default
                if (Stores.Count > 1)
                {
                    var cboEditStores = row.FindControl <DropDownList>("cboEditStores");
                    if (cboEditStores.SelectedIndex == 0) // All means also the default store
                    {
                        storeId = defaultStore.StoreID;
                    }
                    else
                    {
                        storeId = cboEditStores.SelectedValue.ToNativeInt();
                    }
                }
                else
                {
                    storeId = row.FindControl <Label>("lblStoreId").Text.ToNativeInt();
                }

                var owningStore = Stores.FirstOrDefault(store => store.StoreID == storeId);

                // check if the user specified a different storeid
                if (storeId != prevStoreId)
                {
                    // check if we have a previous string resource with that storeid+name+locale
                    var prevStringResource = StringResourceManager.GetStringResource(prevStoreId, selectedLocale, name);
                    var newStoreString     = StringResourceManager.GetStringResource(storeId, selectedLocale, name);

                    // check if we have a duplicate on the destination store
                    if (newStoreString != null)
                    {
                        // just update that one instead
                        newStoreString.Update(name, selectedLocale, value);

                        string updateNotice = string.Format("Item [{0}] updated for store: {1} ({2})", name, owningStore.Name, owningStore.StoreID);
                        resetError(updateNotice, false);
                        gMain.EditIndex = -1;

                        // nuke the other store string
                        if (prevStringResource != null)
                        {
                            // nuke the previous one
                            prevStringResource.Owner.Remove(prevStringResource);
                        }
                    }
                    else
                    {
                        // create a copy of that string resource for this store
                        newStoreString = StringResource.Create(storeId, name, selectedLocale, value);

                        var storeStrings = StringResourceManager.GetStringResources(storeId);
                        storeStrings.Add(newStoreString);

                        DuplicatedStringResource = newStoreString.StringResourceID;
                        if (prevStringResource != null)
                        {
                            DuplicatedFromStringResource = prevStringResource.StringResourceID;
                        }

                        string updateNotice = string.Format("Item [{0}] duplicated for store: {1} ({2})", name, owningStore.Name, owningStore.StoreID);
                        resetError(updateNotice, false);
                        gMain.EditIndex = -1;
                    }
                }
                else
                {
                    // find if there's an existing string resource with that name+locale+storeid pair
                    var dupString = StringResourceManager.GetStringResource(storeId, selectedLocale, name);
                    if (dupString != null && dupString.StringResourceID != stringResourceId)
                    {
                        // prompt for error editing duplicate in same Store Strings
                        resetError("Another string exists with that Name and Locale combination.", true);
                        return;
                    }

                    // just edit the current string resource
                    var str = StringResourceManager.GetStringResource(storeId, stringResourceId);
                    if (str != null)
                    {
                        str.Update(name, selectedLocale, value);
                        resetError("Item updated", false);
                        gMain.EditIndex = -1;
                    }
                    else
                    {
                        resetError("Item could not be found in collection", true);
                    }
                }

                resultFilter("", Localization.CheckLocaleSettingForProperCase(selectedLocale));
            }
        }