2007年6月17日星期日
2007年6月12日星期二
使用JavaScript实现Web程序中多个文本框的批量选择、批量修改
我最近几年一直从事B/S信息系统的开发和实施工作,期间总会听到用户抱怨说上了信息系统还不如以前用Excel的时候方便。的确,无论是登录信息还是查找信息,Web程序都要比Excel麻烦很多。其中,不能方便地批量更新一直是用户抱怨较多的地方。最近,我使用纯Javascript实现了一个批量修改文本框中的数据的功能,请看看效果先。
这是初始页面:
现在,让我们选择第2、3、4、6、7个文本框:
输入新值:
结果:
实现方法概述
首先,将页面上所有的TextBox控件保存在数组text_boxes中;将每个TextBox控件的left、right、top、bottom信息保存到client_rects数组中。
然后,接管document.onmousemove、document.onkeydown、document.onkeyup事件,当Ctrl和Alt键同时按下时,在onmousemove事件中判断鼠标是否经过了某个TextBox控件(我们已经把每个TextBox控件的left、right、top、bottom信息保存到client_rects数组中^_^),将鼠标经过的TextBox控件保存到 _control_selected数组中。
最后,弹出对话框,要求用户给出新的值,然后修改 _control_selected 数组中的所有TextBox的值。
实际使用时...
实际使用时,我将实现这个功能的Javascript代码放到了一个用户控件中。以后,只要哪个页面需要这个批量修改的功能,直接将用户控件拖放到那个页面中就行了,不用多加一行代码。
下载源代码
您可以到这个地址http://download.csdn.net/source/193470下载全部源代码。需要安装VS2005才能打开工程并运行。如果您没有安装VS2005,可以使用记事本打开Default.aspx查看源代码。
2007年6月5日星期二
要是函数能指定使用范围就好了
当我们重构的时候,经常会从一个函数中抽取出十个八个只有几行代码的“小”函数。有些小函数在逻辑上比较独立,可以预期它们会被其它的函数调用;而有的函数被抽取出来仅仅是为了提高代码的可读性,我们并不希望它们被其它的函数调用,或者我们至少想知道它到底会给哪几个函数提供服务。具体点说,我希望能够这样编程:(C#伪代码)
public bool isAdult()
{
return age(birthday) >= 18;
}
private int age(DateTime birthday) used by isAdult()
{
return DateTime.Now.Year - birthday.Year;
}
2007年6月4日星期一
终于找到RDLC报表中使用嵌入图像后导出PDF出现“绘图错误”的原因了
我在VS2005的RDLC报表中使用了几张嵌入图片,结果总时不时的在打开导出的PDF文件时出现“绘图错误”。经过一番排查,发现原来是嵌入的PNG格式的图像的色深必须要大于24bit。我喜欢使用SnagIt7的虚拟打印机生成Png图片,而SnagIt7默认的Png图片的色深是1bit,所以总会出现“绘图错误”。
2007年5月31日星期四
制作一个自动登录Blogger的快捷方式
每次登录Blogger都要输入长长的用户名和密码(我数了一下,一共要输入28个字母),实在是很麻烦。于是我作了一个放在桌面上的网页文件,双击它即可自动登录到我的Blogger上。



它的制作方法是这样的,
第一步:在桌面上新建一个文本文档,然后把扩展名由.txt改为.htm,我建的是MyBlog.htm。
第二步:用记事本打开MyBlog.htm,在里面输入如下内容
<input type="hidden" name="continue" value="http://www.blogger.com/loginz?d=%2Fstart">
<input type="hidden" name="service" value="blogger">
<input type="hidden" name="nui" value="8">
<input type="hidden" name="naui" value="8">
<input type="hidden" name="fpui" value="2">
<input type="hidden" name="uilel" value="3">
<input type="hidden" name="skipvpage" value="true">
<input type="hidden" name="rm" value="false">
<input type="hidden" name="hl" value="zh_CN">
<input type="hidden" name="alwf" value="true">
<input type="hidden" name="roeu" value="https://www.blogger.com/login.g"> <input type="hidden" name="GA3T" value="DJY310qrAc8">
<input type="hidden" name="Email" value="你的mailto:zahuifan@163.com" tabindex="1" id="Email" size="10">
<input type="hidden" name="Passwd" value="你的密码" autocomplete="off" tabindex="2" id="Passwd" size="10">
</form>
<script type='text/javascript'>
document.forms[0].submit();
</script>
第三步:保存。
然后当我想登录Blogger的时候,只要双击桌面上的MyBlog.htm就可以了。
2007年5月26日星期六
在进入和离开网页时应用CSS滤镜
只要把下面这两行放到网页的HEAD区中,就可以在进入和离开网页时应用相应的CSS的滤镜了。本例中应用的是动态的马赛克效果。
<meta content="progid:DXImageTransform.Microsoft.Pixelate(Duration=3)" http-equiv="Page-Exit">
2007年5月19日星期六
我的 Formatter
你如何将 DateTime 对象转换成 String?这是我的答案:
// 那个"?"不是乱码呦!这个相当
// 于写Nullbale<DateTime> birthday...
DateTime? birthday = new DateTime(2007, 1, 1);
DateTime? birthday2 = null;
string s = Formatter.New("d") ¦ birthday; // s = "2007-1-1"
string s2 = Formatter.New("d") ¦ birthday2; // s2 = ""
string s3 = Formatter.New("d", "不详") ¦ birthday2; // s3 = "不详"
怎么样,是不是很酷? 其实 Formatter 的实现相当的简单,下面是全部源代码
public class Formatter
{
private string _fmt = "";
private string _nullString = "";
public Formatter(string fmt, string nullString)
{
_fmt = fmt;
_nullString = nullString;
}
public static Formatter New(string fmt)
{
return new Formatter(fmt, "");
}
public static Formatter New(string fmt, string nullString)
{
return new Formatter(fmt, nullString);
}
public static string operator ¦(Formatter lhs, Nullable<DateTime> rhs)
{
if (rhs.HasValue)
{
return rhs.Value.ToString(lhs._fmt);
}
else
{
return lhs._nullString;
}
}
} // class Formatter
其实就是重载了竖线操作符而已。其实我想重载“<<”来着,可惜 .Net 规定“<<”操作符的右操作数必须是 int,真TNND气死我了,杀死比尔。






