zoukankan      html  css  js  c++  java
  • dengluzhucehaiyouxianshiMVC

    --登录
     登录
            /// </summary>
            /// <param name="uid"></param>
            /// <param name="pwd"></param>
            /// <returns></returns>
            public List<Admin> DengLu(string uid,string pwd)
            {
                string sql = $"select * from Admin where UID='{uid}' and PWD='{pwd}' ";
                return DBHelper.GetList<Admin>(sql);
            }
            /// <summary>
            /// 注册
            /// </summary>
            /// <param name="s"></param>
            /// <returns></returns>
            public int ZhuChe(Admin s)
            {
                string sql = $"insert into Admin values('{s.UID}','{s.PWD}')";
                return DBHelper.ExecuteNonQuery(sql);
            }
    -----
    登录视图
    @{
        ViewBag.Title = "Index";
    }
        <div style="align-content:center">
            <h2 style="color:greenyellow">登录</h2>
            <div>
                <table>
                    <tr>
                        <td>账号:</td>
                        <td><input type="text" id="uid" /></td>
                    </tr>
                    <tr>
                        <td>---</td>
                    </tr>
                    <tr>
                        <td></td>
                    </tr>
                    <tr>
                        <td>密码:</td>
                        <td><input type="text" id="pwd" /></td>
                    </tr>
                    <tr>
                        <td>    </td>
                        <td>
                            <input style="
                            <input style="background-color:aqua" type="button" value="注册" onclick="location.href='/DL/ZC'" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    <script>
       
        function DL() {
            var s = {};
            s.uid = $("#uid").val();
            s.pwd = $("#pwd").val();
           
            $.ajax({
                url: 'http://localhost:44391/api/GouWuChe/DengLu/',
                data: s,
                type: 'get',
                dataType: 'json',
                success: function (d) {
                    if (d !="") {
                        alert("登录成功");
                        sessionStorage["name"] = this.uid;
                        location.href = '/Shop/IndexShang';
                       
                       
                    }
                    else {
                        alert("登录失败");
                        return;
                    }
                }
            })
        }
    </script>
    ------------注册视图
    <h2>注册京东账号</h2>
    <div>
        <table>
            <tr>
                <td>账号</td>
                <td><input type="text" id="uid" /></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="text" id="pwd" /></td>
            </tr>
            <tr>
                <td>    </td>
                <td><input type="button" value="提交" onclick="tijiao()" /></td>
            </tr>
        </table>
    </div>
    <script>
        function tijiao() {
            var s = {};
            s.uid = $("#uid").val();
            s.pwd = $("#pwd").val();
            $.ajax({
                url: 'http://localhost:44391/api/GouWuChe/ZhuChe',
                data: s,
                type: 'post',
                dataType: 'json',
                success: function (d) {
                    if (d > 0) {
                        alert("注册成功");
                        location.href = '/DL/Index';
                    }
                    else {
                        alert("注册失败");
                    }
                }
            })
        }
    </script>
     
     
     
     

    显示‘’‘’
    dal层带异常处理
     //获取产品表
            public List<ChanPinModel> GetChanPin()
            {
                try
                {
                    string sql = "select * from ChanPin";
                    return LogHelper.GetShows<ChanPinModel>(sql);
                }
                catch (Exception)
                {
                    throw;
                }
              
            }

            //获取订单表
            public List<DingDanModel> GetDingDan()
            {
                try
                {
                    string sql = "select * from DingDan";
                    return LogHelper.GetShows<DingDanModel>(sql);
                }
                catch (Exception)
                {
                    throw;
                }
            }
    --API的控制器
     Dal dal = new Dal();
            //产品表的获取
            [HttpGet]
            [Route("api/ChanPin")]
            public List<ChanPinModel> GetChanPin()
            {
                return dal.GetChanPin();
            }
            //订单表的获取
            [HttpGet]
            [Route("api/DingDan")]
            public List<DingDanModel> GetDingDan()
            {
                return dal.GetDingDan();
            }
    ------------------------------------视图显示页面
    <script src="~/Scripts/jquery-3.3.1.js"></script>
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <span>产品列表</span>
    <table class="table table-bordered">
        <thead>
            <tr>
                <td>编号</td>
                <td>产品名称</td>
                <td>价格</td>
            </tr>
        </thead>
        <tbody id="Body"></tbody>
    </table>

    <span>订单列表</span>
    <table class="table table-bordered">
        <thead>
            <tr>
                <td>编号</td>
                <td>订单号</td>
                <td>总价</td>
            </tr>
        </thead>
        <tbody id="BodyDan"></tbody>
    </table>
    <script>
        $(function () {
            ShowChanPin();
        })
        function ShowChanPin() {
            $.ajax({
                url: "http://localhost:62506/api/ChanPin",
                DataType: "json",
                type: "get",
                success: function (i) {
                    ShowDingDan();
                    $("#Body").empty();
                    var line;
                    $(i).each(function () {
                        line = '<tr>' +
                            '<td>' + this.Id + '</td>' +
                            '<td>' + this.Name + '</td>' +
                            '<td>' + this.Money + '</td>' +
                            '</tr>';
                        $("#Body").append(line);
                    })
                }
            })
        }
            function ShowDingDan() {
            $.ajax({
                url: "http://localhost:62506/api/DingDan",
                DataType: "json",
                type: "get",
                success: function (i) {
                    $("#BodyDan").empty();
                    var line;
                    $(i).each(function () {
                        line = '<tr>' +
                            '<td>' + this.Id + '</td>' +
                            '<td>' + this.DanHao + '</td>' +
                            '<td>' + this.SumMoney + '</td>' +
                            '</tr>';
                        $("#BodyDan").append(line);
                    })
                }
            })
        }
    </script>
     
     
     
  • 相关阅读:
    Django路由系统
    修改数据库时区问题
    Django框架篇
    前端css
    前端html
    前端初识
    数据库3
    数据库2
    数据库1
    数据库初识
  • 原文地址:https://www.cnblogs.com/gc1229/p/13266815.html
Copyright © 2011-2022 走看看