1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
namespace Random_Name_Generator
{
public partial class datafile_tool : UserControl
{
public datafile_tool()
{
InitializeComponent();
cb_tag1.Text = "";
cb_tag2.Text = "";
cb_tag3.Text = "";
cb_tag5.Text = "";
cb_tag6.Text = "";
cb_tag7.Text = "";
}
private void ts_opnf_Click(object sender, System.EventArgs e)
{
OFD.ShowDialog();
}
private void OFD_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
string mfile = OFD.FileName;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(mfile))
{
string line;
Dictionary<int, string> RechercheDoublons = new Dictionary<int, string>();
int counter1 = 0;
while ((line = sr.ReadLine()) != null)
{
string[] divide = line.Split(Convert.ToChar(" "));
if (divide.Length > 0)
{
foreach (string str in divide)
{
string str1 = str.Trim();
if (!RechercheDoublons.ContainsValue(str1))
RechercheDoublons.Add(counter1, str1);
counter1++;
}
}
else
{
if (!RechercheDoublons.ContainsValue(line.Trim()))
RechercheDoublons.Add(counter1, line.Trim());
counter1++;
}
}
foreach (KeyValuePair<int, string> kvp in RechercheDoublons)
{
lv_names.Items.Add(kvp.Value);
}
}
}
catch (Exception ex)
{
// Let the user know what went wrong.
MessageBox.Show(ex.ToString());
}
Application.DoEvents();
}
}
} |