Exemplo n.º 1
0
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (StreamReader rd = new StreamReader(printerfile))
                {
                    string line = null;
                    while ((line = rd.ReadLine()) != null)
                    {
                        fileLines.Add(line);
                    }
                }
                for (int i = 0; i < fileLines.Count; ++i)
                {
                    if (Regex.IsMatch(fileLines[i], originalPrinter) && !Regex.IsMatch(fileLines[i], @"^#"))
                    {
                        fileLines[i] = fileLines[i].Insert(0, "#");
                    }
                    if (Regex.IsMatch(fileLines[i], currentPrinterTextBox.Text) && Regex.IsMatch(fileLines[i], @"^#"))
                    {
                        fileLines[i] = fileLines[i].TrimStart('#');
                    }
                }
                using (StreamWriter writer = new StreamWriter(printerfile))
                {
                    foreach (string prtrline in fileLines)
                    {
                        writer.WriteLine(prtrline);
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("Error saving new printer.\n" + ex.Message, "Can't Save New Printer");
            }

            if (originalPrinter != currentPrinterTextBox.Text)
            {
                UpdateProgressWindow pr = new UpdateProgressWindow("Updating Printer Preference...");
                pr.Show();
            }
            Close();
        }
Exemplo n.º 2
0
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            var samesame = ((MainWindow)Application.Current.MainWindow).Prefixes.Count == usedListBox.Items.Count
                        && ((MainWindow)Application.Current.MainWindow).Prefixes.All(usedListBox.Items.Contains);
            try
            {
                usedPrefixes.Clear();
                ignoredPrefixes.Clear();
                foreach (string item in usedListBox.Items)
                {
                    usedPrefixes.Add(item);
                }
                foreach (string item in ignoredListBox.Items)
                {
                    ignoredPrefixes.Add(item);
                }
                List<string> writeToFileStrs = usedPrefixes.Concat(ignoredPrefixes).ToList();
                SortFileStrs(writeToFileStrs);

                using (StreamWriter writer = new StreamWriter(prefixFile))
                {
                    foreach (string item in writeToFileStrs)
                    {
                        writer.WriteLine(item);
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("Error saving new prefixes (okButton_Click() event)).\n\n" + ex.Message, "Can't save new prefixes...");
            }

            ((MainWindow)Application.Current.MainWindow).Prefixes = usedPrefixes.Distinct().ToList();
            ((MainWindow)Application.Current.MainWindow).IgnoredPrefixes = ignoredPrefixes.Distinct().ToList();
            if (!samesame)
            {
                UpdateProgressWindow pr = new UpdateProgressWindow("Updating Prefixes...");
                pr.Show();
            }
            Close();
        }