Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace Index_Checker
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         int maxCnt = 0;
  18.         List<string> addrList;
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.             maxCnt = 100;
  23.             addrList = new List<string>();
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "TXT|*.txt|CSV|*.csv" })
  29.             {
  30.                 if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  31.                 {
  32.                     string file = ofd.FileName;
  33.                     if (file.EndsWith("txt"))
  34.                     {
  35.                         radioButton1.Checked = true;
  36.                     }
  37.                     else radioButton2.Checked = true;
  38.                     textBox1.Text = file;
  39.                 }
  40.             }
  41.         }
  42.  
  43.         private void button2_Click(object sender, EventArgs e)
  44.         {
  45.             using (SaveFileDialog ofd = new SaveFileDialog() { Filter = "TXT|*.txt|CSV|*.csv" })
  46.             {
  47.                 if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  48.                 {
  49.                     string file = ofd.FileName;
  50.                     if (file.EndsWith("txt"))
  51.                     {
  52.                         radioButton4.Checked = true;
  53.                     }
  54.                     else radioButton3.Checked = true;
  55.                     textBox2.Text = file;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         private void button6_Click(object sender, EventArgs e)
  61.         {
  62.             if (!File.Exists(textBox1.Text)) { MessageBox.Show("Входной файл не существует"); return; }
  63.             addrList = new List<string>(File.ReadAllLines(textBox1.Text));
  64.             maxCnt = addrList.Count;
  65.             progressBar1.Maximum = maxCnt;
  66.             label4.Text = string.Format("0/{0} (0%)", maxCnt);
  67.         }
  68.  
  69.         private void button3_Click(object sender, EventArgs e)
  70.         {
  71.             Task task = new Task(() =>
  72.             {
  73.                 for (int i = 0; i < 100; i++)
  74.                 {
  75.                     UpdateResults(i);
  76.                     Thread.Sleep(1000);
  77.                 }
  78.  
  79.  
  80.             });
  81.             task.Start();
  82.         }
  83.  
  84.         void UpdateResults(int current)
  85.         {
  86.             BeginInvoke(new Action(() =>
  87.             {
  88.                 progressBar1.Value = current;
  89.                 label4.Text = string.Format("{0}/{1} ({2}%)", current, maxCnt, current * 100 / maxCnt);
  90.             }));
  91.         }
  92.         void UpdateInfo(string addr, string index)
  93.         {
  94.             BeginInvoke(new Action(() =>
  95.             {
  96.                 label9.Text = index;
  97.                 label8.Text = addr;
  98.             }));
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement