posts - 6,  comments - 9,  trackbacks - 0
摘要: jq 瀑布式布局阅读全文
posted @ 2011-12-30 12:08 誓言 阅读(403) 评论(0) 编辑
 

关于插件:

一个基于jQuery的弹出层。最新版本2.7;
支持拖拽,支持多窗口。内容为文字,ID,图片,SWF,URL,框架;
这个插件前前后后修改了几个月了。一直在改进;到现在差不多了。以后不会经常更新了;

 

这个插件迄今为止是我看到不说最好的插件.弹出层会随着滚动条滚动而没有任何跳动

 

 以下附上截图

 

 

 这个能看出来各种弹出层的位置

 

 

 

 

 

 

 

摘自  http://leotheme.cn/wp-content/uploads/Example/js/tipswindow/index.html   此地址付下载地址/+实例  

  

posted @ 2011-12-29 17:02 誓言 阅读(118) 评论(0) 编辑
跨域:
为js同源策略的限制,a.com 域名下的js脚本无法操作b.com或是c.a.com域名下的对象。  

 ajax的应用中,由于安全的问题,浏览器默认是不支持js跨域调用的。  

1.主域相同,子域不同,如xxx.aaa.com和yyy.aaa.com  

2.域名相同,端口不同,如xxx.aaa.com:8000和xxx.aaa.com  

3.域名相同,协议不同,如http://www.aaa.com/和https://www.aaa.com/  

4.主机相同,用ip和域名的,http://127.0.0.1/和http://localhost/  

都是会造成跨域的。

 

 

 使用jq的getJSON实现跨域实例

 

 

例如:http://localhost:5540/test/aaa.aspx 调用 http://localhost:3956/text/AJAX.aspx里面的json

 

 

/*http://localhost:5540/test/aaa.aspx*/ 

 <script type="text/javascript">

    $("#images").click(function () {
        var url = "http://localhost:3956/text/AJAX.aspx?callback=?";
       
        $.getJSON(url, function (aa) {
            alert(aa.my_tags);
        
        })
    });
</script>

 

 

 http://localhost:3956/text/AJAX.aspx

 cs页面中

 public string cb;

cb = Context.Request["callback"];

  

 aspx页面显示

 <%=cb%>({"my_tags":["美国","成长","魔幻","奇幻","青春","动作","惊悚","内地","悬疑","动画","3D"],"html":"my html","interest_status":"","popular_tags":["美国","爱情","喜剧","同意翻译成炮友","2011","轻喜剧","搞笑","浪漫","生活","剧情"],"tags":[]})  

 

以前不知道直接在aspx页面显示{"my_tags":["美国"]["青春"]["动作"]["惊悚"]}

导致出各种错误 抱 以下错误

 

不知道原因.. 现在知道了...记住所犯之错..加以谨记...

 

原来这个方式的跨域是jsonp跨域..

 

jsonp是先构造一个方法 比如 fun12321312 这个方法会调用你之前写好的回调函数, 把跨域的url 和这个方法名 以 <script src="{你的url}?callback=fun123">方式添加到head中,浏览器是允许这种方式加载js的 加载完成后就调用fun12321312 ()参数就是你原来的json,就达到了返回json一样的效果

 

 此文只是用于记住所犯之错.代码居多..

 

 

 

 

posted @ 2011-12-28 17:05 誓言 阅读(61) 评论(0) 编辑

今天看了看工厂模式把他们整理了一下,下面是我整理好的。

下面就由我介绍一下如何使用工厂模式

 win7 操作系统    vs2008

数据库: zhihuigu

表名:uinfo

字段:id int primary key identity(1,1),
   uname varchar(10),
   pwd varchar(30),

1,创建网站

2,创建Model层,BLL层,IDAL层,Factory层,AccessDAL层,DButility层,SQlServerDAL层

3,准备工作完毕,下面开始写代码

三层架构不会的请看【浅谈】<.net>三层架构,因为这和三层架构还有关系

写的不是很严谨,有什么不对的地方 还希望你们多多赐教。

Model层

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
/// <summary>
/// 用户信息
/// </summary>
public class UserInfo
{
/// <summary>
/// 用户id
/// </summary>
private int id;

public int Id
{
get { return id; }
set { id = value; }
}
/// <summary>
/// 用户名称
/// </summary>
private string uname;

public string Uname
{
get { return uname; }
set { uname = value; }
}
/// <summary>
/// 用户密码
/// </summary>
private string pwd;

public string Pwd
{
get { return pwd; }
set { pwd = value; }
}
}
}

IDAL层:引用Model层

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace IDAL
{
    public interface IUser
//定义接口
    {
        Boolean IsLogin(UserInfo info);
    }
}

Factory层:引用IDAL,SQlServerDAL,AccessDAL,System.configuration,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using System.Configuration;
using System.Reflection;
using SQLServerDAL;

//此处要引用System.Configuration  Factory下面的--> 右击引用-->添加引用-->.net-->System.Configuration-->确定  最后在此页面添加命名空间
namespace Factory   
{
    public class DataAccessFactory  
    {
        private static string path = ConfigurationManager.AppSettings["WebDAL"].ToString();
        
