private void btnValider_Click(object sender, RoutedEventArgs e) { if ((!String.IsNullOrEmpty(txtNomPlat.Text)) && (!String.IsNullOrEmpty(txtprix.Text)) && (cmbType.SelectedIndex != -1) && cmbType.SelectedValue != null && cmbType.SelectedItem != null) { //int lastFetchedId = dao.getNumberOfElements(); a.Libelle = txtNomPlat.Text; a.Prix = Decimal.Parse(txtprix.Text); //List<Article> l = new List<Article>(); int l = catDAO.getIdByLib(cmbType.Text); a.IdCategorie = l; //a.IdArticle = lastFetchedId + 1; try { if (!dao.find(a)) { if (dao.add(a) == 1) { MessageBox.Show("ajouté avec succes"); } } else { MessageBox.Show("article déja ajouté"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnValider_Click(object sender, RoutedEventArgs e) { try { if ((!String.IsNullOrEmpty(txtNomPlat.Text)) && (!String.IsNullOrEmpty(txtprix.Text)) && (cmbType.SelectedIndex != -1) && cmbType.SelectedValue != null && cmbType.SelectedItem != null) { CategorieDAO daoc = new CategorieDAO(); int catg = daoc.getIdByLib(cmbType.Text); Article ab = new Article(idTransferred, txtNomPlat.Text, decimal.Parse(txtprix.Text), catg); if (dao.update(ab) == 1) { MessageBox.Show("màj faite!"); this.Close(); } else { MessageBox.Show("erreur!"); } } else { MessageBox.Show("Vous devez remplir les champs !"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }