Example #1
0
        private void GerarDados(Dictionary <string, string> listaDirArquivo)
        {
            try
            {
                if (File.Exists(txtIndentificador.Text + ".xml"))
                {
                    DialogResult dResult = MessageBox.Show("O catálogo '"
                                                           + txtIndentificador.Text
                                                           + "' já existe! Deseja substituir?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dResult != DialogResult.Yes)
                    {
                        return;
                    }
                }

                DriveData driveData = new DriveData();
                driveData.Identificador = txtIndentificador.Text;
                driveData.Data          = dtpData.Value.ToShortDateString();
                driveData.TipoArquivos  = cbTipoArquivos.Text;
                driveData.File          = new List <ChaveValorSer <string, string> >();
                progressBar1.Value      = 0;
                progressBar1.Maximum    = listaDirArquivo.Count;

                foreach (KeyValuePair <string, string> dirArquivo in listaDirArquivo)
                {
                    if (cancelar)
                    {
                        cancelar = false;
                        return;
                    }
                    else
                    {
                        progressBar1.Value += 1;
                        ChaveValorSer <string, string> info = new ChaveValorSer <string, string>();
                        info.Size = dirArquivo.Value;
                        info.File = dirArquivo.Key;
                        driveData.File.Add(info);
                    }
                    Application.DoEvents();
                }

                XmlSerializer writer = new XmlSerializer(driveData.GetType());
                StreamWriter  file   = new StreamWriter(driveData.Identificador + ".xml", false);
                writer.Serialize(file, driveData);
                file.Close();
                file.Dispose();
                MessageBox.Show("Arquivo de catálogo gerado com sucesso.",
                                "Catálogo gerado", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao gerar arquivo de catálogo.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                progressBar1.Value = 0;
            }
        }
Example #2
0
        private void frConsulta_Load(object sender, EventArgs e)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(Application.StartupPath);

            FileInfo[]   filesInfos = dirInfo.GetFiles("*.xml");
            StreamReader sr;

            listaDados = new List <DriveData>();
            foreach (FileInfo fInfo in filesInfos)
            {
                sr = new StreamReader(fInfo.DirectoryName + Path.DirectorySeparatorChar + fInfo.Name);
                XmlSerializer xs        = new XmlSerializer(typeof(DriveData));
                DriveData     driveData = (DriveData)xs.Deserialize(sr);
                listaDados.Add(driveData);
            }

            PopulaListaArquivos(listaDados);
        }