        //此处得到配置文件里面的<AppSettings/>
        //将其改为<AppSettings></AppSettings>
        //添加数据
        //(
    //    <appSettings>
    //    <add key="WebDAL" value="SQLServerDAL"/>
    //    </appSettings>
       // )
        //其中的value值是如果你想用sql数据库 就用SQlServerDAL(此处和你添加的类库名称相同)
        //
        public static IUser CreateUser()
        {
            string className = path + ".User";
            return (IUser)Assembly.Load(path).CreateInstance(className);

        }
        //如果还想写一些别的话可以再重新创建一个按照以下格式当然也可以自己写

        //public static IBlog CreateBlog()
        //{
        //    string className = path + ".Blog";
        //    return (IBlog)Assembly.Load(path).CreateInstance(className);
        //}
    }
}

DButility层:引用SQLHelper

BLL层:引用Factory,Model,IDAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using Model;
using Factory;

namespace BLL
{
    public class User
    {
        IUser user = DataAccessFactory.CreateUser();
        public Boolean IsLogin(UserInfo info)
        {
            return user.IsLogin(info);
            
        }
    }
}

AccessDAL层 引用DButility,Model,IDAL,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using Model;
using DBUtility;
using System.Data.OleDb;


namespace AccessDAL
{
    public class User:IUser//此处实现接口
    {
        /// <summary>
        /// 得到access的数据连接对象
        /// </summary>
        /// <returns></returns>
        public OleDbConnection GetConn()
        {
            OleDbConnection conn = new OleDbConnection();
            //此处为连接对象
            conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\2010-12-22上午\web\App_Data\zhihuigu.mdb;Persist Security Info=False";
            conn.Open();
            return conn;
        }
    
            #region IUser 成员
        /// <summary>
        /// 数据库中是否有此人的信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns>有还是没</returns>
            public bool  IsLogin(UserInfo info)
            {
                OleDbConnection conn = GetConn();
                string sql = "select count(*) from uinfo where uname=@uname and pwd=@pwd";
                OleDbCommand comm = new OleDbCommand(sql,conn);
                comm.Parameters.AddWithValue("@uname", info.Uname);
                comm.Parameters.AddWithValue("@pwd", info.Pwd);

                int cnt = (int)AccessHelper.ExecuteScalar(comm);
                return cnt > 0 ? true : false;
            }

            #endregion
    }
}

SQlServerDAL层:引用DButility,IDAL,Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using IDAL;

using BibleDAL.SqlHelper;
using Model;

