您的位置:首页 > 编程语言

个人随笔-20070621关键代码-2

2007-06-21 18:09 281 查看
1.获取最大id
2.在已经得到表的情况下 用gridview对其进行筛选 排序得到最大值
(1). 定义列时必须注意System.Int32
3.曾经年轻时代的代码 连接数据方法,添加删除修改等

4.保留小数的几中种方法

5.function 中调用后台 变量

6.透明flash

7.div 弹出窗口

8.加个外框

9.0823Membership 所设计到的代码

10.string[] 与ArrayList 的转换 并且判断是否包含某个 字段

=======================获取最大id
string getid = "select max(sp_id) from SoppingBag";//sp_id 类型为int 型的列,SoppingBag:数据表名

public static int GetMax_id(string strcmd)//获取留言反馈 数据库中的 最大 ID

{

string CString="integrated security=SSPI;data source=.;persist security info=False;initial catalog=gunrunning";

SqlConnection Conn=new SqlConnection(CString);//创建连接对象
int index;

System.Data.SqlClient.SqlCommand cmd = new SqlCommand();

cmd.CommandText = strcmd;

cmd.Connection = Conn;

Conn.Open();

object re = cmd.ExecuteScalar();

Conn.Close();

index = Convert.ToInt32(re);

return index;

}

====================在已经得到表的情况下 用gridview对其进行筛选 排序得到最大值

static int GetMaxId(DataTable dt)

{

int s = 0;

DataView dv = dt.DefaultView;

dv.Sort = "ProductId DESC";//ProductId 为列名

s =Convert.ToInt32(dv[0].Row["ProductId"]);

return s + 1;

}

定义列时必须注意System.Int32
DataColumn column = new DataColumn();

column.DataType = System.Type.GetType("System.Int32");

column.AllowDBNull = false;

column.Caption = "ProductId";

column.ColumnName = "ProductId";

=========================曾经年轻时代的代码 连接数据方法,添加删除修改等
public static DataSet gungunDb(string Table)

{

string ConnString = "integrated security=SSPI;data source=.;persist security info=False;initial catalog=gunrunning";

string CmdString= "select * from "+Table;

SqlConnection conn = new SqlConnection (ConnString);

conn.Open();

SqlDataAdapter Ada =new SqlDataAdapter(CmdString,conn);

DataSet ds = new DataSet();

Ada.Fill(ds);

conn.Close();

return ds;

}

public static int UpdateInsertDelete(string CmdString)

{

string ConnString = "integrated security=SSPI;data source=.;persist security info=False;initial catalog=gunrunning";

SqlConnection conn = new SqlConnection (ConnString);

conn.Open();

SqlCommand cmd = new SqlCommand (CmdString,conn);

cmd.ExecuteNonQuery();

conn.Close();

return 0;

}

================== 保留小数的几中种方法

方法--:

decimal de = Math.Round(2.123456465m,2);

TextBox1.Text = de.ToString();

二:

double de = 2.123456465;

Response.Write (de.ToString("N5"));//这里n5表示保留5位小数

double de = 2.123456465;

Response.Write (de.ToString("0.000000"));//这里00000表示保留5位小数

=====================视频播放

<object id="player" width="200" height="200" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">

<param name="AutoStart" value="-1" />

<param name="Balance" value="0" />

<param name="Enabled" value="-1" />

<param name="EnableContextMenu" value="-1" />

<param name="Url" value="要显示的图片或者视频文件地址" />

<param name="PlayCount" value="10" />

<param name="Rate" value="1" />

<param name="CurrentPosition" value="0" />

<param name="CurrentMarker" value="0" />

<param name="DefaultFrame" value="" />

<param name="stretchToFit" value="0" />

<param name="volume" value="50" />

<param name="mute" value="0" />

<param name="uiMode" value="None" />

<param name="windowlessVideo" value="0" />

<param name="fullScreen" value="0" />

<param name="enableErrorDialogs" value="-1" />

<!--是否自动播放-->

<!--调整左右声道平衡,同上面旧播放器代码-->

<!--播放器是否可人为控制-->

<!--是否启用上下文菜单-->

<!--播放的文件地址-->

<!--播放次数控制,为整数-->

<!--播放速率控制,1为正常,允许小数,1.0-2.0-->

<!--控件设置:当前位置-->

<!--控件设置:当前标记-->

<!--显示默认框架-->

<!--是否按比例伸展-->

<!--默认声音大小0%-100%,50则为50%-->

<!--是否静音-->

<!--播放器显示模式:Full显示全部;mini最简化;None不显示播放控制,只显示视频窗口;invisible全部不显示-->

<!--如果是0可以允许全屏,否则只能在窗口中查看-->

<!--开始播放是否自动全屏-->

<!--是否启用错误提示报告-->

</object>

