1.这两天在考虑一个问题,频繁的读写磁盘会不会对磁盘造成影响。最后看了http://www.cnblogs.com/slime/archive/2010/03/09/1681198.html 此文章,明白了,我1秒有最多22个线程的读写根本不算是频繁读写。
2.怎么保存一个byte[]到文本中去。
3.在判断状态的时候,太多if,else经常会有漏掉状态的情况,考虑使用 职责链模式。
最近在找如果让GridView有可以改变列宽的能力,找了很久,同时也要用到updatepanle,其实是自己太懒了,不注意去分析,最后终于看到有个加拿大人以此写了一个ajax的扩展控件。于是拿过来用。出了一些问题。因为他用的是ajaxtoolkit的早期版本。在.net3.5会报告说是找不到ajaxtoolkit,其实很简单,看了,ajaxtoolkit的代码,将他源码中最后注册部分的ajaxtookit变成Sys.Extended.UI,注意是GridViewResizeBehavior.js.文件。
1 /*
2 This source code was adapted from Matt Berseth code:
3 http://mattberseth.com/blog/2007/08/creating_a_gridview_with_resiz.html
4 */
5
6 Type.registerNamespace('LavaBlast.AJAX.GridViewResizeExtender');
7
8 LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior = function(element) {
9 LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior.initializeBase(this, [element]);
10
11 // Properties
12 // true when a header is currently being resized
13 this._isResizing;
14 // a reference to the header column that is being resized
15 this._element;
16 // an array of all of the tables header cells
17 this._ths;
18 }
19
20 LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior.prototype = {
21
22 initialize : function() {
23 LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior.callBaseMethod(this, 'initialize');
24
25 // get all of the th elements from the gridview
26 this._ths = this.get_element().getElementsByTagName('TH');
27
28 var args = {behavior: this};
29
30 // if the grid has at least one th element
31 if(this._ths.length > 1){
32
33 for(i = 0; i < this._ths.length; i++){
34 // determine the widths
35 this._ths[i].style.width = Sys.UI.DomElement.getBounds(this._ths[i]).width + 'px';
36
37 // attach the mousemove and mousedown events
38 if(i < this._ths.length - 1){
39 $addHandler(this._ths[i], 'mousemove', Function.createCallback(this._onMouseMove, args));
40 $addHandler(this._ths[i], 'mousedown', Function.createCallback(this._onMouseDown, args));
41 }
42 }
43
44 // add a global mouseup handler
45
46 $addHandler(document, 'mouseup', Function.createCallback(this._onMouseUp, args));
47 // add a global selectstart handler
48 $addHandler(document, 'selectstart', Function.createCallback(this._onSelectStart, args));
49 }
50 },
51
52 _onMouseMove : function(args, e){
53 if(e.behavior._isResizing){
54 // determine the new width of the header
55 var bounds = Sys.UI.DomElement.getBounds(e.behavior._element);
56 var width = args.clientX - bounds.x;
57
58 // we set the minimum width to 1 px, so make
59 // sure it is at least this before bothering to
60 // calculate the new width
61 if(width > 1)
62 {
63 // get the next th element so we can adjust its size as well
64 var nextColumn = e.behavior._element.nextSibling;
65 var nextColumnWidth;
66 if(width < e.behavior._toNumber(e.behavior._element.style.width)){
67 // make the next column bigger
68 nextColumnWidth = e.behavior._toNumber(nextColumn.style.width) + e.behavior._toNumber(e.behavior._element.style.width) - width;
69 }
70 else if(width > e.behavior._toNumber(e.behavior._element.style.width)){
71 // make the next column smaller
72 nextColumnWidth = e.behavior._toNumber(nextColumn.style.width) - (width - e.behavior._toNumber(e.behavior._element.style.width));
73 }
74
75 // we also don't want to shrink this width to less than one pixel,
76 // so make sure of this before resizing ...
77 if(nextColumnWidth > 1){
78 e.behavior._element.style.width = width + 'px';
79 nextColumn.style.width = nextColumnWidth + 'px';
80 }
81 }
82 }
83 else
84 {
85 // get the bounds of the element. If the mouse cursor is within
86 // 4px of the border, display the e-cursor -> cursor:e-resize
87 var bounds = Sys.UI.DomElement.getBounds(args.target);
88 if(Math.abs((bounds.x + bounds.width) - (args.clientX)) <= 4) {
89 args.target.style.cursor = 'e-resize';
90 }
91 else{
92 args.target.style.cursor = '';
93 }
94 }
95 },
96
97 _onMouseDown : function(args, e){
98 // if the user clicks the mouse button while
99 // the cursor is in the resize position, it means
100 // they want to start resizing. Set this._isResizing to true
101 // and grab the th element that is being resized
102 if(args.target.style.cursor == 'e-resize') {
103 e.behavior._isResizing = true;
104 e.behavior._element = args.target;
105 }
106 },
107
108 _onMouseUp : function(args, e){
109 // the user let go of the mouse - so
110 // they are done resizing the header. Reset
111 // everything back
112 if(e.behavior._isResizing){
113
114 // set back to default values
115 e.behavior._isResizing = false;
116 e.behavior._element = null;
117
118 // make sure the cursor is set back to default
119 for(i = 0; i < e.behavior._ths.length; i++){
120 e.behavior._ths[i].style.cursor = '';
121 }
122 }
123 },
124
125 _onSelectStart : function(args, e){
126 // Don't allow selection during drag
127 if(e.behavior._isResizing){
128 args.preventDefault();
129 return false;
130 }
131 },
132
133 _toNumber : function(m) {
134 // helper function to peel the px off of the widths
135 return new Number(m.replace('px', ''));
136 }
137 }
138
139 LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior.registerClass('LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior', Sys.Extended.UI.BehaviorBase);
以上是js代码,因为我不知道怎么上传文件的,只好发代码了。
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using AjaxControlToolkit.Design;
5
6 namespace LavaBlast.AJAX.GridViewResizeExtender
7 {
8 public class GridViewResizeDesigner : ExtenderControlBaseDesigner<GridViewResizeExtender>
9 {
10 }
11 }
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Web.UI.WebControls;
5 using System.Web.UI;
6 using System.ComponentModel;
7 using System.ComponentModel.Design;
8 using AjaxControlToolkit;
9
10 [assembly: System.Web.UI.WebResource("LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior.js", "text/javascript")]
11
12 namespace LavaBlast.AJAX.GridViewResizeExtender
13 {
14 [Designer(typeof(GridViewResizeDesigner))]
15 [ClientScriptResource("LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior", "LavaBlast.AJAX.GridViewResizeExtender.GridViewResizeBehavior.js")]
16 [TargetControlType(typeof(GridView))]
17 public class GridViewResizeExtender : ExtenderControlBase
18 {
19
20 }
21 }
本人愚钝,编程近六年,才明白了责任分离是啥意思。
以设计模式解析(第2版)的例子来说明,强调下:
假设你是一个会议上担任讲师,听课的人在课后还要去听其他课,但他们不知道下堂课的听课地点,你的责任之一,就是确保大家都知道下堂课去哪上。
一般是这样做的。
1.get听课人的名单
2.for i=0 i< 人数
a.getnextclass //找到当前的人的下堂课是什么,
b.getplace //找到地点
c.getpath //找到路线
d.givemap //设置听课人的属性
现在我这样做
1.get听课人的集合
2.tell集合gonextclass
3.集合的gonextclass
for i=0 i< 人数
人.gonextclass
4.人的gonextclas
a.getnextclass //下堂课是什么,
b.getplace //找到地点
c.getpath //找到路线
d.设置自己的属性
对比一下,那种更好,我觉得是第二种,第二种是多了一些代码,但是更好维护了。也更明确了。
目前所做的工作,大多是这样的:
第一种:
1.后台sql.
2.前台ui.
逻辑全部放到了ui.
sql的辅助类。
ui to sql的辅助类。
sql to ui的辅助类。
第二种:
1.后台sql.
2.中间层.
3.前台ui.
逻辑大部分放到了中间层.
sql的辅助类。
ui to sql的辅助类。
sql to ui的辅助类。
中间层,权限,业务逻辑,业务规则。等等。
程序员非常勤快的,1,2,3,换了一个平台,继续1,2,3。
可以换种方式吗?
通用权限管理系统的模型设计
原来的权限管理,是将“模块权限”和“资源权限”直接分配给“用户”。
好处:易于实现,在“模块权限”和“资源权限”的控制上面,比较方便,容易。
坏处:用户类别多,用户数量大时,整个系统维护工作量大。
如果引入“角色”,如果将“用户”归到“角色”中,将“权限”分配到“角色”中,权限管理的维护工作将大大降低。同时,系统也方便实现,以下是基于“角色”的权限管理模型。

