个人随笔----关键代码
目录:
1。打开一个新页面
2。打开一个 固定大小的页面
3。视图查询
4。ASP.NET为我们提供了传递参数的三种方式,
5。gridview / 实验分页功能 / GridView 数据行光棒效果 / CheckBoxField 复选框字段
6。TreeView(展开 折叠 结点)
7。传递多个参数
8.鼠标经过改变背景颜色、更换图片
8.鼠标经过改变背景颜色、更换图片
9.延迟效果
10.无刷新打开新页面
11.datalist分页
12.一个SharePoint事件处理程序实例 .txt
13.天气预报 获取源代码
14. 调用cs文件中的方法
15. 获取当前页名称
16.定义数组并且判断数组中是否存在 某个字段
17.下拉列表的数据邦定邦定
=========打开一个新页面
Response.Write("<script>window.open('NewPage(页名).aspx')</script>");
Response.Write("<script>window.open('NewPage(页名).aspx')</script>");
二 、
函数方法
onclick="OpenExtranetHelpWindow('/_layouts/GSEGC/Law/GetLawRoles.aspx?btnID='+'ctl00_ContentPlaceHolderMain_TxtComVRoles');"
==========打开一个 固定大小的页面
在父页面弹出一个新窗口,在对新窗口进行提交的时候,为何又弹出一个和前面的新窗口一样的页面
在那个对话框的网页中的HEAD之间加入<base target="_self">就可以了
(1)
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script lang='javascript'>window.showModalDialog('Default6.aspx',window,'dialogHeight:400px;dialogWidth:500px;center:Yes;Help:No;Hotkeys:yes;Resizable:no;Scroll:auto;Status:no;')</script>");
}
(2)
函数方法实现
函数方法实现
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" base target=_self>
<title>无标题页</title>
<script language=javascript>
function openwindow()
{
window.showModalDialog('Default6.aspx',window,'dialogHeight:400px;dialogWidth:500px;center:Yes;Help:No;Hotkeys:yes;Resizable:no;Scroll:auto;Status:no;');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Button ID="Button3" runat="server" Text="Button" OnClientClick ="openwindow();"/>
<input id="Button2" type="button" value="button" onclick="openwindow();" />
base target=_self</div>
</form>
</body>
</html>
<head runat="server" base target=_self>
<title>无标题页</title>
<script language=javascript>
function openwindow()
{
window.showModalDialog('Default6.aspx',window,'dialogHeight:400px;dialogWidth:500px;center:Yes;Help:No;Hotkeys:yes;Resizable:no;Scroll:auto;Status:no;');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Button ID="Button3" runat="server" Text="Button" OnClientClick ="openwindow();"/>
<input id="Button2" type="button" value="button" onclick="openwindow();" />
base target=_self</div>
</form>
</body>
</html>
=========视图查询
SELECT dbo.Users.UserID, dbo.UserType.RelationID, dbo.UserType.UserType, dbo.ProUserRelation.ProjectID, dbo.ProUserRelation.UserID AS Expr1,
dbo.ProUserRelation.RelationID AS Expr2, dbo.Users.UserName
FROM dbo.Users INNER JOIN
dbo.ProUserRelation ON dbo.Users.UserID = dbo.ProUserRelation.UserID INNER JOIN
dbo.UserType ON dbo.ProUserRelation.RelationID = dbo.UserType.RelationID
WHERE (dbo.ProUserRelation.RelationID = '4') AND (dbo.ProUserRelation.ProjectID = '99')
dbo.ProUserRelation.RelationID AS Expr2, dbo.Users.UserName
FROM dbo.Users INNER JOIN
dbo.ProUserRelation ON dbo.Users.UserID = dbo.ProUserRelation.UserID INNER JOIN
dbo.UserType ON dbo.ProUserRelation.RelationID = dbo.UserType.RelationID
WHERE (dbo.ProUserRelation.RelationID = '4') AND (dbo.ProUserRelation.ProjectID = '99')
参数解释:
<SCRIPT LANGUAGE="javascript"> js脚本开始;
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
</SCRIPT> js脚本结束
=========视图查询
<SCRIPT LANGUAGE="javascript"> js脚本开始;
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
</SCRIPT> js脚本结束
=========视图查询
SELECT dbo.Users.UserName
FROM dbo.Users INNER JOIN
dbo.ProUserRelation ON dbo.Users.UserID = dbo.ProUserRelation.UserID INNER JOIN
dbo.UserType ON dbo.ProUserRelation.RelationID = dbo.UserType.RelationID
WHERE (dbo.ProUserRelation.RelationID = '8') AND (dbo.ProUserRelation.ProjectID = '102')
FROM dbo.Users INNER JOIN
dbo.ProUserRelation ON dbo.Users.UserID = dbo.ProUserRelation.UserID INNER JOIN
dbo.UserType ON dbo.ProUserRelation.RelationID = dbo.UserType.RelationID
WHERE (dbo.ProUserRelation.RelationID = '8') AND (dbo.ProUserRelation.ProjectID = '102')
========== ASP.NET为我们提供了传递参数的三种方式,
一种是可以通过用QueryString来传送相应的值.
再一种是通过session变量来传送相应的值.
还有就是通过Server.Transfer方法来实现。下面分别一一介绍:
一种是可以通过用QueryString来传送相应的值.
再一种是通过session变量来传送相应的值.
还有就是通过Server.Transfer方法来实现。下面分别一一介绍:
一、使用Querystring
Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象。如果你想传
Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象。如果你想传
递一个安全性不是那么太重要或者是一个简单的数值时,用此方法最好不过了。下面通过一个小例子来完成传值工作,步骤如下:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
string url;
url="webform2.aspx?name=" +
TextBox1.Text + "&email=" +
TextBox2.Text;
Response.Redirect(url);
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
运行,即可看到传递后的结果了。
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
string url;
url="webform2.aspx?name=" +
TextBox1.Text + "&email=" +
TextBox2.Text;
Response.Redirect(url);
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
运行,即可看到传递后的结果了。
二、使用Session变量
使用Session变量传值是一种最常见的方式了,此中方式不仅可以把值传递到下一个页面,还可以交叉传递到多个页面,直至把Session变量的
值removed后,变量才会消失。举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_ClickF
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
运行,即可看到传递后的结果了。
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_ClickF
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
运行,即可看到传递后的结果了。
三、使用Server.Transfer
虽然这种方法有点复杂,但也不失为一种在页面传值的方式。
举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("webform2.aspx");
}
4、创建过程来返回TextBox1,TextBox2控件的值代码如下:
public string Name
{
get
{
return TextBox1.Text;
}
}
虽然这种方法有点复杂,但也不失为一种在页面传值的方式。
举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("webform2.aspx");
}
4、创建过程来返回TextBox1,TextBox2控件的值代码如下:
public string Name
{
get
{
return TextBox1.Text;
}
}
public string EMail
{
get
{
return TextBox2.Text;
}
}
5、新建一个目标页面命名为webform2
6、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
//创建原始窗体的实例
WebForm1 wf1;
//获得实例化的句柄
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
{
get
{
return TextBox2.Text;
}
}
5、新建一个目标页面命名为webform2
6、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
//创建原始窗体的实例
WebForm1 wf1;
//获得实例化的句柄
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
}
============ gridview
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.GridView1.Caption = " 实验分页功能";
//设置分页按扭
this.GridView1.PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;
this.GridView1.PagerSettings.FirstPageImageUrl="~/image/first.gif";
this.GridView1.PagerSettings.PreviousPageImageUrl = "~/image/up.gif";
this.GridView1.PagerSettings.NextPageImageUrl="~/image/down.gif";
this.GridView1.PagerSettings.LastPageImageUrl="~/image/last.gif";
}
}
{
if (!Page.IsPostBack)
{
this.GridView1.Caption = " 实验分页功能";
//设置分页按扭
this.GridView1.PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;
this.GridView1.PagerSettings.FirstPageImageUrl="~/image/first.gif";
this.GridView1.PagerSettings.PreviousPageImageUrl = "~/image/up.gif";
this.GridView1.PagerSettings.NextPageImageUrl="~/image/down.gif";
this.GridView1.PagerSettings.LastPageImageUrl="~/image/last.gif";
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
this.Label1.Text = "目前所在分页码(" + (this.GridView1.PageIndex + 1) + "/" + this.GridView1.PageCount + ")"; //显示 第几页 和 总的页数
switch (e.Row.RowType) //GridView 数据行光棒效果
{
case DataControlRowType.Header://标题部分
e.Row.BackColor = Color.FromArgb(153, 0, 0);
e.Row.ForeColor = Color.Red;
break;
case DataControlRowType.DataRow://创建奇数偶数数据行的 onmouseout,onmouseover的颜色变换
if (Convert.ToInt16(ViewState["LineNo"]) == 0)
{
e.Row.BackColor = Color.Green;//当鼠标还没移到该行之前的 显示颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = '#fffbd6';this.style.color='black'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor = '#C0C0FF';this.style.color='#ffffff'");
ViewState["LineNo"] = 1;
}
else
{
e.Row.BackColor = Color.White;//当鼠标还没移到该行之前的 显示颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = '#ffffff';this.style.color='black'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor = '#FFC080';this.style.color='#FF8080'");// 鼠标移入 改变背景颜色的 字体颜色
ViewState["LineNo"] = 0;
}
break;
}
{
this.Label1.Text = "目前所在分页码(" + (this.GridView1.PageIndex + 1) + "/" + this.GridView1.PageCount + ")"; //显示 第几页 和 总的页数
switch (e.Row.RowType) //GridView 数据行光棒效果
{
case DataControlRowType.Header://标题部分
e.Row.BackColor = Color.FromArgb(153, 0, 0);
e.Row.ForeColor = Color.Red;
break;
case DataControlRowType.DataRow://创建奇数偶数数据行的 onmouseout,onmouseover的颜色变换
if (Convert.ToInt16(ViewState["LineNo"]) == 0)
{
e.Row.BackColor = Color.Green;//当鼠标还没移到该行之前的 显示颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = '#fffbd6';this.style.color='black'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor = '#C0C0FF';this.style.color='#ffffff'");
ViewState["LineNo"] = 1;
}
else
{
e.Row.BackColor = Color.White;//当鼠标还没移到该行之前的 显示颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = '#ffffff';this.style.color='black'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor = '#FFC080';this.style.color='#FF8080'");// 鼠标移入 改变背景颜色的 字体颜色
ViewState["LineNo"] = 0;
}
break;
}
}
=====CheckBoxField 复选框字段
在Gridview 智能标签中点击[编辑列]加个CheckBoxField 字段,注意"确保数据库中有个 内容只为 true false 的列 与之邦定" 就ok了
============TreeView(展开 折叠 结点)
protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
{
if (e.Node.Expanded == false)
{
Response.Write("您折叠了结点");
}
{
if (e.Node.Expanded == false)
{
Response.Write("您折叠了结点");
}
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (IsPostBack)
{
if (e.Node.Expanded == true)
{
Response.Write("<script>alert('您展开了结点')</script>");
}
}
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (IsPostBack)
{
if (e.Node.Expanded == true)
{
Response.Write("<script>alert('您展开了结点')</script>");
}
}
}
========== 传递多个参数
default.aspx?name={q}&title={ttt}
==========鼠标经过改变背景颜色、更换图片
可以在源里这样写:
可以在源里这样写:
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click" onmouseover="this.style.backgroundColor='00ccff'" onmouseout="this.style.background='#EEEEEE'">LinkButton</asp:LinkButton>
鼠标经过更换图片
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/image/1.jpg" onmouseover= "this.src='image/2.jpg'" onmouseout = "this.src='image/1.jpg'" />
或者可以在 代码中
protected void Page_Load(object sender, EventArgs e)
{
//this.ImageButton1.Attributes["onmouseover"] = "this.src='image/2.jpg'";
//this.ImageButton1.Attributes["onmouseout"] = "this.src='image/1.jpg'";
this.Button1.Attributes["onmouseover"] = "this.style.backgroundColor='00ccff'";
}
{
//this.ImageButton1.Attributes["onmouseover"] = "this.src='image/2.jpg'";
//this.ImageButton1.Attributes["onmouseout"] = "this.src='image/1.jpg'";
this.Button1.Attributes["onmouseover"] = "this.style.backgroundColor='00ccff'";
}
==================延迟效果
System.Threading.Thread.Sleep(50000);//毫秒为单位 (这个是延迟 触发的事件)
System.Threading.Thread.Sleep(50000);//毫秒为单位 (这个是延迟 触发的事件)
===============无刷新打开新页面
function ad(id)
{
window.open('/_layouts/GSEGC/Meeting2/AddMeetings.aspx?InstanceID='+id,'_blank', 'height=260,width=260,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no') ;
}
</script>
function ad(id)
{
window.open('/_layouts/GSEGC/Meeting2/AddMeetings.aspx?InstanceID='+id,'_blank', 'height=260,width=260,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no') ;
}
</script>
<a href="javascript:ed('<%# Eval("ID") %>','<%= _ID %>')" title="修改" >修改</a>
===============datalist分页
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Specialized;
using Microsoft.SharePoint.WebControls;
using System.Collections.Specialized;
public partial class ShowImg2 : System.Web.UI.UserControl
{
public int _ID;
string _listName = "图片库";
string _listPinglun = "评论";
string _webName = "/";
string url;
public DataTable dt;
{
public int _ID;
string _listName = "图片库";
string _listPinglun = "评论";
string _webName = "/";
string url;
public DataTable dt;
//static int i = 0;
[WebBrowsable]
[WebDisplayName("网站列表名称")]
[WebDescription("网站列表名称,默认为 meetingform ")]
public string ListName
{
get { return _listName; }
set
{
if (string.IsNullOrEmpty(value))
{
_listName = "图片库";
}
else
{
_listName = value;
}
}
}
[WebDisplayName("网站列表名称")]
[WebDescription("网站列表名称,默认为 meetingform ")]
public string ListName
{
get { return _listName; }
set
{
if (string.IsNullOrEmpty(value))
{
_listName = "图片库";
}
else
{
_listName = value;
}
}
}
[WebBrowsable]
[WebDisplayName("网站列表名称")]
[WebDescription("网站列表名称,默认为 meetingform ")]
public string ListPinglun
{
get { return _listPinglun; }
set
{
if (string.IsNullOrEmpty(value))
{
_listPinglun = "评论";
}
else
{
_listPinglun = value;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
}
ScriptManager.RegisterStartupScript(this, typeof(ShowImg2), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
[WebDisplayName("网站列表名称")]
[WebDescription("网站列表名称,默认为 meetingform ")]
public string ListPinglun
{
get { return _listPinglun; }
set
{
if (string.IsNullOrEmpty(value))
{
_listPinglun = "评论";
}
else
{
_listPinglun = value;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
{
this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
}
}
ScriptManager.RegisterStartupScript(this, typeof(ShowImg2), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
int i = 0;
ViewState["id"] = i;
url = "http://" + Environment.MachineName + ":9090" + _webName + "default.aspx?";
ViewState["id"] = i;
url = "http://" + Environment.MachineName + ":9090" + _webName + "default.aspx?";
if (!Page.IsPostBack)
{
ViewState["CurrentPageIndex"] = 0;
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
//SPListItem item = web.GetList(this.Page.Request.Url.ToString()).GetItemById(_ID);
SPList splist = web.Lists[ListName];//this.Page.Request.Url.ToString()
{
ViewState["CurrentPageIndex"] = 0;
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
//SPListItem item = web.GetList(this.Page.Request.Url.ToString()).GetItemById(_ID);
SPList splist = web.Lists[ListName];//this.Page.Request.Url.ToString()
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
//query.RowLimit = 10;//获取前 N 条记录
query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
//query.RowLimit = 10;//获取前 N 条记录
query.ViewFields = "<FieldRef Name=\"ID\" /><FieldRef Name=\"FileLeafRef\" /><FieldRef Name=\"RequiredField\" /><FieldRef Name=\"Title\" />";
SPListItemCollection items = splist.GetItems(query);
SPListItemCollection items = splist.GetItems(query);
dt = items.GetDataTable();
ViewState["DataTable"] = dt;
ViewState["Index"] = 0;
ViewState["DataTable"] = dt;
ViewState["Index"] = 0;
if (dt.Rows.Count > 0)
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[0][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[0]["ID"].ToString();
}
}
}
}
Bind(0);
}
protected void ButImg_Click(object sender, EventArgs e)
{
}
void Bind(int currentIndex)//邦定评论列表
{
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
//SPListItem item = web.GetList(this.Page.Request.Url.ToString()).GetItemById(_ID);
SPList splist = web.Lists[ListPinglun];//this.Page.Request.Url.ToString()
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[0][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[0]["ID"].ToString();
}
}
}
}
Bind(0);
}
protected void ButImg_Click(object sender, EventArgs e)
{
}
void Bind(int currentIndex)//邦定评论列表
{
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
//SPListItem item = web.GetList(this.Page.Request.Url.ToString()).GetItemById(_ID);
SPList splist = web.Lists[ListPinglun];//this.Page.Request.Url.ToString()
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='_x8bc4__x8bba_ID' /><Value Type='Choice'>" +Convert.ToInt32(LabIndex.Text.ToString())+ "</Value></Eq></Where>";//<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>
query.RowLimit = 100;
query.ViewFields = "<FieldRef Name='_x8bc4__x8bba_ID' /><FieldRef Name='Title' />";
SPListItemCollection items = splist.GetItems(query); //init(items);
DataTable dtt = items.GetDataTable();
ViewState["DataTable2"] = dtt;
//this.DataList1.DataSource = items.GetDataTable();
//this.DataList1.DataBind();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = items.GetDataTable().DefaultView;
pds.AllowPaging = true;
pds.PageSize = 3;
pds.CurrentPageIndex = currentIndex;
query.Query = "<Where><Eq><FieldRef Name='_x8bc4__x8bba_ID' /><Value Type='Choice'>" +Convert.ToInt32(LabIndex.Text.ToString())+ "</Value></Eq></Where>";//<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>
query.RowLimit = 100;
query.ViewFields = "<FieldRef Name='_x8bc4__x8bba_ID' /><FieldRef Name='Title' />";
SPListItemCollection items = splist.GetItems(query); //init(items);
DataTable dtt = items.GetDataTable();
ViewState["DataTable2"] = dtt;
//this.DataList1.DataSource = items.GetDataTable();
//this.DataList1.DataBind();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = items.GetDataTable().DefaultView;
pds.AllowPaging = true;
pds.PageSize = 3;
pds.CurrentPageIndex = currentIndex;
ViewState["PageCount"] = pds.PageCount;
this.LabShowPage.Text = currentIndex + 1 + "/" + pds.PageCount;
DataList1.DataSource = pds;
DataList1.DataBind();
}
}
}
protected void ButAdd2_Click(object sender, EventArgs e)
{
using (SPSite site = new SPSite(url))
{
using (SPWeb myweb = site.OpenWeb())
{
myweb.AllowUnsafeUpdates = true;//虚拟管理员身份
DataList1.DataSource = pds;
DataList1.DataBind();
}
}
}
protected void ButAdd2_Click(object sender, EventArgs e)
{
using (SPSite site = new SPSite(url))
{
using (SPWeb myweb = site.OpenWeb())
{
myweb.AllowUnsafeUpdates = true;//虚拟管理员身份
SPListItemCollection items = myweb.Lists[ListPinglun].Items;
SPListItem item = items.Add();
//SPListItem items1 = items.GetItemById("12");
item["Title"] = this.TextTitle.Text;
item["_x8bc4__x8bba_ID"] = this.LabIndex.Text;
item.Update();
//SPListItem items1 = items.GetItemById("12");
item["Title"] = this.TextTitle.Text;
item["_x8bc4__x8bba_ID"] = this.LabIndex.Text;
item.Update();
myweb.AllowUnsafeUpdates = true;
}
}
//ViewState["CurrentPageIndex"] = 0;
Bind(0);
this.TextTitle.Text = "";
//Response.Redirect(Page.Request.Url.AbsoluteUri);
}
protected void ButFirst_Click(object sender, EventArgs e)
{
}
protected void ButUp_Click(object sender, EventArgs e)
{
}
}
//ViewState["CurrentPageIndex"] = 0;
Bind(0);
this.TextTitle.Text = "";
//Response.Redirect(Page.Request.Url.AbsoluteUri);
}
protected void ButFirst_Click(object sender, EventArgs e)
{
}
protected void ButUp_Click(object sender, EventArgs e)
{
}
protected void ButLast_Click(object sender, EventArgs e)
{
protected void ButLast_Click(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (this.PanAdd.Visible == true)
this.PanAdd.Visible = false;
else
this.PanAdd.Visible = true;
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (this.PanPL.Visible == true)
{
this.PanPL.Visible = false;
this.LBtShowPL.Text = "<<显示评论";
}
else
{
this.PanPL.Visible = true;
this.LBtShowPL.Text = "<<隐藏评论";
}
}
{
if (this.PanAdd.Visible == true)
this.PanAdd.Visible = false;
else
this.PanAdd.Visible = true;
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (this.PanPL.Visible == true)
{
this.PanPL.Visible = false;
this.LBtShowPL.Text = "<<显示评论";
}
else
{
this.PanPL.Visible = true;
this.LBtShowPL.Text = "<<隐藏评论";
}
}
protected void ImBtFirst_Click(object sender, ImageClickEventArgs e)
{
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtUp_Click(object sender, ImageClickEventArgs e)
{
int currentIndex = (int)ViewState["CurrentPageIndex"];
if (currentIndex > 0)
{
ViewState["CurrentPageIndex"] = currentIndex - 1;
}
Bind((int)ViewState["CurrentPageIndex"]);
}
protected void ImBtDown_Click(object sender, ImageClickEventArgs e)
{
int currentIndex = (int)ViewState["CurrentPageIndex"];
if (currentIndex < (int)ViewState["PageCount"] - 1)
{
ViewState["CurrentPageIndex"] = currentIndex + 1;
{
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtUp_Click(object sender, ImageClickEventArgs e)
{
int currentIndex = (int)ViewState["CurrentPageIndex"];
if (currentIndex > 0)
{
ViewState["CurrentPageIndex"] = currentIndex - 1;
}
Bind((int)ViewState["CurrentPageIndex"]);
}
protected void ImBtDown_Click(object sender, ImageClickEventArgs e)
{
int currentIndex = (int)ViewState["CurrentPageIndex"];
if (currentIndex < (int)ViewState["PageCount"] - 1)
{
ViewState["CurrentPageIndex"] = currentIndex + 1;
}
Bind((int)ViewState["CurrentPageIndex"]);
}
protected void ImBtLast_Click(object sender, ImageClickEventArgs e)
{
ViewState["CurrentPageIndex"] = (int)ViewState["PageCount"] - 1;
Bind((int)ViewState["CurrentPageIndex"]);
}
protected void ImBtF_Click(object sender, ImageClickEventArgs e)
{
ViewState["Index"] = 0;
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
DataTable dt = (DataTable)ViewState["DataTable"];
if (dt.Rows.Count > 0)
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtU_Click(object sender, ImageClickEventArgs e)
{
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
DataTable dt = (DataTable)ViewState["DataTable"];
if (dt.Rows.Count > 0)
{
if (i > 0)
{
ViewState["Index"] = i - 1;
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i - 1][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i - 1]["ID"].ToString();
}
else
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtD_Click(object sender, ImageClickEventArgs e)
{
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
DataTable dt = (DataTable)ViewState["DataTable"];
if (dt.Rows.Count > 0)
{
if (i < dt.Rows.Count - 1)
{
ViewState["Index"] = i + 1;
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i + 1][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i + 1]["ID"].ToString();
}
else
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtL_Click(object sender, ImageClickEventArgs e)
{
DataTable dt = (DataTable)ViewState["DataTable"];
ViewState["Index"] = dt.Rows.Count - 1;
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
if (dt.Rows.Count > 0)
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
}
Bind((int)ViewState["CurrentPageIndex"]);
}
protected void ImBtLast_Click(object sender, ImageClickEventArgs e)
{
ViewState["CurrentPageIndex"] = (int)ViewState["PageCount"] - 1;
Bind((int)ViewState["CurrentPageIndex"]);
}
protected void ImBtF_Click(object sender, ImageClickEventArgs e)
{
ViewState["Index"] = 0;
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
DataTable dt = (DataTable)ViewState["DataTable"];
if (dt.Rows.Count > 0)
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtU_Click(object sender, ImageClickEventArgs e)
{
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
DataTable dt = (DataTable)ViewState["DataTable"];
if (dt.Rows.Count > 0)
{
if (i > 0)
{
ViewState["Index"] = i - 1;
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i - 1][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i - 1]["ID"].ToString();
}
else
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtD_Click(object sender, ImageClickEventArgs e)
{
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
DataTable dt = (DataTable)ViewState["DataTable"];
if (dt.Rows.Count > 0)
{
if (i < dt.Rows.Count - 1)
{
ViewState["Index"] = i + 1;
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i + 1][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i + 1]["ID"].ToString();
}
else
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
protected void ImBtL_Click(object sender, ImageClickEventArgs e)
{
DataTable dt = (DataTable)ViewState["DataTable"];
ViewState["Index"] = dt.Rows.Count - 1;
int i = (int)ViewState["Index"];
this.Image1.ImageUrl = null;
if (dt.Rows.Count > 0)
{
this.Image1.ImageUrl = "http://sps003:9090/DocLib1/_w/" + dt.Rows[i][1].ToString().Replace(".", "_") + ".jpg";
this.LabIndex.Text = dt.Rows[i]["ID"].ToString();
}
ViewState["CurrentPageIndex"] = 0;
Bind(0);
}
}
===============一个SharePoint事件处理程序实例 .txt
[Update:呵呵,把代码缩进改了改……]
[重要UPDATE:今天实际在生产环境中测试,发现调用SPWeb的时候,一定要site.OpenWeb(WebID)才可以虚拟管理员身份,也就是说,直接site.OpenWeb()或properties.OpenWeb()是不行的!
另外,一定要在虚拟身份之后重新获得网站对象模型,才能使用提升到系统账户的安全性上下文。]
监控一个列表,一旦有新条目生成,就将这个条目的权限继承关系断开,并把发布者设置为只读。这样,所有新建数据都只有提交人只读可见,但系统帐号可以监控所有的。
只是个非常简单的例子,但可以暴露出很多值得注意的东西。
稍后将争取与了不起的Erucy一起写一篇详细介绍SharePoint新权限系统的文章。
public class DemoHandler : SPItemEventReceiver //继承SharePoint数据条目事件监控类
{
public override void ItemAdded(SPItemEventProperties properties) //重载ItemAdded函数,监控新建列表条目事件
{
SPSecurity.RunWithElevatedPrivileges(delegate() //用此方法模拟管理员账户运行此事件处理程序
{
using (SPSite site = new SPSite(properties.SiteId)) //用此方法的话就不用dispose()了
{
using (SPWeb web = site.OpenWeb(properties.OpenWeb().ID)) //注意获得web的方法!!!
{
try
{
SPList list = web.Lists[properties.ListId]; //获得触发事件的列表
SPListItem item = list.Items.GetItemById(properties.ListItemId); //获得触发事件的列表条目
{
public override void ItemAdded(SPItemEventProperties properties) //重载ItemAdded函数,监控新建列表条目事件
{
SPSecurity.RunWithElevatedPrivileges(delegate() //用此方法模拟管理员账户运行此事件处理程序
{
using (SPSite site = new SPSite(properties.SiteId)) //用此方法的话就不用dispose()了
{
using (SPWeb web = site.OpenWeb(properties.OpenWeb().ID)) //注意获得web的方法!!!
{
try
{
SPList list = web.Lists[properties.ListId]; //获得触发事件的列表
SPListItem item = list.Items.GetItemById(properties.ListItemId); //获得触发事件的列表条目
if (!item.HasUniqueRoleAssignments) item.BreakRoleInheritance(false); //将此条目取消权限继承,如果是“false”,则将去除所有权限,只保留系统账户,如果是“true”,则将上一级权限复制过来。
SPUser user = web.Users.GetByID(properties.CurrentUserId); //获得触发此事件的用户
SPUser user = web.Users.GetByID(properties.CurrentUserId); //获得触发此事件的用户
SPRoleAssignment ra = new SPRoleAssignment(web.EnsureUser(user.LoginName)); //生成一个新的角色分配
ra.RoleDefinitionBindings.Add(web.RoleDefinitions["读取"]); //将此角色分配绑定“读取”权限级别
item.RoleAssignments.Add(ra); //将此新权限绑定到列表条目上
}
catch (Exception ee)
{
}
}
ra.RoleDefinitionBindings.Add(web.RoleDefinitions["读取"]); //将此角色分配绑定“读取”权限级别
item.RoleAssignments.Add(ra); //将此新权限绑定到列表条目上
}
catch (Exception ee)
{
}
}
}
}
);
}
}
==================天气预报 获取源代码
}
);
}
}
==================天气预报 获取源代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
private static string _connString = ConfigurationManager.AppSettings["ConnectonString"].ToString();
private static string _url = ConfigurationManager.AppSettings["URL"].ToString();
private static string _citys = ConfigurationManager.AppSettings["Citys"].ToString();
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
private static string _connString = ConfigurationManager.AppSettings["ConnectonString"].ToString();
private static string _url = ConfigurationManager.AppSettings["URL"].ToString();
private static string _citys = ConfigurationManager.AppSettings["Citys"].ToString();
static void IUDData(string strsql)
{
SqlConnection conn = new SqlConnection(_connString);
try
{
conn.Open();
Console.WriteLine("连接数据库成功");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = strsql; //在这儿写sql语句
cmd.ExecuteNonQuery();
Console.WriteLine("数据插入成功!");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
conn.Close();
}
}
{
SqlConnection conn = new SqlConnection(_connString);
try
{
conn.Open();
Console.WriteLine("连接数据库成功");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = strsql; //在这儿写sql语句
cmd.ExecuteNonQuery();
Console.WriteLine("数据插入成功!");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
conn.Close();
}
}
static int ExistsData(string city, string today)//判断数据是否存在
{
SqlConnection conn = new SqlConnection(_connString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from [GSEGC_AD]..[Weather] where city='" + city + "' and today='" + today + "'";// "insert [Weather](city,datetime,today_weather) select "; //在这儿写sql语句
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
return 1;
}
else
{
return 0;
}
}
{
SqlConnection conn = new SqlConnection(_connString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from [GSEGC_AD]..[Weather] where city='" + city + "' and today='" + today + "'";// "insert [Weather](city,datetime,today_weather) select "; //在这儿写sql语句
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
return 1;
}
else
{
return 0;
}
}
static void Main(string[] args)
{
string city = "";
string today;
string today_weather = "";
string today_ltemp = "";
string today_htemp = "";
string today_pic = "";
string today_wind = "";
string tomorrow;
string tomorrow_weather = "";
string tomorrow_ltemp = "";
string tomorrow_htemp = "";
string tomorrow_pic = "";
string tomorrow_wind = "";
{
string city = "";
string today;
string today_weather = "";
string today_ltemp = "";
string today_htemp = "";
string today_pic = "";
string today_wind = "";
string tomorrow;
string tomorrow_weather = "";
string tomorrow_ltemp = "";
string tomorrow_htemp = "";
string tomorrow_pic = "";
string tomorrow_wind = "";
WebRequest webRequest = WebRequest.Create(_url);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
string[] citys = _citys.Split(new char[] { ',' });//得到数组
//string DeleteData = "delete [GSEGC_AD]..[Weather]";
//IUDData(DeleteData);
string sLine = "";
//string DeleteData = "delete [GSEGC_AD]..[Weather]";
//IUDData(DeleteData);
string sLine = "";
while (sLine != null)
{
sLine = streamReader.ReadLine();
for (int i = 1; i<citys.Length; i++)
{
if (sLine != null && sLine.StartsWith("new Array(\"" + i.ToString() + "\",\"" + citys[i] + "\""))
{
Console.WriteLine(i + " " + citys[i]);
{
sLine = streamReader.ReadLine();
for (int i = 1; i<citys.Length; i++)
{
if (sLine != null && sLine.StartsWith("new Array(\"" + i.ToString() + "\",\"" + citys[i] + "\""))
{
Console.WriteLine(i + " " + citys[i]);
string delimStr = ",";
string delim = "\"";
string delim = "\"";
sLine = sLine.Substring(sLine.IndexOf("(") + 1, sLine.LastIndexOf(")") - sLine.IndexOf("(") - 1);
string[] weatherInfo = sLine.Split(delimStr.ToCharArray());
city = weatherInfo[1].Trim(delim.ToCharArray());//城市名称
today = weatherInfo[2].Trim(delim.ToCharArray());
today_weather = weatherInfo[3].Trim(delim.ToCharArray());
today_ltemp = weatherInfo[4].Trim(delim.ToCharArray());
today_htemp = weatherInfo[5].Trim(delim.ToCharArray());
today_pic = weatherInfo[6].Replace("\\", "").Trim(delim.ToCharArray());
today_wind = weatherInfo[7].Trim(delim.ToCharArray());
tomorrow = weatherInfo[8].Trim(delim.ToCharArray());
tomorrow_weather = weatherInfo[9].Trim(delim.ToCharArray());
tomorrow_ltemp = weatherInfo[10].Trim(delim.ToCharArray());
tomorrow_htemp = weatherInfo[11].Trim(delim.ToCharArray());
tomorrow_pic = weatherInfo[12].Replace("\\", "").Trim(delim.ToCharArray());
tomorrow_wind = weatherInfo[13].Trim(delim.ToCharArray());
string[] weatherInfo = sLine.Split(delimStr.ToCharArray());
city = weatherInfo[1].Trim(delim.ToCharArray());//城市名称
today = weatherInfo[2].Trim(delim.ToCharArray());
today_weather = weatherInfo[3].Trim(delim.ToCharArray());
today_ltemp = weatherInfo[4].Trim(delim.ToCharArray());
today_htemp = weatherInfo[5].Trim(delim.ToCharArray());
today_pic = weatherInfo[6].Replace("\\", "").Trim(delim.ToCharArray());
today_wind = weatherInfo[7].Trim(delim.ToCharArray());
tomorrow = weatherInfo[8].Trim(delim.ToCharArray());
tomorrow_weather = weatherInfo[9].Trim(delim.ToCharArray());
tomorrow_ltemp = weatherInfo[10].Trim(delim.ToCharArray());
tomorrow_htemp = weatherInfo[11].Trim(delim.ToCharArray());
tomorrow_pic = weatherInfo[12].Replace("\\", "").Trim(delim.ToCharArray());
tomorrow_wind = weatherInfo[13].Trim(delim.ToCharArray());
string DeleteData = "delete [GSEGC_AD]..[Weather] where city='"+city+"'";
string strsql = "insert [GSEGC_AD]..[Weather](city,today,today_weather,today_ltemp,today_htemp,";
strsql += "today_pic,today_wind,tomorrow,tomorrow_weather,tomorrow_ltemp,tomorrow_htemp,tomorrow_pic,tomorrow_wind)";
strsql += "select '" + city + "','" + today + "','" + today_weather + "','" + today_ltemp + "','" + today_htemp + "','" + today_pic + "','" + today_wind + "','" + tomorrow + "','" + tomorrow_weather + "','" + tomorrow_ltemp + "','" + tomorrow_htemp + "','" + tomorrow_pic + "','" + tomorrow_wind + "'";
//Console.WriteLine(ExistsData(city, today));
//Console.WriteLine(sLine);
if (ExistsData(city, today) == 0)
{
IUDData(DeleteData);
IUDData(strsql);
}
else
{
Console.WriteLine("数据已经存在");
}
}
}
}
Console.Read();
string strsql = "insert [GSEGC_AD]..[Weather](city,today,today_weather,today_ltemp,today_htemp,";
strsql += "today_pic,today_wind,tomorrow,tomorrow_weather,tomorrow_ltemp,tomorrow_htemp,tomorrow_pic,tomorrow_wind)";
strsql += "select '" + city + "','" + today + "','" + today_weather + "','" + today_ltemp + "','" + today_htemp + "','" + today_pic + "','" + today_wind + "','" + tomorrow + "','" + tomorrow_weather + "','" + tomorrow_ltemp + "','" + tomorrow_htemp + "','" + tomorrow_pic + "','" + tomorrow_wind + "'";
//Console.WriteLine(ExistsData(city, today));
//Console.WriteLine(sLine);
if (ExistsData(city, today) == 0)
{
IUDData(DeleteData);
IUDData(strsql);
}
else
{
Console.WriteLine("数据已经存在");
}
}
}
}
Console.Read();
}
}
}
add.config 里的内容
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectonString" value="server=sqlsvr;database=GSEGC_AD;uid=adupdate;pwd=gsegc;"/>
<add key="URL" value="http://minisite.qq.com/Weather/index.html"/>
<add key="Citys" value=",北京,广州,上海,天津,重庆,沈阳,南京,武汉,成都,西安,石家庄,太原,郑州,长春,哈尔滨,呼和浩特,济南,合肥,杭州,福州,厦门,长沙,深圳,南宁,桂林,南昌,贵阳,香港,澳门,昆明,台北,拉萨,海口,兰州,西宁,银川,乌鲁木齐,"/>
</appSettings>
</configuration>
<configuration>
<appSettings>
<add key="ConnectonString" value="server=sqlsvr;database=GSEGC_AD;uid=adupdate;pwd=gsegc;"/>
<add key="URL" value="http://minisite.qq.com/Weather/index.html"/>
<add key="Citys" value=",北京,广州,上海,天津,重庆,沈阳,南京,武汉,成都,西安,石家庄,太原,郑州,长春,哈尔滨,呼和浩特,济南,合肥,杭州,福州,厦门,长沙,深圳,南宁,桂林,南昌,贵阳,香港,澳门,昆明,台北,拉萨,海口,兰州,西宁,银川,乌鲁木齐,"/>
</appSettings>
</configuration>
================================调用cs文件中的方法
新建一个 为cs.sql的 cs文件,内容
public class sql
{
public sql()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static int getid()
{
return 0;
}
}
{
public sql()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static int getid()
{
return 0;
}
}
当在 aspx页面调用时 Response.Write(sql.getid()); 得到数据
=====================获取当前页名称
System.IO.Path.GetFileName(Request.PhysicalPath);
======================== 定义数组并且判断数组中是否存在 某个字段
ArrayList al = new ArrayList();
string _ltdName = string.Empty;
string _ltdName = string.Empty;
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
al.Add("gseA");
al.Add("gsedA");
al.Add("gseiA");
al.Add("gswgA");
al.Add("gswmA");
}
_ltdName = Request.PhysicalPath;
_ltdName = _ltdName.Substring(0, _ltdName.LastIndexOf('.'));
if (al.Contains(_ltdName))
{
PageName = _ltdName.Replace(".aspx", "A.xml");
PopulateProductInfo("100");
Response.Write(PageName.ToString());
}
else
{
//PageName =al[0].ToString()+".xml";
PageName = "products.xml";
PopulateProductInfo("100");
}
}
{
if (!Page.IsPostBack)
{
al.Add("gseA");
al.Add("gsedA");
al.Add("gseiA");
al.Add("gswgA");
al.Add("gswmA");
}
_ltdName = Request.PhysicalPath;
_ltdName = _ltdName.Substring(0, _ltdName.LastIndexOf('.'));
if (al.Contains(_ltdName))
{
PageName = _ltdName.Replace(".aspx", "A.xml");
PopulateProductInfo("100");
Response.Write(PageName.ToString());
}
else
{
//PageName =al[0].ToString()+".xml";
PageName = "products.xml";
PopulateProductInfo("100");
}
}
===============下拉列表的数据邦定邦定
this.DropDownList1.DataSource = dtList; //dtList是一个datatable
this.DropDownList1.Items.Clear();
this.DropDownList1.DataTextField = "Title";
this.DropDownList1.DataValueField = "ProductId";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Clear();
this.DropDownList1.DataTextField = "Title";
this.DropDownList1.DataValueField = "ProductId";
this.DropDownList1.DataBind();
posted on 2007-06-20 14:00 RevengeBoy 阅读(1031) 评论(0) 编辑 收藏 举报