zoukankan      html  css  js  c++  java
  • Moon.Orm在MVC3中应用

    配置文件(注意修改 AUTO_COMPLIE_DIRECTORY_PATH 的值为 实际项目的bin路径)

    <configuration>
      
        <appSettings>
            <add key="AUTO_COMPLIE_DIRECTORY_PATH" value="E:\Documents and Settings\aa\My Documents\SharpDevelop Projects\Razor.Moon\Razor.Moon\bin\" />
            <add key="dbType" value="MSSQL" />
            <add key="linkString" value="Server=aa-E15014A6665\SQLEXPRESS;Database=MyNorthwind;uid=sa;Password=123456;" />
        </appSettings>
       
    </configuration>

    数据库

    代码

    /*
     * 由SharpDevelop创建。
     
     * 日期: 2013-4-20
     * 时间: 9:23
     * 
     * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
     */
    using System;
    using System.Web.Mvc;
    using mynorthdb;
    using Moon.Orm;
    
    namespace Razor.Moon.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                string sql="select OrderDate,Finished from Orders";
                var list=DBFactory.GetAutoEntities(sql,"CustomersLeftJoinOrders");
                return View(list);
            }
            
            public ActionResult Contact()
            {
                Customers data=DBFactory.GetEntity<Customers>(CustomersTable.CustomerID.Equal(1));
                return View(data);
            }
            void ReturnTextString(Object data)
            {
                Response.StatusCode=200;
                Response.ContentType = "text/plain";
                Response.Write(data);
                Response.End();
            }
            [HttpPost]
            public void Contact(Customers cus)
            {
                cus.SetOnlyMark(CustomersTable.CustomerID.Equal(cus.CustomerID));
                DBFactory.Update(cus);
                ReturnTextString(1);
            }
        }
    }

    前端代码

    Contact

    @model Customers
    @{
        ViewBag.Title = "Contact";
         
    }
    <script>
        $(function(){
            $("#sub").click(function(){
                var data=$("#form1").serialize();
                $.post("@Url.Action("Contact","Home")",data,function(data){
                    alert("修改成功");
                });
            });
        });
    </script>
    <h2>数据更新</h2>
    @using (Html.BeginForm("Contact","Home",FormMethod.Post,new{@id="form1"}))
    {
     <table>
      <tr><td>CustomerID:</td><td>@Html.TextBoxFor(m=>m.CustomerID)</td></tr>
    <tr><td>用户名:</td><td>@Html.TextBoxFor(m=>m.CustomerName)</td></tr>
     <tr><td>用户地址</td><td>@Html.TextBoxFor(m=>m.Address)</td></tr>
     <tr> <td><input type="button" id="sub" value="submit" /></td></tr>
    </table>
    }

    Index

    @model dynamic
    @{
        ViewBag.Title = "Home";
        
    }
    
    
    <h2>Home</h2>
    <table>
    
    @foreach(var a in Model){
    <tr><td>@a.OrderDate</td><td>@a.Finished</td></tr>
    }
    </table>

    项目及数据库备份文件下载.

    点此下载

  • 相关阅读:
    Project Euler Problem 26-Reciprocal cycles
    Project Euler Problem 24-Lexicographic permutations
    Project Euler Problem 23-Non-abundant sums
    AtCoder Beginner Contest 077 D Small Multiple(最短路)
    浮点数表示及其实现
    ACM water
    Makefile经典教程(掌握这些足够)
    Linux makefile 教程 非常详细,且易懂
    C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏
    自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/humble/p/3076143.html
Copyright © 2011-2022 走看看