Beispiel #1
0
 public Form2()
 {
     InitializeComponent();
     if (File.Exists(outp))
     {
         button1.Enabled = true;
         encDecr en = new encDecr();
         en.DecryptFile(outp, decr);
         File.Delete(outp);
         StreamReader read = new StreamReader(decr);
         String       line;
         int          c      = 0;
         int          i      = 0;
         Label[]      labels = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11 };
         while (c < 5 && (line = read.ReadLine()) != null)
         {
             var    d     = line.Split(' ');
             String name  = d[0];
             String score = d[1];
             labels[i].Text    = name;
             labels[i].Visible = true;
             i++;
             labels[i].Text    = score;
             labels[i].Visible = true;
             i++;
             c++;
         }
         read.Close();
         en.EncryptFile(decr, outp);
         File.Delete(decr);
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            string  outp = @"../../Resources/scorencr.txt";
            string  decr = @"../../Resources/scoredecr.txt";
            encDecr en   = new encDecr();

            if (!File.Exists(outp))
            {
                File.Create(decr).Close();
                StreamWriter wr = new StreamWriter(decr, true);
                wr.WriteLine(textBox1.Text + ' ' + textBox2.Text);
                wr.Flush();
                wr.Close();
                en.EncryptFile(decr, outp);
                File.Delete(decr);
            }
            else
            {
                en.DecryptFile(outp, decr);
                File.Delete(outp);

                hs.Add(new Tuple <String, int>(textBox1.Text, int.Parse(textBox2.Text)));
                StreamReader read = new StreamReader(decr);
                String       line;
                while ((line = read.ReadLine()) != null)
                {
                    var    d    = line.Split(' ');
                    String name = d[0];
                    int    scr  = int.Parse(d[1]);
                    hs.Add(new Tuple <String, int>(name, scr));
                }
                read.Close();
                hs.Sort((x, y) => y.Item2.CompareTo(x.Item2));
                File.Delete(decr);
                File.Create(decr).Close();
                StreamWriter wr = new StreamWriter(decr, true);
                for (int j = 0; j < hs.Count; j++)
                {
                    wr.WriteLine(hs[j].Item1 + ' ' + hs[j].Item2);
                }
                wr.Flush();
                wr.Close();
                en.EncryptFile(decr, outp);
                File.Delete(decr);
            }
            this.Hide();
            Form1 home = new Form1();
            int   i    = 1;

            home.res(i);
        }
Beispiel #3
0
        public Data(string category)
        {
            encDecr e = new encDecr();

            this.category = category;
            string path = "";

            if (category.Equals("Animals"))
            {
                string inp = @"../../Resources/animalsenc.txt";
                path = @"../../Resources/animals.txt";
                e.DecryptFile(inp, path);
            }
            else if (category.Equals("Capital cities"))
            {
                string inp = @"../../Resources/citiesenc.txt";
                path = @"../../Resources/cities.txt";
                e.DecryptFile(inp, path);
            }
            else if (category.Equals("FINKI"))
            {
                string inp = @"../../Resources/finkienc.txt";
                path = @"../../Resources/finki.txt";
                e.DecryptFile(inp, path);
            }

            StreamReader file;
            string       lines;

            file = new StreamReader(path);
            while ((lines = file.ReadLine()) != null)
            {
                if (category.Equals("Animals"))
                {
                    animals.Add(lines);
                }
                else if (category.Equals("Capital cities"))
                {
                    cities.Add(lines);
                }
                else if (category.Equals("FINKI"))
                {
                    finki.Add(lines);
                }
            }
            if (category.Equals("Animals"))
            {
                string inp = @"../../Resources/animals.txt";
                file.Close();
                File.Delete(inp);
            }
            else if (category.Equals("Capital cities"))
            {
                string inp = @"../../Resources/cities.txt";
                file.Close();
                File.Delete(inp);
            }
            else if (category.Equals("FINKI"))
            {
                string inp = @"../../Resources/finki.txt";
                file.Close();
                File.Delete(inp);
            }
        }