private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         DigitalScales tempScale = (DigitalScales)dataGrid.SelectedItem;
         id = packingShop.digitalScales.IndexOf(tempScale);
         textBoxMinimum.Text     = packingShop[id].MinNumber.ToString();
         textBoxMaximum.Text     = packingShop[id].MaxNumber.ToString();
         textBoxWeight.Text      = packingShop[id].Number.ToString();
         textBoxCostOne.Text     = packingShop[id].OneCost.ToString();
         textBoxCommonCost.Text  = packingShop[id].CommonCost.ToString();
         textBoxWeightError.Text = packingShop[id].WeightError.ToString();
     }
     catch (Exception) { }
 }
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            DigitalScales nextProduct = new DigitalScales();

            nextProduct.MinNumber   = Convert.ToDouble(textBoxMinimum.Text);
            nextProduct.MaxNumber   = Convert.ToDouble(textBoxMaximum.Text);
            nextProduct.Number      = Convert.ToDouble(textBoxWeight.Text);
            nextProduct.OneCost     = Convert.ToDouble(textBoxCostOne.Text);
            nextProduct.CommonCost  = Convert.ToDouble(textBoxCommonCost.Text);
            nextProduct.WeightError = Convert.ToDouble(textBoxWeightError.Text);
            packingShop.digitalScales.Add(nextProduct);
            dataGrid.ItemsSource = packingShop.digitalScales.Cast <DigitalScales>();
            dataGrid.Items.Refresh();
            dataGrid.SelectedIndex = packingShop.digitalScales.Count - 1;
        }
        public MainWindow()
        {
            packingShop = new PackingShop();
            id          = 0;
            DigitalScales tempDigitalScale = new DigitalScales();

            packingShop.digitalScales.Add(tempDigitalScale);
            tempDigitalScale         = new DigitalScales();
            tempDigitalScale.Number += 10.2;
            packingShop.digitalScales.Add(tempDigitalScale);
            tempDigitalScale         = new DigitalScales();
            tempDigitalScale.Number += 20.3;
            packingShop.digitalScales.Add(tempDigitalScale);
            tempDigitalScale         = new DigitalScales();
            tempDigitalScale.Number += 30.4;
            packingShop.digitalScales.Add(tempDigitalScale);
            tempDigitalScale         = new DigitalScales();
            tempDigitalScale.Number += 40.7;
            packingShop.digitalScales.Add(tempDigitalScale);
            InitializeComponent();
            dataGrid.SelectedIndex = 0;
            dataGrid.ItemsSource   = packingShop.digitalScales.Cast <DigitalScales>();
            GetCalculationResults();
        }