예제 #1
0
        public void integration(String text)
        {
            int countFailedArticle = 0;

            this.progressBar1.Value = 0;

            Console.WriteLine("Lecture du fichier xml " + text);
            label3.Text = "Lecture du fichier XML..";
            label3.Update();

            XmlDocument doc = new XmlDocument();

            doc.Load(text);

            XmlNode     node     = doc.DocumentElement;
            XmlNodeList nodeList = node.SelectNodes("/materiels/article");

            label3.Text = nodeList.Count + " articles ont été détectés, intégration dans la base de données..";
            label3.Update();
            Console.WriteLine(nodeList.Count + " articles ont été détectés");
            this.progressBar1.Maximum = nodeList.Count;

            for (int i = 0; i < nodeList.Count; i++)
            {
                String description = nodeList[i].SelectNodes("description").Item(0).InnerText;
                String refArticle  = nodeList[i].SelectNodes("refArticle").Item(0).InnerText;
                String marque      = nodeList[i].SelectNodes("marque").Item(0).InnerText;
                String famille     = nodeList[i].SelectNodes("famille").Item(0).InnerText;
                String sousFamille = nodeList[i].SelectNodes("sousFamille").Item(0).InnerText;
                float  prixHT      = float.Parse(nodeList[i].SelectNodes("prixHT").Item(0).InnerText);

                Articles article = new Articles(refArticle);
                if (article.loadFromDB() == null)
                {
                    Marques marques = new Marques();
                    marques.Nom = marque;
                    marques.saveInDB();
                    Familles familles = new Familles();
                    familles.Nom = famille;
                    familles.saveInDB();
                    SousFamilles sfamilles = new SousFamilles();
                    sfamilles.Nom        = sousFamille;
                    sfamilles.RefFamille = familles.RefFamille;
                    sfamilles.saveInDB();

                    article.Description    = description;
                    article.PrixHT         = prixHT;
                    article.RefMarque      = marques.RefMarque;
                    article.RefSousFamille = sfamilles.RefSousFamille;
                    if (!article.saveInDB())
                    {
                        countFailedArticle++;
                    }
                }
                progressBar1.PerformStep();
            }
            SystemSounds.Beep.Play();
            label3.Text = "Intégration terminée. " + countFailedArticle + " articles n'ont pas été intégrés";
            label3.Update();
        }
예제 #2
0
        private void ButtonVal_Click(object sender, EventArgs e)
        {
            if (CheckValidData())
            {
                article.RefArticle = textBoxRef.Text;
                if (article != null)
                {
                    DialogResult result;
                    result = MessageBox.Show("Etes vous sur de vouloir modifier cet article?", "Attention : modification d'un article existant", MessageBoxButtons.YesNo);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        article.RefArticle     = textBoxRef.Text;
                        article.Description    = textBoxDescrip.Text;
                        article.RefMarque      = Marques.getRefMarqueFromName(comboBoxMar.SelectedItem.ToString());
                        article.RefSousFamille = SousFamilles.getRefSousFamilleFromName(comboBoxSsFam.SelectedItem.ToString());
                        article.PrixHT         = (float)decimal.ToDouble(numericUpDown1.Value);
                        article.Quantite       = decimal.ToInt32(numericUpDown2.Value);

                        article.updateInDB();
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    DialogResult result;
                    result = MessageBox.Show("Etes vous sur de vouloir ajouter cet article?", "Attention : ajout d'un nouvel article", MessageBoxButtons.YesNo);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        article            = new Articles();
                        article.RefArticle = textBoxRef.Text;

                        if (article.loadFromDB() == null)
                        {
                            article.Description    = textBoxDescrip.Text;
                            article.RefMarque      = Marques.getRefMarqueFromName(comboBoxMar.SelectedItem.ToString());
                            article.RefSousFamille = SousFamilles.getRefSousFamilleFromName(comboBoxSsFam.SelectedItem.ToString());
                            article.PrixHT         = prix;
                            article.Quantite       = quantite;
                            article.saveInDB();
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Impossible d'ajouter cet article", "Attention : ajout d'un article existant");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Veuillez remplir correctement les champs", "Erreur");
            }
        }