private void cmbType_SelectionChanged(object sender, SelectionChangedEventArgs e) { txtPrice.Text = cmbType.SelectedValue.ToString(); KeyValuePair <DoughnutMachine.DoughnutType, double> selectedEntry = (KeyValuePair <DoughnutMachine.DoughnutType, double>)cmbType.SelectedItem; DoughnutMachine.DoughnutType selectedDoughnut = selectedEntry.Key; }
private void btnAdd_Click(object sender, RoutedEventArgs e, DoughnutMachine.DoughnutType selectedDoughnut) { if (ValidateQuantity(selectedDoughnut) > 0) { lstSale.Items.Add(txtQuantity.Text + " " + selectedDoughnut.ToString() + ":" + txtPrice.Text + " " + double.Parse(txtQuantity.Text) * double.Parse(txtPrice.Text)); } else { MessageBox.Show("Cantitatea introdusa nu este disponibila in stoc!"); } }
private int ValidateQuantity(DoughnutMachine.DoughnutType selectedDoughnut) { int q = int.Parse(txtQuantity.Text); int r = 1; switch (selectedDoughnut) { case DoughnutMachine.DoughnutType.Glazed: if (q > mRaisedGlazed) { r = 0; } break; case DoughnutMachine.DoughnutType.Sugar: if (q > mRaisedSugar) { r = 0; } break; case DoughnutMachine.DoughnutType.Chocolate: if (q > mFilledChocolate) { r = 0; } break; case DoughnutMachine.DoughnutType.Lemon: if (q > mFilledLemon) { r = 0; } break; case DoughnutMachine.DoughnutType.Vanilla: if (q > mFilledVanilla) { r = 0; } break; } return(r); }