private void deleteLigne() { if (this._dataGridContenuSupplementaire.SelectedItem != null && this._dataGridContenuSupplementaire.SelectedItems.Count == 1) { try { ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Quantite_Livree = 0; ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Reference = ""; ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Designation = ""; ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Quantite = 0; ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Prix_Remise = 0; ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Prix_Total = 0; ((Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem).Prix_Unitaire = 0; } catch (Exception) { } Bon_Livraison_Contenu_Commande_Supplementaire item = new Bon_Livraison_Contenu_Commande_Supplementaire(); try { item = (Bon_Livraison_Contenu_Commande_Supplementaire)this._dataGridContenuSupplementaire.SelectedItem; item.Bon_Livraison1 = null; ((Bon_Livraison)this.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Remove(item); ((App)App.Current).mySitaffEntities.Detach(item); } catch (Exception) { try { ((App)App.Current).mySitaffEntities.Detach(item); ((Bon_Livraison)this.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Remove(item); } catch (Exception) { try { this._dataGridContenuSupplementaire.Items.Remove(item); } catch (Exception) { } } } } else { if (this._dataGridContenuSupplementaire.SelectedItems.Count != 0) { ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire> toRemove = new ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire>(); foreach (Bon_Livraison_Contenu_Commande_Supplementaire item in this._dataGridContenuSupplementaire.SelectedItems.OfType<Bon_Livraison_Contenu_Commande_Supplementaire>()) { toRemove.Add(item); } foreach (Bon_Livraison_Contenu_Commande_Supplementaire item in toRemove) { try { item.Quantite_Livree = 0; item.Reference = ""; item.Designation = ""; item.Quantite = 0; item.Prix_Remise = 0; item.Prix_Total = 0; item.Prix_Unitaire = 0; } catch (Exception) { } try { item.Bon_Livraison1 = null; ((Bon_Livraison)this.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Remove(item); ((App)App.Current).mySitaffEntities.Detach(item); } catch (Exception) { try { ((App)App.Current).mySitaffEntities.Detach(item); ((Bon_Livraison)this.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Remove(item); } catch (Exception) { try { this._dataGridContenuSupplementaire.Items.Remove(item); } catch (Exception) { } } } } } } this.calculDataGridContenuSupp(); }
public ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire> PasteDataBonLivraisonWindow() { if (Clipboard.ContainsText(TextDataFormat.Text)) { ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire> toReturn = new ObservableCollection<Bon_Livraison_Contenu_Commande_Supplementaire>(); String data = Clipboard.GetText(); ObservableCollection<String> listLignes = new ObservableCollection<string>(data.Split('\n')); int nbLignes = 1; int ligneToIgnore = listLignes.Count(); foreach (String ligne in listLignes) { if (nbLignes != ligneToIgnore) { if (this.verifNombreColonnes(ligne, 4)) { ObservableCollection<String> listColonnes = new ObservableCollection<string>(ligne.Split('\t')); int i = 1; Bon_Livraison_Contenu_Commande_Supplementaire toAdd = new Bon_Livraison_Contenu_Commande_Supplementaire(); foreach (String colonne in listColonnes) { if (i == 1) { toAdd.Reference = colonne; } if (i == 2) { toAdd.Designation = colonne; } if (i == 3) { double val; if (double.TryParse(colonne.Replace(".", ","), out val)) { toAdd.Quantite_Livree = double.Parse(colonne.Replace(".", ",")); } else { MessageBox.Show("Le collage s'arrete car à la ligne n°" + nbLignes + ", vous essayez de rentrer une quantité qui n'est pas un chiffre", "Coller : erreur !", MessageBoxButton.OK, MessageBoxImage.Error); return null; } } if (i == 4) { double val; if (double.TryParse(colonne.Replace(".", ","), out val)) { toAdd.Prix_Remise = double.Parse(colonne.Replace(".", ",")); } else { MessageBox.Show("Le collage s'arrete car à la ligne n°" + nbLignes + ", vous essayez de rentrer un prix unitaire qui n'est pas un chiffre", "Coller : erreur !", MessageBoxButton.OK, MessageBoxImage.Error); return null; } } toReturn.Add(toAdd); i = i + 1; } nbLignes = nbLignes + 1; } else { MessageBox.Show("Le collage s'arrete car à la ligne n°" + nbLignes + ", le nombre de colonne n'est pas bon, il doit y en avoir 4 (Référence, désignation, Quantité, Prix unitaire).", "Coller : erreur !", MessageBoxButton.OK, MessageBoxImage.Error); return null; } } } return toReturn; } else { return null; } }
private void import() { if (this.commandeWindow != null) { foreach (ItemShop item in this._dataGridFournisseur.SelectedItems.OfType<ItemShop>()) { try { Contenu_Commande_Fournisseur newItem = new Contenu_Commande_Fournisseur(); newItem.Reference = item.Reference; newItem.Designation = item.Designation; newItem.Quantite = 1; newItem.Prix_Unitaire = double.Parse(item.Min_Prix_Unitaire.ToString()); ((Commande_Fournisseur)this.commandeWindow.DataContext).Contenu_Commande_Fournisseur.Add(newItem); } catch (Exception) { } } try { this.commandeWindow._dataGridContenuCommande.Items.Refresh(); } catch (Exception) { } } if (this.bonLivraisonWindow != null) { foreach (ItemShop item in this._dataGridFournisseur.SelectedItems.OfType<ItemShop>()) { try { Bon_Livraison_Contenu_Commande_Supplementaire newItem = new Bon_Livraison_Contenu_Commande_Supplementaire(); newItem.Reference = item.Reference; newItem.Designation = item.Designation; newItem.Quantite_Livree = 1; newItem.Prix_Remise = double.Parse(item.Min_Prix_Unitaire.ToString()); ((Bon_Livraison)this.bonLivraisonWindow.DataContext).Bon_Livraison_Contenu_Commande_Supplementaire.Add(newItem); } catch (Exception) { } } try { this.bonLivraisonWindow._dataGridContenuSupplementaire.Items.Refresh(); } catch (Exception) { } } if (this.sortieAtelierWindow != null) { foreach (ItemShop item in this._dataGridFournisseur.SelectedItems.OfType<ItemShop>()) { try { Contenu_Sortie_Atelier newItem = new Contenu_Sortie_Atelier(); newItem.Reference = item.Reference; newItem.Designation = item.Designation; newItem.Quantite = 1; newItem.Prix = double.Parse(item.Moyenne_Prix_Unitaire.ToString()); newItem.Prix_Remise = double.Parse(item.Min_Prix_Unitaire.ToString()); ((Sortie_Atelier)this.sortieAtelierWindow.DataContext).Contenu_Sortie_Atelier.Add(newItem); } catch (Exception) { } } try { this.sortieAtelierWindow._dataGridContenu.Items.Refresh(); } catch (Exception) { } } }