2010桌面
-------------------------------------------------------------------------------------------------------------- 泛型 反射 JQURY调用ajax ajax调用webservice linq 类工厂 mvc 匿名方法(C# 编程指南)。 序列化 触发器 泛型委托 socket GDI -------------------------------------------------------------------------------------------------------------- 四川省 广安市 广安区 新南街 新南门社区 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- DataTable dt = new DataTable(); dt = PublicMessageInfoDataTableCreate(); DataRow dr = dt.NewRow(); dr["msgReceiver"] = msg_Receiver; dr["msgSender"] = msg_Sender; dr["msg"] = msg;
if (objectName.Split(',').Length == 2) { dr["objectName"] = objectName.Split(',')[0]; dr["BatchID"] = objectName.Split(',')[1]; } else { dr["objectName"] = objectName; dr["BatchID"] = "0"; }
Guid endowId = Guid.Empty;//注意Empty
DropDownList3.SelectedIndex = DropDownList3.Items.IndexOf(DropDownList3.Items.FindByValue(endow.LowSurveyLevel.Id.ToString()));
在使用存储过程的时候遇到字符串类型转换为GUID类型的问题,解决方法如下:
string strid = "EF41A66B-25E1-46B2-964B-E4F70534807F";
System.Guid myguid=new Guid(strid);
com.Parameters.Add("@para",SqlDbType.UniqueIdentifier);//c#的Guid对应sql里的UniqueIdentifier com.Parameters["@para"].Value = myguid;
1、aspx页面中的文本框控件
程序代码 <asp:TextBox ID="textbox1" runat="server">请输入您的用户名</asp:TextBox>
2、在相关的cs页面中输入以下红色的代码
程序代码 protected void Page_Load(object sender, EventArgs e) { textbox1.Attributes.Add("onfocus", "if (this.value=='请输入您的用户名') this.value=''"); textbox1.Attributes.Add("onblur", "if (this.value=='') this.value='请输入您的用户名'"); }
------------------------------------------------------------------------------------------------------------------- c++优先级 逻辑运算 not 算术运算(*,/,%) 算术运算符(+,-) 相对关联运算符(<,>,<=,>=) 相对关联运算符(=,!=) 逻辑运算符 and 逻辑运算符 or 赋值(assignment)运算符 ---------------------------------------------------------------------------------------------------------------------- 联想ThinkPad R400(2784A74) -----------------------------------------------上传大文件-------------------------------------------------------------
在web.config中增加以下一段 executionTimeout 获取或设置请求的允许执行时间。 maxRequestLength 获取或设置请求的最大大小。 useFullyQualifiedRedirectUrl 获取或设置一个值,该值指示是否完全限定客户端重定向。 <httpRuntime executionTimeout="30000" maxRequestLength="2097151" useFullyQualifiedRedirectUrl="false"/> --------------------------------------------------------------------------------------------------------------
---------------------------------------command.ExecuteScalar()---------------------------------------------------- C# public void CreateSqlCommand(string queryString, SqlConnection connection) { SqlCommand command = new SqlCommand(queryString, connection); command.Connection.Open(); command.ExecuteScalar();//返回单个结果--可用与 connection.Close(); } ----------------------------------------------------------------------------------------------------------------------
---------------------------------------command.ExecuteNonQuery()---------------------------------------------------- C# private static void CreateCommand(string queryString,string connectionString) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); command.Connection.Open(); command.ExecuteNonQuery();//对于 UPDATE、INSERT 和 DELETE 语句,返回值为该命令所影响的行数 } } ----------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------- parenthesis D.J.[p?'renθ?s?s] K.K.[p?'r?nθ?s?s] n. 插入语,插入成分 圆括号 left parenthesis 左括号 right parenthesis 右括号 roundparenthesis 圆括弧, 圆括号 间歇,插曲 parenthetic adj. ---------------------------------获取web.config中的字节--------------------------------------------------- /// 获取到Web.config中配置的系统所属省 /// </summary> public static string GetProvince { get { return ConfigurationSettings.AppSettings["Province"]; } } ---------------------------------------------------------------------------------------------------------------------- 泛型 ---------------------------------------------------------------------------------------------------------------------- List<T> 表示可通过索引访问的对象的强类型列表。提供用于对列表进行搜索、排序和操作的方法。 ---------------------------------------------------------------------------------------------------------------------- Queue<T> 表示对象的先进先出集合。 ---------------------------------------------------------------------------------------------------------------------- IList 接口 表示可按照索引单独访问的对象的非泛型集合。 备注 IList 泛型接口是 ICollection 接口的子代,并且是所有非泛型列表的基接口。 IList 实现有三种类别:只读、固定大小、可变大小。无法修改只读 IList。固定大小的 IList 不允许添加或移除元素,但允许修改现有元素。可变大小的 IList 允许添加、移除和修改元素。
---------------------------------------------------------------------------------------------------------------------- Reference Types (C# Reference) 引用类型的变量又称为对象,可存储对实际数据的引用。 ---------------------------------------------------------------------------------------------------------------------- 泛型类(C# 编程指南)
泛型类封装不是特定于具体数据类型的操作。泛型类最常用于集合,如链接列表、哈希表、堆栈、队列、树等。像从集合中添加和移除项这样的操作都以大体上相同的方式执行,与所存储数据的类型无关。
---------------------------------------------------------------------------------------------------------------------- 泛型委托
委托 可以定义自己的类型参数。引用泛型委托的代码可以指定类型参数以创建已关闭的构造类型,就像实例化泛型类或调用泛型方法一样,如下例所示: public delegate void Del<T>(T item); public static void Notify(int i) { }
Del<int> m1 = new Del<int>(Notify);
---------------------------------------------------------------------------------------------------------------------- Lambda表达式 var list = new [] { "aa", "bb", "ac" }; var result = Array.FindAll(list, s => (s.IndexOf("a") > -1)); foreach (var v in result) Console.WriteLine(v); ---------------------------------------------------------------------------------------------------------------------- 这个不理解 public delegate int mydg(int a, int b); public static class LambdaTest { public static int oper(this int a, int b, mydg dg) { return dg(a, b); } } Console.WriteLine(1.oper(2, (a, b) => a + b)); Console.WriteLine(2.oper(1, (a, b) => a - b)); ---------------------------------------------------------------------------------------------------------------------- var persons = new List<Person> { new Person {username = "a", age=19}, new Person {username = "b", age=20}, new Person {username = "a", age=21}, }; var selectperson = from p in persons where p.age >= 20 select p.username.ToUpper(); foreach(var p in selectperson) Console.WriteLine(p); ---------------------------------------------------------------------------------------------------------------------- DataContext是实体和数据库之间的桥梁,那么首先我们需要定义映射到数据表的实体。 ---------------------------------------------------------------------------------------------------------------------- 如果没有指定Column特性的Name属性,那么系统会把属性名作为数据表的字段名,也就是说实体类的属性名就需要和数据表中的字段名一致。 ---------------------------------------------------------------------------------------------------------------------- DbParameter 需要引用using System.Data.Common;命名空间
---------------------------------------------------------------------------------------------------------------------- string newcity = "Shanghai"; ctx.ExecuteCommand("update Customers set City={0} where CustomerID like 'A%'", newcity); IEnumerable<Customer> customers = ctx.ExecuteQuery<Customer>("select * from Customers where CustomerID like 'A%'");
---------------------------------------------------------------------------------------------------------------------- linq穿件数据库 namespace WebApplication1 { //创建数据库 protected void Button1_Click(object sender, EventArgs e)//btn事件 { testContext ct = new testContext("server=YFB-YINDONGLI\\YZZZJ;User ID=sa;Password=ygzzj;database=testDB;Connection Reset=FALSE"); ct.CreateDatabase();
} //--------------------test类--------------------------- using System.Data.Linq.Mapping; using System.Data.Linq; using System.Data; [Table(Name="test")] public class test { [Column(IsPrimaryKey = true, IsDbGenerated = true)] public int ID { get; set; } [Column(DbType="varchar(20)")] public string Name{get;set;}
} //---------------testContext类---------------------------- class testContext:DataContext {
public Table<test> test;
public testContext(string connection): base(connection) { }
} } ---------------------------------------------------------------------------------------------------------------------- var conn = new SqlConnection("server=YFB-YINDONGLI\\YZZZJ;User ID=sa;Password=ygzzj;database=Northwind;Connection Reset=FALSE"); var ctx = new DataContext(conn); var cmd = new SqlCommand("select* from customers where customerID like 'H%'",conn); conn.Open(); var reader = cmd.ExecuteReader(); GridView1.DataSource = ctx.Translate<Customer>(reader); GridView1.DataBind(); ---------------------------------------------------------------------------------------------------------------------- linq 之 DataContext DataContext类型(数据上下文)是System.Data.Linq命名空间下的重要类型,用于把查询句法翻译成SQL语句,以及把数据从数据库返回给调用方和把实体的修改写入数据库。 DataContext提供了以下一些使用的功能: 以日志形式记录DataContext生成的SQL 执行SQL(包括查询和更新语句) 创建和删除数据库 ---------------------------------------------------------------------------------------------------------------------- var yibanfenzu = from c in ctx.Customers group c by c.Country into g where g.Count() > 5 orderby g.Count() descending select new { 国家 = g.Key, 顾客数 = g.Count() }; ---------------------------------------------------------------------------------------------------------------------- 当 SET NOCOUNT 为 ON 时,不返回计数。当 SET NOCOUNT 为 OFF 时,返回计数。 ---------------------------------------------------------------------------------------------------------------------- (5) 查询选修课程超过5门的学员学号和所属单位?
答:select sn,sd from s where s# in(select s# from sc group by s# having count(distinct c#)>5) ---------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------- SQL HAVING 语法 SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value
---------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------- sql server联机丛书都说的很清楚了: 可使用 UNIQUE 约束确保在非主键列中不输入重复值。尽管 UNIQUE 约束和 PRIMARY KEY约束都强制唯一性,但在强制下面的唯一性时应使用 UNIQUE 约束而不是 PRIMARY KEY 约束:
非主键的一列或列组合。 一个表可以定义多个 UNIQUE 约束,而只能定义一个 PRIMARY KEY 约束。
允许空值的列。 允许空值的列上可以定义 UNIQUE 约束,而不能定义 PRIMARY KEY 约束。
---------------------------------------------------------------------------------------------------------------------- left join 是 join左边的表完全显示出来,右边无值的为null ---------------------------------------------------------------------------------------------------------------------- (1)使用标准SQL嵌套语句查询选修课程名称为’税收基础’的学员学号和姓名?
--解法一: select S#,SN from S where S# in (select S# from C, SC where C.C#=SC.C# and C.CN='税收基础') --解法二: select S.S#,S.SN from S inner join (select S# from C left join SC on C.C#=SC.C# where C.CN='税收基础') T on T.S#=S.S# ---------------------------------------------------------------------------------------------------------------------- linq延迟执行 IQueryable query = from c in ctx.Customers select c; ---------------------------------------------------------------------------------------------------------------------- 延迟执行的优点在于我们可以像拼接SQL那样拼接查询句法,然后再执行: var query = from c in ctx.Customers select c; var newquery = (from c in query select c).OrderBy(c => c.CustomerID); ---------------------------------------------------------------------------------------------------------------------- 用反射获取类型 public void Process( object processObj ) { Type t = processsObj.GetType(); if( t.GetInterface(“ITest”) !=null ) … }
---------------------------------------------------------------------------------------------------------------------- 这样,在具体页面,我们就可以通过如下代码添加 CSS 引用:
protected void Page_Load(object sender, EventArgs e) { ControlHelper.AddStyleSheet(this.Page, "css/projectPage.css"); }
本篇文章来自<A href='http://www.soidc.net'>IDC专家网</a> 原文链接:http://www.soidc.net/articles/1213781277395/20060524/1214038506649_1.html ---------------------------------------------------------------------------------------------------------------------- .aspx、MasterPage、.ascx加载顺序
1. Master page中的用户控件的 page_init 2. Aspx页面中的用户控件的 page_init 3. Master page的page_init 4. Aspx的 page_init 5. Aspx的page_load 6. Master page的page_load 7. Master page中的用户控件的 page_load 8. Aspx页面中的用户控件的 page_load
.aspx、.master、ascx这三个页面中Page_Load的执行顺序是:.aspx中的pg-->.master中的 pg-->ascx中的pg( pg-->page_load)
---------------------------------------------------------------------------------------------------------------------- google圆角按钮 <html> <head> <style> .g_a{display:inline-block; border-width:1px 0; border-color:#bbbbbb; border-style:solid; vertical-align:middle;} .g_b{float:left; background:#e3e3e3; border-width:0 1px; border-color:#bbbbbb; border-style:solid; margin:0 -1px; position:relative;} .g_c{display:block; line-height:0.6em; background:#f9f9f9; border-bottom:2px solid #eeeeee;} .g_d{display:block; padding:0.1em 0.6em; margin-top:-0.6em; cursor:pointer;}
</style> </head> <body>
<a href="#nogo" class="g_a"> <span class="g_b"> <span class="g_c"> </span> <span class="g_d">圆角按钮</span> </span> </a> <input type="button" value="圆角按钮"> </body> </html> ---------------------------------------------圆角div-------------------------------------------------------------------- <html> <head> <style type="text/css"> /*这些对#xsnazzy下面的标签的控制 #xsnazzy h1, #xsnazzy h2, #xsnazzy p {margin:0 10px; letter-spacing:1px;} #xsnazzy h1 {font-size:2.5em; color:#fff;} #xsnazzy h2 {font-size:2em;color:#06a; border:0;} #xsnazzy p {padding-bottom:0.5em;} #xsnazzy h2 {padding-top:0.5em;} #xsnazzy {background: transparent; margin:1em;} */ .xtop, .xbottom {display:block; background:transparent; font-size:1px;width:300px;} .xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden;} .xb1, .xb2, .xb3 {height:1px;} .xb2, .xb3, .xb4 {background:#fff; border-left:1px solid #08c; border-right:1px solid #08c;} .xb1 {margin:0 5px; background:#08c;} .xb2 {margin:0 3px; border-width:0 2px;} .xb3 {margin:0 2px;} .xb4 {height:2px; margin:0 1px;}
.xboxcontent {display:block; background:#fff; border:0 solid #08c; border-width:0 1px;width:300px; } /*这里是内容的那个div要和上面xtop.xbottom的width 相同*/ /*其background要与.xb2, .xb3, .xb4 {background:#fff;---相同*/
</style> </head> <body> <div id="xsnazzy"> <b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b> <div class="xboxcontent">
------------------在这里添写内容-------------
</div> <b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b> </div> </body> </html>
---------------------------------------------------------------------------------------------------------------------- 1、在1个页面中应用Theme: 如果想在某1个页面中应用Theme,直接在aspx文件中修改<%@ Page Theme="..." %>,比如你想这个页面应用default2 theme,设置<%@ Page Theme="default2" %>就OK
2、在所有页面应用同1个Theme: 如果要在所有页面上使用相同的Theme,在web.config中的<system.web>节点下加上句<pages theme="..."/>
3、让控件不应用Theme: 第1个例子中我们看到了2个Label的风格都变了,就是说.skin文件中的风格在页面上所有Label都起作用了。但有时我们希望某1个Label不应用.skin中的风格,这时你只需设置Label的EnableTheming属性为false的时候就可以了。 也许你还想不同的label显示不同的风格,你只需设置label的SkinID属性就可以,见下面的实例: App_Themes\default\1.skin
<asp:label runat="server" font-bold="true" forecolor="Red" /> <asp:label runat="server" SkinID="Blue" font-bold="true" forecolor="blue" /> deafult.aspx
<%@ Page Language="C#" Theme="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 id="Head1" runat="server"> <title>Page with Example Theme Applied</title> </head> <body> <form id="form1" runat="server"> <asp:Label ID="Label2" runat="server" Text="Hello 2" SkinID="Blue" /><br /> <asp:Label ID="Label3" runat="server" Text="Hello 3" /><br /> </form> </body> </html> ---------------------------------------------------------------------------------------------------------------------- 三、后台代码轻松为网站换府肤 前面讲的都是在aspx文件或web.config中应用theme,而在blog这样的每个用户都有不同的skin的网站中用上面的方法来实现换skin显然是不方便的。 下面就介绍怎么在后台代码中动态的引用theme来解决上面的情况,theme必须在page被请求的最早期就应用上,所以我们必须在Page_PreInit事件中写代码,代码很简单,就1句: Page.Theme = "..."; 这里我们只要从数据库中去读取每个用户设置的不同theme名就可以轻松实现每个用户都有不同的skin了。

浙公网安备 33010602011771号