做个CMS吧(一)-站点基本设置

无聊正好有点时间就做个CMS吧。
预计用于个人博客和企业站。
思路有点乱,骑驴看唱本,走着瞧吧。

WebMatrix,Razor+sqlce

先做网站基本配置页面:
预想是这样的:

  • 进入网站,判断是否是第一次运行,也就是说判断网站是否候配置好。
    • 是:直接进入默认页
    • 否:进入Install.cshtml页

这里就有问题了: 我的预想如何实现?请高手指教,谢谢。 我想在_appstart.cshtml页面里面写判断代码,但是这个页面貌似有限制。

基本表设计和Install.cshtml如下:
欢迎斧正·拍砖·讨论
借鉴了MiniCMS

    数据库表SiteSet:
    名称        类型
    sitename    nvarchar(50)
    sitelink    nvarchar(50)
    nickname    nvarchar(50)
    username    nvarchar(50)
    password    nvarchar(50)

Install.cshtml:

@{
    var db = Database.Open("RazorCMS");
    var sqlSle = "Select TOP 1 * From SiteSet";
    var siteSet = db.QuerySingle(sqlSle);

    if(IsPost&&siteSet==null){
        var sitename = Request.Form["sitename"];
        var sitelink = Request.Form["sitelink"];
        var nickname = Request.Form["nickname"];
        var username = Request.Form["username"];
        var password = Request.Form["password"];

        var sqlIns = "insert into siteset (sitename,sitelink,nickname,username,password) values (@0,@1,@2,@3,@4) ";
        var i = db.Execute(sqlIns,sitename,sitelink,nickname,username,password);
        if(i!=0){Response.Redirect("default.cshtml");}
    }
}

<html lang="zh-CN"><head>
<meta charset="UTF-8">
<title>RazorCMS</title>
<style>
* {padding:0;margin:0;font-family:"Microsoft YaHei",Segoe UI,Tahoma,Arial,Verdana,sans-serif;}
html,body { height:100%; }
body { background:#f5f5f5; color:#2d2d2d; font-size:14px; }
#main { position:absolute; left:50%; top:50%; }
#mainbox { background-color: #fff; border: 1px solid #e5e5e5; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .05); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .05); box-shadow: 0 1px 2px rgba(0, 0, 0, .05); padding:20px; margin-bottom:20px; }
.btn { display: inline-block;padding: 4px 12px;margin-bottom: 0;font-size: 15px;line-height: 21px;color: #434848;text-align: center;text-shadow: 0 1px 1px rgba(255,255,255,0.75);vertical-align: middle;cursor: pointer;background-color: #f8f8f8;background-image: -moz-linear-gradient(top,#fff,#eee);background-image: -webkit-gradient(linear,0 0,0 100%,from(#fff),to(#eee));background-image: -webkit-linear-gradient(top,#fff,#eee);background-image: -o-linear-gradient(top,#fff,#eee);background-image: linear-gradient(to bottom,#fff,#eee);background-repeat: repeat-x;border: 1px solid #ccc;border-color: #eee #eee #c8c8c8;border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);border-bottom-color: #b3b3b3;-webkit-border-radius: 4px;-moz-border-radius: 4px;border-radius: 4px;filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffeeeeee',GradientType=0);filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);-moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05); }
.btn-primary { color: #fff;text-shadow: 0 -1px 0 rgba(0,0,0,0.25);background-color: #0aaaf1;background-image: -moz-linear-gradient(top,#11b6ff,#09d);background-image: -webkit-gradient(linear,0 0,0 100%,from(#11b6ff),to(#09d));background-image: -webkit-linear-gradient(top,#11b6ff,#09d);background-image: -o-linear-gradient(top,#11b6ff,#09d);background-image: linear-gradient(to bottom,#11b6ff,#09d);background-repeat: repeat-x;border-color: #09d #09d #006491;border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff11b6ff',endColorstr='#ff0099dd',GradientType=0);filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); }
.btn:hover, .btn:focus {color: #fff;background-color: #09d;text-decoration: none;background-position: 0 -15px;-webkit-transition: background-position .1s linear;-moz-transition: background-position .1s linear;-o-transition: background-position .1s linear;transition: background-position .1s linear; }
label { font-weight:bold; color:#333; font-size:12px; }
.textbox input { border:none; padding:0; font-size:18px; width:312px; color:#333; outline:0; }
.textbox { border:1px solid #e0e0e0; padding:6px; margin:6px 0 20px; border-radius:3px 3px 3px 3px; }
</style>
<script type="text/javascript">
function vMiddle(inner){
    var outer = (inner.parentNode.tagName == 'body') ?  document.documentElement : inner.parentNode;

    var innerHeight = inner.offsetHeight,
        innerWidth = inner.offsetWidth,
        outerHeight = outer.offsetHeight ,
        outerWidth = outer.offsetWidth ;

    (outerHeight > innerHeight) ? (function(){
        inner.style.marginTop = -innerHeight/2 + "px" ;
        inner.style.top = "50%";
    })()
    : (function(){
        inner.style.marginTop = 0;
        inner.style.top = 0;
    })();

    (outerWidth > innerWidth) ?  (function(){
        inner.style.marginLeft = -innerWidth/2 + "px" ;
        inner.style.left = "50%";
    })()
    : (function(){
        inner.style.marginLeft = 0;
        inner.style.left = 0;
    })();
}

window.onload = window.onresize = function(){
    vMiddle(document.getElementById("main"));
}
</script>
</head>
<body style="background:#f2f2f2;">
  <div id="main" style="margin-top: -322px; top: 50%; margin-left: -184px; left: 50%;">
    <div style="font-size:32px;font-weight:bold;text-align:center;padding-top:40px;">RazorCMS安装程序</div>
    <div style="font-size:13px;color:#888;text-align:center;padding:10px 0 20px;">v1.0</div>
    <div id="mainbox">@{
            if(!IsPost&&siteSet==null){
                <form method="post" action="/install.cshtml" id="869548056">
      <label>网站标题</label>
      <div class="textbox"><input type="text" name="sitename" value="我的网站"></div>
      <label>网站地址</label>
      <div class="textbox"><input type="text" name="sitelink" id="sitelink" value=""></div>
      <script type="text/javascript">
      document.getElementById('sitelink').value = location.href.substring(0, location.href.lastIndexOf('/'));
      </script>
      <label>您的昵称</label>
      <div class="textbox"><input type="text" name="nickname" value="神秘人"></div>
      <label>后台账号</label>
      <div class="textbox"><input type="text" name="username" value="admin"></div>
      <label>后台密码</label>
      <div class="textbox"><input type="text" name="password" value="123456"></div>
      <div style="text-align:center;"><input type="submit" name="start_install" value="开始安装" class="btn btn-primary"></div>

    </form>
            }
            else{  
                <label>网站貌似已创建,请不要重复运行此页面,如创建成功请删除Install.cshtml文件</label>
            }}

    </div>
  </div>

</body></html>
View Code

 

欢迎讨论
posted @ 2014-04-17 11:52  cgfun  阅读(242)  评论(0编辑  收藏  举报