SNS

用Reapeter不用返回字符串

cs文件中的方法名要跟其中调用的方法名区别

aspx页面返回字符串的写法:

1.<%=this.GetHtmlHead() %>

2.<% Response.Write(this.GetHtmlHead()); %>

正文内容与搜索内容用同一个方法实现。

编辑时,把设置控件内容的代码写在if (!IsPostBack)中。

 

Page.ClientScript.RegisterStartupScript(Page.GetType(), "message3", "<script language='javascript' defer>alert('此名称的类别已经存在!');location='manage.aspx';</script>");

Response.Write("<script>alert('该用户名不存在!');  this.location='javascript:history.back(-1)';</script>");

 

ref、rev两个关键属性:

<a  href="javascript:void(0)" rev="DelComment" rel="http://www.cnblogs.com/inc/ajax/album/PhotoOperator.aspx?action=DelComment&commentid=<%# DataBinder.Eval(Container.DataItem, "ID") %>">删除</a>

<input type="submit" class="f-button" rel="http://www.cnblogs.com/inc/ajax/album/PhotoOperator.aspx?action=CommentAdd&r[0]=<%=Phi.PhotoID %>" rev="CommentAdd" value="发表评论" />

 

分页不正确,看order by 的条件。

 

<%#this.GetHeadImage(Convert.ToInt32(Eval("userid")), 1) %>   //取得头像

string path = this.GetHeadPath(this.UserID);//取得头像路径

//非头像corInfo

                    photoPath = "" + this.GetOrgPic(Phi.FilePath);

                    orgPhotoPath = "" + this.GetOrgPic(Phi.FilePath);

 

在现有DataTable基础上增加列:

DataTable dt = UtilPage.GetPage("Friend_Index_Hot_aspx", PageIndex, 15, out ReCount, out PgCount, null);

            dt.Columns.Add("d", typeof(string));

            for (int i = 0; i < dt.Rows.Count; i++)

            {

 

                    string src = this.GetHeadImage(Convert.ToInt32(dt.Rows[i]["userid"].ToString()), 1);

                    dt.Rows[i]["d"] = src;

            }

            this.DLhotusers.DataSource = dt;

 

创建DataTable:

Array arr = Session["UploadPhotos"] as Array;

            DataTable dt = new DataTable("table1");

            dt.Columns.Add("FilePath", typeof(string));

            for (int i = 0; i < arr.Length; i++)

            {

                DataRow newRow = dt.NewRow();

                newRow["FilePath"] = ((object[])(arr))[0].ToString();

                dt.Rows.Add(newRow);

            }

            this.RptPhotoList.DataSource = dt;

   this.RptPhotoList.DataBind();

 

dt.Clear(); dt.Dispose();

 

if (Input.IsInteger(Request.QueryString["albumid"]))

            {

                Albumid = Convert.ToInt32(Request.QueryString["albumid"]);

            }

            else

            {

                Response.Write("<script>alert('缺少必要的参数!');  this.location='javascript:history.back(-1)';</script>");

                Response.End();

            }

过滤掉TextBox文本框中的字符串:JuSNS.Common.Input.Filter(key.Trim());   //如果为空,则返回null

aspx页面<%#JuSNS.Common.Input.GetSubString(Eval("content").ToString(),36,"...") %>

截取字符串:JuSNS.Common.Input.GetSubString(dt.Rows[0]["Content"].ToString(),120,"...");

过滤文本框中的字符串:JuSNS.Common.Input.LostHTML(JuSNS.Common.Input.ForTXT(info.Content))

显示表情图片:<%# JuSNS.Common.Public.CheckSma(DataBinder.Eval(Container.DataItem, "Content").ToString())%>

获得IP地址:JuSNS.Common.Public.GetClientIP();

删除文件:

string path = System.Web.HttpContext.Current.Server.MapPath("/web/uploads/photo/" + info.FilePath);

JuSNS.Common.Public.DelFile(path);

public static void DelFile(string path)

        {

            try

            {

                if (File.Exists(path))

                {

                    File.Delete(path);

                }

            }

            catch (IOException e) { }

        }

 

 

分页多个条件:new SqlConditionInfo("@UserID", Convert.ToInt32(r[0]), TypeCode.Int32), new SqlConditionInfo("@AlbumID", Convert.ToInt32(r[1]), TypeCode.Int32)

存储过程:

SqlParameter[] Param = new SqlParameter[3];

            Param[0] = new SqlParameter("@Title", SqlDbType.NVarChar, 40);

            Param[0].Value = info.Title;

            Param[1] = new SqlParameter("@Content", SqlDbType.NText);

            Param[1].Value = info.Content;

   Param[2] = new SqlParameter("@RecordCount", SqlDbType.Int);

            Param[2].Direction = ParameterDirection.Output;

