.NET
- .NET 委托/事件_开水报警
//事件类,定义事件订阅消息及触发事件
public class TempterLisenting
{
//public event EventHandler<WaterTempterEventAgrs> WaterEvent;
public delegate void WaterEventHandler(object sender, WaterTempterEventAgrs e);
public event WaterEventHandler WaterEvent;
public void WaterTempterAdd(int waterTempter)
{
if (WaterEvent != null)
{
WaterEvent(this, new WaterTempterEventAgrs(waterTempter));
}
}
}
//客户类,事件订阅者
public class Listener
{
public void IsWaterBoiling(object sender, WaterTempterEventAgrs e)
{
if (e.WaterTempter >= 90 && e.WaterTempter <= 99)
{
Console.WriteLine("the water is will boiling:{0}", e.WaterTempter);
}
else if (e.WaterTempter == 100)
{
Console.WriteLine("the water is boiling:{0}", e.WaterTempter);
}
}
public void Register(TempterLisenting listener)
{
listener.WaterEvent += IsWaterBoiling;
}
}
*******************
public class WaterTempterPublish
{
public delegate void WaterTempterDel(int tempter);
public event WaterTempterDel waterTempterevent;
public void WatreTempterAdd(int tempter)
{
if (waterTempterevent != null)
{
waterTempterevent(tempter);
}
}
}
public class WaterTempterListening
{
public void IsWaterBoiling(int tempter)
{
if (tempter < 100)
{
Console.WriteLine("the waterTempter is :{0}", tempter);
}
else if (tempter == 100)
{
Console.WriteLine("the water is Boiling,Now the waterTempter is :{0}", tempter);
}
}
public void Register(WaterTempterPublish waterTemprerPublish)
{
waterTemprerPublish.waterTempterevent += IsWaterBoiling;
}
}
- .NET 事件与委托_C#语言程序设计基础
namespace CodeSample
{
public delegate void BookDelegate(string bookName, string bookType);
public class Custormers
{
private string custormerName;
private string custormerBooktype;
public string CustormerName
{
get { return custormerName; }
set { custormerName = value; }
}
public string CustormerBooktype
{
get { return custormerBooktype; }
set { custormerBooktype = value; }
}
public Custormers(string m_custormerName, string m_custormerBooktype)
{
custormerBooktype = m_custormerBooktype;
custormerName = m_custormerName;
}
public void Registre(BookStore bookStore)
{
bookStore.BookDelegate += BookStore_BookDelegate;
}
void BookStore_BookDelegate(string bookName, string bookType)
{
if (bookType == CustormerBooktype)
{
Console.WriteLine("{0},您好。您在本店预约的书类为"{1}"的书籍<<{2}>>到货了。", custormerName, bookType, bookName);
}
}
}
public class BookStore
{
public event BookDelegate BookDelegate;
public void NewBook(string bookName, string bookType)
{
BookDelegate(bookName, bookType);
}
}
public class CodeSampleMain
{
public static void Main()
{
BookStore bookStore = new BookStore();
Custormers[] custormer = new Custormers[3];
custormer[0] = new Custormers("黄**", "计算机");
custormer[1] = new Custormers("二少", "英语");
custormer[2] = new Custormers("**杰", "玄幻小说");
for (int i = 0; i < custormer.Length; i++)
{
custormer[i].Registre(bookStore);
}
bookStore.NewBook("计算机组成原理", "计算机");
bookStore.NewBook("走遍美国", "英语");
bookStore.NewBook("紫川", "玄幻小说");
Console.ReadKey();
}
}
}
JavaScript
- jQuery version_0.01
(function () {
var $ = (function () {
function f(selector, context) {
return f.prototype.init(selector, context);
}
f.prototype.init = function (selector, context) {
context = context || document;
var nodeList = context.querySelectorAll(selector);
this.length = nodeList.length;
this.elements = [];
for (var i = 0; i < this.length; i++) {
this.elements[i] = nodeList[i];
}
return this;
};
return f;
})();
window.$ = $;
})();
- jQuery Core
(function (window, undefined) {
var jQuery = (function () {
// 构建jQuery对象
var jQuery = function (selector, context) {
return new jQuery.fn.init(selector, context, rootjQuery);
};
// jQuery对象原型
jQuery.fn = jQuery.prototype = {
constructor : jQuery,
init : function (selector, context, rootjQuery) {
// selector有以下7种分支情况:
// DOM元素
// body(优化)
// 字符串:HTML标签、HTML字符串、#id、选择器表达式
// 函数(作为ready回调函数)
// 最后返回伪数组
}
};
//把jQuery的prototype赋值给init方法的prototype
jQuery.fn.init.prototype = jQuery.fn;
// 合并内容到第一个参数中,后续大部分功能都通过该函数扩展
// 通过jQuery.fn.extend扩展的函数,大部分都会调用通过jQuery.extend扩展的同名函数
jQuery.extend = jQuery.fn.extend = function () {};
// 在jQuery上扩展静态方法
jQuery.extend({
// ready bindReady
// isPlainObject isEmptyObject
// parseJSON parseXML
// globalEval
// each makeArray inArray merge grep map
// proxy
// access
// uaMatch
// sub
// browser
});
return jQuery;
})();
window.jQuery = window.$ = jQuery;
})(window);
SQL
- SQL递归查询
CREATE TABLE [aaa](
[id] [int] NULL,
[pid] [int] NULL,
[name] [nchar](10)
)
GO
INSERT INTO aaa VALUES(1,0,'a')
INSERT INTO aaa VALUES(2,0,'b')
INSERT INTO aaa VALUES(3,1,'c')
INSERT INTO aaa VALUES(4,1,'d')
INSERT INTO aaa VALUES(5,2,'e')
INSERT INTO aaa VALUES(6,3,'f')
INSERT INTO aaa VALUES(7,3,'g')
INSERT INTO aaa VALUES(8,4,'h')
GO
下面的Sql是查询出1结点的所有子结点
with my1 as(select * from aaa where id = 1
union all select aaa.* from my1, aaa where my1.id = aaa.pid
)
select * from my1 --结果包含1这条记录,如果不想包含,可以在最后加上:where id <> 1
下面的Sql是查询出8结点的所有父结点
with my1 as(
select * from aaa where id = 8
union all select aaa.* from my1, aaa where my1.pid = aaa.id
)
select * from my1;
下面是递归删除1结点和所有子结点的语句
with my1 as(
select * from aaa where id = 1
union all select aaa.* from my1, aaa where my1.id = aaa.pid
)
delete from aaa where exists (select id from my1 where my1.id = aaa.id)