private void SaveData() { ShippingMethod.Name = this.NameField.Text.Trim(); ShippingMethod.ZoneId = long.Parse(this.lstZones.SelectedItem.Value); ShippingMethod.AdjustmentType = (ShippingMethodAdjustmentType)int.Parse(AdjustmentDropDownList.SelectedValue); ShippingMethod.Adjustment = decimal.Parse(AdjustmentTextBox.Text, System.Globalization.NumberStyles.Currency); // Global Settings MyPage.MTApp.CurrentStore.Settings.ShippingUSPostalDiagnostics = this.Diagnostics.Checked; // Method Settings USPostalServiceSettings Settings = new USPostalServiceSettings(); Settings.Merge(ShippingMethod.Settings); // Service Code List <MerchantTribe.Shipping.IServiceCode> filter = new List <MerchantTribe.Shipping.IServiceCode>(); foreach (ListItem item in ShippingTypesCheckBoxList.Items) { if (item.Selected) { MerchantTribe.Shipping.ServiceCode code = new MerchantTribe.Shipping.ServiceCode() { Code = item.Value, DisplayName = item.Text }; filter.Add(code); } } Settings.ServiceCodeFilter = filter; ShippingMethod.Settings.Merge(Settings); MyPage.MTApp.UpdateCurrentStore(); }
private void LoadData() { NameField.Text = ShippingMethod.Name; if (NameField.Text == string.Empty) { NameField.Text = Localization.GetString("USPostalServiceInternational"); } // Adjustment AdjustmentDropDownList.SelectedValue = ((int)ShippingMethod.AdjustmentType).ToString(); if (ShippingMethod.AdjustmentType == ShippingMethodAdjustmentType.Amount) { AdjustmentTextBox.Text = string.Format("{0:c}", ShippingMethod.Adjustment); } else { AdjustmentTextBox.Text = string.Format("{0:f}", ShippingMethod.Adjustment); } // Zones if (lstZones.Items.FindByValue(ShippingMethod.ZoneId.ToString()) != null) { lstZones.ClearSelection(); lstZones.Items.FindByValue(ShippingMethod.ZoneId.ToString()).Selected = true; } // Global txtUserId.Text = HccApp.CurrentStore.Settings.ShippingUSPostalUserId; chbDiagnostics.Checked = HccApp.CurrentStore.Settings.ShippingUSPostalDiagnostics; var settings = new USPostalServiceSettings(); settings.Merge(ShippingMethod.Settings); foreach (ServiceCode code in settings.ServiceCodeFilter) { foreach (ListItem item in ShippingTypesCheckBoxList.Items) { if (string.Compare(item.Value, code.Code, true) == 0) { item.Selected = true; break; } } } // Select Hightlights var highlight = settings.GetSettingOrEmpty("highlight"); if (lstHighlights.Items.FindByText(highlight) != null) { lstHighlights.ClearSelection(); lstHighlights.Items.FindByText(highlight).Selected = true; } }
private void LoadData() { this.NameField.Text = ShippingMethod.Name; if (this.NameField.Text == string.Empty) { this.NameField.Text = "US Postal Service"; } // Adjustment AdjustmentDropDownList.SelectedValue = ((int)ShippingMethod.AdjustmentType).ToString(); if (ShippingMethod.AdjustmentType == ShippingMethodAdjustmentType.Amount) { AdjustmentTextBox.Text = string.Format("{0:c}", ShippingMethod.Adjustment); } else { AdjustmentTextBox.Text = string.Format("{0:f}", ShippingMethod.Adjustment); } // Zones if (this.lstZones.Items.FindByValue(ShippingMethod.ZoneId.ToString()) != null) { this.lstZones.ClearSelection(); this.lstZones.Items.FindByValue(ShippingMethod.ZoneId.ToString()).Selected = true; } // Global this.Diagnostics.Checked = MyPage.MTApp.CurrentStore.Settings.ShippingUSPostalDiagnostics; USPostalServiceSettings settings = new USPostalServiceSettings(); settings.Merge(ShippingMethod.Settings); foreach (MerchantTribe.Shipping.ServiceCode code in settings.ServiceCodeFilter) { foreach (ListItem item in ShippingTypesCheckBoxList.Items) { if (string.Compare(item.Value, code.Code, true) == 0) { item.Selected = true; break; } } } string matchPackage = ((int)settings.PackageType).ToString(); if (lstPackageType.Items.FindByValue(matchPackage) != null) { lstPackageType.ClearSelection(); lstPackageType.Items.FindByValue(matchPackage).Selected = true; } }
private void SaveData() { ShippingMethod.Name = NameField.Text.Trim(); ShippingMethod.ZoneId = long.Parse(lstZones.SelectedItem.Value); ShippingMethod.AdjustmentType = (ShippingMethodAdjustmentType)int.Parse(AdjustmentDropDownList.SelectedValue); ShippingMethod.Adjustment = decimal.Parse(AdjustmentTextBox.Text, NumberStyles.Currency); if (ShippingMethod.AdjustmentType == ShippingMethodAdjustmentType.Amount) { ShippingMethod.Adjustment = Money.RoundCurrency(ShippingMethod.Adjustment); } // Global Settings HccApp.CurrentStore.Settings.ShippingUSPostalUserId = txtUserId.Text.Trim(); HccApp.CurrentStore.Settings.ShippingUSPostalDiagnostics = chbDiagnostics.Checked; HccApp.UpdateCurrentStore(); // Method Settings var Settings = new USPostalServiceSettings(); Settings.Merge(ShippingMethod.Settings); // Service Code var filter = new List <IServiceCode>(); foreach (ListItem item in ShippingTypesCheckBoxList.Items) { if (item.Selected) { var code = new ServiceCode { Code = item.Value, DisplayName = item.Text }; filter.Add(code); } } Settings.ServiceCodeFilter = filter; Settings["highlight"] = lstHighlights.SelectedValue; // Package var packageCode = lstPackageType.SelectedItem.Value; var packageCodeInt = -1; if (int.TryParse(packageCode, out packageCodeInt)) { Settings.PackageType = (DomesticPackageType)packageCodeInt; } ShippingMethod.Settings.Merge(Settings); }
private void SaveData() { ShippingMethod.Name = this.NameField.Text.Trim(); ShippingMethod.ZoneId = long.Parse(this.lstZones.SelectedItem.Value); ShippingMethod.AdjustmentType = (ShippingMethodAdjustmentType)int.Parse(AdjustmentDropDownList.SelectedValue); ShippingMethod.Adjustment = decimal.Parse(AdjustmentTextBox.Text, System.Globalization.NumberStyles.Currency); // Global Settings MyPage.MTApp.CurrentStore.Settings.ShippingUSPostalDiagnostics = this.Diagnostics.Checked; MyPage.MTApp.AccountServices.Stores.Update(MyPage.MTApp.CurrentStore); // Method Settings USPostalServiceSettings Settings = new USPostalServiceSettings(); Settings.Merge(ShippingMethod.Settings); // Service Code List <MerchantTribe.Shipping.IServiceCode> filter = new List <MerchantTribe.Shipping.IServiceCode>(); foreach (ListItem item in ShippingTypesCheckBoxList.Items) { if (item.Selected) { MerchantTribe.Shipping.ServiceCode code = new MerchantTribe.Shipping.ServiceCode() { Code = item.Value, DisplayName = item.Text }; filter.Add(code); } } Settings.ServiceCodeFilter = filter; Settings["highlight"] = this.lstHighlights.SelectedValue; // Package string packageCode = this.lstPackageType.SelectedItem.Value; int packageCodeInt = -1; if (int.TryParse(packageCode, out packageCodeInt)) { Settings.PackageType = (MerchantTribe.Shipping.USPostal.v4.DomesticPackageType)packageCodeInt; } ShippingMethod.Settings.Merge(Settings); }
protected void btnGetRates_Click(object sender, EventArgs e) { MerchantTribe.Shipping.Shipment shipment = new MerchantTribe.Shipping.Shipment(); shipment.DestinationAddress.PostalCode = this.ToZipField.Text.Trim(); shipment.SourceAddress.PostalCode = this.FromZipField.Text.Trim(); // box MerchantTribe.Shipping.Shippable item = new MerchantTribe.Shipping.Shippable(); decimal length = 0m; decimal.TryParse(this.LengthField.Text.Trim(), out length); decimal height = 0m; decimal.TryParse(this.HeightField.Text.Trim(), out height); decimal width = 0m; decimal.TryParse(this.WidthField.Text.Trim(), out width); decimal weightPounds = 0m; decimal.TryParse(this.WeightPoundsField.Text.Trim(), out weightPounds); decimal weightOunces = 0m; decimal.TryParse(this.WeightOuncesField.Text.Trim(), out weightOunces); item.BoxLength = length; item.BoxHeight = height; item.BoxWidth = width; item.BoxLengthType = MerchantTribe.Shipping.LengthType.Inches; item.BoxWeight = weightPounds + MerchantTribe.Web.Conversions.OuncesToDecimalPounds(weightOunces); item.BoxWeightType = MerchantTribe.Shipping.WeightType.Pounds; item.QuantityOfItemsInBox = 1; shipment.Items.Add(item); // Global Settings MerchantTribe.Shipping.USPostal.USPostalServiceGlobalSettings globalSettings = new USPostalServiceGlobalSettings(); globalSettings.DiagnosticsMode = true; globalSettings.IgnoreDimensions = false; // Settings MerchantTribe.Shipping.USPostal.USPostalServiceSettings settings = new USPostalServiceSettings(); MerchantTribe.Shipping.ServiceCode code = new MerchantTribe.Shipping.ServiceCode(); code.Code = this.lstServiceTypes.SelectedItem.Value; code.DisplayName = this.lstServiceTypes.SelectedItem.Text; List <MerchantTribe.Shipping.IServiceCode> codes = new List <MerchantTribe.Shipping.IServiceCode>(); codes.Add(code); settings.ServiceCodeFilter = codes; int temp = -1; int.TryParse(this.lstPackagingType.SelectedItem.Value, out temp); settings.PackageType = (MerchantTribe.Shipping.USPostal.v4.DomesticPackageType)temp; // Provider MerchantTribe.Web.Logging.TextLogger logger = new MerchantTribe.Web.Logging.TextLogger(); MerchantTribe.Shipping.USPostal.DomesticProvider provider = new DomesticProvider(globalSettings, logger); provider.Settings = settings; List <MerchantTribe.Shipping.IShippingRate> rates = provider.RateShipment(shipment); this.litRates.Text = "<ul>"; foreach (MerchantTribe.Shipping.IShippingRate rate in rates) { this.litRates.Text += "<li>" + rate.EstimatedCost.ToString("c") + " - " + rate.DisplayName + "</li>"; } this.litRates.Text += "</ul>"; this.litMessages.Text = "<ul>"; foreach (MerchantTribe.Shipping.ShippingServiceMessage msg in provider.LatestMessages) { switch (msg.MessageType) { case MerchantTribe.Shipping.ShippingServiceMessageType.Diagnostics: this.litMessages.Text += "<li>DIAGNOSTICS:"; break; case MerchantTribe.Shipping.ShippingServiceMessageType.Information: this.litMessages.Text += "<li>INFO:"; break; case MerchantTribe.Shipping.ShippingServiceMessageType.Error: this.litMessages.Text += "<li>ERROR:"; break; } this.litMessages.Text += System.Web.HttpUtility.HtmlEncode(msg.Description + " " + msg.Code) + "</li>"; } this.litMessages.Text += "</ul>"; this.litXml.Text = ""; while (logger.Messages.Count > 0) { string tempXml = logger.Messages.Dequeue(); tempXml = tempXml.Replace("\n", "<br />"); tempXml = tempXml.Replace("\r", "<br />"); tempXml = tempXml.Replace("\t", " "); this.litXml.Text += "<li>" + System.Web.HttpUtility.HtmlEncode(tempXml) + "</li>"; } }
protected void btnGetRates_Click(object sender, EventArgs e) { pnlRates.Visible = true; var shipment = new Shipment { DestinationAddress = { PostalCode = ToZipField.Text.Trim() }, SourceAddress = { PostalCode = FromZipField.Text.Trim() } }; // box var item = new Shippable(); var length = 0m; decimal.TryParse(LengthField.Text.Trim(), out length); var height = 0m; decimal.TryParse(HeightField.Text.Trim(), out height); var width = 0m; decimal.TryParse(WidthField.Text.Trim(), out width); var weightPounds = 0m; decimal.TryParse(WeightPoundsField.Text.Trim(), out weightPounds); var weightOunces = 0m; decimal.TryParse(WeightOuncesField.Text.Trim(), out weightOunces); item.BoxLength = length; item.BoxHeight = height; item.BoxWidth = width; item.BoxLengthType = LengthType.Inches; item.BoxWeight = weightPounds + Conversions.OuncesToDecimalPounds(weightOunces); item.BoxWeightType = WeightType.Pounds; item.QuantityOfItemsInBox = 1; shipment.Items.Add(item); // Global Settings var globalSettings = new USPostalServiceGlobalSettings { UserId = HccApp.CurrentStore.Settings.ShippingUSPostalUserId, DiagnosticsMode = true, IgnoreDimensions = false }; // Settings var settings = new USPostalServiceSettings(); var code = new ServiceCode { Code = lstServiceTypes.SelectedItem.Value, DisplayName = lstServiceTypes.SelectedItem.Text }; var codes = new List <IServiceCode> { code }; settings.ServiceCodeFilter = codes; var temp = -1; int.TryParse(lstPackagingType.SelectedItem.Value, out temp); settings.PackageType = (DomesticPackageType)temp; // Provider var logger = new TextLogger(); var provider = new DomesticProvider(globalSettings, logger) { Settings = settings }; var rates = provider.RateShipment(shipment); var sbRates = new StringBuilder(); sbRates.Append("<ul>"); foreach (var rate in rates) { sbRates.Append("<li>"); sbRates.Append(rate.EstimatedCost.ToString("c")); sbRates.Append(" - "); sbRates.Append(rate.DisplayName); sbRates.Append("</li>"); } sbRates.Append("</ul>"); litRates.Text = sbRates.ToString(); var sbMessages = new StringBuilder(); sbMessages.Append("<ul>"); foreach (var msg in provider.LatestMessages) { sbMessages.Append("<li>"); switch (msg.MessageType) { case ShippingServiceMessageType.Diagnostics: sbMessages.Append(Localization.GetString("Diagnostics")); break; case ShippingServiceMessageType.Information: sbMessages.Append(Localization.GetString("Info")); break; case ShippingServiceMessageType.Error: sbMessages.Append(Localization.GetString("Error")); break; } sbMessages.Append(":"); sbMessages.Append(HttpUtility.HtmlEncode(string.Concat(msg.Description, " ", msg.Code))); sbMessages.Append("</li>"); } sbMessages.Append("</ul>"); litMessages.Text = sbMessages.ToString(); litXml.Text = string.Empty; while (logger.Messages.Count > 0) { var tempXml = logger.Messages.Dequeue(); tempXml = tempXml.Replace("\n", "<br />"); tempXml = tempXml.Replace("\r", "<br />"); tempXml = tempXml.Replace("\t", " "); litXml.Text += "<li>" + HttpUtility.HtmlEncode(tempXml) + "</li>"; } }