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

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

//该源码下载自www.51aspx.com(51aspx.com)

namespace NETManage.Web.Admin
{
    public partial class Default : PageBase//System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IsLogin();
            if (!Page.IsPostBack)
            {
                NETManage.BLL.OnlinePC pcbll = new NETManage.BLL.OnlinePC();
                DataSet ds = pcbll.GetList("1=1 ORDER BY [IP]");
                ViewState["ds"] = ds;
                GVBind();
            }
        }


        protected void GVBind()
        {
            DataSet ds = (DataSet)ViewState["ds"];
            GV_OnlinPC.DataSource = ds;
            GV_OnlinPC.DataKeyNames = new string[] { "MAC" };
            GV_OnlinPC.DataBind();
            int count = GV_OnlinPC.Rows.Count;
            for (int i = 0; i < count; i++)
            {
                if (GV_OnlinPC.Rows[i].Cells[4].Text == "待绑定")
                {
                    GV_OnlinPC.Rows[i].ForeColor = System.Drawing.Color.BlueViolet;
                }
                else if (GV_OnlinPC.Rows[i].Cells[4].Text == "关闭")
                {
                    GV_OnlinPC.Rows[i].ForeColor = System.Drawing.Color.Red;
                }
            }
        }

        protected void Button_Search_Click(object sender, EventArgs e)
        {
            string search_mode = this.search_mode.Value;
            string Key = this.Key.Text;
            string search = string.Empty;
            switch (search_mode)
            {
                case "MAC":
                    search = "MAC";
                    break;
                case "IP":
                    search = "IP";
                    break;
                case "房间号":
                    search = "RoomNum";
                    break;
            }
            if (Key.Length == 0)
            {
                NETManage.BLL.OnlinePC pcbll = new NETManage.BLL.OnlinePC();
                DataSet ds = pcbll.GetList("1=1 ORDER BY [" + search + "]");
                ViewState["ds"] = ds;
            }
            else
            {
                NETManage.BLL.OnlinePC pcbll = new NETManage.BLL.OnlinePC();
                DataSet ds = pcbll.GetList("[" + search + "] LIKE '%" + Key + "%' ORDER BY [" + search + "]");
                ViewState["ds"] = ds;
            }
            GVBind();
        }

        protected void Button_Add_Click(object sender, EventArgs e)
        {
            Response.Redirect("EditOnlinePC.aspx");
        }

        protected void GV_OnlinPC_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView theGrid = sender as GridView;  // refer to the GridView
            int newPageIndex = 0;

            if (-2 == e.NewPageIndex)
            { // when click the "GO" Button
                TextBox txtNewPageIndex = null;
                //GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
                GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow

                if (null != pagerRow)
                {
                    txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   // refer to the TextBox with the NewPageIndex value
                }

                if (null != txtNewPageIndex)
                {
                    newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
                }
            }
            else
            {  // when click the first, last, previous and next Button
                newPageIndex = e.NewPageIndex;
            }

            // check to prevent form the NewPageIndex out of the range
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
            theGrid.PageIndex = newPageIndex;

            GVBind();
        }

        protected void Button_Edit_Click(object sender, EventArgs e)
        {
            string MAC = string.Empty;
            try
            {
                MAC = this.GV_OnlinPC.SelectedDataKey.Value.ToString();
            }
            catch
            {
                MsgBox("请先选择要操作的记录!");
            }

            if (MAC != null && MAC.Length > 0)
            {
                Server.Transfer("EditOnlinePC.aspx?MAC=" + MAC);
            }
            else
            {
                MsgBox("请先选择要操作的记录!");
            }
        }

        protected void Button_DEL_Click(object sender, EventArgs e)
        {
            string MAC = string.Empty;
            try
            {
                MAC = this.GV_OnlinPC.SelectedDataKey.Value.ToString();
            }
            catch
            {
                MsgBox("请先选择要操作的记录!");
            }

            if (MAC != null && MAC.Length > 0)
            {
                NETManage.BLL.OnlinePC pcbll = new NETManage.BLL.OnlinePC();
                try
                {
                    pcbll.Delete(MAC);
                    Response.Redirect("Default.aspx");
                }
                catch(Exception ee)
                {
                    MsgBox("删除失败!"+ee.Message);
                }
            }
            else
            {
                MsgBox("请先选择要操作的记录!");
            }
        }

        protected void Button_M_Click(object sender, EventArgs e)
        {
            Response.Redirect("Manager.aspx");
        }

        protected void Button_Logout_Click(object sender, EventArgs e)
        {
            Response.Redirect("logout.aspx");
        }

        protected void Button_R_Click(object sender, EventArgs e)
        {
            NETManage.BLL.OnlinePC pcbll = new NETManage.BLL.OnlinePC();
            DataSet ds = pcbll.GetList("1=1 ORDER BY [RoomNum]");
            ViewState["ds"] = ds;
            GVBind();
        }
    }
}

⌨️ 快捷键说明

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