/// <summary> /// Supprime l'élement sélectionné du bon tableau /// </summary> /// <param name="NodeName"></param> /// <param name="SelectedItem"></param> private void DeleteItemListView(String NodeName, ListViewItem SelectedItem) { switch (NodeName) { case "Articles": ArticleDAO.DeleteArticle(SelectedItem.SubItems[2].Text); UpdateListView("Articles"); break; case "Marques": BrandDAO.DeleteBrand(int.Parse(SelectedItem.SubItems[1].Text)); UpdateListView("Marques"); break; case "Familles": FamilyDAO.DeleteFamily(int.Parse(SelectedItem.SubItems[1].Text)); UpdateListView("Familles"); break; case "Sous familles": SubFamilyDAO.DeleteSubFamily(int.Parse(SelectedItem.SubItems[1].Text)); UpdateListView("Sous familles"); break; default: break; } }
/// <summary> /// Créer la famille lorsque l'on clique sur le bouton valider /// </summary> /// <param name="Sender"></param> /// <param name="Event"></param> private void OkButton_Click(object Sender, EventArgs Event) { int IntRef; // vérifie si le contenue du champ reference est bien un nombre if (int.TryParse(RefTextBox.Text, out IntRef)) { // vérifie que le champ nom soit remplie if (NameTextBox.Text != "") { if (FamilyDAO.GetFamilyById(IntRef) == null) { Family NewFamily = new Family(IntRef, NameTextBox.Text); FamilyDAO.AddFamily(NewFamily); this.Close(); } else { MessageBox.Show("Ref existe déjà", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Les champs doivent etre remplient", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Référence doit etre un chiffre", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Constructeur de la fenetre qui initialise tout les champs à partir des données de la sous famille modifiée /// </summary> /// <param name="SelectedItem"></param> public ModifySubFamilyForm(ListViewItem SelectedItem) { InitializeComponent(); // rempli la combo box famille avec la liste des familles existante int Index = 0; int IndexFamily = 0; Family[] AllFamily = FamilyDAO.GetAllFamilies(); foreach (Family F in AllFamily) { FamilyComboBox.Items.Add(F); if (F.ToString() == SelectedItem.SubItems[2].Text) { IndexFamily = Index; } Index++; } FamilyComboBox.SelectedIndex = IndexFamily; // initialise les champs avec les données de la sous famille modifiée SubFamilyNameLabel.Text = SelectedItem.SubItems[1].Text; NameTextBox.Text = SelectedItem.SubItems[0].Text; }
/// <summary> /// Remplie la combobox SubFamilies à chaque changement de la combobox families /// </summary> /// <param name="Sender"></param> /// <param name="Event"></param> private void FamilyComboBox_SelectionChangeCommitted(object Sender, EventArgs Event) { SubFamilyComboBox.Items.Clear(); SubFamily[] AllLinkedSubFamilies = FamilyDAO.GetAllSubFamilies((Family)FamilyComboBox.SelectedItem); foreach (SubFamily SF in AllLinkedSubFamilies) { SubFamilyComboBox.Items.Add(SF); } }
/// <summary> /// Constructeur de la fenetre /// </summary> public AddSubFamilyForm() { InitializeComponent(); // rempli la combo box famille avec la liste des familles existante Family[] AllFamily = FamilyDAO.GetAllFamilies(); foreach (Family F in AllFamily) { FamilyComboBox.Items.Add(F); } }
/// <summary> /// Si les modifications sont valides change la famille concernée à l'appuie sur le bouton valider /// </summary> /// <param name="Sender"></param> /// <param name="Event"></param> private void OkButton_Click(object Sender, EventArgs Event) { if (NameTextBox.Text != "") { FamilyDAO.EditFamily(int.Parse(FamilyNameLabel.Text), NameTextBox.Text); this.Close(); } else { MessageBox.Show("Les champs doivent etre remplient", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public TaxonomyService(string context) { // TODO: REFACTOR this._familyDAO = new FamilyDAO(context); this._genusDAO = new GenusDAO(context); this._speciesDAO = new SpeciesDAO(context); this._cropForCwrDAO = new CropForCwrDAO(context); this._cwrMapDAO = new CwrMapDAO(context); this._cwrTraitDAO = new CwrTraitDAO(context); this._folderDAO = new FolderDAO(context); this._citationDAO = new CitationDAO(context); this._referenceDAO = new ReferenceDAO(context); this._regulationDAO = new RegulationDAO(context); this._reportDAO = new ReportDAO(context); }
public TaxonomyService(string context) { this._familyDAO = new FamilyDAO(context); this._genusDAO = new GenusDAO(context); this._speciesDAO = new SpeciesDAO(context); this._cropForCwrDAO = new CropForCwrDAO(context); this._cwrMapDAO = new CwrMapDAO(context); this._cwrTraitDAO = new CwrTraitDAO(context); this._folderDAO = new FolderDAO(context); this._authorDAO = new AuthorDAO(context); this._citationDAO = new CitationDAO(context); this._referenceDAO = new ReferenceDAO(context); this._regulationDAO = new RegulationDAO(context); this._reportDAO = new ReportDAO(context); this.geographyDAO = new GeographyDAO(context); }
/// <summary> /// Créé une famille à partir de son nom /// </summary> /// <param name="NameFamilyToSet"></param> public Family(String NameFamilyToSet) { NameFamily = NameFamilyToSet; RefFamily = -1; int TestRef = -1; // Recherche d'un id inutilisé while (RefFamily == -1) { TestRef++; if (FamilyDAO.GetFamilyById(TestRef) == null) { RefFamily = TestRef; } } }
/// <summary> /// Constructeur de la fenetre /// </summary> public AddArticleForm() { InitializeComponent(); // rempli la combo box marque avec la liste des marques existante Brand[] AllBrand = BrandDAO.GetAllBrands(); foreach (Brand B in AllBrand) { BrandComboBox.Items.Add(B); } // rempli la combo box famille avec la liste des familles existante Family[] AllFamily = FamilyDAO.GetAllFamilies(); foreach (Family F in AllFamily) { FamilyComboBox.Items.Add(F); } //attend qu'une famille soit sélectionnée SubFamilyComboBox.Items.Add("Selectionnez d'abord une famille"); }
/// <summary> /// Recréer les tableaux en fonctions des données de la bdd pour le mettre à jour /// </summary> /// <param name="NodeName"></param> private void UpdateListView(String NodeName) { int ColumnsWidth = 0; // reinitialise le trie MainListView.ListViewItemSorter = null; // choisi quel tableau mettre à jour ou créer switch (NodeName) { case "Articles": Article[] Articles = ArticleDAO.GetAllArticles(); MainListView.Columns.Clear(); MainListView.Items.Clear(); MainListView.Groups.Clear(); ColumnsWidth = MainListView.Width / 7; MainListView.Columns.Add("Quantité", ColumnsWidth); MainListView.Columns.Add("Description", ColumnsWidth); MainListView.Columns.Add("Référence", ColumnsWidth); MainListView.Columns.Add("Marque", ColumnsWidth); MainListView.Columns.Add("Famille", ColumnsWidth); MainListView.Columns.Add("Sous-Famille", ColumnsWidth); MainListView.Columns.Add("Prix H.T.", ColumnsWidth); foreach (Article A in Articles) { string[] ArticleToAdd = new string[7]; ListViewItem ArticleItem; // ajoute les items a la ListView ArticleToAdd[0] = A.Quantity.ToString(); ArticleToAdd[1] = A.Description; ArticleToAdd[2] = A.RefArticle; ArticleToAdd[3] = A.RefBrand.ToString(); ArticleToAdd[4] = A.RefSubFamily.RefFamily.ToString(); ArticleToAdd[5] = A.RefSubFamily.ToString(); ArticleToAdd[6] = A.PriceHT.ToString(); ArticleItem = new ListViewItem(ArticleToAdd); MainListView.Items.Add(ArticleItem); } break; case "Marques": Brand[] Brands = BrandDAO.GetAllBrands(); MainListView.Columns.Clear(); MainListView.Items.Clear(); MainListView.Groups.Clear(); ColumnsWidth = MainListView.Width / 2; MainListView.Columns.Add("Nom", ColumnsWidth); MainListView.Columns.Add("Référence", ColumnsWidth); foreach (Brand B in Brands) { string[] BrandToAdd = new string[2]; ListViewItem BrandItem; // ajoute les items a la ListView BrandToAdd[0] = B.NameBrand; BrandToAdd[1] = B.RefBrand.ToString(); BrandItem = new ListViewItem(BrandToAdd); MainListView.Items.Add(BrandItem); } break; case "Familles": Family[] Families = FamilyDAO.GetAllFamilies(); MainListView.Columns.Clear(); MainListView.Items.Clear(); MainListView.Groups.Clear(); ColumnsWidth = MainListView.Width / 2; MainListView.Columns.Add("Nom", ColumnsWidth); MainListView.Columns.Add("Référence", ColumnsWidth); foreach (Family F in Families) { string[] FamilyToAdd = new string[2]; ListViewItem FamilyItem; // ajoute les items a la ListView FamilyToAdd[0] = F.NameFamily; FamilyToAdd[1] = F.RefFamily.ToString(); FamilyItem = new ListViewItem(FamilyToAdd); MainListView.Items.Add(FamilyItem); } break; case "Sous familles": SubFamily[] SubFamilies = SubFamilyDAO.GetAllSubFamilies(); MainListView.Columns.Clear(); MainListView.Items.Clear(); MainListView.Groups.Clear(); ColumnsWidth = MainListView.Width / 3; MainListView.Columns.Add("Nom", ColumnsWidth); MainListView.Columns.Add("Référence", ColumnsWidth); MainListView.Columns.Add("Familles", ColumnsWidth); foreach (SubFamily SF in SubFamilies) { string[] SubFamilyToAdd = new string[3]; ListViewItem SubFamilyItem; // ajoute les items a la ListView SubFamilyToAdd[0] = SF.NameSubFamily; SubFamilyToAdd[1] = SF.RefSubFamily.ToString(); SubFamilyToAdd[2] = SF.RefFamily.ToString(); SubFamilyItem = new ListViewItem(SubFamilyToAdd); MainListView.Items.Add(SubFamilyItem); } break; default: break; } }
/// <summary> /// Constructeur de la fenetre qui initialise tout les champs à partir des données de l'article modifié /// </summary> /// <param name="SelectedItem"></param> public ModifyArticleForm(ListViewItem SelectedItem) { InitializeComponent(); // rempli la combo box marque avec la liste des marques existante int Index = 0; int IndexBrand = 0; Brand[] AllBrand = BrandDAO.GetAllBrands(); foreach (Brand B in AllBrand) { BrandComboBox.Items.Add(B); if (B.ToString() == SelectedItem.SubItems[3].Text) { IndexBrand = Index; } Index++; } BrandComboBox.SelectedIndex = IndexBrand; // rempli la combo box famille avec la liste des familles existante Index = 0; int IndexFamily = 0; Family[] AllFamily = FamilyDAO.GetAllFamilies(); foreach (Family F in AllFamily) { FamilyComboBox.Items.Add(F); if (F.ToString() == SelectedItem.SubItems[4].Text) { IndexFamily = Index; } Index++; } FamilyComboBox.SelectedIndex = IndexFamily; // rempli la combo box sous famille avec la liste des sous familles appartenant à la famille selectionnée Index = 0; int IndexSubFamily = 0; SubFamilyComboBox.Items.Clear(); SubFamily[] AllLinkedSubFamilies = FamilyDAO.GetAllSubFamilies((Family)FamilyComboBox.SelectedItem); foreach (SubFamily SF in AllLinkedSubFamilies) { SubFamilyComboBox.Items.Add(SF); if (SF.ToString() == SelectedItem.SubItems[4].Text) { IndexSubFamily = Index; } Index++; } SubFamilyComboBox.SelectedIndex = IndexSubFamily; // initialise les champs avec les données de l'article modifié ArticleNameLabel.Text = SelectedItem.SubItems[2].Text; DescriptionTextBox.Text = SelectedItem.SubItems[1].Text; PriceHTTextBox.Text = SelectedItem.SubItems[6].Text; QuantityTextBox.Text = SelectedItem.SubItems[0].Text; }
/// <summary> /// Lance l'import au clic sur "importer et Ecraser" /// </summary> /// <param name="Sender"></param> /// <param name="Event"></param> private void OverwriteButton_Click(object Sender, EventArgs Event) { //Nombre de ligne du fichier (-1 pour éviter la colonne titre) int NbLine = -1; // test les erreurs avec le fichier CSV try { // compte le nombre de ligne du fichier using (var reader = new StreamReader(@CSVNameTextBox.Text)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); NbLine++; } } // met le maximun de la progress bar au nombre de ligne ImportProgressBar.Maximum = NbLine; using (var reader = new StreamReader(@CSVNameTextBox.Text)) { // nettoie la bd try { using (var con = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;")) { // supprime le contenu de la table articles using (var Command = new SQLiteCommand("DELETE FROM Articles;")) { //execute query Command.Connection = con; Command.Connection.Open(); Command.ExecuteNonQuery(); con.Close(); } // supprime le contenu de la table marques using (var Command = new SQLiteCommand("DELETE FROM Marques;")) { //execute query Command.Connection = con; Command.Connection.Open(); Command.ExecuteNonQuery(); con.Close(); } // supprime le contenu de la table sousfamilles using (var Command = new SQLiteCommand("DELETE FROM SousFamilles;")) { //execute query Command.Connection = con; Command.Connection.Open(); Command.ExecuteNonQuery(); con.Close(); } // supprime le contenu de la table familles using (var Command = new SQLiteCommand("DELETE FROM Familles;")) { //execute query Command.Connection = con; Command.Connection.Open(); Command.ExecuteNonQuery(); con.Close(); } } } catch (Exception ExceptionCaught) { MessageBox.Show("Error while clearing db : " + ExceptionCaught.Message, ExceptionCaught.GetType().ToString()); } bool TitleLine = true; while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); // verification qui permet d'éviter la ligne titre if (TitleLine == false) { // verifie si la reference est valide if (ArticleDAO.VerifArticleRef(values[1]) == true) { // cherche la quantité, si elle existe, dans la premiere colonne var firstSpaceIndex = values[0].IndexOf(" "); var Quantity = values[0].Substring(0, firstSpaceIndex); // la quantite si elle existe var Description = values[0].Substring(firstSpaceIndex + 1); // la description si il y a un quantite int IntQuantity; if (int.TryParse(Quantity, out IntQuantity) == false) { Description = values[0]; IntQuantity = 1; } // si la famille existe la trouve sinon la creer Family FamilyToAdd = FamilyDAO.GetFamilyByName(values[3]); if (FamilyToAdd == null) { FamilyToAdd = new Family(values[3]); FamilyDAO.AddFamily(FamilyToAdd); } // si la sous famille existe la trouve sinon la creer SubFamily SubFamilyToAdd = SubFamilyDAO.GetSubFamilyByName(values[4], FamilyToAdd); if (SubFamilyToAdd == null) { SubFamilyToAdd = new SubFamily(values[4], FamilyToAdd); SubFamilyDAO.AddSubFamily(SubFamilyToAdd); } // si la marque existe la trouve sinon la creer Brand BrandToAdd = BrandDAO.GetBrandByName(values[2]); if (BrandToAdd == null) { BrandToAdd = new Brand(values[2]); BrandDAO.AddBrand(BrandToAdd); } // vérifie si le prix est bien un double float FloatPrice; if (float.TryParse(values[5], out FloatPrice)) { // si la reference de l'article existe la trouve sinon creer l'article Article ArticleToAdd = ArticleDAO.GetArticleById(values[1]); if (ArticleToAdd == null) { //créer l'article et le rajoute à la bd ArticleToAdd = new Article(values[1], Description, SubFamilyToAdd, BrandToAdd, FloatPrice, IntQuantity); ArticleDAO.AddArticle(ArticleToAdd); // une ligne rajoutée, on avance donc d'une étape dans la progress bar ImportProgressBar.PerformStep(); } } } } else { TitleLine = false; } } this.Close(); } } catch (Exception ExceptionCaught) { MessageBox.Show(ExceptionCaught.Message, "Erreur : " + ExceptionCaught.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } }