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

📄 codetable.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;

public partial class admin_Default2 : System.Web.UI.Page
{
    BaseClass bc = new BaseClass();
    protected void Page_Load(object sender, EventArgs e)
    {

        //if (Convert.ToString(Session["UID"]) == "")
        //{
        //    Response.Redirect("login.aspx");

        //}
        if (!IsPostBack)
        {
            bc.ExecDropDownList(para,"select * from type where type='title'","name","typecode");
        }
    }
    protected void bind()
    {
       string type=para.SelectedItem.Value;
       
        string sqlcount="select count(*) from type where type='"+type+"'";
        int count=(int)bc.ExecCscalar(sqlcount);
        Label1.Text="合计共有记录数:"+count.ToString();
        string sql="select id,code,name,(select name from type where type='title' and typecode=a.type) as typename from type a where type='"+type+"' order by code";
        //Response.Write(sql);
        //Response.End();
        bc.ExecGridView(GridView1,sql);

       

    }





    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.bind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.GridView1.EditIndex = e.NewEditIndex;
        this.bind();
    }
    protected void GridView1_RowCanceling(object sender, GridViewCancelEditEventArgs e)
    {
        this.GridView1.EditIndex = -1;
        this.bind();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
         string sql = "update type set name='" + name + "' where id=" + id;
        // Response.Write(sql);
        // Response.End();
         bc.ExecSql(sql);
         this.GridView1.EditIndex = -1;
         this.bind();
       

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sql = "delete type where id=" + id;
       
        if (!bc.ExecSql(sql))
        {
            Response.Write("<script>alert('删除失败,请重试!');</script>");
            return;
        }
        this.bind();

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {



           //   ((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗,删除将不能恢复?')");
             //  e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#22dd22';this.Style.color='buttontext';this.Style.cursor='default';");
           //  e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string type = para.SelectedItem.Value;
        string code = txtcode.Text.Trim();
        string name = txtname.Text.Trim();
        string valsql = "select count(*) from type where code='" + code + "' and type='" + type + "'";
      // Response.Write(valsql);
        //Response.End();
        int count = (int)bc.ExecCscalar(valsql);
        if (count > 0)
        {
            Label2.Visible = true;
            Label2.Text = "代码重复";

        }
        else
        {
            string sql = "insert into type (code,name,type) values('" + code + "','" + name + "','" + type + "')";
            if (bc.ExecSql(sql))
            {
                Response.Write("<script>alert('添加成功');</script>");
                this.bind();

            }
        }

    }
}
       
       

⌨️ 快捷键说明

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