Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FillCountryRegionOptionsHtml();

            if (!IsPostBack)
            {
                LoadShippingTransactions();

                int?deleteRateId = WA.Parser.ToInt(Request.QueryString["deleteRate"]);
                if (deleteRateId.HasValue)
                {
                    ShippingServiceRate toDelete = new ShippingServiceRate();
                    if (toDelete.LoadByPrimaryKey(deleteRateId.Value))
                    {
                        toDelete.MarkAsDeleted();
                        toDelete.Save();
                    }
                }
                short?deleteId = WA.Parser.ToShort(Request.QueryString["delete"]);
                if (deleteId.HasValue)
                {
                    DataModel.ShippingServiceRateType toDelete = new DataModel.ShippingServiceRateType();
                    if (toDelete.LoadByPrimaryKey(deleteId.Value))
                    {
                        toDelete.MarkAsDeleted();
                        toDelete.Save();
                    }
                }

                chkShippingTablesEnabled.Checked = shippingTablesService.IsEnabled;

                // FEDEX
                chkFedExEnabled.Checked = fedExService.IsEnabled;
                Dictionary <string, string> fedexSettings = fedExService.GetSettingsDictionary();
                txtFedExAccountNum.Text         = fedexSettings.TryGetValueOrEmpty("accountNumber");
                txtFedExMeterNum.Text           = fedexSettings.TryGetValueOrEmpty("meterNumber");
                txtFedExSmartPostHub.Text       = fedexSettings.TryGetValueOrEmpty("smartPostHubId");
                txtFedExApiKey.Text             = fedexSettings.TryGetValueOrEmpty("apiKey");
                txtFedExApiPassword.Text        = fedexSettings.TryGetValueOrEmpty("apiPassword");
                chkFedExIsTestGateway.Checked   = WA.Parser.ToBool(fedexSettings.TryGetValueOrEmpty("isTestGateway")).GetValueOrDefault(false);
                ddlLabelStockType.SelectedValue = fedexSettings.TryGetValueOrDefault("labelStockType", "0");

                // UPS
                chkUpsEnabled.Checked = upsService.IsEnabled;
                Dictionary <string, string> upsSettings = upsService.GetSettingsDictionary();
                txtUpsUserId.Text           = upsSettings.TryGetValueOrEmpty("userId");
                txtUpsPassword.Text         = upsSettings.TryGetValueOrEmpty("password");
                txtUpsAccountNumber.Text    = upsSettings.TryGetValueOrEmpty("accountNumber");
                txtUpsAccessKey.Text        = upsSettings.TryGetValueOrEmpty("accessKey");
                chkUpsIsTestGateway.Checked = WA.Parser.ToBool(upsSettings.TryGetValueOrEmpty("isTestGateway")).GetValueOrDefault(false);

                LoadShippingRates();
            }
        }
Ejemplo n.º 2
0
        private void SaveShippingRows()
        {
            const string inputPrefix = "shippingRow";
            Regex        rxInputName = new Regex(@"shippingRow\[(\d+)\]\[(.*?)\]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);

            Dictionary <int, Dictionary <string, string[]> > shipMethodIdToNameValues = new Dictionary <int, Dictionary <string, string[]> >();

            foreach (string key in Request.Form)
            {
                Match m = rxInputName.Match(key);
                if (m.Success)
                {
                    int?   shipMethodId = WA.Parser.ToInt(m.Groups[1].Value);
                    string fieldName    = m.Groups[2].Value;
                    if (shipMethodId.HasValue)
                    {
                        if (!shipMethodIdToNameValues.ContainsKey(shipMethodId.Value))
                        {
                            shipMethodIdToNameValues[shipMethodId.Value] = new Dictionary <string, string[]>();
                        }
                        shipMethodIdToNameValues[shipMethodId.Value][fieldName] = Request.Form.GetValues(key);
                    }
                }
            }

            // delete existing rates for this service (we'll re-add them below)
            shippingTablesService.GetAllRateTypes().ForEach(rt => rt.DeleteAllRates());

            //--- Save the dictionary structure to the database
            foreach (var methods in shipMethodIdToNameValues)
            {
                int rateTypeId = methods.Key;

                //ShippingServiceRateCollection.DeleteAllRates(shippingMethodId);

                string[] countryRegionValues = methods.Value["ddlCountryRegion"];
                string[] minWeightValues     = methods.Value["minWeight"];
                string[] maxWeightValues     = methods.Value["maxWeight"];
                string[] costValues          = methods.Value["cost"];

                for (int i = 0; i < countryRegionValues.Length; i++)
                {
                    string  countryValue = "";
                    string  regionValue  = "";
                    decimal?minWeight    = null;
                    decimal?maxWeight    = null;
                    decimal?cost         = null;

                    string[] parts = countryRegionValues[i].Split('|');
                    if (parts.Length == 2)
                    {
                        // Country AND Region
                        countryValue = parts[0];
                        regionValue  = parts[1];
                    }
                    else if (parts.Length == 1)
                    {
                        // Country only
                        countryValue = parts[0];
                    }
                    if (countryValue.ToLower() == "none")
                    {
                        countryValue = "";
                    }
                    minWeight = WA.Parser.ToDecimal(minWeightValues[i]);
                    maxWeight = WA.Parser.ToDecimal(maxWeightValues[i]);
                    cost      = WA.Parser.ToDecimal(costValues[i]);

                    if (cost.HasValue)
                    {
                        // add the rate to the db
                        ShippingServiceRate newRate = new ShippingServiceRate();
                        newRate.RateTypeId  = (short)rateTypeId;
                        newRate.CountryCode = countryValue;
                        newRate.Region      = regionValue;
                        newRate.WeightMin   = minWeight.GetValueOrDefault(0);
                        newRate.WeightMax   = maxWeight.GetValueOrDefault(99999999);
                        newRate.Cost        = cost;
                        newRate.Save();
                    }
                }
            }
        }