protected override void btnSave_Click(object sender, EventArgs e) { //base.btnSave_Click(sender, e); if (ValidateInput()) { string result = string.Empty; TransportPriceConfiguration configuration = GetConfigurationInfo(); if (_isUpdating) { configuration.id = SelectedItemID; result = _business.Update(configuration); } else { configuration.id = IDGenerator.NewId <TransportPriceConfiguration>(true); result = _business.Insert(configuration); } if (string.IsNullOrEmpty(result)) { ChangeViewStatus(false); DataBind(); } else { MessageBox.Show(result, Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void LoadConfigurationInfo(TransportPriceConfiguration configuration) { if (configuration != null) { cboSize.SelectedItem = configuration.size; tbWeightFrom.Text = configuration.weight_from.ToString(); tbWeightTo.Text = configuration.weight_to != Constants.MAX_WEIGHT_VALUE ? configuration.weight_to.ToString() : string.Empty; tbTransportPrice.Text = configuration.transport_price.ToString("N0"); } }
public static TransportPriceConfiguration ConvertToPriceTransport(TTransportPrice tprice) { TransportPriceConfiguration price = new TransportPriceConfiguration(); price.id = tprice.PriceId; price.size = tprice.Size; price.weight_from = tprice.WeightFrom; price.weight_to = tprice.WeightTo; price.transport_price = decimal.Parse(tprice.TransportPrice.ToString()); return(price); }
public static TTransportPrice ConvertToTTransportPrice(TransportPriceConfiguration price) { TTransportPrice tprice = new TTransportPrice(); tprice.PriceId = price.id; tprice.Size = price.size; tprice.WeightFrom = double.Parse(price.weight_from.ToString()); tprice.WeightTo = double.Parse(price.weight_to.ToString()); tprice.TransportPrice = double.Parse(price.transport_price.ToString()); return(tprice); }
private void dgvListDetails_SelectionChanged(object sender, EventArgs e) { if (dgvItemsList.SelectedRows.Count > 0) { btnUpdate.Enabled = true; btnDelete.Enabled = true; TransportPriceConfiguration configuration = _business.Get(SelectedItemID); LoadConfigurationInfo(configuration); } else { btnUpdate.Enabled = false; btnDelete.Enabled = false; } }
private decimal CalculateTotalCost(double weight, string size, decimal value, int quantity) { decimal totalCost = 0; try { decimal transportPrice = 0; decimal guaranteeFee = 0; TransportPriceConfiguration transportPriceConfig = _transportPriceConfigurations.FirstOrDefault(e => e.size.Equals(size) && weight >= e.weight_from && weight < e.weight_to); if (transportPriceConfig != null) { transportPrice = transportPriceConfig.transport_price; tbTotalCost.Enabled = false; // Only load GuaranteeFeeConfiguration if TransportPriceConfiguration is available GuaranteeFeeConfiguration guaranteeFeeConfig = _guaranteeFeeConfigurations.FirstOrDefault(e => value >= e.value_from && value < e.value_to); if (guaranteeFeeConfig != null) { guaranteeFee = guaranteeFeeConfig.guarantee_fee; } } else { tbTotalCost.Enabled = true; } totalCost = transportPrice * quantity + guaranteeFee; } catch (FormatException) { // Ignore FormatException AppLogger.logDebug(this.ToString(), "The FormatException was thrown but intentionally ignored."); } catch (Exception ex) { AppLogger.logError(this.ToString(), "Error occur when calculating total cost.", ex); } return(totalCost); }