void grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { if (method != null && method.ShippingMethodId > 0) { var lstTableRates = new List <ShippingTableRate>(); switch ((ShippingMethodProvider)method.ShippingProvider) { case ShippingMethodProvider.ByOrderTotal: case ShippingMethodProvider.ByWeight: lstTableRates = ShippingTableRate.GetByMethod(shippingMethodId); grid.DataSource = lstTableRates; grid.Columns.FindByUniqueName("GeoZoneName").Visible = false; break; case ShippingMethodProvider.ByGeoZoneAndFixed: case ShippingMethodProvider.ByGeoZoneAndOrderTotal: case ShippingMethodProvider.ByGeoZoneAndWeight: lstTableRates = ShippingTableRate.GetByMethod(shippingMethodId); grid.DataSource = lstTableRates; grid.Columns.FindByUniqueName("GeoZoneName").Visible = true; break; } switch ((ShippingMethodProvider)method.ShippingProvider) { case ShippingMethodProvider.ByOrderTotal: grid.Columns.FindByUniqueName("FromValue").Visible = true; grid.Columns.FindByUniqueName("FromValue").HeaderText = ProductResources.ShippingFeeByOrderTotal; break; case ShippingMethodProvider.ByWeight: grid.Columns.FindByUniqueName("FromValue").Visible = true; grid.Columns.FindByUniqueName("FromValue").HeaderText = ProductResources.ShippingFeeByOrderWeight; break; case ShippingMethodProvider.ByGeoZoneAndFixed: grid.Columns.FindByUniqueName("FromValue").Visible = false; break; case ShippingMethodProvider.ByGeoZoneAndOrderTotal: grid.Columns.FindByUniqueName("FromValue").Visible = true; grid.Columns.FindByUniqueName("FromValue").HeaderText = ProductResources.ShippingFeeByOrderTotal; break; case ShippingMethodProvider.ByGeoZoneAndWeight: grid.Columns.FindByUniqueName("FromValue").Visible = true; grid.Columns.FindByUniqueName("FromValue").HeaderText = ProductResources.ShippingFeeByOrderWeight; break; } if (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndFixed || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight) { grid.Columns.FindByUniqueName("FreeShippingOverXValue").Visible = true; } if (lstTableRates.Count > 0) { divExportData.Visible = true; } } }
public bool DeleteContent(string shippingMethodId) { try { ShippingMethod method = new ShippingMethod(Convert.ToInt32(shippingMethodId)); if (method != null && method.ShippingMethodId > 0) { ContentLanguage.DeleteByContent(method.Guid); ShippingTableRate.DeleteByMethod(method.ShippingMethodId); ShippingMethod.Delete(method.ShippingMethodId); } } catch (Exception) { return(false); } return(true); }
private DataTable GetShippingTableRatesForExport(ShippingMethodProvider provider, bool exportGeoZone) { DataTable dt = new DataTable(); string geoZoneIdColumn = ProductResources.ShippingFeeGeoZoneId; string geoZoneNameColumn = ProductResources.ShippingFeeGeoZoneName; if (!exportGeoZone) { geoZoneIdColumn = " "; geoZoneNameColumn = " "; } string shippingFeeColumn = ProductResources.ShippingFeeLabel; string orderColumn = ProductResources.ShippingFeeByOrderTotal; if (provider == ShippingMethodProvider.ByWeight || provider == ShippingMethodProvider.ByGeoZoneAndWeight) { orderColumn = ProductResources.ShippingFeeByOrderWeight; } dt.Columns.Add(geoZoneIdColumn, typeof(Guid)); dt.Columns.Add(geoZoneNameColumn, typeof(string)); dt.Columns.Add(shippingFeeColumn, typeof(string)); if (provider != ShippingMethodProvider.ByGeoZoneAndFixed) { dt.Columns.Add(orderColumn, typeof(string)); } string freeShippingOverXColumn = ProductResources.ShippingMethodFreeShippingOverX; if (provider == ShippingMethodProvider.ByGeoZoneAndFixed || provider == ShippingMethodProvider.ByGeoZoneAndWeight) { dt.Columns.Add(freeShippingOverXColumn, typeof(string)); } var lstTableRates = ShippingTableRate.GetByMethod(shippingMethodId); foreach (ShippingTableRate tableRate in lstTableRates) { DataRow row = dt.NewRow(); if (exportGeoZone) { row[geoZoneIdColumn] = tableRate.GeoZoneGuid; row[geoZoneNameColumn] = tableRate.GeoZoneName; } bool isAddional = tableRate.AdditionalFee > 0 && tableRate.AdditionalValue > 0 && (method.ShippingProvider == (int)ShippingMethodProvider.ByWeight || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight); if (isAddional) { row[shippingFeeColumn] = Convert.ToDouble(tableRate.ShippingFee).ToString() + "+" + Convert.ToDouble(tableRate.AdditionalFee).ToString(); } else { row[shippingFeeColumn] = Convert.ToDouble(tableRate.ShippingFee); } if (provider != ShippingMethodProvider.ByGeoZoneAndFixed) { if (isAddional) { row[orderColumn] = Convert.ToDouble(tableRate.FromValue).ToString() + "+" + Convert.ToDouble(tableRate.AdditionalValue).ToString(); } else { row[orderColumn] = Convert.ToDouble(tableRate.FromValue); } } if (provider == ShippingMethodProvider.ByGeoZoneAndFixed || provider == ShippingMethodProvider.ByGeoZoneAndWeight) { row[freeShippingOverXColumn] = Convert.ToDouble(tableRate.FreeShippingOverXValue); } dt.Rows.Add(row); } return(dt); }
private bool ImportData(ShippingMethod method) { bool result = false; int i = 1; try { HSSFWorkbook workbook = new HSSFWorkbook(fileUpload.UploadedFiles[0].InputStream, true); ISheet worksheet = workbook.GetSheetAt(0); if (worksheet == null) { return(false); } int iFinished = 0; bool shippingByGeoZone = (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndFixed || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndOrderTotal || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight ); List <ShippingTableRate> lstTableRates = new List <ShippingTableRate>(); if (shippingMethodId > 0) { lstTableRates = ShippingTableRate.GetByMethod(method.ShippingMethodId); } for (i = 1; i <= worksheet.LastRowNum; i++) { IRow dataRow = worksheet.GetRow(i); if (dataRow != null) { string excelGeoZoneGuid = GetValueFromExcel(dataRow.GetCell(0)).Trim(); string excelShippingFee = GetValueFromExcel(dataRow.GetCell(2)).Trim(); string excelFromValue = GetValueFromExcel(dataRow.GetCell(3)).Trim(); string excelOverXValue = GetValueFromExcel(dataRow.GetCell(4)).Trim(); bool isValid = true; if (string.IsNullOrEmpty(excelShippingFee)) { isValid = false; } if (shippingByGeoZone) { if (excelGeoZoneGuid.Length != 36) { isValid = false; } if ((method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndOrderTotal || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight) && string.IsNullOrEmpty(excelFromValue)) { isValid = false; } } else if (string.IsNullOrEmpty(excelFromValue)) { isValid = false; } if (!isValid) { iFinished += 1; if (iFinished >= 2) { break; } continue; } iFinished = 0; var lstShippingFee = excelShippingFee.SplitOnChar('+'); var lstFromValue = excelFromValue.SplitOnChar('+'); Guid geoZoneGuid = Guid.Empty; decimal shippingFee = Convert.ToDecimal(lstShippingFee[0]); decimal fromValue = decimal.Zero; decimal additionalFee = decimal.Zero; decimal additionalValue = decimal.Zero; if (shippingByGeoZone) { geoZoneGuid = new Guid(excelGeoZoneGuid); if ((method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndOrderTotal || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight)) { fromValue = Convert.ToDecimal(lstFromValue[0]); } } else { fromValue = Convert.ToDecimal(lstFromValue[0]); } if (lstShippingFee.Count == 2 && lstFromValue.Count == 2 && (method.ShippingProvider == (int)ShippingMethodProvider.ByWeight || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight)) { additionalFee = Convert.ToDecimal(lstShippingFee[1]); additionalValue = Convert.ToDecimal(lstFromValue[1]); } int shippingTableRateId = -1; foreach (ShippingTableRate tblRate in lstTableRates) { if (shippingByGeoZone) { if (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndFixed) { if (shippingFee == tblRate.ShippingFee && geoZoneGuid == tblRate.GeoZoneGuid) { tblRate.MarkAsDeleted = false; shippingTableRateId = tblRate.ShippingTableRateId; break; } } else if (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndOrderTotal) { if (shippingFee == tblRate.ShippingFee && geoZoneGuid == tblRate.GeoZoneGuid && fromValue == tblRate.FromValue) { tblRate.MarkAsDeleted = false; shippingTableRateId = tblRate.ShippingTableRateId; break; } } else if (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight) { if (shippingFee == tblRate.ShippingFee && geoZoneGuid == tblRate.GeoZoneGuid && fromValue == tblRate.FromValue) { tblRate.MarkAsDeleted = false; shippingTableRateId = tblRate.ShippingTableRateId; break; } } } else { if (shippingFee == tblRate.ShippingFee && fromValue == tblRate.FromValue) { tblRate.MarkAsDeleted = false; shippingTableRateId = tblRate.ShippingTableRateId; break; } } } ShippingTableRate tableRate = null; if (shippingTableRateId > 0) { tableRate = new ShippingTableRate(shippingTableRateId); } else { tableRate = new ShippingTableRate(); tableRate.ShippingMethodId = method.ShippingMethodId; } if (shippingByGeoZone) { tableRate.GeoZoneGuid = geoZoneGuid; if (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndOrderTotal || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight) { tableRate.FromValue = fromValue; } } else { tableRate.FromValue = fromValue; } tableRate.FreeShippingOverXValue = 0; if (method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndFixed || method.ShippingProvider == (int)ShippingMethodProvider.ByGeoZoneAndWeight) { if (!string.IsNullOrEmpty(excelOverXValue)) { tableRate.FreeShippingOverXValue = Convert.ToDecimal(excelOverXValue); } } tableRate.ShippingFee = shippingFee; tableRate.AdditionalFee = additionalFee; tableRate.AdditionalValue = additionalValue; tableRate.Save(); result = true; } } foreach (ShippingTableRate tblRate in lstTableRates) { if (tblRate.MarkAsDeleted) { ShippingTableRate.Delete(tblRate.ShippingTableRateId); } } } catch (Exception ex) { result = false; message.ErrorMessage = ex.Message; log.Error(ex.Message); } return(result); }