Esempio n. 1
0
        private void LoadTariffTables(IUnitOfWork uow, Models.TariffVersion tariffVersion)
        {
            cboTariffTable.Items.Clear();

            var tariffTables         = tariffVersion.TariffTables.OrderBy(tt => tt.Description).Select(tt => new { tt.TariffTableID, tt.Description });
            var currentTariffTableID = (cboTariffTable.SelectedIndex > -1) ? int.Parse(cboTariffTable.SelectedValue) : (int?)null;

            //Populate the TariffTable combo
            cboTariffTable.DataValueField = "TariffTableID";
            cboTariffTable.DataTextField  = "Description";
            cboTariffTable.DataSource     = tariffTables;
            cboTariffTable.DataBind();

            if (cboTariffTable.Items.Any())
            {
                //If a TariffTable was passed try to find it in the combo and select it
                int?tariffTableID = currentTariffTableID ?? this.TariffTableID;

                if (tariffTableID.HasValue)
                {
                    var selectedItem = cboTariffTable.FindItemByValue(tariffTableID.Value.ToString());

                    if (selectedItem != null)
                    {
                        selectedItem.Selected = true;
                    }
                }
            }

            LoadTariffTable(uow);
        }
Esempio n. 2
0
        private Models.TariffVersion CreateEmptyTariffVersion()
        {
            //Create a new TariffVersion and assign entered values
            var version = new Models.TariffVersion
            {
                Description = txtVersionDescription.Text,
                ZoneMapID   = int.Parse(cboZoneMap.SelectedValue),
                ScaleID     = int.Parse(cboScale.SelectedValue),
            };

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var tariff          = this.GetTariff(uow);
                var previousVersion = this.GetPreviousVersion(tariff);

                version.StartDate = previousVersion.FinishDate.Value.AddDays(1);

                //Add the new TariffVersion to the Tariff
                tariff.TariffVersions.Add(version);

                //Save changes to database
                uow.SaveChanges();
            }

            //and return the new tariff with its assigned TariffId
            return(version);
        }
Esempio n. 3
0
        private void LoadCopyFromTariffs(Models.TariffVersion tariffVersion)
        {
            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var repo = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);

                var tariffs =
                    from t in repo.GetAll()
                    orderby t.Description
                    select new { t.TariffID, t.Description };

                cboCopyFromTariff.Items.Clear();
                cboCopyFromTariff.DataValueField = "TariffID";
                cboCopyFromTariff.DataTextField  = "Description";
                cboCopyFromTariff.DataSource     = tariffs.ToList();
                cboCopyFromTariff.DataBind();
            }

            //Default to the Tariff of the TariffVersion passed
            if (cboCopyFromTariff.Items.Count > 0)
            {
                cboCopyFromTariff.SelectedValue = tariffVersion.TariffID.ToString();
            }

            //LoadCopyFromVersions should NOT be called here as a bug with the RadCombo means that if
            //it is later loaded from the requestItems AJAX call, and the user does not chnage
            //the default (first) selection, the value of SelectedValue will be incorrect.
        }
Esempio n. 4
0
        private Models.Tariff CopyTariffVersion(int tariffVersionID)
        {
            //Create a new Tariff and assign entered values
            var tariff = new Models.Tariff
            {
                Description        = txtTariffDescription.Text,
                IsForSubContractor = chkIsForSubContractor.Checked,
            };

            //Create a new TariffVersion and assign entered values
            var version = new Models.TariffVersion
            {
                StartDate   = dteStartDate.SelectedDate.Value.Date,
                Description = txtVersionDescription.Text,
            };

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var repo = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);

                //Get the TariffVersion to copy from
                var copyFromVersion = repo.FindTariffVersion(tariffVersionID);

                //Copy the ZoneType, Metric and Multiplier values from the selected Tariff
                var copyFromTariff = copyFromVersion.Tariff;
                tariff.ZoneType             = copyFromTariff.ZoneType;
                tariff.Metric               = copyFromTariff.Metric;
                tariff.MultiplyByOrderValue = copyFromTariff.MultiplyByOrderValue;
                tariff.AdditionalMultiplier = copyFromTariff.AdditionalMultiplier;
                tariff.IgnoreAdditionalCollectsFromADeliveryPoint = copyFromTariff.IgnoreAdditionalCollectsFromADeliveryPoint;

                //Add the new Tariff
                repo.Add(tariff);

                //Use the selected version's ZoneMap and Scale
                version.ZoneMap = copyFromVersion.ZoneMap;
                version.Scale   = copyFromVersion.Scale;

                //Add the new TariffVersion to the new Tariff
                tariff.TariffVersions.Add(version);

                //Save changes to database
                uow.SaveChanges();

                //Call a sproc to copy the selected TariffVersion's TariffTables to the new TariffVersion (including ExtraTypeRates)
                var increaseRate = txtIncreaseRate.Value.HasValue ? (decimal)txtIncreaseRate.Value.Value : 0m;

                repo.TariffVersionCopyTariffTables(
                    copyFromVersion.TariffVersionID,
                    version.TariffVersionID,
                    increaseRate);
            }

            //Return the new tariff with its assigned TariffID
            return(tariff);
        }
