예제 #1
0
        void btnExportData_Click(object sender, EventArgs e)
        {
            string fileName = "shipping-table-rates-" + DateTimeHelper.GetDateTimeStringForFileName() + ".xls";
            ShippingMethodProvider provider = (ShippingMethodProvider)Convert.ToInt32(ddlShippingProvider.SelectedValue);

            switch (provider)
            {
            case ShippingMethodProvider.ByOrderTotal:
                DataTable dt = GetShippingTableRatesForExport(provider, false);
                ExportHelper.ExportDataTableToExcel(HttpContext.Current, dt, fileName);
                break;

            case ShippingMethodProvider.ByWeight:
                dt = GetShippingTableRatesForExport(provider, false);
                ExportHelper.ExportDataTableToExcel(HttpContext.Current, dt, fileName);
                break;

            case ShippingMethodProvider.ByGeoZoneAndFixed:
            case ShippingMethodProvider.ByGeoZoneAndOrderTotal:
            case ShippingMethodProvider.ByGeoZoneAndWeight:
                dt = GetShippingTableRatesForExport(provider, true);
                ExportHelper.ExportDataTableToExcel(HttpContext.Current, dt, fileName);
                break;
            }
        }
예제 #2
0
        private void PopulateFreeShipping()
        {
            ShippingMethodProvider shippingMethodId = (ShippingMethodProvider)Convert.ToInt32(ddlShippingProvider.SelectedValue);

            switch (shippingMethodId)
            {
            case ShippingMethodProvider.Free:
            case ShippingMethodProvider.ByOrderTotal:
            case ShippingMethodProvider.ByGeoZoneAndOrderTotal:
                divFreeShippingOverXEnabled.Visible = false;
                divFreeShippingOverXValue.Visible   = false;
                break;

            case ShippingMethodProvider.Fixed:
            case ShippingMethodProvider.FixedPerItem:
            case ShippingMethodProvider.ByWeight:
                divFreeShippingOverXEnabled.Visible = true;
                divFreeShippingOverXValue.Visible   = chkFreeShippingOverXEnabled.Checked;
                break;

            default:
                divFreeShippingOverXEnabled.Visible = true;
                divFreeShippingOverXValue.Visible   = false;
                break;
            }
        }
예제 #3
0
        private void PopulateShippingProvider()
        {
            ShippingMethodProvider shippingMethodId = (ShippingMethodProvider)Convert.ToInt32(ddlShippingProvider.SelectedValue);

            switch (shippingMethodId)
            {
            case ShippingMethodProvider.Free:
                lblShippingFee.Text    = ProductResources.ShippingFreeLabel;
                divShippingFee.Visible = false;
                break;

            case ShippingMethodProvider.Fixed:
                lblShippingFee.Text    = ProductResources.ShippingFeeLabel;
                divShippingFee.Visible = true;
                break;

            case ShippingMethodProvider.FixedPerItem:
                lblShippingFee.Text    = ProductResources.ShippingFeePerItemLabel;
                divShippingFee.Visible = true;
                break;

            default:
                lblShippingFee.Text    = ProductResources.ShippingFeeDefaultLabel;
                divShippingFee.Visible = true;
                break;
            }

            divImportExport.Visible   = false;
            chkExportDistrict.Visible = false;
            switch (shippingMethodId)
            {
            case ShippingMethodProvider.ByOrderTotal:
            case ShippingMethodProvider.ByWeight:
                divImportExport.Visible = true;
                break;

            case ShippingMethodProvider.ByGeoZoneAndFixed:
            case ShippingMethodProvider.ByGeoZoneAndOrderTotal:
            case ShippingMethodProvider.ByGeoZoneAndWeight:
                divImportExport.Visible   = true;
                chkExportDistrict.Visible = true;
                break;
            }

            PopulateFreeShipping();
        }
예제 #4
0
        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);
        }
예제 #5
0
        private DataTable GetShippingTemplateForExport(ShippingMethodProvider provider, bool exportGeoZone = true)
        {
            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;
            }
            else if (provider == ShippingMethodProvider.ByGeoZoneAndFixed)
            {
                orderColumn = "   ";
            }

            string freeShippingOverXColumn = "    ";

            if (provider == ShippingMethodProvider.ByGeoZoneAndFixed || provider == ShippingMethodProvider.ByGeoZoneAndWeight)
            {
                freeShippingOverXColumn = ProductResources.ShippingMethodFreeShippingOverX;
            }

            dt.Columns.Add(geoZoneIdColumn, typeof(Guid));
            dt.Columns.Add(geoZoneNameColumn, typeof(string));
            dt.Columns.Add(shippingFeeColumn, typeof(string));
            dt.Columns.Add(orderColumn, typeof(string));
            dt.Columns.Add(freeShippingOverXColumn, typeof(string));

            if (exportGeoZone)
            {
                var lstProvinces = GeoZone.GetByCountry(siteSettings.DefaultCountryGuid, 1);
                foreach (GeoZone province in lstProvinces)
                {
                    DataRow row = dt.NewRow();

                    row[geoZoneIdColumn]   = province.Guid;
                    row[geoZoneNameColumn] = province.Name;
                    row[shippingFeeColumn] = string.Empty;
                    if (provider != ShippingMethodProvider.ByGeoZoneAndFixed)
                    {
                        row[orderColumn] = string.Empty;
                    }
                    if (provider == ShippingMethodProvider.ByGeoZoneAndFixed || provider == ShippingMethodProvider.ByGeoZoneAndWeight)
                    {
                        row[freeShippingOverXColumn] = string.Empty;
                    }
                    dt.Rows.Add(row);

                    if (chkExportDistrict.Checked)
                    {
                        var lstDistricts = GeoZone.GetByListParent(province.Guid.ToString(), 1);
                        foreach (GeoZone district in lstDistricts)
                        {
                            DataRow rowDistrict = dt.NewRow();

                            rowDistrict[geoZoneIdColumn]   = district.Guid;
                            rowDistrict[geoZoneNameColumn] = province.Name + " >> " + district.Name;
                            rowDistrict[shippingFeeColumn] = string.Empty;
                            if (provider != ShippingMethodProvider.ByGeoZoneAndFixed)
                            {
                                rowDistrict[orderColumn] = string.Empty;
                            }
                            if (provider == ShippingMethodProvider.ByGeoZoneAndFixed || provider == ShippingMethodProvider.ByGeoZoneAndWeight)
                            {
                                row[freeShippingOverXColumn] = string.Empty;
                            }
                            dt.Rows.Add(rowDistrict);
                        }
                    }
                }
            }

            return(dt);
        }