============== 得到一个字符串中 某个字符的个数

string str = "fdsfds/fdsfd/s//fd/sfds/sfds";

int i = str.Split('/').Length - 1;
string path = "/node";

string rootpath = "SiteMap";

for (int j = 0; j < i; j++)

{

rootpath = rootpath + path;

}

Response.Write(rootpath);

============== function 中调用后台 变量

function getpet () {

var birthyear = <%= i %> ;

}

后代的定义

public int i = 1986;

=============透明flash

<embed src=images/revengeboy.swf wmode=transparent width=700 height=87>

==========div 弹出窗口

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

</style>

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

//关闭弹出层调用函数

function hiddenWindows()

//打开弹出层调用的函数,可控制层的宽度和高度

function openWindows(width,height,gname_old)

</script>

</head>

<body>

<table width="500">

<tr>

<td>

<form id="form1" name="form1" method="post" action="">

</form>

<input type="submit" name="Submit" onclick="openWindows(300,80,'123');" value="提交" /></td>

<input id="Button2" type="button" value="button" onclick="openWindows(300,80,'123');"/>

</tr>

</table>

<div id="LockWindows" style="z-index: 101"> 

</div>

<div id="WindowDIV" style="display:none; z-index: 102;" >

<div id="popupControls" >

<table width="100%"><tr><td align="left" style="height: 22px">修改照片内容</td>

<td align="right" style="height: 22px">

<img src="http://pic.51.com/i/uc/close.gif" onclick="hiddenWindows();" />

</td>

</tr>

</table>

</div>

<div id="editControls">

<form id="form2" name="form2" method="post" action="">

分类名改为: <input name="gname" type="text" /><br><br>

<input type="submit" name="Submit2" style="background-color:#cb3497; color:#FFFFFF" onclick="hiddenWindows();" value="确定" /> 

<input type="submit" name="Submit2" style="background-color:#cb3497; color:#FFFFFF" onclick="hiddenWindows();" value="取消" />

</form>

</div>

</div>

</body>

</html>

==============在存储过程中 定义表变量

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go
ALTER PROCEDURE [dbo].[Pagination_Revengeboy]

(@startIndex INT,

@pageSize INT,

@WhichID varchar(16),

@TableName nvarchar(50)

)

AS

declare @Tab nvarchar(50)

declare @sql varchar(200)

set @Tab= @TableName

set @sql = 'WITH tablelist AS (SELECT ROW_NUMBER() OVER (ORDER BY Tmp.'+ @WhichID+' DESC) AS Row, * from '+ @Tab +' as Tmp)

SELECT * FROM tablelist WHERE Row between '+cast(@startIndex as varchar(20)) +' and '+ cast(@startIndex + @pageSize -1 as varchar(20))

begin

exec (@sql)

print @sql

end

==============加个外框

<fieldset style="height: 191px; padding-bottom:6px; padding-top:4px; width: 340px;"><legend><span>

<asp:Label ID="lbCompanyInfors" runat="server" Text="revengeboy"></asp:Label></span></legend>

内容

</fieldset>

=========0823Membership 所设计到的代码

后台代码

using System;

using System.Data;

using System.Configuration;

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.SqlClient;

public partial class _Default : System.Web.UI.Page

前台代码

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

<!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>

  

<table>

<tr>

<td style="width: 100px">

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="同步AD" /></td>

<td style="width: 100px">

<asp:LoginStatus ID="LoginStatus1" runat="server" />

</td>

<td align="right" style="width: 100px">

<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="获取" /> </td>

</tr>

<tr>

<td style="width: 100px">

</td>

<td style="width: 100px">

<asp:ListBox ID="listUser" runat="server" Height="258px" Width="181px"></asp:ListBox></td>

<td style="width: 100px">

<asp:ListBox ID="list2" runat="server" Height="229px" Width="163px"></asp:ListBox></td>

</tr>

<tr>

<td style="width: 100px">

</td>

<td style="width: 100px">

<asp:Button ID="BtnDel" runat="server" OnClick="BtnDel_Click" Text="delete" /></td>

<td style="width: 100px">

<asp:Button ID="Button2" runat="server" OnClick="Button2_Click1" Text="添加到管理员" /></td>

</tr>

</table>

<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="锁定" />

<asp:Button ID="Button5" runat="server" OnClick="Button5_Click" Text="解锁" /> <br />

 <br />

</div>

</form>

</body>

</html>

=========string[] 与ArrayList 的转换 并且判断是否包含某个 字段

string[] ListRoles = Roles.GetAllRoles();

ArrayList al = new ArrayList(ListRoles);

if (al.Contains(RolesName))

{

//Response.Write("已存在"+RolesName);

}

else

{

//Response.Write("不存在" + RolesName);

Roles.CreateRole(RolesName);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: