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

📄 dept_modify.aspx.cs

📁 本套软件适用于各大高校、中小学、幼儿园、培训机构等单位的教学管理软件。
💻 CS
字号:
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.SqlClient;
using jianke;

public partial class  dept_modify : System.Web.UI.Page
{
    protected int LastEditePage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Panel2.Visible = true;
            this.Panel1.Visible = false;
            AllBind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.TextBox1.Text == "")
        {
            Response.Write("<script>alert('搜索内容为空!');</script>");


        }
        else
        {


            this.Panel1.Visible = true;
            this.Panel2.Visible = false;
            SearchBind();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.Panel1.Visible = false;
        this.Panel2.Visible = true;
        AllBind();
    }
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    protected void PageChange(object source, DataGridPageChangedEventArgs e)
    {
        dg2.CurrentPageIndex = e.NewPageIndex;
        AllBind();
        ShowStats();
    }
    private void ShowStats()
    {
        lblCurrentIndex.Text = "第 " + (dg2.CurrentPageIndex + 1).ToString() + " 页";
        lblPageCount.Text = "总共 " + dg2.PageCount.ToString() + " 页";
    }
    public void PagerButtonClick(object sender, EventArgs e)
    {
        string arg = ((LinkButton)sender).CommandArgument.ToString();
        switch (arg)
        {
            case "next":
                if (dg2.CurrentPageIndex < (dg2.PageCount - 1))
                {
                    dg2.CurrentPageIndex += 1;
                }
                break;
            case "prev":
                if (dg2.CurrentPageIndex > 0)
                {
                    dg2.CurrentPageIndex -= 1;
                }
                break;
            case "last":
                dg2.CurrentPageIndex = (dg2.PageCount - 1);
                break;
            default:
                dg2.CurrentPageIndex = System.Convert.ToInt32(arg);
                break;
        }
        AllBind();
        ShowStats();
    }
    public void SearchBind()
    {
        string key = this.TextBox1.Text.Trim();
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();


        SqlDataAdapter da = new SqlDataAdapter("Select * from Dept where dept_name  like '%" + key + "%'  ", Conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        dg1.DataSource = ds;
        dg1.DataBind();
        Conn.Close();

    }
    public void AllBind()
    {

        SqlConnection Conn = DB.creatconnection();
        Conn.Open();


        SqlDataAdapter da = new SqlDataAdapter("Select * from Dept ", Conn); // 绑定到满足条件的 数据上  ?
        DataSet ds = new DataSet();
        da.Fill(ds);
        dg2.DataSource = ds;
        dg2.DataBind();
        Conn.Close();
        ShowStats();

    }



    protected void cancel(object source, DataGridCommandEventArgs e)
    {
        dg1.EditItemIndex = -1;
        SearchBind();
    }
    protected void edit(object source, DataGridCommandEventArgs e)
    {
        dg1.EditItemIndex = (int)e.Item.ItemIndex;
        SearchBind();
    }
    protected void update(object source, DataGridCommandEventArgs e)
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();
        String str = "UPDATE  Dept SET  dept_name='" + ((TextBox)e.Item.Cells[0].Controls[0]).Text + "  where  teacher_id='" + dg1.DataKeys[e.Item.ItemIndex] + "' ";
        SqlCommand com = new SqlCommand(str, Conn);
        com.ExecuteNonQuery();

        Conn.Close();
        SearchBind();
    }
    protected void delete(object source, DataGridCommandEventArgs e)
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();
        String h = "DELETE FROM Dept where  dept_id='" + dg1.DataKeys[e.Item.ItemIndex] + "'";
        SqlCommand activecm = new SqlCommand(h, Conn);
        activecm.ExecuteNonQuery();
        Conn.Close();
        SearchBind();
    }



    //protected void Edit(object source, DataGridCommandEventArgs e)
    //{

    //    dg1.EditItemIndex = (int)e.Item.ItemIndex;
    //    AllBind();

    //}
    //protected void Updata(object source, DataGridCommandEventArgs e)
    //{
    //    SqlConnection con = new SqlConnection("server=.;database=salary_system;uid=sa;pwd=");
    //    con.Open();

    //    String str = "UPDATE  employee_salary SET  employee_name='" + ((TextBox)e.Item.Cells[0].Controls[0]).Text + "',employee_base_salary='" + ((TextBox)e.Item.Cells[3].Controls[0]).Text + "' ,employee_reward='" + ((TextBox)e.Item.Cells[4].Controls[0]).Text + "'  where employee_id='" + dg1.DataKeys[e.Item.ItemIndex] + "' ";
    //    SqlCommand com = new SqlCommand(str, con);
    //    com.ExecuteNonQuery();

    //    con.Close();
    //    AllBind();
    //}


    //protected void Cancel(object source, DataGridCommandEventArgs e)
    //{
    //    dg1.EditItemIndex = -1;
    //    AllBind();
    //}

    protected void cancel1(object source, DataGridCommandEventArgs e)
    {
        dg2.EditItemIndex = -1;
        AllBind();
    }
    protected void edit1(object source, DataGridCommandEventArgs e)
    {
        dg2.EditItemIndex = (int)e.Item.ItemIndex;
        AllBind();
    }
    protected void delete1(object source, DataGridCommandEventArgs e)
    {


        int emqID = (int)dg2.DataKeys[e.Item.ItemIndex];


        SqlConnection Conn = DB.creatconnection();
        Conn.Open();
        String h = "DELETE FROM Dept where  dept_id='" + dg2.DataKeys[e.Item.ItemIndex] + "'";
        SqlCommand activecm = new SqlCommand(h, Conn);
        try
        {
            activecm.ExecuteNonQuery();
            LastEditePage = dg2.CurrentPageIndex;
            if ((dg2.PageCount - dg2.CurrentPageIndex == 1) && dg2.Items.Count == 1)
            {
                if (dg2.PageCount > 1)
                {
                    LastEditePage = LastEditePage - 1;
                }
                else
                {
                    LastEditePage = 0;
                }
            }
            dg2.CurrentPageIndex = LastEditePage;

            AllBind();

        }

        catch (SqlException err)
        {
            Response.Write(err.ToString());
        }
        finally
        {
            Conn.Close();
        }




    }
    protected void update1(object source, DataGridCommandEventArgs e)
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();
        String str = "UPDATE  Dept SET  dept_name='" + ((TextBox)e.Item.Cells[0].Controls[0]).Text + "'  where  dept_id='" + dg2.DataKeys[e.Item.ItemIndex] + "' ";
        SqlCommand com = new SqlCommand(str, Conn);
        com.ExecuteNonQuery();

        Conn.Close();
        AllBind();
    }
}

⌨️ 快捷键说明

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