DataTable dt = DbHelper.ExecuteTable(CommandType.StoredProcedure, "NTP_MyPage", Param);

Sql语句:

SqlParameter Param = new SqlParameter("@userid", SqlDbType.Int, 4);

            Param.Value = userid;

            string Sql = "select bcategoryid,categorytitle,blogcount from nt_blogcategory where userid=@userid";

            return DbHelper.ExecuteTable(CommandType.Text, Sql, Param);

 

返回DataTable:

public DataTable GetPersonInfo(int userid)

        {

            SqlParameter param = new SqlParameter("@userid",SqlDbType.Int,4);

            param.Value = userid;

            string sql = "select a.username,c.name,a.portrait,b.sex,b.birthday from nt_user a, nt_userinfo b,NT_Dict_Area c where a.userid=b.userid and c.id=a.city and a.userid=@userid";

            DataTable dt = DbHelper.ExecuteTable(CommandType.Text, sql, param);

            return dt;

        }

 

GetHeadImage(Convert.ToInt32(dt.Rows[i]["VisitorID"].ToString()), 1)

 

获得系统消息:new News().GetSysNews(1,1);

 

读取会员基本信息:

JuSNS.Home.Space sp = new JuSNS.Home.Space();

DataTable dt = sp.getUserInfo(uID, 0);

 

增加积分:

JuSNS.SQLServer.User us=new JuSNS.SQLServer.User();

us.updateinte(Info.Userid, 5, 0, 0, "添加日志类别");

 

更新足迹:

UserDyn(trans, 0, 0, "blog", info.UserID, 0, n, "发表了新日志", n.ToString());//n被操作的id

 

取得好友日志:

SqlConditionInfo friend_st = new SqlConditionInfo("@UserID", GetUserID(), TypeCode.Int32);

dt = JuSNS.Home.UtilPage.GetPage("blog_list_friend", PageIndex, PAGESZ, out ReCount, out PgCount, friend_st);

 

 

<script type="text/javascript">

   function postblog()

   {

        var uid='<%=GetUserID() %>';

        if(uid=="0")

        {

        alert("需要登录后才能发表日志!");return false;

        }

        else

        {

            return true;

        }

   }

</script>

 

分页HTML:

if (ReCount > PAGESZ)

            {

                this.DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, PgCount, ""+rooDir+"/home/blog/?r=" + r + "&key="+key+"");

            }

            else

            {

                this.DivPage.Visible = false;

            }

 

 

 

相册中的照片:

Photo p = new Photo();

List<PhotoInfo> infolist = p.InfoList(AlbumID, UserID);

this.GetSmallPic(infolist[i].FilePath, 0)

 

 

 

declare @tempSql nvarchar(3250)

create table #PageIndex 

(

 IndexID int identity(1,1),

 ColumnId int

)

select @tempSql =

'

insert into #PageIndex(ColumnID)

       select bCategoryid 

  from [dbo].[NT_blogcategory] where '

+@WhereCondition+@OrderByExpression

EXEC sp_executesql @tempSql 

 

 

日期输入文本框:

<script language="javascript" type="text/javascript" src="http://www.cnblogs.com/js/date.js"></script>

<input type="text" id="EndTime" maxlength="100" runat="server" onclick="SelectDate(this,'yyyy-MM-dd')" class="f-text" style="width: 100px;" />

 

switch (r)

                    {

                        case "friend":

 

                            dt = UtilPage.GetPage("vote_friend_aspx", PageIndex, 20, out c, out p, st);

                            break;

 

                        case "hot":

 

                            dt = UtilPage.GetPage("vote_hot_aspx", PageIndex, 20, out c, out p, st);

                            break;

                    }

 

 

onfocus="if(this.value=='发表你的意见...'){this.value='';}" onblur="if(this.value==''){this.value='发表你的意见...';}"

 

 

时间间隔:<%# JuSNS.Common.Public.getTimeEXPINSpan(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "AddTime")))%>

 

个人图像的地址:<%# GetHeadImage((int)DataBinder.Eval(Container.DataItem, "UserID"),1)%>

 

衔接到个人空间:http://www.cnblogs.com/user/<%# JuSNS.Common.Public.URLWrite("", "r", Eval("userid").ToString()) %>

 

 

数据字典的绑定:1.