Esempio n. 5
0
        private void LoadZones(Models.TariffVersion tariffVersion)
        {
            var zones = tariffVersion.ZoneMap.Zones.OrderBy(z => z.Description).Select(z => new { z.ZoneID, z.Description });

            cboCollectionZone.DataValueField = "ZoneID";
            cboCollectionZone.DataTextField  = "Description";
            cboCollectionZone.DataSource     = zones.ToList();
            cboCollectionZone.DataBind();
            cboCollectionZone.Items.Insert(0, new RadComboBoxItem("Any"));
        }
Esempio n. 6
0
        private void LoadTariff(Models.Tariff tariff, Models.TariffVersion previousVersion)
        {
            if (!previousVersion.FinishDate.HasValue)
            {
                throw new ApplicationException("The last tariff version has not been finished.");
            }

            lblTariffDescription.Text = tariff.Description;

            //Set the new TariffVersion StartDate to the day after the previous version's FinishDate
            lblStartDate.Text = previousVersion.FinishDate.Value.AddDays(1).ToString("dd/MM/yy");

            //Default the new TariffVersion's Description
            txtVersionDescription.Text = lblTariffDescription.Text + " - " + lblStartDate.Text;
        }
Esempio n. 7
0
        private void LoadExtraTypeRates(IUnitOfWork uow, Models.TariffVersion tariffVersion)
        {
            var extraTypeRepo = DIContainer.CreateRepository <Repositories.IExtraTypeRepository>(uow);

            var tariffRepo          = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);
            var extraTypesWithRates = tariffRepo.GetExtraTypeRateSummaryForTariffVersion(tariffVersion.TariffVersionID);

            var extraTypesForSerialization =
                extraTypesWithRates.Select(etwr => new ExtraTypeWithRates
            {
                extraTypeID     = etwr.ExtraTypeID,
                description     = etwr.Description,
                scaleValueRates = etwr.ScaleValueRates.Select(svr => new ExtraTypeWithRates.ScaleValueRate
                {
                    scaleValue = svr.ScaleValue,
                    rate       = svr.Rate,
                    isDirty    = false,
                }),
            });

            hidExtraTypeRates.Value = Newtonsoft.Json.JsonConvert.SerializeObject(extraTypesForSerialization);

            foreach (var extraType in extraTypesWithRates)
            {
                //Add a cell for the Extra
                var table = new HtmlTable();
                pnlExtraTypeRates.Controls.Add(table);
                table.Attributes.Add("class", "rgMasterTable");

                var tr = new HtmlTableRow();
                table.Rows.Add(tr);
                tr.Attributes.Add("class", "rgRow");

                var th = new HtmlTableCell("th");
                tr.Cells.Add(th);
                th.Attributes.Add("class", "rgHeader");
                th.InnerText = extraType.Description;

                //Create a new cell
                var td = new HtmlTableCell();
                td.Attributes.Add("class", "extraTypeRateSummary");
                td.Attributes.Add("data-extra-type-id", extraType.ExtraTypeID.ToString());
                tr.Cells.Add(td);
            }
        }
Esempio n. 8
0
        private void LoadScales(IUnitOfWork uow, Models.Tariff tariff, Models.TariffVersion previousVersion)
        {
            //Get the Scales that are relevant for the Tariff's Metric and load the combo with them
            var scaleRepo = DIContainer.CreateRepository <Repositories.IScaleRepository>(uow);
            var scales    = scaleRepo.GetForMetric(tariff.Metric).Select(s => new { s.ScaleID, s.Description });

            cboScale.DataValueField = "ScaleID";
            cboScale.DataTextField  = "Description";

            cboScale.DataSource = scales.ToList();
            cboScale.DataBind();

            //Default to the previous version's ZoneMap
            if (cboScale.Items.Any())
            {
                cboScale.SelectedValue = previousVersion.ScaleID.ToString();
            }
        }
