예제 #1
0
        /// <summary>
        /// Récupére l'id client et le type client pour instancier la class client.
        /// Afin denvoyer les informations a l'userControl UC_Update
        /// </summary>
        /// <param name="id">id client</param>
        /// <param name="type">type client</param>
        private void UpdateClient(int id, string type)
        {
            List <string> phone = new List <string>();

            UC_updateClient.fRM_Clients = this;
            if (type.Equals("Particulier"))
            {
                SQLiteDataReader readerIndividual      = database.Extraction("SELECT id, last_name, first_name, address, city, postal_code, email FROM clients AS c, individual AS i WHERE c.id = i.id_client AND c.id = " + id);
                SQLiteDataReader readerIndividualPhone = database.Extraction("SELECT phone FROM clients AS c, phone AS p WHERE c.id = p.id_client AND c.id = " + id);
                while (readerIndividualPhone.Read())
                {
                    phone.Add(readerIndividualPhone[0].ToString());
                }

                ClientIndividual clientIndividual = new ClientIndividual(int.Parse(readerIndividual[0].ToString()), readerIndividual[1].ToString(), readerIndividual[2].ToString(), readerIndividual[3].ToString(), readerIndividual[4].ToString(), int.Parse(readerIndividual[5].ToString()), readerIndividual[6].ToString(), phone);
                UC_updateClient.individual = clientIndividual;
                UC_updateClient.Show();
            }
            else if (type.Equals("Professionnel"))
            {
                SQLiteDataReader readerProfessional      = database.Extraction("SELECT id, socid_reason, siret, address, city, postal_code, email FROM clients AS c, professional AS p WHERE c.id = p.id_client AND c.id = " + id);
                SQLiteDataReader readerProfessionalPhone = database.Extraction("SELECT phone FROM clients AS c, phone AS p WHERE c.id = p.id_client AND c.id = " + id);
                while (readerProfessionalPhone.Read())
                {
                    phone.Add(readerProfessionalPhone[0].ToString());
                }
                ClientProfessional clientProfessional = new ClientProfessional(int.Parse(readerProfessional[0].ToString()), readerProfessional[1].ToString(), long.Parse(readerProfessional[2].ToString()), readerProfessional[3].ToString(), readerProfessional[4].ToString(), int.Parse(readerProfessional[5].ToString()), readerProfessional[6].ToString(), phone);
                UC_updateClient.professional = clientProfessional;
                UC_updateClient.Show();
            }
        }
예제 #2
0
        /// <summary>
        /// Bouton ajouter les clients dans un tableau et lire le fichier CSV
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BT_importClients_Click(object sender, EventArgs e)
        {
            //Affiche une boîte de dialogue standard qui invite l'utilisateur à ouvrir un fichier.
            OpenFileDialog openFile = new OpenFileDialog
            {
                Filter        = "CSV|*.csv", // fichier au format .csv
                ValidateNames = true,
                Multiselect   = false
            };

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                //Implémente TextReader qui lit les caractères à partir d'un flux d'octets dans un encodage particulier.
                try
                {
                    StreamReader streamReader = new StreamReader(openFile.FileName);
                    DGV_ListImportClient.Visible = false;
                    PL_importVisual.Visible      = true;

                    while (!streamReader.EndOfStream)
                    {
                        string line = streamReader.ReadLine(); // lire une ligne

                        if (line != ";;;;;;;;")
                        {
                            string[] data = line.Split(';'); // Split de line récuprer les données sous un tableau
                                                             // clé C = client, CP == client pro
                            if (data[1] == "C")
                            {
                                List <string> phones = new List <string>();
                                // list de téléphone
                                for (int i = 0; i < data[8].Split('*').Length; i++)
                                {
                                    phones.Add(data[8].Split('*')[i]);
                                }
                                // check email
                                if (data[7] == "" || data[7] == null)
                                {
                                    data[7] = "*****@*****.**";
                                }

                                individual = new ClientIndividual(int.Parse(data[0]), data[2].ToUpper(), data[3], data[4], data[5], int.Parse(data[6]), data[7], phones);
                                DGV_ListImportClient.Rows.Add(data[0], data[1], data[2].ToUpper(), data[3], data[4], data[5], data[6], data[7], phones[0]); // DataGridView
                                clientList.Add(individual);                                                                                                 // ajouter les clients a la list
                            }
                            else if (data[1] == "CP")
                            {
                                List <string> phones = new List <string>();

                                // list de téléphone
                                for (int i = 0; i < data[8].Split('*').Length; i++)
                                {
                                    phones.Add(data[8].Split('*')[i]);
                                }

                                // check email
                                if (data[7] == "" || data[7] == null)
                                {
                                    data[7] = "*****@*****.**";
                                }

                                professional = new ClientProfessional(int.Parse(data[0]), data[2], long.Parse(data[3]), data[4], data[5], int.Parse(data[6]), data[7], phones);
                                DGV_ListImportClient.Rows.Add(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], phones[0]); // DataGridView
                                clientProfessionalsList.Add(professional);                                                                        // ajouter les clients pro a la list
                            }
                        }

                        PB_importClient.PerformStep();
                    }

                    DGV_ListImportClient.Visible = true;
                    PL_importVisual.Visible      = false;
                }catch (Exception ex)
                {
                    MessageBox.Show("Une erreur est survenue :" + ex.Message);
                }
            }
        }