1. 程式人生 > 實用技巧 >客車網上售票系統(分解七)

客車網上售票系統(分解七)

1、今日完成任務:
(1)使用者管理頁面顯示所有使用者資訊

(2)根據使用者輸入的查詢條件顯示滿足條件的使用者資訊

(3)刪除使用者資訊

2、核心原始碼:

(1)使用者管理頁面顯示所有使用者資訊前臺效果

(2)使用者管理頁面顯示所有使用者資訊前臺程式碼

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0
"> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <link href="../css/reset.css" rel="stylesheet" /> <link href="../css/iconfont.css" rel="stylesheet" /> <link href="../css/aa.css" rel="stylesheet" /> <script src="../js/jquery-1.9.1.min.js"></script> <script src="
../js/f.js"></script> <script src="../js/laydate/laydate.js"></script> <script> //執行一個laydate例項 laydate.render({ elem: '#test1' //指定元素 }); </script> <style type="text/css"> .icon-weibiaoti1:before { content:
"\e695"; } .icon-xinxiliulan:before { content: "\e614"; } #test1 { clear: both; border: 1px solid #ccc; height: 25px; position: relative; left: 50px; bottom: 20px; } .InputDiv { border: none; } #txtCfd, #txtMdd { border: 1px solid #ccc; height: 25px; } #btnSelect { color: #fff; } .auto-style1 { background: #fff; margin-left: 40px; } .headboxtext { height: 30px; line-height: 30px; } #Label1 { font-size: 20px; } #GridView1 { text-align: center; } .btn { color: #fff; background-color: #FD4C4C; width: 90PX; height: 30px; } #txtRealName{ line-height:30px; } </style> <title>使用者管理</title> </head> <body> <form id="form1" runat="server"> <div class="PublicHead clearfix"> <div class="leftBox clearfix"> <!--<div class="companyLogo"> <img src="images/logo.jpg" /> </div>--> <!--<i class="iconfont icon-caidan"></i>--> <div class="companyText"> 客車網上售票系統 </div> </div> <div class="RightBox clearfix"> <div class="UserPhotoBox"> <div class="UserPic"> <img src="../Images/user.jpg" /> </div> <div class="UserName"> 使用者 </div> </div> <a href="Login.aspx"> <div class="dropOutBox"> <i class="iconfont icon-app_icons--"></i> <span>退出</span> </div> </a> </div> </div> <div class="PublicDownWhole clearfix"> <!--左側--> <div class="leftBox"> <ul> <a href="UpdateAdminInfo.aspx"> <li class=""><i class="iconfont icon-yonghuguanli"></i><span>使用者資訊</span></li> </a> <a href="UserInfo.aspx"> <li class="Select"><i class="iconfont icon-tubiao_dingdan"></i><span>使用者管理</span></li> </a> <a href="Pwgl.aspx"> <li class=""><i class="iconfont icon-fenlei"></i><span>票務管理</span></li> </a> </ul> </div> <!--右側--> <div class="RightBox"> <div class="PublicContentBox"> <!--公用指向頁面名字--> <div class="PublicPointToAgeText"> <span class="span1">客車網上售票系統 </span><span class="span2">使用者管理</span> </div> <!--查詢--> <div class="InquireBox clearfix"> <div class="InquireleftBox"> <div class="Text">真實姓名:</div> <div class="InputDiv"> <asp:TextBox ID="txtRealName" runat="server"></asp:TextBox></div> </div> <div class="InquireleftBox"> <div class="Text">使用者狀態:</div> <div class="InputDiv" style="border-style:none;margin-top:2px;" > <asp:RadioButtonList ID="radType" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Value="0">普通使用者</asp:ListItem> <asp:ListItem Value="1">管理員</asp:ListItem> <asp:ListItem Value="2" Selected="True">全部</asp:ListItem> </asp:RadioButtonList> </div> </div> <div class="InquireleftBox"> <div class="Text">使用者型別:</div> <div class="InputDiv" style="border-style:none;margin-top:2px;"> <asp:RadioButtonList ID="radMark" runat="server" RepeatDirection="Horizontal" CellPadding="5" CellSpacing="1" BorderStyle="None"> <asp:ListItem Value="0">正常使用者</asp:ListItem> <asp:ListItem Value="1">無效使用者</asp:ListItem> <asp:ListItem Value="2" Selected="True">全部</asp:ListItem> </asp:RadioButtonList> </div> </div> <div class="PublicBtnIcon Color1Btn fr" style="margin-right:550px;"> <asp:Button ID="Button1" runat="server" Text="新增" Style="width: 48px;color:#fff;" OnClick="Button1_Click" /> </div> <div class="PublicBtnIcon Color1Btn fr" > <i class="iconfont icon-icon-chaxun"></i> <%--<span>查詢</span>--%> <asp:Button ID="btnSelect" runat="server" Text="查詢" Style="width: 38px" OnClick="btnSelect_Click" /> </div> </div> <!--表修改--> <div class="auto-style1" style="margin-left: 0px; height: 700px;"> <div class="headbox"> <div class="headboxtext"> <%--<span class="span1">車票查詢</span>--%> <asp:Label ID="lblSelect" runat="server" Text="使用者資訊:"></asp:Label> </div> </div> <div id="content"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderWidth="1px" CellPadding="4" Height="139px" Width="796px" DataKeyNames="Uid" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"> <Columns> <asp:BoundField DataField="Uid" HeaderText="使用者編號" /> <asp:BoundField DataField="Uname" HeaderText="使用者名稱" /> <asp:BoundField DataField="Upwd" HeaderText="密碼" /> <asp:BoundField DataField="Urealname" HeaderText="真實姓名" /> <asp:BoundField DataField="Email" HeaderText="郵箱" /> <asp:BoundField DataField="Tel" HeaderText="電話" /> <asp:TemplateField HeaderText="身份型別"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%#(int)Eval("Utype")==0?"普通使用者":"管理員" %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="使用者狀態"> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%#(int)Eval("Umark")==0?"正常":"無效" %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="操作"> <ItemTemplate> <asp:Button ID="Button2" runat="server" Text="刪除" OnClientClick="return confirm('確定要刪除嗎?')" CommandName="delete" /> <asp:Button ID="Button3" runat="server" Text="編輯" CommandName="edit"/> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> <HeaderStyle BackColor="#fe7844" Font-Bold="True" ForeColor="#FFFFCC" /> <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> <RowStyle BackColor="White" ForeColor="#330099" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> <SortedAscendingCellStyle BackColor="#FEFCEB" /> <SortedAscendingHeaderStyle BackColor="#AF0101" /> <SortedDescendingCellStyle BackColor="#F6F0C0" /> <SortedDescendingHeaderStyle BackColor="#7E0000" /> </asp:GridView> </div> </div> </div> </div> </div> </form> </body> </html>

