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

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

1、今日完成任務:
(1)增加使用者資訊

(2)編輯使用者資訊

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; } #GridView1 { text-align: center; } table { width: 800px; border-collapse: collapse; } table tr td { border: 1px solid #000; } .auto-style2 { width: 812px; height: 134px; } .auto-style3 { width: 810px; height: 80px; } #ts { width: 300px; } #ts tr td { border: none; } .auto-style4 { height: 35px; } .btn{ background-color:#FD4C4C; width:80PX; height:30px; color:#fff; } .txt { border: 1px solid #808080; height:20px; } .left { width: 80px; padding-left: 5px; } </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="Select"><i class="iconfont icon-yonghuguanli"></i><span>使用者資訊</span></li> </a> <a href="UserInfo.aspx"> <li class=""><i class="iconfont icon-tubiao_dingdan"></i><span>使用者管理</span></li> </a> <a href="Pwgl.aspx"> <li><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>&nbsp;&nbsp;&nbsp;&nbsp;<span class="span2">新增使用者</span> </div> <!--表修改--> <div class="auto-style1" style="margin-left: 0px; height: 700px;"> <!--查詢到的表格--> <div style="width: 810px; margin-left: 10px;"> <table class="auto-style3" id="ts"> <tr style="background-color: #fe7844; height: 30px; color: #fff; text-align: left;"> <td colspan="2">&nbsp;&nbsp;新增使用者</td> </tr> <tr> <td class="auto-style4 left">使用者名稱: </td> <td class="auto-style4 right"> <asp:TextBox ID="txtUserName" runat="server" CssClass="txt"></asp:TextBox> <td class="auto-style4"> </tr> <tr> <td class="auto-style4 left">密碼: </td> <td class="auto-style4 right"> <asp:TextBox ID="txtPwd" runat="server" CssClass="txt"></asp:TextBox> <td class="auto-style4"> </tr> <tr> <td class="auto-style4 left">身份證號: </td> <td class="auto-style4 right"> <asp:TextBox ID="txtCard" runat="server" CssClass="txt"></asp:TextBox> <td class="auto-style4"> </tr> <tr> <td class="auto-style4 left">真實姓名: </td> <td class="auto-style4 right"> <asp:TextBox ID="txtRealName" runat="server" CssClass="txt"></asp:TextBox> <td class="auto-style4"> </tr> <tr> <td class="auto-style4 left">郵箱: </td> <td class="auto-style4 right"> <asp:TextBox ID="txtEmail" runat="server" CssClass="txt"></asp:TextBox> <td class="auto-style4"> </tr> <tr> <td class="auto-style4 left">電話: </td> <td class="auto-style4 right"> <asp:TextBox ID="txtTel" runat="server" CssClass="txt"></asp:TextBox> <td class="auto-style4"> </tr> <tr> <td class="auto-style4 left">使用者型別: </td> <td class="auto-style4 right"> <asp:RadioButtonList ID="radType" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow"> <asp:ListItem Value="0">普通使用者</asp:ListItem> <asp:ListItem Value="1" Selected="True">管理員</asp:ListItem> </asp:RadioButtonList> <td class="auto-style4"> </tr> <tr style="text-align:center;"> <td colspan="2"> <asp:Button ID="btnShang" runat="server" Text="上一步" CssClass="btn" OnClick="btnShang_Click"/> <asp:Button ID="btnAdd" runat="server" Text="新增" CssClass="btn" OnClick="btnAdd_Click" /> </td> </tr> </table> </div> </div> </div> </div> </div> </form> </body> </html>

(2)增加使用者資訊後臺頁面程式碼

   UserinfoManager bll = new UserinfoManager();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //獲取前臺資料
            string userName = this.txtUserName.Text;
            string pwd = this.txtPwd.Text;
            string card = this.txtCard.Text;
            string realName = this.txtRealName.Text;
            string email = this.txtEmail.Text;
            string tel = this.txtTel.Text;
            int type = Convert.ToInt32(this.radType.SelectedValue);
            bool boo = bll.AddUser(userName, pwd, card, realName, email, tel,type);
            if (boo)
            {
                Response.Write("<script>alert('新增成功!!!')</script>");
                Response.Redirect("UserInfo.aspx");
            }
            else
            {
                Response.Write("<script>alert('新增失敗!!!')</script>");
            }
        }

        protected void btnShang_Click(object sender, EventArgs e)
        {
            Response.Redirect("UserInfo.aspx");
        }
