Пример #1
0
        private void addPrice_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new AddPriceDialogBox(_clientState, true);
            dlg.origin.Text = "NA";
            dlg.origin.IsEnabled = false;

            dlg.dest.Text = "NA";
            dlg.dest.IsEnabled = false;

            // Open the dialog box modally
            dlg.ShowDialog();
            if (dlg.DialogResult != false)
            {
                ComboBoxItem origin = dlg.origin.SelectedItem as ComboBoxItem;
                ComboBoxItem dest = dlg.dest.SelectedItem as ComboBoxItem;
                Priority priority = Priority.Air;
                if (dlg.priority.SelectedIndex == 0)
                    priority = Priority.Standard;
                else if (dlg.priority.SelectedIndex == 1)
                    priority = Priority.Air;
                else
                {
                    //should never happen
                    MessageBox.Show("You must select Standard or Air priorty.");
                }

                if (dlg.gramPrice.Text == String.Empty || dlg.cubicCmPrice.Text == String.Empty)
                {
                    MessageBox.Show("Empty fields entered");
                    return;
                }

                try
                {
                    Int32.Parse(dlg.gramPrice.Text);
                    Int32.Parse(dlg.cubicCmPrice.Text);
                }
                catch
                {
                    MessageBox.Show("NaN enterered in a one of the price fields. Please enter a  number");
                    return;
                }

                var weightPrice = Convert.ToInt32(dlg.gramPrice.Text);
                var volumePrice = Convert.ToInt32(dlg.cubicCmPrice.Text);

                try
                {
                    _clientCon.AddDomesticPrice(priority, weightPrice, volumePrice);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #2
0
        private void editPrice_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new AddPriceDialogBox(_clientState, true);

            // Open the dialog box modally
            var price = ((Price)domesticPriceList.SelectedItem);
            dlg.Title = "Edit Domnestic Price";

            dlg.origin.IsEnabled = false;
            dlg.origin.Text = price.Origin.Country.Name;
            dlg.dest.IsEnabled = false;
            dlg.dest.Text = price.Destination.Country.Name;
            dlg.priority.Text = price.Priority.ToString();
            dlg.priority.IsEnabled = false;

            dlg.gramPrice.Text = Convert.ToString(((Price)domesticPriceList.SelectedItem).PricePerGram);
            dlg.cubicCmPrice.Text = Convert.ToString(((Price)domesticPriceList.SelectedItem).PricePerCm3);

            dlg.ShowDialog();
            if (dlg.DialogResult != false)
            {
                ComboBoxItem origin = dlg.origin.SelectedItem as ComboBoxItem;
                ComboBoxItem dest = dlg.dest.SelectedItem as ComboBoxItem;
                Priority priority = Priority.Standard;
                if (dlg.priority.SelectedIndex == 0)
                    priority = Priority.Standard;
                else if (dlg.priority.SelectedIndex == 1)
                    priority = Priority.Air;
                else
                {
                    //should never happen
                    MessageBox.Show("You must select Standard or Air priorty.");
                }
                var weightPrice = Convert.ToInt32(dlg.gramPrice.Text);
                var volumePrice = Convert.ToInt32(dlg.cubicCmPrice.Text);

                try
                {
                    _clientCon.EditPrice(price.ID, weightPrice, volumePrice);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #3
0
        private void addIntlPrice_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new AddPriceDialogBox(_clientState, false);

            // Open the dialog box modally
            dlg.ShowDialog();
            if (dlg.DialogResult != false)
            {
                ComboBoxItem origin = dlg.origin.SelectedItem as ComboBoxItem;
                ComboBoxItem dest = dlg.dest.SelectedItem as ComboBoxItem;
                Priority priority = Priority.Standard;
                if (dlg.priority.SelectedIndex == 0)
                    priority = Priority.Standard;
                else if (dlg.priority.SelectedIndex == 1)
                    priority = Priority.Air;
                else
                {
                    //should never happen
                    MessageBox.Show("You must select Standard or Air priorty.");
                }

                if (origin == null || dest == null)
                {
                    MessageBox.Show("Invalid origin/destination");
                    return;
                }
                var weightPrice = Convert.ToInt32(dlg.gramPrice.Text);
                var volumePrice = Convert.ToInt32(dlg.cubicCmPrice.Text);

                try
                {
                    _clientCon.AddPrice(Convert.ToInt32(origin.Tag), Convert.ToInt32(dest.Tag), priority, weightPrice, volumePrice);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }