private Models.TariffTable PopulateEmptyTariffTable() { var table = new Models.TariffTable { RateDecimalPlaces = 2, Description = txtTableDescription.Text, MultiCollectRate = (decimal)rntxtMultiCollectRate.Value, MultiDropRate = (decimal)rntxtMultiDropRate.Value, UseGreatestRateForPrimaryRate = chkUseGreatestRateForPrimaryRate.Checked, }; if (cboCollectionZone.SelectedIndex > 0) { table.CollectionZoneID = int.Parse(cboCollectionZone.SelectedValue); } if (cboServiceLevel.SelectedIndex > 0) { table.OrderServiceLevelID = int.Parse(cboServiceLevel.SelectedValue); } if (cboPalletType.SelectedIndex > 0) { table.PalletTypeID = int.Parse(cboPalletType.SelectedValue); } if (cboGoodsType.SelectedIndex > 0) { table.GoodsTypeID = int.Parse(cboGoodsType.SelectedValue); } return(table); }
protected void btnSave_Click(object sender, EventArgs e) { //If the Copy option is selelected get the TariffVersionID of the selected //TariffVersion and use it to copy the Tariff Models.TariffTable table = null; //We can't use SelectedIndex to check if a selection has been made because //when a combo is AJAX populated Items, SelectedIndex and SelectedItem are not updated if (optCopyTable.Checked && !string.IsNullOrEmpty(cboCopyFromTable.SelectedValue)) { table = CopyTariffTable(int.Parse(cboCopyFromTable.SelectedValue)); } else if (optEmptyTable.Checked) { table = CreateEmptyTariffTable(); } else if (optImportTable.Checked) { try { table = ImportRateTable(); } catch (ApplicationException ae) { this.lblImportErrorMessage.Text = ae.Message; } } //Redirect and pass new TariffTableID so that it is selected if (table != null) { this.Response.Redirect("~/Tariff/EditTariff.aspx?TariffTableID=" + table.TariffTableID.ToString()); } }
private void LoadTariffRates(Models.TariffTable tariffTable) { //Reset the hidden field that holds the selected cellIDs hidTariffRateChanges.Value = string.Empty; //Return now if a TariffTable has not been selected if (tariffTable == null) { return; } //Get the Metric var tariffVersion = tariffTable.TariffVersion; var metric = tariffVersion.Tariff.Metric; //Get a list of zones for the selected TariffTable's TariffVersion's ZoneMap var zones = (from z in tariffVersion.ZoneMap.Zones orderby z.Description select new { z.ZoneID, z.Description }).ToList(); //Get a list of scale values for the selected TariffTable's TariffVersion's ZoneMap var scaleValues = (from sv in tariffVersion.Scale.ScaleValues orderby sv.Value select new { sv.ScaleValueID, sv.Value }).ToList(); //Get the TariffRates for the selected TariffTable var rates = tariffTable.TariffRates.Where(tr => tr.IsEnabled); //If the TariffTable decimal places is not the default of 2 then set it var format = "0.00"; if (tariffTable.RateDecimalPlaces != 2) { (rimTariffRates.InputSettings[0] as NumericTextBoxSetting).DecimalDigits = tariffTable.RateDecimalPlaces; format = "0." + new string('0', tariffTable.RateDecimalPlaces); } HtmlTableRow cornerTR; HtmlTableRow headerTR; HtmlTableRow metricTR; HtmlTableRow mainTR; HtmlTableCell td; //Load the Corner and Header Row with Metric and Zones cornerTR = new HtmlTableRow(); headerTR = new HtmlTableRow(); grdTariffRatesCorner.Rows.Add(cornerTR); grdTariffRatesHeader.Rows.Add(headerTR); //Add the top left corner cell td = new HtmlTableCell(); cornerTR.Cells.Add(td); td.Attributes.Add("class", "rgHeader"); switch (metric) { case eMetric.PalletSpaces: case eMetric.PalletforceSpaces: td.InnerText = "Pals"; break; case eMetric.Weight: td.InnerText = "Kgs"; break; case eMetric.Volume: td.InnerText = "m3"; break; } foreach (var zone in zones) { td = new HtmlTableCell(); headerTR.Cells.Add(td); td.Attributes.Add("class", "rgHeader"); td.InnerText = zone.Description; } var altRow = false; foreach (var scaleValue in scaleValues) { //Add a row to the Metric and Main parts. metricTR = new HtmlTableRow(); mainTR = new HtmlTableRow(); if (!altRow) { mainTR.Attributes.Add("class", "rgRow"); altRow = true; } else { mainTR.Attributes.Add("class", "rgAltRow"); altRow = false; } grdTariffRatesMetric.Rows.Add(metricTR); grdTariffRates.Rows.Add(mainTR); //Add a row heading with the number of pallets td = new HtmlTableCell(); metricTR.Cells.Add(td); td.Attributes.Add("class", "rgHeader"); td.InnerText = scaleValue.Value.ToString(); //Load the rate for the zone and pallet foreach (var zone in zones) { //Create a new cell td = new HtmlTableCell(); mainTR.Cells.Add(td); //Create a new input box and add it to the cell //Set the cells id so that it indicates to Zone and Pallets var input = new TextBox(); td.Controls.Add(input); input.ID = string.Format("cell:{0}:{1}", zone.ZoneID, scaleValue.ScaleValueID); //Find the TariffRate for this cells Zone and Pallets var rate = rates.FirstOrDefault(r => r.ZoneID == zone.ZoneID && r.ScaleValueID == scaleValue.ScaleValueID); if (rate != null) { input.Text = rate.Rate.ToString(format); } //Each input box will call a function when its value is chnaged so that //the cell colour can be changed and the id of th input recorded in the hidden field input.Attributes.Add("onchange", "TariffRate_onchange(this);"); } } }