⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_y.aspx.cs.svn-base

📁 大学英语学习系统
💻 SVN-BASE
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;


public partial class SubjectManage_Subject_Y : System.Web.UI.Page
{
    public static  bool res = true;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["USERSTYLE"] == "TEACHER")
        {

        }
        else
        {
            Dialog("对不起,你没有权限访问这个页面!");
            Response.Redirect("~/SystemManage/Login.aspx");
        }
    }
    private void Dialog(String Str)
    {
        Response.Write(@"<script type='text/JavaScript'>");
        Response.Write(@"alert('" + Str + "');");
        //Response.Write(@"window.location='./list_logingroup.aspx';");
        Response.Write(@"</script>");
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        String tno = texTno.Text;
        String FileName = "第" + tno + "题.txt";
        String content = FileName;
        String grade = ddlGrade.Text;

        String qno = texNo.Text;
        String con = changeWord(texCon.Text);
        String a = changeWord(texA.Text); String b = changeWord(texB.Text); String c = changeWord(texC.Text); String d = changeWord(texD.Text);
        String key = ddlKey.Text;

        String[] InsertStr1 = {tno,content,grade };

        String[] InsertStr2 = { qno,con,a,b,c,d,key,tno};

        SqlData sql = new SqlData();
        bool f = true; ;
            if (res == true)
            {
                if (sql.CheckStringUnique("TAB_TESTREAD", "TRNO", tno) == 2)
                {
                    sql.InsertRow("TAB_TESTREAD", InsertStr1, InsertStr1.Length);
                    res = false;
                    sql.SqlDataClose();
               
                    String s = texConetnt.Text;
                    String A = MapPath("Read");
                    FileStream fs = new FileStream(A + "\\" + FileName, FileMode.OpenOrCreate);
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(s);
                    sw.Close();
                }
                else
                {
                    Label2.Text = "题号为" + tno + "已经存在!";
                    f = false;
                }                   
            }
            if (f == true)
            {
                if(sql.InsertRow("TAB_TESTREADKEY", InsertStr2, InsertStr2.Length) == true) 
                Label2.Text = "操作成功!";
                else
                    Label2.Text = "录入失败!";
                sql.SqlDataClose();
            }


          

    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        res = true;
        int i=1;
        String s=i.ToString();
        SqlData sql=new SqlData();
        while (sql.CheckStringUnique("TAB_TESTREAD", "TRNO", s) == 1)
        {
            i++;
            s = i.ToString();
        }
        texTno.Text = s;
        texNo.Text = "1";
        texConetnt.Text = "";
        texCon.Text = ""; texA.Text = ""; texB.Text = ""; texC.Text = ""; texD.Text = "";
        Label2.Text = "继续录入";
    }
    protected void btnNext_1_Click(object sender, EventArgs e)
    {
        String s = texNo.Text;
        int i = int.Parse(s);
        i++;
        texNo.Text = i.ToString();
        texCon.Text = ""; texA.Text = ""; texB.Text = ""; texC.Text = ""; texD.Text = "";
        Label2.Text = "继续录入问题";
        res = false;
    }
    protected void btnFind_Click(object sender, EventArgs e)
    {
        String str1= texTno.Text;
        String str2=texNo.Text;
        string ConnectionString =
        ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(ConnectionString);

        String conString = "select * from TAB_TESTREAD where TRNO=" + str1;
        SqlDataAdapter myAdapter = new SqlDataAdapter(conString, myConnection);

        DataSet myDataSet = new DataSet();
        myAdapter.Fill(myDataSet, "info");
        DataTable Table = myDataSet.Tables[0];

        if (Table.Rows.Count == 0)
        {
            Label2.Text = "没有此记录!";
            texConetnt.Text = "";
        }
        else
        {
            DataRow row = Table.Rows[0];

            String tno = texTno.Text;
            String FileName = "第" + tno + "题.txt";       
            String A = MapPath("Read");
            FileStream fs = new FileStream(A+"\\"+FileName, FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            String ss = sr.ReadToEnd();
            texConetnt.Text = ss;
            sr.Close();

            ddlGrade.Text = row["TRGRADE"].ToString();
            Label2.Text = "";

            if (str2 == "") { str2 = "1"; texNo.Text = str2; }
            String conString1 = "select * from TAB_TESTREADKEY where TRNO=" + str1 + "and QNO=" + str2;
            SqlDataAdapter myAdapter1 = new SqlDataAdapter(conString1, myConnection);

            DataSet myDataSet1 = new DataSet();
            myAdapter1.Fill(myDataSet1, "info1");
            DataTable Table1 = myDataSet1.Tables[0];
            if (Table1.Rows.Count == 0)
            {
                Label2.Text = "没有此问题!";
                texCon.Text = "";
                texA.Text = ""; texB.Text = ""; texC.Text = ""; texD.Text = "";
            }
            else
            {
                DataRow row1 = Table1.Rows[0];
                texCon.Text = row1["TRQESTION"].ToString();
                texA.Text = row1["A"].ToString();
                texB.Text = row1["B"].ToString();
                texC.Text = row1["C"].ToString();
                texD.Text = row1["D"].ToString();
                ddlKey.Text = row1["TRKEY"].ToString();
                Label2.Text = "";
            }
        }
        
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        String tno = texTno.Text;
        String FileName = "第" + tno + "题.txt";
        String content = FileName;
        String grade = ddlGrade.Text;

        String qno = texNo.Text;
        String con = changeWord(texCon.Text);
        String a = changeWord(texA.Text); String b = changeWord(texB.Text); String c = changeWord(texC.Text); String d = changeWord(texD.Text);
        String key = ddlKey.Text;

        String[] InsertStr1 = { content, grade };

        String[] InsertStr2 = { con, a, b, c, d, key };
        String[] UpdateCloumn1 ={ "TRCONTENT","TRGRADE"};
        String[] UpdateCloumn2 ={ "TRQESTION","A","B","C","D","TRKEY"};

        String[] WhereCloumn={"QNO","TRNO"};
        String[] WhereStr={qno,tno};
        SqlData sql = new SqlData();
        if (sql.updateRow("TAB_TESTREAD", UpdateCloumn1, InsertStr1, InsertStr1.Length, "TRNO", tno) == true)
        {
            sql.SqlDataClose();

            
            String s = texConetnt.Text;
            String A = MapPath("Read");
            FileStream fs = new FileStream(A + "\\" + FileName, FileMode.Open);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(s);
            sw.Close();
            if (sql.updateRow("TAB_TESTREADKEY", UpdateCloumn2, InsertStr2, InsertStr2.Length, WhereCloumn, WhereStr) == true)
            {
                Label2.Text = "修改成功!";
            }
            sql.SqlDataClose();
        }
        else
        {
            Label2.Text = "修改失败!";
            sql.SqlDataClose();
        } 

    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        String str1 = texTno.Text;

        SqlData sql = new SqlData();
        if (sql.CheckStringUnique("TAB_SAVETESTREAD", "TRNO", str1) == 1)
        {
            Label2.Text = "该题已经被选进试卷,不能被删除!";
        }
        else
        {
            if (sql.DeleteRow("TAB_TESTREADKEY", "TRNO", str1) == true)
            {
                sql.SqlDataClose();
                texNo.Text = "";
                texCon.Text = "";
                texA.Text = ""; texB.Text = ""; texC.Text = ""; texD.Text = "";

                if (sql.DeleteRow("TAB_TESTREAD", "TRNO", str1) == true)
                {
                    String tno = texTno.Text;
                    String FileName = "第" + tno + "题.txt";
                    String A = MapPath("Read");
                    FileInfo fi = new FileInfo(A + "\\" + FileName);
                    fi.Delete();

                    Label2.Text = "删除成功!";
                    sql.SqlDataClose();
                    texTno.Text = "";
                    texConetnt.Text = "";
                }
            }
        }
        
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/SystemManage/TeacherMain.aspx");
    }
    public string changeWord(string str)
    {
        String[] sArray = str.Split('\'');
        String result = "";
        foreach (String head in sArray)
        {
            result += " " + head.ToString();
        }
        return result;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -