Esempio n. 1
0
        private void SetControls(bool isEnabled)
        {
            if (InvokeRequired)
            {
                Invoke(new SetControlsDelegate(SetControls), isEnabled);
            }
            else
            {
                TextBoxKey.Enabled        = isEnabled;
                TextBoxValue.Enabled      = isEnabled;
                ButtonAddVariable.Enabled = isEnabled;

                if (isEnabled)
                {
                    TextBoxKey.Clear();
                    TextBoxValue.Clear();
                }
            }
        }
Esempio n. 2
0
        private void AddCommodity_Click(object sender, RoutedEventArgs e)
        {
            double value;

            try
            {
                value = Convert.ToDouble(TextBoxValue.Text);
            }
            catch (FormatException)
            {
                ErrorDialog("Mængden er ikke korrekt indtastet");
                return;
            }

            // We need to figure out if the Commodity added already exists or if it
            // just a text string.
            // First we will try to cast it as a Commodity object...
            Commodity commodity = null;

            try
            {
                commodity = (Commodity)CommodityName.SelectedItem;
            }
            catch (InvalidCastException exp)
            {
                // This isn't a severe exception
                Console.Write($@"Couldn't cast: {exp}");
            }

            if (commodity != null)
            {
                // Commodity could not be casted. therefore it must be a string...
                _shawdowCommodities.Add(new CommodityShadow
                {
                    Id        = 1,
                    Commodity = commodity,
                    Name      = commodity.Name,
                    Value     = value,
                    Unit      = (Units)ComboBoxUnit.SelectionBoxItem
                });
            }
            else
            {
                var name = CommodityName.Text;
                if (name.Length < 1)
                {
                    ErrorDialog("Råvare navnet er ikke gyldigt.");
                    return;
                }

                _shawdowCommodities.Add(new CommodityShadow
                {
                    Id    = 1,
                    Name  = name,
                    Value = value,
                    Unit  = (Units)ComboBoxUnit.SelectionBoxItem
                });
            }

            TextBoxValue.Clear();
            CommodityName.SelectedIndex = -1;
            CommodityName.Text          = "";

            ListBoxCommodities.ItemsSource = _shawdowCommodities;
            ListBoxCommodities.Items.Refresh();
        }
 private void ButtonSend_Click(object sender, RoutedEventArgs e)
 {
     SendValue(TextBoxValue.Text);
     TextBoxValue.Clear();
 }