• 老陈 ASP.NET封装


    第一个页面

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.IO;
    public partial class _Default : System.Web.UI.Page
    {
      
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs 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();
            ListBox1.Items.Add(TextBox1.Text + TextBox2.Text + TextBox3.Text + "
    ");
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
        }
        protected void Button2_Click(object sender, EventArgs e)
        {//跳转页面
            Response.Redirect("Default2.aspx");
        }
    }
    

      第二个页面

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }//开始
        public static int Count = 0;
        public static int right = 0;
        //总计的个数和正确的个数
         int m = 0;
        protected void Button1_Click(object sender, EventArgs 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++;
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox4.Enabled = false;
            Response.Write("运算结束!");
            TextBox5.Text = Default2.Count.ToString();//题目总数
            TextBox6.Text = Default2.right.ToString();
            TextBox7.Text = ((Default2.right / (double)(Default2.Count)) * 100).ToString() + "%";//正确率
        }
    
        protected void Button4_Click(object sender, EventArgs 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 (con.answer == int.Parse(TextBox4.Text))
            {
                Response.Write("回答正确!下一题请按开始按钮!");
                right++;
                Count++;
            }
            else
            {
                Response.Write("回答错误!下一题请按开始按钮!");
                Count++;
            }
        }
    }
    

      .net的封装

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    ///Class1 的摘要说明
    /// </summary>
    public class Class1
    {
        public Class1()
        {
    
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
            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;
    
            }
    }
    

      运行后

  • 相关阅读:
    【JZOJ4928】【NOIP2017提高组模拟12.18】A
    【JZOJ4922】【NOIP2017提高组模拟12.17】环
    【JZOJ4923】【NOIP2017提高组模拟12.17】巧克力狂欢
    【JZOJ4924】【NOIP2017提高组模拟12.17】向再见说再见
    【JZOJ4919】【NOIP2017提高组模拟12.10】神炎皇
    【JZOJ4920】【NOIP2017提高组模拟12.10】降雷皇
    【JZOJ4921】【NOIP2017提高组模拟12.10】幻魔皇
    【罗宾欺诈者】回环符文——回文树(回文自动机)
    【怪物】KMP畸形变种——扩展KMP
    【51NOD1304】字符串的相似度
  • 原文地址:https://www.cnblogs.com/fjhdmn/p/5023270.html
Copyright © 2020-2023  润新知