zoukankan      html  css  js  c++  java
  • 老陈 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;
    
            }
    }
    

      运行后

  • 相关阅读:
    【C语言】判断学生成绩等级
    如何强制卸载软件,强制卸载的工具。
    网站添加左下角某易云音乐播放器代码
    ASCII码表
    C语言当中int,float,double,char这四个有什么区别?
    未来HTML5的发展前景如何?黑客专家是这样回答的
    2018年需要关注5个与黑客安全相关趋势
    2025年的技术:为第四次工业革命做准备
    量子计算可以给企业竞争带来的七种优势
    目前投资区块链三大风险
  • 原文地址:https://www.cnblogs.com/fjhdmn/p/5023270.html
Copyright © 2011-2022 走看看