namespace SQLServerDAL
{
    public class User:IUser
//此处实现接口s
{ /// <summary> /// 得到数据库连接对象 /// </summary> /// <returns></returns> public SqlConnection GetConn() { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "server=.;database=zhihuigu;uid=sa;pwd=;"; conn.Open(); return conn; } #region IUser 成员 public bool IsLogin(UserInfo info) { SqlConnection conn = GetConn(); string sql = "select count(*) from uinfo where uname=@uname and pwd=@pwd"; SqlCommand comm = new SqlCommand(sql, conn); comm.Parameters.AddWithValue("@uname", info.Uname); comm.Parameters.AddWithValue("@pwd", info.Pwd); int cnt = (int)SqlHelper.ExecuteScalar(comm); return cnt > 0 ? true : false; } #endregion } }
posted @ 2011-03-28 21:57 誓言 阅读(125) 评论(0) 编辑

今天用三层架构做的新闻的分页,用的是第三方控件<AspNetPager>下面就介绍一下如何使用第三方控件AspNetPager

第一步:先在网上下载AspNetPager.dll文件。

第二步:把AspNetPager.dll文件添加到选项卡中。(打开<工具箱>,在空白处右击鼠标,选择<选择项>,浏览找到<AspNetPager.dll>点击确定),这样就把AspNetPager控件引进来了。

第三步:把AspNetPager文件引入到bin文件夹下。

第四步:把AspNetPager控件拖进你要用分页的页面。(准备工作完成,写代码)

DBtitly 层:

  引用SqlHelper

DAL层:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DButility;
using Model;
using System.Data;
using BibleDAL.SqlHelper;
namespace DAL
{
public class News
{
/// <summary>
/// 新闻分页列表
/// </summary>
/// <param name="page">当前页</param>
/// <param name="pageSize">每页显示多少条</param>
/// <returns>分页列表</returns>
public List<NewsInfo> GetNewsByPage(int page, int pageSize)
{
List
<NewsInfo> newsList = new List<NewsInfo>();
SqlConnection conn
= GetConn();
string sql = "select top " + pageSize + " * from news where id not in (select top " + (page - 1) * pageSize + " id from news order by times desc ) order by times desc";
DataSet ds
= SqlHelper.ExecuteDataset(conn, CommandType.Text, sql);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
NewsInfo info
= new NewsInfo();
info.Id
= Convert.ToInt32(ds.Tables[0].Rows[i]["id"].ToString());
info.Title
= ds.Tables[0].Rows[i]["title"].ToString();
info.Contents
= ds.Tables[0].Rows[i]["contents"].ToString();
info.Times
= Convert.ToDateTime(ds.Tables[0].Rows[i]["times"].ToString());
newsList.Add(info);
}
return newsList;
}

/// <summary>
/// 根据id得到此条新闻
/// </summary>
/// <param name="id">新闻id</param>
/// <returns>新闻内容</returns>
public NewsInfo GetNewsById(int id)
{
SqlConnection conn
= GetConn();
string sql = "select * from news where id=" + id;
SqlCommand comm
= new SqlCommand(sql, conn);
comm.Parameters.AddWithValue(
"@id", id);
DataSet ds
= SqlHelper.ExecuteDataset(comm);

NewsInfo info
= new NewsInfo();

if (ds.Tables[0].Rows.Count>0)
{
info.Id
= Convert.ToInt32(ds.Tables[0].Rows[0]["id"].ToString());
info.Title
= ds.Tables[0].Rows[0]["title"].ToString();
info.Contents
= ds.Tables[0].Rows[0]["contents"].ToString();
info.Times
= Convert.ToDateTime(ds.Tables[0].Rows[0]["times"].ToString());
}
return info;
}
/// <summary>
/// 得到此表中总共有多少条新闻信息
/// </summary>
/// <returns>多少条</returns>
public int GetRecordCount()
{
SqlConnection conn
= GetConn();
string sql = "select count(*) from news";
SqlCommand comm
= new SqlCommand(sql, conn);
int cnt = (int)comm.ExecuteScalar();
conn.Close();
return cnt;
}


/// <summary>
/// 得到数据库连接对象
/// </summary>
/// <returns></returns>
public static SqlConnection GetConn()
{
SqlConnection conn
= new SqlConnection();
conn.ConnectionString
= "server=.;database=zhihuigu;uid=sa;pwd=;";
conn.Open();
return conn;
}
}
}

BLL层:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;

namespace BLL
{
    public class News
    {
        public DAL.News news = new DAL.News();
        /// <summary>
        /// 根据分页显示新闻
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<NewsInfo> NewsInfoByPage(int page,int pageSize)
        {
            return news.GetNewsByPage(page, pageSize);
        }
        /// <summary>
        /// 得到该id对应的新闻
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public NewsInfo GetNewsById(int id)
        {
            return news.GetNewsById(id);
        }
        /// <summary>
        /// 得到新闻的总条数
        /// </summary>
        /// <returns></returns>
        public int GetRecordCount()
        {
            return news.GetRecordCount();
        }
    }
}

UI层:(用Repeater绑定做的)

aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="newsinfoBypage.aspx.cs" Inherits="newsinfoBypage" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    
</head>
<body>

    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
            <ul>
        </HeaderTemplate>
        
        <ItemTemplate>
            <li>
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"id","looknews.aspx?id={0}") %>'><%#Eval("title") %></asp:HyperLink>
            </li>
        </ItemTemplate>
        
        <FooterTemplate>
            </ul>
        </FooterTemplate>
        </asp:Repeater>
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPage1_PageChanged">
    </webdiyer:AspNetPager>
    s    </div>
    </form>
</body>
</html>

 .cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using Model;




public partial class newsinfoBypage : System.Web.UI.Page
{
    public BLL.News news = new News();
    protected void Page_Load(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;//当前显示页默认第一页
        AspNetPager1.PageSize = 2;//每页显示几条信息
        AspNetPager1.RecordCount = Convert.ToInt32(news.GetRecordCount());//总共有多少页?
        Bindnews();
    }
    private void Bindnews()
    {
        Repeater1.DataSource = news.NewsInfoByPage(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
        Repeater1.DataBind();
    }
    protected void AspNetPage1_PageChanged(object sender, EventArgs e)
    {
        Bindnews();
    }
}

至此关于AspNetPager的分页就完成了,有什么错误的地方希望大家指出来。

posted @ 2011-03-26 19:10 誓言 阅读(330) 评论(0) 编辑
摘要: 这几天我们复习三层架构因此对三层架构有了更新一层的认识,下面就由我来介绍一下.net中的三层架构其实一般说是三层但是可以根据不同的需求可以多加几层我一般会用以下几层 1、表现层(UI):通俗讲就是展现给用户的界面,即用户在使用一个系统的时候他的所见所得。 2、业务逻辑层(BLL):针对具体问题的操作,也可以说是对数据层的操作,对数据业务逻辑处理。 3、数据访问层(DAL):该层所做事务直接操作数据库,针对数据的增添、删除、修改、更新、查找等。s 4、Model 这个不能算是一个层,因为他只承载实体类 5、数据帮助层 (DButility):数据帮助层 主要是引用一些第三方控件使用的 像什么(s阅读全文
posted @ 2011-03-25 13:50 誓言 阅读(1211) 评论(9) 编辑
仅列出标题