第一个版本
因为,这个“权限管理模型”不是单独一个系统使用,它是几个系统同时使用,所以在设计时,时刻需要注意,“权限”粒度的问题。以下为设计时,所需要注意的问题。
1.“用户”可以拥有多个“角色”,如果“用户”只有一个“角色”,的确是很方便实现,但是有以下的情况存在:
例如,某用户,在系统A中,分配的“权限”是可以查看和修改某类资源的“权限”,跟其他部分用户权限一样,而在系统B中,分配的“权限”是“管理员”的“权限”,但是其他部分用户的权限不是“管理员”的“权限”。
如果在“权限管理”中,分配一个“角色”,对应一个“用户”,对于以上的问题,将会有“角色”会彭胀,同时,无法“复用”已经分配好的“角色”。所以应该是,将权限分配到不同的“角色”上。“用户”同时分配几个不同的“角色”,注意,“角色”中不要有冲突。
例如:“角色A”拥有管理系统A模板A的“审核权限”,“角色A1”却只拥有查看系统A模板A的“查看权限”,将“角色A”和“角色A1”,同时分配给“用户1”,“用户1”登录系统A时,将无法判断,使用那一个角色。
2.“操作权限”,系统是由各种“模块”组成的,这里并不将模块先进行分类,然后再给予权限,这是因为每种类“模块”拥有权限控制也不一定相同,
例如,列表,在不同的模块下面,它拥有的权限也是不一样的。可能有,“删除”,“修改”,也可能只有“查看”功能。同时,编辑页面来讲,在类似论坛的这种系统上面,它可以有审核,修改,删除,置顶之类的操作,而在业务类的系统中,它无法置顶。
3.“权限”,系统中所拥有的细节“权限”,它只是用于标记,因为在分模块的团队开发中,在“权限”控制上面,各模块的开发者可能都会用自己的方言来定义各种“权限”标识,不利维护和统一维护。
4.“模块”,系统中所拥有的“模块”,包含用于“导航”并没有具体页面的模块,用于最后编辑修改的非导航的“模块”等。
5.“资源”,系统中所拥有的各种“资源”,一般是“表”,针对“表”的字段写条件表达式。
6.“系统”,子系统的集合。
这个“权限管理”解决了,维护工作量大的问题,而且在分配权限上面,相当的方便。
带来一个问题,在同一个系统中,同一个模块,同样的操作下,资源的受权不一样,如下表:
|
角色
|
模块
|
操作
|
资源
|
|
A
|
A
|
修改,查看
|
{A},{A,B}
|
|
B
|
A
|
修改,查看
|
{A,B},{A,B}
|
表 不同角色相同操作不同资源
在这种细粒度下的分配资源,按以上方式,会不方便,不灵活。可见变化点其实在于资源的分配上面。借助于历史上各位前辈的思想,再给资源和角色之间,加一个间接层,如下图所示:

