Esempio n. 1
0
        /// <summary>
        /// Méthode pour lire un fichier xml
        /// </summary>
        public void ReadFileXml()
        {
            PB_logoCompany.BackgroundImage = null;
            PB_logoCompany.Image           = null;
            PB_logoCompany.BackColor       = Color.White;

            try
            {
                XmlSerializer  serializer     = new XmlSerializer(typeof(SettingCompany));                                  // Désérialise
                StreamReader   streamReader   = new StreamReader(Application.StartupPath + "/company/setting_company.xml"); // Lire Xml
                SettingCompany settingCompany = (SettingCompany)serializer.Deserialize(streamReader);                       // Cast les données en SettingCompany

                MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(settingCompany.Logo));

                TXT_nameCompany.Invoke((MethodInvoker) delegate { TXT_nameCompany.Text = settingCompany.Denomination; });

                if (settingCompany.Logo == null || settingCompany.Logo == "")
                {
                    PB_logoCompany.Invoke((MethodInvoker) delegate { PB_logoCompany.BackgroundImage = Properties.Resources.Image_en_attente; });
                }
                else
                {
                    PB_logoCompany.Invoke((MethodInvoker) delegate { PB_logoCompany.BackgroundImage = Image.FromStream(memoryStream); });
                }

                TXT_siren.Invoke((MethodInvoker) delegate { TXT_siren.Text = settingCompany.Siren; });
                TXT_siret.Invoke((MethodInvoker) delegate { TXT_siret.Text = settingCompany.Siret; });
                TXT_tvaCompany.Invoke((MethodInvoker) delegate { TXT_tvaCompany.Text = settingCompany.Tva; });
                TXT_activityCompany.Invoke((MethodInvoker) delegate { TXT_activityCompany.Text = settingCompany.ActivityCode; });
                TXT_addressCompany.Invoke((MethodInvoker) delegate { TXT_addressCompany.Text = settingCompany.Address; });
                TXT_bossName.Invoke((MethodInvoker) delegate { TXT_bossName.Text = settingCompany.Name; });
                TXT_webCompany.Invoke((MethodInvoker) delegate { TXT_webCompany.Text = settingCompany.WebSite; });
                TXT_phoneCompany.Invoke((MethodInvoker) delegate { TXT_phoneCompany.Text = settingCompany.Phone; });
                TXT_emailCompany.Invoke((MethodInvoker) delegate { TXT_emailCompany.Text = settingCompany.Email; });

                streamReader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Une erreur c'est produite" + ex.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 2
0
        public void WriteFileXml()
        {
            if (File.Exists(Application.StartupPath + "/company/setting_company.xml"))
            {
                File.Delete(Application.StartupPath + "/company/setting_company.xml");
            }
            else
            {
                SettingCompany settingCompany = new SettingCompany()
                {
                    Denomination = TXT_nameCompany.Text, Logo = pictureByteEncode, Address = TXT_addressCompany.Text, Siren = TXT_siren.Text, Siret = TXT_siret.Text, Tva = TXT_tvaCompany.Text.ToUpper(), ActivityCode = TXT_activityCompany.Text.ToUpper(), Name = TXT_bossName.Text, Phone = TXT_phoneCompany.Text, Email = TXT_emailCompany.Text, WebSite = TXT_webCompany.Text
                };                                                                                                        // class SettingCompany
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(SettingCompany));                                  // Sérialiser une classe qui se compose simplement de champs et de propriétés publics
                StreamWriter  writerXml     = new StreamWriter(Application.StartupPath + "/company/setting_company.xml"); // Ecrire un fichier dans un flux selon un encodage particulier.
                xmlSerializer.Serialize(writerXml, settingCompany);                                                       // Ecrit

                writerXml.Close();                                                                                        // Ferme l'ecriture

                MessageBox.Show("Les données ont bien été sauvegardé.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }