老陈 WPF

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace 老陈Wpf
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        public static int Count = 0;
        public static int right = 0;
        int m = 0;
       
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            StreamWriter n1 = File.AppendText("C:\\n1.txt");
            n1.WriteLine(textBox1.Text);
            n1.Close();
            StreamWriter n2 = File.AppendText("C:\\n2.txt");
            n2.WriteLine(textBox2.Text);
            n2.Close();
            StreamWriter n3 = File.AppendText("C:\\n3.txt");
            n3.WriteLine(textBox3.Text);
            n3.Close();
            MessageBox.Show("录题成功");
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //出题
            string[] n1 = new string[100];
            n1 = File.ReadAllLines("C:\\n1.txt");
            textBox1.Text = n1[m];
            string[] n2 = new string[100];
            n2 = File.ReadAllLines("C:\\n2.txt");
            textBox2.Text = n2[m];
            string[] n3 = new string[100];
            n3 = File.ReadAllLines("C:\\n3.txt");
            textBox3.Text = n3[m];
            m++;
        }
        //结束
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            textBox5.Text = MainWindow.Count.ToString();//题目总数
            textBox6.Text = MainWindow.right.ToString();
            textBox7.Text = ((MainWindow.right / (double)(MainWindow.Count)) * 100).ToString() + "%";//正确率
        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            int a = int.Parse(textBox1.Text);
            int b = int.Parse(textBox3.Text);
            Char c = Convert.ToChar(textBox2.Text);
            Class1 con = new Class1();
            con.chu(a, b, c);
            if (e.Key == Key.Enter)
            {

                if (con.answer == int.Parse(textBox4.Text))
                {
                    MessageBox.Show("回答正确!下一题请按开始按钮!");
                    right++;
                    Count++;
                }

                else
                {

                    MessageBox.Show("回答错误!下一题请按开始按钮!");
                    Count++;

                }
                textBox4.Clear();
            }
        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {
            StreamWriter n1 = File.AppendText("C:\\n1.txt");
            n1.WriteLine(textBox1.Text);
            n1.Close();
            StreamWriter n2 = File.AppendText("C:\\n2.txt");
            n2.WriteLine(textBox2.Text);
            n2.Close();
            StreamWriter n3 = File.AppendText("C:\\n3.txt");
            n3.WriteLine(textBox3.Text);
            n3.Close();
            MessageBox.Show("录题成功");
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }
    }
}

 封装

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 老陈Wpf
{
    class Class1
    {
        public int sum;
        public int answer
        {
            get
            {
                return sum;
            }
        }

        public int chu(int n1, int n2, char fuhao)
        {
            if (fuhao == '+')
            {
                return sum = n1 + n2;
            }
            else if (fuhao == '-')
            {
                return sum = n1 - n2;
            }
            else if (fuhao == '*')
            {
                return sum = n1 * n2;
            }
            return sum;

        }
    }
}

  运行的界面如下:

posted @ 2015-12-11 18:11  你向我微笑  阅读(176)  评论(2编辑  收藏  举报