public static void AcquireXML(TextReader reader, string fileName)
        {
            string xml;

            using (reader)
            {
                xml = reader.ReadToEnd();
            }

            object enitiyBase;

            try
            {
                using (StreamReader readerDue = new StreamReader(fileName, Encoding.UTF8, true))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(PASSPORTSCAN));//, new XmlRootAttribute("EricsoftGuestData"));
                    enitiyBase = serializer.Deserialize(readerDue);
                }
            }
            catch (InvalidOperationException operationEx)
            {
                throw new ApplicationException("Il file selezionato non è corretto. " + operationEx.Message);
            }

            try
            {
                if (!GestioneMySql.OpenConnection())
                {
                    throw new Exception("Errore nell'apertura della connessione. ");
                }

                GestioneMySql.TransazioneBegin();

                PassportscanDB.Save(enitiyBase as PASSPORTSCAN);
                FileInfo fileInfo = new FileInfo(fileName);

                TemplateXml templateXml = new TemplateXml();
                templateXml.FILE_NM   = fileInfo.Name;
                templateXml.FILE_PATH = fileInfo.FullName;

                TemplateXmlDB.SaveTemplate(templateXml);

                if (!GestioneMySql.OpenConnection())
                {
                    throw new Exception("Errore nell'apertura della connessione. ");
                }

                GestioneMySql.TransazioneCommit();

                if (!GestioneMySql.CloseConnection())
                {
                    throw new Exception("Errore nella chiusura della connessione. ");
                }
            }
            catch (Exception e)
            {
                GestioneMySql.TransazioneRollback();
                throw e;
            }
        }
Beispiel #2
0
        private void btnAddUtenzeFromFile_Click(object sender, EventArgs e)
        {
            if (DialogResult.No == MessageBox.Show(string.Format("Verrà acquisito un file xml per l'importazione delle utenze." + Environment.NewLine + "Vuoi proseguire?", ""), "Acquisizione File", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                return;
            }

            string filePath;

            filePath = FileService.CaricaFile("xml", "XML files (*.xml)|*.xml|All files (*.*)|*.*");

            if (!File.Exists(filePath))
            {
                MessageBox.Show("Impossibile trovare il file nella posizione indicata.", "File non trovato", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (TemplateXmlDB.Exists(filePath))
            {
                MessageBox.Show("Il file risulta già importato.", "File già presente", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            FileService.AcquireXML(new StreamReader(filePath), filePath);

            MessageBox.Show("File correttamente acquisito.", "Acquisizione File", MessageBoxButtons.OK, MessageBoxIcon.Information);
            LoadGridUtenze();
        }