(3)使用者管理頁面顯示所有使用者資訊後臺程式碼

 UserinfoManager bll = new UserinfoManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGv();
            }
        }
        protected void BindGv()
        {
            this.GridView1.DataSource = bll.GetAll();
            this.GridView1.DataBind();
        }
DAL層: 
public DataSet GetAll()
        {
            string sql = "select * from Userinfo";
            return dbHelper.GetData(sql);
        }

(1)根據使用者輸入的查詢條件顯示滿足條件的使用者資訊前臺效果圖

(2)根據使用者輸入的查詢條件顯示滿足條件的使用者資訊後臺程式碼

 /// <summary>
        /// 查詢
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            string realName = this.txtRealName.Text;
            int type = Convert.ToInt32(this.radType.SelectedValue);
            int mark = Convert.ToInt32(this.radMark.SelectedValue);
            this.GridView1.DataSource = bll.GetDataByInfo(realName, type, mark);
            this.GridView1.DataBind();
        }
DAL層:
  public DataSet GetDataByInfo(string realName,int type,int mark)
        {
            string sql = "select * from Userinfo where 1=1 ";
            if (realName!="")
            {
                sql += $"and Urealname like'%{realName}%'";
            }
            if (type!=2)
            {
                sql += $"and Utype={type}";
            }
            if (mark!=2)
            {
                sql += $"and Umark={mark}";
            }
            DataSet ds = dbHelper.GetData(sql);
            return ds;
        }

(1)刪除使用者資訊前臺效果圖

(2)刪除使用者資訊後臺程式碼

 /// <summary>
        /// 刪除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //獲取Uid
            int uid = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
            bool boo = bll.Delete(uid);
            if (boo)
            {
                //刪除成功
                Response.Write("<script>alert('刪除成功!!!')</script>");
                BindGv();
            }
            else
            {
                Response.Write("<script>alert('刪除失敗!!!')</script>");
            }
        }
 DAL層:
  public bool Delete(int uid)
        {
            string sql = $"delete from Userinfo where Uid={uid}";
            int num = dbHelper.ExecuteNonQuery(sql);
            if (num > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


3、遇到的問題:
(1)很多想實現的效果因為能力有限沒辦法實現,需要前端技術
4、解決的方法:
(1)技術能力方面需要利用這個暑假做提升