Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
     }
 }