第二个版本
“资源角色”体现的就是“角色”在“模块”中“操作”受限的“资源”。在设计“资源角色”注意点。
1.“资源角色”是一个变化点,在维护资源的时候,“资源”在,“资源角色”在,“资源”删除,“资源角色”也需要删除。
2.“资源角色”需要体现“模块”,“操作”,“资源”的特性。可以看到此模型比较复杂,“资源角色”好像是占了“角色”的责任。
3.“模块”应该是一种,拥有“资源”的可“操作”的对象。这里好像,“资源”跟“模块”不在一起了。

第三版本
“模块”本来就应该拥有“操作”和“资源”,在现实中,它有一个隐含条件,要么是拥有一个“操作”,意味着,拥有了可以操作,跟此“操作”相关的所有资源的权限;要么是拥有一个“操作”,只有“操作”没有“资源”。
“资源”是,“模块”中的受控资源。
“资源规则”体现的是“模块”+“操作”+“资源”形式的规则。所以它跟三块都有关系。这里和“资源”分离,是因为,它可变性很大,而“资源”可变性小。
欢迎批评。
摘要: 编译器错误信息: CS0016: 未能写入输出文件,..\Temporary ASP.NET Files\WebApp\d087da43\c12930d8\9ze28k_8.dll”--拒绝访问今天给客户安装网站,最后出现这个错误。经常查找,说是要给windows下面的temp文件夹建用户。因为客户的是XP系统,所以我就加了Network service用户的权限。然后没有重启IIS错...
阅读全文
摘要: 从来没有写过博客,这是本人第一篇博客。没有中心意思。随便写写,发泄下。 最近心情不知道怎么表达,同组的三个.net开发人员,有两个人闪。我想起去年,部门老大有一次不礼貌的找我谈话(他在办公室里翻东西,要我坐下跟他谈话),说是不打算发展.net,对我们做的事情不是很满意(我想是很不满意吧。),结果,这些两个人要走了,要我接手他们的工作,同时又对我说,准备发展.net(总觉得是忽悠我吧,因为前面有一个...
阅读全文