Ejemplo n.º 1
0
 private void sanitizeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (ImportProgressForm form = new ImportProgressForm())
     {
         form.Worker.DoWork += SanitizeNames;
         form.ShowDialog();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String filename = null;

            using(OpenFileDialog dia = new OpenFileDialog())
            {
                dia.Filter = "CSV (*.csv)|*.csv|All files (*.*)|*.*";

                if (dia.ShowDialog() != DialogResult.OK)
                    return;

                filename = dia.FileName;
            }

            using(NameMapForm form = new NameMapForm())
            {
                using (TextReader r = new StreamReader(filename))
                {
                    CsvReader reader = new CsvReader(r);
                    reader.Configuration.HasHeaderRecord = true;
                    reader.Read();

                    for(Int32 i = 0; i < reader.FieldHeaders.Length; i++)
                    {
                        String str = reader.FieldHeaders[i];

                        NameColumn column = new NameColumn(i, str);

                        DataGridViewRow row = new DataGridViewRow();
                        DataGridViewTextBoxCell name = new DataGridViewTextBoxCell();
                        name.Value = column;

                        DataGridViewComboBoxCell type = new DataGridViewComboBoxCell();

                        foreach(String property in Enum.GetNames(typeof(NameProperty)))
                        {
                            type.Items.Add(property);
                        }

                        row.Cells.Add(name);
                        row.Cells.Add(type);

                        form.DataGrid.Rows.Add(row);
                    }
                }

                if (form.ShowDialog() != DialogResult.OK)
                    return;

                NameImporter importer = new NameImporter(form.Culture);
                importer.DefaultYear = Convert.ToInt32(form.DefaultYear);

                foreach(DataGridViewRow row in form.DataGrid.Rows)
                {
                    NameProperty property = (NameProperty)Enum.Parse(
                        typeof(NameProperty), row.Cells[1].Value.ToString(), false);

                    importer.AddMapping(property, ((NameColumn)row.Cells[0].Value).Index);
                }

                using (progressForm = new ImportProgressForm())
                {
                    using(TextReader reader = new StreamReader(filename))
                    {
                        CsvReader csv = new CsvReader(reader);
                        CsvImportSource source = new CsvImportSource(csv);

                        importer.OnProcessing += delegate(Int64 entries, String name) {
                            progressForm.UpdateText(String.Format("Importing {0} ({1} entries processed)...", name, entries));
                        };
                        importer.OnCommitting += delegate(Int64 cached)
                        {
                            progressForm.UpdateText(String.Format("Committing {0} entries to the database...", cached));
                        };
                        progressForm.Worker.DoWork += new DoWorkEventHandler(delegate {
                            importer.Import(source);
                        });
                        progressForm.ShowDialog();
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private void recalculateProbabilitiesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using(ImportProgressForm form = new ImportProgressForm())
     {
         form.Worker.DoWork += RecalculateProbabilities;
         form.ShowDialog();
     }
 }