DAL層:
  public bool AddUser(string userName,string pwd,string card,string realName,string email,string tel,int type)
        {
            string sql = $"insert into Userinfo values('{userName}','{pwd}','{card}','{realName}','{email}','{tel}',{type},0)";
            int num = dbHelper.ExecuteNonQuery(sql);
            if (num>0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

(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;
        }

        #GridView1 {
            text-align: center;
        }

        table {
            width: 800px;
            border-collapse: collapse;
        }

            table tr td {
                border: 1px solid #000;
            }

        .auto-style2 {
            width: 812px;
            height: 134px;
        }

        .auto-style3 {
            width: 810px;
            height: 80px;
        }

        #ts {
            width: 300px;
        }

            #ts tr td {
                border: none;
            }

        .auto-style4 {
            height: 35px;
        }
        .btn{
            background-color:#FD4C4C;
            width:80PX;
            height:30px;
            color:#fff;
        }
        .txt {
            border: 1px solid #808080;
            height:20px;
        }

        .left {
            width: 80px;
            padding-left: 5px;
        }
    </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="Select"><i class="iconfont icon-yonghuguanli"></i><span>使用者資訊</span></li>
                    </a>
                    <a href="UserInfo.aspx">
                        <li class=""><i class="iconfont icon-tubiao_dingdan"></i><span>使用者管理</span></li>
                    </a>
                    <a href="Pwgl.aspx">
                        <li><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>&nbsp;&nbsp;&nbsp;&nbsp;<span class="span2">編輯使用者資訊</span>
                    </div>

                    <!--表修改-->
                    <div class="auto-style1" style="margin-left: 0px; height: 700px;">

                        <!--查詢到的表格-->
                        <div style="width: 810px; margin-left: 10px;">
                            <table class="auto-style3" id="ts">
                                <tr style="background-color: #fe7844; height: 30px; color: #fff; text-align: left;">
                                    <td colspan="2">&nbsp;&nbsp;新增使用者</td>
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">使用者名稱:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:TextBox ID="txtUserName" runat="server" CssClass="txt"></asp:TextBox>
                                    <td class="auto-style4">
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">密碼:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:TextBox ID="txtPwd" runat="server" CssClass="txt"></asp:TextBox>
                                    <td class="auto-style4">
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">身份證號:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:TextBox ID="txtCard" runat="server" CssClass="txt"></asp:TextBox>
                                    <td class="auto-style4">
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">真實姓名:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:TextBox ID="txtRealName" runat="server" CssClass="txt"></asp:TextBox>
                                    <td class="auto-style4">
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">郵箱:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:TextBox ID="txtEmail" runat="server" CssClass="txt"></asp:TextBox>
                                    <td class="auto-style4">
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">電話:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:TextBox ID="txtTel" runat="server" CssClass="txt"></asp:TextBox>
                                    <td class="auto-style4">
                                </tr>
                                <tr>
                                    <td class="auto-style4 left">使用者型別:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:RadioButtonList ID="radType" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                                            <asp:ListItem Value="0">普通使用者</asp:ListItem>
                                            <asp:ListItem Value="1">管理員</asp:ListItem>
                                        </asp:RadioButtonList>
                                    <td class="auto-style4">
                                </tr>
                                 <tr>
                                    <td class="auto-style4 left">使用者狀態:
                                    </td>
                                    <td class="auto-style4 right">
                                        <asp:RadioButtonList ID="radMark" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                                            <asp:ListItem Value="0">正常使用者</asp:ListItem>
                                            <asp:ListItem Value="1">無效</asp:ListItem>
                                        </asp:RadioButtonList>
                                    <td class="auto-style4">
                                </tr>
                                <tr style="text-align:center;">
                                    <td colspan="2">
                                        <asp:Button ID="btnShang" runat="server" Text="上一步" CssClass="btn" OnClick="btnShang_Click"/>
                                        <asp:Button ID="btnUpdate" runat="server" Text="確定" CssClass="btn" OnClick="btnUpdate_Click"/>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>
</html>

(3)編輯使用者資訊後臺程式碼

 public partial class UpdateUserinfo : System.Web.UI.Page
    {
        UserinfoManager bll = new UserinfoManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int uid = Convert.ToInt32(Request.QueryString["uid"]);
                DataSet ds = bll.GetDataByUid(uid);
                this.txtUserName.Text = ds.Tables[0].Rows[0]["Uname"].ToString();
                this.txtPwd.Text=ds.Tables[0].Rows[0]["Upwd"].ToString();
                this.txtRealName.Text=ds.Tables[0].Rows[0]["Urealname"].ToString();
                this.txtCard.Text=ds.Tables[0].Rows[0]["Ucard"].ToString();
                this.txtEmail.Text=ds.Tables[0].Rows[0]["Email"].ToString();
                this.txtTel.Text=ds.Tables[0].Rows[0]["Tel"].ToString();
                this.radType.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0]["Utype"]) == 0 ? 0 : 1;
                this.radMark.SelectedIndex = Convert.ToInt32(ds.Tables[0].Rows[0]["Umark"]) == 0 ? 0 : 1;
            }
        }

        protected void btnShang_Click(object sender, EventArgs e)
        {
            Response.Redirect("UserInfo.aspx");
        }
        /// <summary>
        /// 確定修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int uid = Convert.ToInt32(Request.QueryString["uid"]);
            //獲取前臺資料
            string userName = this.txtUserName.Text;
            string pwd = this.txtPwd.Text;
            string card = this.txtCard.Text;
            string realName = this.txtRealName.Text;
            string email = this.txtEmail.Text;
            string tel = this.txtTel.Text;
            int type = Convert.ToInt32(this.radType.SelectedValue);
            int mark = Convert.ToInt32(this.radMark.SelectedValue);
            bool boo = bll.Update(userName, pwd, card, realName, email, tel, type, mark,uid);
            if (boo)
            {
                //成功
                Response.Write("<script>alert('修改成功!!!')</script>");
                Response.Redirect("UserInfo.aspx");
            }
            else
            {
                //失敗
                Response.Write("<script>alert('修改失敗!!!')</script>");
            }
        }
    }
DAL層:
 public DataSet GetDataByUid(int uid)
        {
            string sql = $"select * from Userinfo where Uid={uid}";
            return dbHelper.GetData(sql);
        }
  public bool Update(string userName, string pwd, string card, string realName, string email, string tel, int type,int mark,int uid)
        {
            string sql = $"update Userinfo set Uname='{userName}',Upwd='{pwd}',Ucard='{card}',Urealname='{realName}',Email='{email}',Tel='{tel}',Utype={type},Umark={mark}  where Uid={uid}";
            int num = dbHelper.ExecuteNonQuery(sql);
            if (num > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


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