Ejemplo n.º 1
0
    //提交专业
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlDataReader read = db.ExceRead("select * from Major where Name='" + this.TextBox1.Text + "'");

        read.Read();
        if (read.HasRows)
        {
            if (this.TextBox1.Text == read["Name"].ToString())
            {
                Response.Write("<script>alert('该专业已存在!')</script>");
                Response.Write("<script>window.location.href='Major_add.aspx'</script>");
            }
        }
        else if (TextBox1.Text == "")
        {
            Response.Write("<script>alert('请填写完整信息!')</script>");
            Response.Write("<script>window.location.href='Major_add.aspx'</script>");
        }
        else
        {
            db.eccom("insert into Major(Name) values ('" + this.TextBox1.Text + "')");
            Response.Write("<script>alert('添加成功!')</script>");
            Response.Write("<script>window.location.href='Major_add.aspx'</script>");
        }
        read.Close();
    }
Ejemplo n.º 2
0
    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        SqlDataReader read = db.ExceRead("select *from Teacher where id='" + this.TextBox1.Text + "'");

        read.Read();
        if (read.HasRows)
        {
            if (this.TextBox1.Text == read["id"].ToString())
            {
                Response.Write("<script>alert('该用户已存在!')</script>");
                Response.Write("<script>window.location.href='Teacher_add.aspx'</script>");
            }
        }
        else if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "")
        {
            Response.Write("<script>alert('请填写完整信息!')</script>");
            Response.Write("<script>window.location.href='Teacher_add.aspx'</script>");
        }
        else
        {
            db.eccom("insert into Teacher(id,name,pwd,JoinTime,degree) values ('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "' ,'" + DateTime.Now.ToString() + "','" + DropDownList1.SelectedItem + "')");

            Response.Write("<script>alert('添加成功!')</script>");
            Response.Write("<script>window.location.href='Teacher_add.aspx'</script>");
        }
        read.Close();
    }
Ejemplo n.º 3
0
    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        SqlDataReader read = db.ExceRead("select * from Admin where ID='" + this.TextBox1.Text + "'");

        read.Read();
        if (read.HasRows)
        {
            if (this.TextBox1.Text == read["ID"].ToString())
            {
                Response.Write("<script>alert('该用户已存在!')</script>");
                Response.Write("<script>window.location.href='admin_add.aspx'</script>");
            }
        }
        else if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "")
        {
            Response.Write("<script>alert('请填写完整信息!')</script>");
            Response.Write("<script>window.location.href='admin_add.aspx'</script>");
        }
        else
        {
            db.eccom("insert into Admin(ID,Name,PWD,JoinTime) values ('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "' ,'" + DateTime.Now.ToString() + "')");

            Response.Write("<script>alert('添加成功!')</script>");
            Response.Write("<script>window.location.href='admin_add.aspx'</script>");
        }
        read.Close();
    }
Ejemplo n.º 4
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     Label8.Visible = false;
     Label7.Visible = false;
     if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "")
     {
         Label8.Visible = true;
     }
     else
     {
         MySqlDataReader read = dataconn.ExceRead("select max(store_id) from store");
         read.Read();
         int a, c;
         c = int.Parse(TextBox2.Text);
         bool b;
         a = (int)read["max(store_id)"];
         b = dataconn.eccom("insert into store(store_id,street,postcode,name,c_id)values("
                            + (a + 1) + ",'" + this.TextBox1.Text + "',"
                            + c + ",'" + this.TextBox3.Text + "','"
                            + DropDownList2.SelectedValue + "')");
         if (b)
         {
             Label7.Visible = true;
         }
         Label7.Text = "Successful! The store ID is:" + (a + 1);
     }
 }
Ejemplo n.º 5
0
    //检测账号是否存在按钮
    protected void Button1_Click1(object sender, EventArgs e)
    {
        SqlDataReader read = dataconn.ExceRead("select * from tb_Student where ID='" + this.txtStuID.Text + "'");

        read.Read();
        if (read.HasRows)
        {
            if (this.txtStuID.Text == read["ID"].ToString())
            {
                Label2.Visible = true;
            }
        }
        else
        {
            Label3.Visible = true;
        }
        read.Close();
    }
