Ejemplo n.º 1
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            if (originComboBox.SelectedItem == null || destinationComboBox.SelectedItem == null)
            {
                MessageBox.Show("Not enough infomation");
                return;
            }

            if (costTextBox.Text.Count() == 0)
            {
                MessageBox.Show("You need fill cost field first");
                return;
            }

            string   originShortName      = originComboBox.SelectedItem.ToString();
            string   destinationShortName = destinationComboBox.SelectedItem.ToString();
            string   costString           = costTextBox.Text;
            RateType rateType;
            Int32    rateCost;

            Enum.TryParse <RateType>(typeComboBox.SelectedItem.ToString(), out rateType);
            Int32.TryParse(costTextBox.Text, out rateCost);

            if (_originalOriginDestinationShortName != _originalOriginRegionShortName || _originalOriginDestinationShortName != destinationShortName)
            {
                if (_carrier.HasRate(originShortName, destinationShortName))
                {
                    MessageBox.Show("Each carrier can only have one rate per lane");
                    return;
                }
            }

            try
            {
                Rate newRate = null;
                switch (rateType)
                {
                case RateType.Flat:
                    newRate = new FlatRate(originShortName, destinationShortName, rateCost);
                    break;

                case RateType.Increase:
                    newRate = new IncreaseRate(originShortName, destinationShortName, rateCost);
                    break;
                }

                _carrier.RemoveRate(_rateToEdit);
                _carrier.AddRate(newRate);
                Carrier.Store.SaveToDisk();
                MessageBox.Show("Rate has been saved");
                this.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }
Ejemplo n.º 2
0
        private void demoDataButton_Click(object sender, EventArgs e)
        {
            _regionStore.Erase();
            _carrierStore.Erase();

            Carrier MasterCarrier = new Carrier {
                SCAC = "MAST", Name = "Master Carrier"
            };
            Carrier SlaveCarrier = new Carrier {
                SCAC = "SLAV", Name = "Slave Carrier"
            };

            Region OriginCityRegion = new RMA.Model.Region {
                XAxis = 0, YAxis = 0, ShortName = "OC", Description = "Origin City"
            };
            Region DestinationCityRegion = new RMA.Model.Region {
                XAxis = 13, YAxis = 13, ShortName = "DC", Description = "Destination City"
            };
            Region ChaosLandRegion = new RMA.Model.Region {
                XAxis = 100, YAxis = 100, ShortName = "CL", Description = "Chaos Land"
            };
            Region VoidWorldRegion = new RMA.Model.Region {
                XAxis = -100, YAxis = -100, ShortName = "VW", Description = "Void World"
            };

            FlatRate     flatRateForMasterCarrier     = new FlatRate(OriginCityRegion, DestinationCityRegion, 1000);
            IncreaseRate increaseRateForMasterCarrier = new IncreaseRate(DestinationCityRegion, ChaosLandRegion, 10);

            FlatRate     flatRateForSlaveCarrier     = new FlatRate(OriginCityRegion, DestinationCityRegion, 800);
            IncreaseRate increaseRateForSlaveCarrier = new IncreaseRate(DestinationCityRegion, ChaosLandRegion, 9);

            MasterCarrier.AddRate(flatRateForMasterCarrier);
            MasterCarrier.AddRate(increaseRateForMasterCarrier);
            SlaveCarrier.AddRate(flatRateForSlaveCarrier);
            SlaveCarrier.AddRate(increaseRateForMasterCarrier);

            MasterCarrier.Insert();
            SlaveCarrier.Insert();

            OriginCityRegion.Insert();
            DestinationCityRegion.Insert();
            ChaosLandRegion.Insert();
            VoidWorldRegion.Insert();

            _carrierStore.SaveToDisk();
            _regionStore.SaveToDisk();

            MessageBox.Show("load demo data task complete");
        }