Dictionary<int, string> dct = friend.GetFriendsForGroup(UserID, Convert.ToInt32(GroupID), "");

                string s_List = "";

                foreach (KeyValuePair<int, string> kvp in dct)

                {

                    s_List += "<div id=\"l" + kvp.Key.ToString() + "\" style=\"height:20px;\"><input type=\"checkbox\" value=\"" + kvp.Key.ToString() + "\" onclick=\"GroupAddMber('" + kvp.Key.ToString() + "','" + kvp.Value + "');\" /> " + kvp.Value + "</div>";

                }

 

 

2.

JuSNS.Home.Friend friend = new JuSNS.Home.Friend();

            Dictionary<int, string> dct = friend.getAllFriendsByUserID(this.UserID);

            DataTable dt = new DataTable();

            DataRow dr;

            dt.Columns.Add("friendID", typeof(int));

            dt.Columns.Add("friendName", typeof(string));

            foreach (KeyValuePair<int, string> kvp in dct)

            {

                dr = dt.NewRow();

                dr["friendID"] = kvp.Key;

                dr["friendName"] = kvp.Value;

                dt.Rows.Add(dr);

            }

            this.RblFriendList.DataSource = dt;

            this.RblFriendList.DataTextField = "friendname";

            this.RblFriendList.DataValueField = "friendid";

            this.RblFriendList.DataBind();

            dt.Dispose();

 

 

string[] uid = this.Hid_UserID.Value.TrimEnd(';').Split(';');  //char类型的参数用单引号引起来

 

上传文件的大小this.FileUpload1.PostedFile.ContentLength;

 

 

只能输入数字的文本框:

<input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" id="invitenum" name="invitenum">

 

 

验证日期格式的js:

if(document.getElementById("starttime").value!=""){

        var a=/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/  

        if (!a.test(document.getElementById("starttime").value)){ 

        alert("活动时间格式不正确!") 

        document.getElementById("starttime").focus();

        return false 

        } 

}

 

事务:

public int Add(nt_favoritesInfo Info)

        {

            SqlConnection Conn = new SqlConnection(DBConfig.CnString);

            Conn.Open();

            SqlTransaction trans = Conn.BeginTransaction();

            try

            {

                SqlParameter[] param = getParameters(Info);

                string Sql = "Insert Into nt_Favorites( [categoryid],[userid],[title],[url],[addtime]) " +

                             "Values(@Categoryid,@Userid,@Title,@Url,@Addtime);" +

                             "Select @@IDENTITY;";

                int id = Convert.ToInt32(DbHelper.ExecuteScalar(trans, CommandType.Text, Sql, param));

                UserDyn(trans, 0, 0, "addFavorites", Info.userid, 0, id, "添加了一个收藏", id.ToString());

                trans.Commit();

 

                return id;

            }

            catch (SqlException e)

            {

                trans.Rollback();

                throw e;

            }

            finally

            {

                if (Conn.State == ConnectionState.Open)

                    Conn.Close();

            }

        }

 

生成随机图片名称:

Random rd = new System.Random();

string extname = Fupload.PostedFile.FileName.Substring(Fupload.PostedFile.FileName.LastIndexOf(".") + 1).ToLower();

string filename =DateTime.Now.ToString("yyyyMM") + rd.Next(1000).ToString() + "." + extname;

 

 

Repeater控件:

        protected void Rpt_newvote_ItemDataBound(object sender, RepeaterItemEventArgs e)

        {

            //foreach (RepeaterItem item in this.Rpt_newvote.Items)

            //{

            //    LinkButton lbnDelete = item.FindControl("lbnDelete") as LinkButton;

            //    if (string.IsNullOrEmpty(Request.QueryString["r"]) || Request.QueryString["r"]=="my")

            //    {

            //        lbnDelete.Visible = true;

            //    }

            //}

            int Rcount = this.Rpt_newvote.Items.Count;

            for (int i = 0; i < Rcount+1; i++)

            {

                LinkButton lbnDelete = e.Item.FindControl("lbnDelete") as LinkButton;

                if (string.IsNullOrEmpty(Request.QueryString["r"]) || Request.QueryString["r"] == "my")

                {

                    lbnDelete.Visible = true;

                } 

            }

        }

 

 

 

过滤输入的内容:

string Content = Request["body1"];

            Content = Common.Input.loseScript(Content);

            Content = Common.Input.loseIframe(Content);

            #region 过滤关键字

            string res = JuSNS.Common.Public.CheckKey(Content, true);

            if (res != "")

            {

                Content = Content.Replace(res, "***");

            }

   #endregion

 

通知:

JuSNS.Home.ParseTemplate pt=new ParseTemplate("{NoteStr}");

pt.Result

 

站内信:

<span id="MailCount" class="font11">(-)</span>

<script type="text/javascript">GetMailCount();</script>

<script language="javascript" type="text/javascript" src="{RootDir}/js/ajax.js"></script>