Ejemplo n.º 6
0
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        SqlDataReader read = db.ExceRead("select * from Course where c_name='" + this.TextBox2.Text + "'");

        read.Read();
        if (read.HasRows)
        {
            if (this.TextBox2.Text == read["c_name"].ToString())
            {
                Response.Write("<script>alert('该用户已存在!')</script>");
                Response.Write("<script>window.location.href='AddCourse.aspx'</script>");
            }
        }
        else
        {
            db.eccom("insert into Course(c_name,c_date,teacher_id) values ('" + this.TextBox2.Text + "','" + DateTime.Now.ToString() + "','" + Session["ID"].ToString() + "')");
            Response.Write("<script>alert('添加成功!')</script>");
            Response.Write("<script>window.location.href='AddCourse.aspx'</script>");
        }
        read.Close();
    }
Ejemplo n.º 7
0
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        SqlDataReader read = dataconn.ExceRead("select *from Student where ID='" + this.txtStuID.Text + "'");

        read.Read();
        if (read.HasRows)
        {
            if (this.txtStuID.Text == read["ID"].ToString())
            {
                Response.Write("<script>alert('该用户已存在!')</script>");
                Response.Write("<script>window.location.href='AddStudent.aspx'</script>");
            }
        }
        else
        {
            dataconn.eccom("insert into Student(ID,Name,PWD,Sex,JoinTime,Question,Answer,profession) values ('" + this.txtStuID.Text + "','" + this.txtStuName.Text + "','" + this.txtStuPwd.Text + "' ,'" + Request["DropDownList1"] + "','" + DateTime.Now.ToString() + "','" + Request["DropDownList3"] + "','" + this.txtAnsPwd.Text + "','" + Request["ddlProfession"] + "')");
            Session["ID"]  = txtStuID.Text;
            Session["PWD"] = txtStuPwd.Text;
            Response.Write("<script>alert('添加成功!')</script>");
            Response.Write("<script>window.location.href='AddStudent.aspx'</script>");
        }
        read.Close();
    }
Ejemplo n.º 8
0
    //导入
    protected void Button1_Click(object sender, EventArgs e)
    {
        int A = 0;//导入成功数

        string cunzai = "";

        try
        {
            string fileName1 = fileName;
            //根据路径打开一个Excel文件并将数据填充到DataSet中
            //string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", excelFilePath);
            string          strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " + fileName1 + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//导入时包含Excel中的第一行数据,并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn    = new OleDbConnection(strConn);
            conn.Open();
            string           strExcel = "select  * from   [sheet1$]";
            OleDbDataAdapter comm     = new OleDbDataAdapter(strExcel, strConn);
            DataSet          ds       = new DataSet();


            for (int i = 1; i < GridView1.Rows.Count; i++)
            {
                try
                {
                    SqlDataReader read = db.ExceRead("select * from Admin where ID='" + GridView1.Rows[i].Cells[0].Text.ToString() + "'");
                    read.Read();
                    if (read.HasRows)
                    {
                        if (GridView1.Rows[i].Cells[0].Text.ToString() == read["ID"].ToString())
                        {
                            //Response.Write("<script>alert('" + "ID:" + GridView1.Rows[i].Cells[0].Text.ToString() + "已存在!')</script>");
                            cunzai += GridView1.Rows[i].Cells[0].Text.ToString() + "、";
                        }
                    }
                    else if (GridView1.Rows[i].Cells[0].Text.ToString() == "" || GridView1.Rows[i].Cells[1].Text.ToString() == "" || GridView1.Rows[i].Cells[2].Text.ToString() == "")
                    {
                        Response.Write("<script>alert('" + "ID:" + GridView1.Rows[i].Cells[0].Text.ToString() + "信息不完整!" + "')</script>");
                    }
                    else
                    {
                        db.eccom("insert into Admin(ID,Name,PWD,JoinTime) values ('" + GridView1.Rows[i].Cells[0].Text.ToString() + "','" + GridView1.Rows[i].Cells[1].Text.ToString() + "','" + GridView1.Rows[i].Cells[2].Text.ToString() + "' ,'" + DateTime.Now.ToString() + "')");
                        A++;//导入成功
                    }
                }
                catch (Exception) {
                    Response.Write("<script>alert('" + "ID:" + GridView1.Rows[i].Cells[0].Text.ToString() + "  失败!" + "');</script>");
                }
            }


            conn.Close();
        }
        catch
        {
            Response.Write("<script>alert('失败');</script>");
        }


        Response.Write("<script>alert('成功导入:" + A + " 失败:" + (GridView1.Rows.Count - A - 1) + "');</script>");
        if (cunzai.Length > 1)
        {
            Response.Write("<script>alert('添加失败 ID:" + cunzai.Substring(0, cunzai.Length - 1) + "');</script>");
        }
        //删除导入文件
        DeleteFile(fileName);
    }