www.pudn.com > LINkSee.rar > Victory.cs


using System; 
 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
 
namespace LinkSee 
{ 
    public partial class Victory : Form 
    { 
        //protected Congratulation infor = new Congratulation(); 
        protected int diff = 0; 
        protected int tm= 0; 
        public int lasttime = 0; 
        protected string nm = null; 
        protected string diff1 = null; 
 
        public Victory() 
        { 
            InitializeComponent(); 
        } 
 
        public Victory(int tm) 
        { 
            InitializeComponent(); 
            this.tm = tm; 
        } 
 
        public Victory(int tm,int diff) 
        { 
            InitializeComponent(); 
            this.tm = tm; 
            this.diff = diff; 
        } 
        public void WriteMark() 
        { 
            try 
            { 
                string path = null; 
                MessageBox.Show("此时难度w:" + this.diff); 
                switch (this.diff) 
                { 
                    case 0: path = @"topmark0.txt"; break; 
                    case 5: path = @"topmark0.txt"; break; 
                    case 10: path = @"topmark1.txt"; break; 
                    case 15: path = @"topmark2.txt"; break; 
                    case 20: path = @"topmark3.txt"; break; 
                } 
                StreamWriter sw = File.CreateText(path); 
                sw.WriteLine(this.diff.ToString());            
                sw.WriteLine(this.name.Text.ToString()); 
                sw.WriteLine(this.tm.ToString()); 
                sw.Flush(); 
                sw.Close();                          
            }  
            catch (Exception ex) 
            { 
                MessageBox.Show(ex.ToString()); 
            } 
        } 
 
        public int  ReadMark() 
        { 
            string path = null; 
            MessageBox.Show("此时难度r:"+this.diff); 
            switch (this.diff) 
            { 
                case 0: path = @"topmark0.txt"; break; 
                case 5: path = @"topmark0.txt"; break; 
                case 10: path = @"topmark1.txt"; break; 
                case 15: path = @"topmark2.txt"; break; 
                case 20: path = @"topmark3.txt"; break; 
            } 
            MessageBox.Show("此时读的文件:"+path); 
            StreamReader sr = File.OpenText(path);             
            switch (Int32.Parse(sr.ReadLine()))//难度 
            { 
                case 5:this.diff1="easy";break; 
                case 10: this.diff1 = "middle"; break; 
                case 15: this.diff1 = "hard"; break; 
                case 20: this.diff1 ="very hard "; break; 
            } 
            this.nm= sr.ReadLine();//名字 
            string tt = sr.ReadLine(); 
            if (tt == null) 
            { 
                throw new ArgumentNullException(); 
            } 
            this.lasttime =Int32.Parse(tt);//分数            
            sr.Close(); 
            return this.lasttime; 
        } 
 
        private void submit_Click(object sender, EventArgs e) 
        {            
            this.WriteMark(); 
            this.DialogResult = DialogResult.Yes; 
        } 
 
        private void history_Click(object sender, EventArgs e) 
        { 
            string path = null; 
            MessageBox.Show("此时难度:" + this.diff); 
            switch (this.diff) 
            { 
                case 0: path = @"topmark0.txt"; break; 
                case 5: path = @"topmark0.txt"; break; 
                case 10: path = @"topmark1.txt"; break; 
                case 15: path = @"topmark2.txt"; break; 
                case 20: path = @"topmark3.txt"; break; 
            } 
            StreamReader sr = File.OpenText(path); 
            switch (Int32.Parse(sr.ReadLine()))//难度 
            { 
                case 5: this.diff1 = "easy"; break; 
                case 10: this.diff1 = "middle"; break; 
                case 15: this.diff1 = "hard"; break; 
                case 20: this.diff1 = "very hard "; break; 
            } 
            this.nm = sr.ReadLine();//名字 
            string tt = sr.ReadLine(); 
            if (tt == null) 
            { 
                throw new ArgumentNullException(); 
            } 
            this.lasttime = Int32.Parse(tt);//分数            
            sr.Close(); 
            MessageBox.Show("难度为:"+this.diff1 +"\n姓名为:" +this.nm +"\n时间为:"+ this.lasttime); 
        } 
    } 
}