<script language="javascript" type="text/javascript" src="{RootDir}/js/public.js"></script>

 

控件添加属性:this.Button1.Attributes.Add("onclick", "govote(" + r + ");");

 

动态:JuSNS.SQLServer.ParseUserLog.cs dyn.config

 

js检查是否为邮箱(引入public.js):if(s == '' || !s.IsEmail())

 

浏览次数:bool addreads = false;

        string cookieid = "PhotoReadA_" + photoid + "_" + usernm;

        if (Request.Cookies[cookieid] == null || Request.Cookies["PhotoReadA_" + photoid + "_" + usernm].Value != "1")

        {

            HttpCookie cooknum = new HttpCookie(cookieid);

            Response.Cookies[cookieid].Value = "1";

            Response.Cookies[cookieid].Expires = DateTime.Now.AddDays(1);

            addreads = true;

        }

        if (Request.Cookies[cookieid] != null && Request.Cookies["PhotoReadA_" + photoid + "_" + usernm].Value != "1")

        {

            Response.Cookies[cookieid].Value = "1";

            Response.Cookies[cookieid].Expires = DateTime.Now.AddDays(1);

            addreads = true;

        }

        if (addreads)

        {

            bllphoto.AddViews(Phi.PhotoID);

        }

 

验证码:

<input type="text" name="TxtVerify" class="f-text" id="TxtVerify" />

 

                                    <script language="javascript" type="text/javascript">

                                       var numkey = Math.random();

                                       numkey = Math.round(numkey*10000);

                                       document.write("<img align=\"adsmiddle\" src=\"inc/code/image.aspx?k="+ numkey +"\" onClick=\"this.src+=Math.random()\" alt=\"点击重新获得验证码\" style=\"cursor:pointer;\" height=\"22\" hspace=\"4\" />");

                                    </script>

 

 

注册表中注册:regsvr32 "D:\VSS\SSSCC.DLL"

查看端口是否打开:telnet 192.168.1.242:8090

端口例外:控制面板 Windows防火墙 例外

 

ajax的处理页面为aspx时,除第一句外其余都删除。

 

用户控件传值:

<uc3:MyIntro ID="MyIntro1" runat="server" UserId="<%=userid %>"/>

.ascx.cs:

protected string userid;

public string UserId

{

     set { userid = value; }

}

 

使用组件,可能还要在web.config中注册

使用Iframe,则Iframe中的衔接问题要考虑到,在父窗口中打开窗口用onclick="parent.location.href='/user/user.aspx'"。

<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

 

updatepanel控件在有designer.cs的项目中无效

 

编辑之前的页面状态应该写在if (!IsPostBack){}中

 

上传图片生成4张不同大小的:

aspx页面:<form method="post" action="" enctype="multipart/form-data" name="uploadpicture" id="uploadpicture" runat="server" onsubmit="return picvalue();">

<input type="file" name="picture" class="f-text" id="picture" />

<script type="text/javascript">

function picvalue()

{

    if(document.getElementById("picture").value=="")

    {

        alert("请选择图片");return false;

    } 

    else

    {

        return true;

    }

</script>

.aspx.cs页面:

JuSNS.Common.PicUpload.PicUpload picup = new HeadUpload();

picup.Start();

abi.FilePath = picup.OutFileName;

 

object b=db.ExecuteScalar(sql1);

if (object!=null)

 

 

留言、礼物、信件等双向的东西,删除时只能是隐藏。

 

将出生日期转化为年龄:

SqlServer,datediff(year,birthday,getdate()) as birthday

Access,datediff('yyyy',birthday,now) as birthday

 

 

CheckBoxList:

for (int i = 0; i < CBLMasterLanguage.Items.Count; i++)

            {

                if (CBLMasterLanguage.Items[i].Selected == true)

                {

                    info.MasterLanguage += CBLMasterLanguage.Items[i].Value + ",";

                }

            } 

 

编辑时:

string[] language = info.MasterLanguage.TrimEnd(',').Split(',');

                for (int n = 0; n < language.Length; n++)

                {

                    this.CBLMasterLanguage.Items.FindByValue(language[n]).Selected = true;

 

                }

 

 

修改密码时要:Input.MD5(this.tbOldPassWord.Text,false)

 

web层是项目的,有.cs文件的不能应用局部无刷新技术,可以用/表示根目录;

web层是网站的,可以应用局部无刷新技术,用<%=Global.GetFullVirPath() %>来表示根目录。

 

鼠标经过变色:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)

    {//鼠标行为

        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFC0C0'");

        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");

    }

posted on 2011-01-29 16:23  cw_volcano  阅读(373)  评论(0编辑  收藏  举报