Esempio n. 9
0
        private void LoadZoneMaps(IUnitOfWork uow, Models.Tariff tariff, Models.TariffVersion previousVersion)
        {
            //Get the ZoneMaps that are relevant for the Tariff's ZoneType and load the combo with them
            var zoneMapRepo = DIContainer.CreateRepository <Repositories.IZoneMapRepository>(uow);
            var zoneMaps    = zoneMapRepo.GetForZoneType(tariff.ZoneType).Select(zm => new { zm.ZoneMapID, zm.Description });

            cboZoneMap.DataValueField = "ZoneMapID";
            cboZoneMap.DataTextField  = "Description";

            cboZoneMap.DataSource = zoneMaps.ToList();
            cboZoneMap.DataBind();

            //Default to the previous version's ZoneMap
            if (cboZoneMap.Items.Any())
            {
                cboZoneMap.SelectedValue = previousVersion.ZoneMapID.ToString();
            }
        }
Esempio n. 10
0
        private Models.TariffVersion CopyTariffVersion(int tariffVersionID)
        {
            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var tariff          = this.GetTariff(uow);
                var previousVersion = this.GetPreviousVersion(tariff);

                //Get the TariffVersion to copy from
                var repo            = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);
                var copyFromVersion = repo.FindTariffVersion(tariffVersionID);

                //Create a new TariffVersion and assign entered values
                var version = new Models.TariffVersion
                {
                    StartDate   = previousVersion.FinishDate.Value.AddDays(1),
                    Description = txtVersionDescription.Text,
                };

                //Copy the selected version's ZoneMap and Scale
                version.ZoneMap = copyFromVersion.ZoneMap;
                version.Scale   = copyFromVersion.Scale;

                //Add the new TariffVersion to the Tariff
                tariff.TariffVersions.Add(version);

                //Save changes to database
                uow.SaveChanges();

                //Call a sproc to copy the selected TariffVersion's TariffTables to the new TariffVersion
                var increaseRate = txtIncreaseRate.Value.HasValue ? (decimal)txtIncreaseRate.Value.Value : 0m;

                repo.TariffVersionCopyTariffTables(
                    copyFromVersion.TariffVersionID,
                    version.TariffVersionID,
                    increaseRate);

                //Return the new tariff with its assigned TariffId
                return(version);
            }
        }
Esempio n. 11
0
        private Models.Tariff CreateEmptyTariff()
        {
            //Create a new Tariff and assign entered values
            var tariff = new Models.Tariff
            {
                Description          = txtTariffDescription.Text,
                IsForSubContractor   = chkIsForSubContractor.Checked,
                ZoneType             = (eZoneType)int.Parse(optZoneType.SelectedValue),
                Metric               = (eMetric)int.Parse(optMetric.SelectedValue),
                MultiplyByOrderValue = chkMultiplyByOrderValue.Checked,
                AdditionalMultiplier = (chkMultiplyByOrderValue.Checked && txtAdditionalMultiplier.Value > 0) ? (decimal?)txtAdditionalMultiplier.Value : null,
                IgnoreAdditionalCollectsFromADeliveryPoint = chkIgnoreAdditionalCollectsFromADeliveryPoint.Checked,
            };

            //Create a new TariffVersion and assign entered values
            var version = new Models.TariffVersion
            {
                StartDate   = dteStartDate.SelectedDate.Value.Date,
                Description = txtVersionDescription.Text,
                ZoneMapID   = int.Parse(cboZoneMap.SelectedValue),
                ScaleID     = int.Parse(cboScale.SelectedValue),
            };

            //Add the new TariffVersion to the new Tariff
            tariff.TariffVersions.Add(version);

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var repo = DIContainer.CreateRepository <Repositories.ITariffRepository>(uow);
                repo.Add(tariff);

                //Save changes to database
                uow.SaveChanges();
            }

            //and return the new tariff with its assigned TariffID
            return(tariff);
        }
Esempio n. 12
0
 private void LoadTariffVersion(Models.TariffVersion tariffVersion)
 {
     lblTariffDescription.Text  = tariffVersion.Tariff.Description;
     lblVersionDescription.Text = tariffVersion.Description;
     lblStartDate.Text          = tariffVersion.StartDate.ToString("dd/MM/yy");
 }