Extjs中如何获取url的QueryString的内容

23. 五月 2009

在使用Extjs时候,遇到一个问题,就是如何获取url的QueryString的内容?

例如:我有个页面的地址是http://www.cgua.net/tags.aspx?tag=something&date=2009-05-13,接下来,我想获取 tag的值(something)还有 date的值(2009-05-13),

一般我们用的方法是

  1. var url = window.location.href; 
  2. var query = '' + url.substring(url.indexOf("?") + 1); 

然后我们再对 query 进行 substr 取到 tag 和 date 的值。

使用Extjs 我们有一个更好的更方便的方法,首先,我定义一个getUrlParam的方法,如下

  1. Ext.getUrlParam = function(param) { 
  2.     var params = Ext.urlDecode(location.search.substring(1)); 
  3.     return param ? params[param] : params; 
  4. }; 

接着就简单了,取tag的值,我们直接 Ext.getUrlParam('tag');就可以了,而取date的值就用Ext.getUrlParam('date'); smile

这样很方便了吧~~~ 

 

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

ExtJs , ,

自己写的一个Access的DataHelper类

23. 五月 2009

      朋友昨天问我有没有Access的DataHelper类,我告诉他有MSSQL的,可以拿去自己修改下,挺好用的,然后他就拿去了,看了下源代码说:“怎么这么复杂的?”。

      确实是有点复杂的,但是人家那可是做的比较全面,十分优秀的呀!他说看看那个类的代码都觉得累...于是,我就自己动手写了个Access的DataHelper类,这里发布出来献丑下,嘿嘿...

  1. /** 
  2.  * Accesss Data Helper class 
  3.  * We should config a connectionstring in web.config first 
  4.  * In web.config add a connection name "ConnectionString" 
  5.  * Copyright (C) 2009 by jerreychen 
  6.  * http://www.cgua.net 
  7.  * 2009-05-20 21:30 
  8.  **/ 
  9. using System; 
  10. using System.Collections.Generic; 
  11. using System.Linq; 
  12. using System.Text; 
  13. using System.Configuration; 
  14. using System.Data.OleDb; 
  15. using System.Data; 
  16.  
  17. namespace DBHelper.DBClient 
  18.     public class AccessClient 
  19.     { 
  20.         static string _connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 
  21.         OleDbConnection _connection; 
  22.         /// <summary> 
  23.         /// The ConnectionString config in web.config Named "ConnectionString" 
  24.         /// </summary> 
  25.         public AccessClient() 
  26.         { 
  27.             _connection = new OleDbConnection(_connectionString); 
  28.         } 
  29.         public AccessClient(string connectionString) 
  30.             : this() 
  31.         { 
  32.             _connectionString = connectionString; 
  33.         } 
  34.  
  35.         public DataSet Query(string querySql) 
  36.         { 
  37.             return Query(querySql, null); 
  38.         } 
  39.         public DataSet Query(string querySql, params OleDbParameter[] parameters) 
  40.         { 
  41.             OleDbCommand command = ExcDbCommand(querySql, parameters); 
  42.             DataSet ds = new DataSet(); 
  43.             OleDbDataAdapter da = new OleDbDataAdapter(command); 
  44.             da.Fill(ds); 
  45.             return ds; 
  46.         } 
  47.  
  48.         /// <summary> 
  49.         /// After call this method, you should call "Close()" method to close this Access Connection 
  50.         /// </summary> 
  51.         /// <param name="querySql"></param> 
  52.         /// <returns></returns> 
  53.         public OleDbDataReader Read(string querySql) 
  54.         { 
  55.             return Read(querySql); 
  56.         } 
  57.         /// <summary> 
  58.         /// After call this method, you should call "Close()" method to close this Access Connection 
  59.         /// </summary> 
  60.         /// <param name="querySql"></param> 
  61.         /// <param name="parameters"></param> 
  62.         /// <returns></returns> 
  63.         public OleDbDataReader Read(string querySql, params OleDbParameter[] parameters) 
  64.         { 
  65.             OleDbCommand command = ExcDbCommand(querySql, parameters); 
  66.             this.Open(); 
  67.             OleDbDataReader reader = command.ExecuteReader(); 
  68.             return reader; 
  69.         } 
  70.  
  71.         public bool Excute(string excuteSql) 
  72.         { 
  73.             return Excute(excuteSql, null); 
  74.         } 
  75.         public bool Excute(string excuteSql, params OleDbParameter[] parameters) 
  76.         { 
  77.             OleDbCommand command = ExcDbCommand(excuteSql, parameters); 
  78.             this.Open(); 
  79.             int result = command.ExecuteNonQuery(); 
  80.             this.Close(); 
  81.             return result > 0; 
  82.         } 
  83.  
  84.         public void Open() 
  85.         { 
  86.             if (_connection.State != ConnectionState.Open) 
  87.                 _connection.Open(); 
  88.         } 
  89.         public void Close() 
  90.         { 
  91.             if (_connection.State != ConnectionState.Closed) 
  92.                 _connection.Close(); 
  93.         } 
  94.  
  95.         OleDbCommand ExcDbCommand(string sql, OleDbParameter[] parameters) 
  96.         { 
  97.             OleDbCommand command = new OleDbCommand(sql, _connection); 
  98.  
  99.             if (parameters == null || parameters.Length == 0) 
  100.                 return command; 
  101.  
  102.             foreach (OleDbParameter param in parameters) 
  103.             { 
  104.                 command.Parameters.Add(param); 
  105.             } 
  106.  
  107.             return command; 
  108.         } 
  109.     } 
  110.  

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Asp.net ,

MultipleActiveResultSets是什么?

23. 四月 2009
ADO.NET 1.x 利用SqlDataReader读取数据,针对每个结果集需要一个独立的连接。当然,你还必须管理这些连接并且要付出相应的内存和潜在的应用程序中的高度拥挤的瓶颈代价-特别是在数据集中的Web应用程序中。

      ADO.NET 2.的一个新特征多数据结果集(Multiple Active Result Sets,简称MARS)-它允许在单个连接上执行多重的数据库查询或存储过程。这样的结果是,你能够在单个连接上得到和管理多个、仅向前引用的、只读的结果集。目前实现这个功能的数据库只有Sql Server 2005。所以当我们针对Sql Sever 2005的时候,需要重新审视DataReader对象的使用。使用SqlServer 2005,可以在一个Command对象上同时打开多个DataReader,节约数据库联接所耗费的服务器资源,在实际开发中普遍存在的一种典型的从数据库中读写数据的情形是,你可以使用多重连接而现在只用一个连接就足够了。例如,如果你有一些来自于几个表中的数据-它们不能被联结到一个查询中,那么你就会有多重的连接-每个连接都有一个与之相关连的命令用于读取数据。同样,如果你正在向一个表写数据,那么你需要另外一个连接或连接集合-如果有多个表要被更新的话。

例如下面的代码

               //MultipleActiveResultSets=true打开联接

              string connstr = "server=(local);database=northwind;integrated security=true;MultipleActiveResultSets=true";

              SqlConnection conn = new SqlConnection(connstr);
            conn.Open();
            SqlCommand cmd1 = new SqlCommand("select * from customers", conn);
            SqlCommand cmd2 = new SqlCommand("select * from orders", conn);
            SqlDataReader rdr1 = cmd1.ExecuteReader();
           // next statement causes an error prior to SQL Server 2005
            SqlDataReader rdr2 = cmd2.ExecuteReader();
           // now you can reader from rdr1 and rdr2 at the same time.

              conn.Close();

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Asp.net ,

使用foreach对DataTable的DataRow进行update、delete

16. 四月 2009
一个朋友问了我一个问题,他在使用foreach删除(Delete)和更新(Update)DataTable的时候发生错误了。
在.Net中,很典型的一个情景是,你需要操作DataTable,通过foreach更新(Update)或者删除(Delete)
如:
foreach(var row in dataTable.Rows)
{
 //some actions, delete or update
}
有的朋友会这么做
foreach(var row in dataTable.Rows)
{
 If (row["Name"] == "Mahesh")
            row.Delete();
 dataTable.AcceptChanges();
}
这样就会报错了,因为这样处理,影响了foreach循环的indexing
我们应该像下面这样做
foreach(var row in dataTable.Rows)
{
 If (row["Name"] == "Mahesh")
            row.Delete();
}
dataTable.AcceptChanges();

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Asp.net , , , ,

传说中雅虎.net岗位的面试题

16. 四月 2009

雅虎公司C#笔试题,包括问答题和选择题两部分。试试看,你能回答出多少题,可以通过雅虎的考试吗?

Question 1. (单选)

在计算机网络中,表征数据传输可靠性的指标是

1. 传输率

2. 误码率

3. 信息容量

4. 频带利用率

Question 2. (单选)

以下关于链式存储结构的叙述中哪一条是不正确的?

1. 结点除自身信息外还包括指针域,因此存储密度小于顺序存储结构

2. 逻辑上相邻的结点物理上不必邻接

3. 可以通过计算直接确定第i个结点的存储地址

4. 插入、删除运算操作方便,不必移动结点

Question 3. (单选)

以下哪一个不是栈的基本运算

1. 删除栈顶元素

2. 删除栈底元素

3. 判断栈是否为空

4. 将栈置为空栈

Question 4. (单选)

以下关于广义表的叙述中,正确的是

1. 广义表是0个或多个单元素或子表组成的有限序列

2. 广义表至少有一个元素是子表

3. 广义表不可以是自身的子表

4. 广义表不能为空表

Question 5. (单选)

如果一棵二叉树结点的前序序列是A、B、C,后序序列是C、B、A,则该二叉树结点的对称序序列

1. 必为A、B、C

2. 必为A、C、B

3. 必为B、C、A

4. 不能确定

Question 6. (单选)

在虚拟页式存储管理方案中,下面哪一部分完成将页面调入内存的工作?

1. 缺页中断处理

2. 页面淘汰过程

3. 工作集模型应用

4. 紧缩技术利用

Question 7. (单选)

在DOS系统中,用于记录和管理磁盘数据区使用情况的数据结构

1. 位图表

2. 空闲块表

3. 文件分配表

4. 文件控制块

Question 8. (单选)

设有关系R(S,D,M),其函数依赖集F={S→D,D→M}。则关系R至多满足

1. 1NF

2. 2NF

3. 3NF

4. BCNF

Question 9. (单选)

在数据库逻辑设计中,当将E-R图转换为关系模式时,下面的做法哪一个是不正确的?

1. 一个实体类型转换为一个关系模式

2. 一个联系类型转换为一个关系模式

3. 由实体类型转换成的关系模式的主键是该实体类型的主键

4. 由联系类型转换成的关系模式的属性是与该联系类型相关的诸实体类型的属性的全体

Question 10. (单选)

计算机网络按照所覆盖的地理范围分类,可以分广域网、局域网与

1. TCP/IP网

2. ATM网

3. ISDN

4. 城域网

Question 11. (单选)

计算机网络拓扑结构主要取决于它的

1. 资源子网

2. FDDI网

3. 通信子网

4. 路由器

Question 12. (单选)

网络协议的三个要素是语法、语义与

1. 工作原理

2. 时序

3. 进程

4. 服务原语

Question 13. (单选)

TCP/IP参考模型中,电子邮件协议SMTP依赖于传输层的

1. UDP协议

2. IP协议

3. TCP协议

4. 802.2协议

Question 14. (单选)

IEEE802.2协议中10BASE-T标准规定在使用5类双绞线时,从网卡到集线器的最大距离为

1. 100m

2. 185m

3. 300m

4. 500m

Question 15. (单选)

100Mbps Fast Ethernet与10Mbps Ethernet 工作原理的相同之处主要在

1. 介质访问控制方法

2. 物理层协议

3. 网络层

4. 发送时钟周期

Question 16. (单选)

在Client/Server计算模式中,中间件middleware的作用是隔离应用与

1. 结构化查询语言SQL

2. 应用进程

3. 网络

4. IP地址

Question 17. (单选)

当用户向ISP申请Internet帐户时,用户的E-mail帐户应包括

1. IP地址

2. WWW地址

3. 用户密码(Password)

4. 用户名(User Name)与用户密码(Password)

Question 18. (单选)

WWW的超链接中定位信息所在的位置使用的是

1. 超文本(hypertext)技术

2. 统一资源定位器(URL, Uniform Resource Locators)

3. 超媒体(hypermedia技术)

4. 超文本标注语言HTML

Question 19. (单选)

计算机网络系统与分布式系统之间的区别主要是

1. 系统物理结构

2. 系统高层软件

3. 传输介质类型

4. 服务器类型

Question 20. (单选)

帧中继系统设计的主要目标是用于互连多个

1. 广域网

2. 电话网

3. 局域网

4. 0)ATIM网

Question 21. (单选)

ATM网络采用固定长厦的信元传送数据,信元长度为

1. 1024B

2. 53B

3. 128B

4. 64B

Question 22. (单选)

TCP/IP参考模型中的主机-网络层对应于OSI RM中的

1. 网络层

2. 物理层

3. 数据链路层

4. 物理层与数据链路层

Question 23. (单选)

计算机网络最突出的优点是:

1. 计算精度高

2. 内存容量大

3. 运算速度快

4. 连网的计算机能够相互共享资源

Question 24. (单选)

计算机网络分为局域网、城域网与广域网,其划分的依据是:

1. 数据传输所使用的介质

2. 网络的作用范围

3. 网络的控制方式

4. 网络的拓扑结构

Question 25. (单选)

用二分法查找一个长度为10的、排好序的线性表,查找不成功时,最多需要比较多少次?

1. 5

2. 2

3. 4

4. 1

Question 26. (单选)

模块内聚度越高,说明模块内各成分彼此结合的程度越

1. 松散

2. 紧密

3. 无法判断

4. 相同

Question 27. (单选)

软件需求分析阶段的输出主要是

1. 需求说明书

2. 开发计划

3. 可行性报告

4. 设计说明书

Question 28. (单选)

以下选项中不是项目经理的职责的是?

1. 需求分析

2. 计划

3. 计划跟踪

4. 质量管理

Question 29. (单选)

单元测试一般在什么时候进行?

1. 编码完成后

2. 系统测试前

3. 测试用例编写完成后

4. 集成测试后

Question 30. (多选)

配置管理能起到以下哪些作用?

1. 版本管理

2. 变更管理

3. 需求管理

4. 测试管理

Question 31. (单选)

根据线程安全的相关知识,分析以下代码,当调用test方法时i>10时是否会引起死锁?

public void test(int i)

{

lock(this)

{

if (i>10)

{

i--;

test(i);

}

}

}

1. 会锁死

2. 不会锁死

Question 32. (单选)

以下描述错误的是()

1. 在C++中支持抽象类而在C#中不支持抽象类。

2. C++中可在头文件中声明类的成员而在CPP文件中定义类的成员,在C#中没有头文件并且在同一处声明和定义类的成员。

3. 在C#中可使用 new 修饰符显式隐藏从基类继承的成员。

4. 在C#中要在派生类中重新定义基类的虚函数必须在前面加Override。

Question 33. (单选)

int[][] myArray3=new int[3][]{new int[3]{5,6,2},new int[5]{6,9,7,8,3},new int[2]{3,2}}; myArray3[2][2]的值是()。

1. 9

2. 2

3. 6

4. 越界

Question 34. (单选)

在C#中利用Socket进行网络通信编程的一般步骤是:建立Socket侦听、( )、利用Socket接收和发送数据。

1. 建立Socket连接

2. 获得端口号;

3. 获得IP地址;

4. 获得主机名;

Question 35. (单选)

如果设treeView1=new TreeView(),TreeNode node=new TreeNode("根结点" ),则treeView1.Nodes.Add(node)返回的是一个 ()类型的值。

1. TreeNode;

2. int;

3. string;

4. TreeView;

Question 36. (单选)

声明一个委托public delegate int myCallBack(int x); 则用该委托产生的回调方法的原型应该是

1. void myCallBack(int x)

2. int receive(int num)

3. string receive(int x)

4. 不确定的

Question 37. (单选)

关于ASP.NET中的代码隐藏文件的描述正确的是

1. Web窗体页的程序的逻辑由代码组成,这些代码的创建用于与窗体交互。编程逻辑唯一与用户界面不同的文件中。该文件称作为“代码隐藏”文件,如果用C#创建,该文件

2. 项目中所有Web窗体页的代码隐藏文件都被编译成.EXE文件

3. 项目中所有的Web窗体页的代码隐藏文件都被编译成项目动态链接库(.dll)文件

4. 以上都不正确

Question 38. (单选)

What compiler switch creates an xml file from the xml comments in the files in an assembly?

1. /text

2. /doc

3. /xml

4. /help

Question 39. (单选)

下面的代码实现了设计模式中的什么模式

public class A {

private A instance;

private A() {

}

public static A Instance {

get

{

if ( A == null )

A = new A();

return instance;

}

}

}

1. Factory

2. Abstract Factory

3. Singleton

4. Builder

Question 40. (单选)

class Class1

{

public static int Count = 0;

static Class1()

{

Count++;

}

public Class1()

{

Count++;

}

}

Class1 o1 = new Class1();

Class1 o2 = new Class1();

请问,Class1.Count的值是多少?( )

1. 1

2. 2

3. 3

4. 4

Question 41. (单选)

abstract class BaseClass

{

public virtual void MethodA()

{

Console.WriteLine("BaseClass");

}

public virtual void MethodB()

{

}

}

class Class1: BaseClass

{

public void MethodA()

{

Console.WriteLine("Class1");

}

public override void MethodB()

{

}

}

class Class2: Class1

{

new public void MethodB()

{

}

}

class MainClass

{

public static void Main(string[] args)

{

Class2 o = new Class2();

o.MethodA();

}

}

请问,此程序输出结果是:

1. BaseClass

2. BassClass Class1

3. Class1

4. Class1 BassClass

Question 42. (单选)

public static void Main(string[] args)

{

int i = 2000;

object o = i;

i = 2001;

int j =(int) o;

Console.WriteLine("i={0},o={1}, j={2}",i,o,j);

}

1. i=2001,o=2000,j=2000

2. i=2001,o=2001,,j=2001

3. i=2000,o=2001,,j=2000

4. i=2001,o=2000,j=2001

Question 43. (多选)

您要创建ASP.NET应用程序用于运行AllWin公司内部的Web站点,这个应用程序包含了50个页面。您想要配置这个应用程序以便当发生一个HTTP代码错误时它可以显示一个自定义的错误页面给用户。您想要花最小的代价完成这些目标,您应该怎么做?(多选)

1. 在这个应用程序的Global.asax文件中创建一个Application_Error过程去处理ASP.NET代码错误。

2. 在这个应用程序的Web.config文件中创建一个applicationError节去处理ASP.NET代码错误。

3. 在这个应用程序的Global.asax文件中创建一个CustomErrors事件去处理HTTP错误。

4. 在这个应用程序的Web.config文件中创建一个CustomErrors节去处理HTTP错误。

Question 44. (单选)

如下程序的运行结果是:

public abstract class A

{

public A()

{

Console.WriteLine(''A'');

}

public virtual void Fun()

{

Console.WriteLine("A.Fun()");

}

}

public class B: A

{

public B()

{

Console.WriteLine(''B'');

}

public new void Fun()

{

Console.WriteLine("B.Fun()");

}

public static void Main()

{

A a = new B();

a.Fun();

}

}

1. A B A.Fun()

2. A B B.Fun()

3. B A A.Fun()

4. B A B.Fun()

Question 45. (单选)

Which of these string definitions will prevent escaping on backslashes in C#?*

1. string s = #”n Test string”;

2. string s = “’n Test string”;

3. string s = @”n Test string”;

4. string s = “n Test string”;

Question 46. (单选)

Which of the following operations can you NOT perform on an ADO.NET DataSet?

1. A DataSet can be synchronised with a RecordSet.

2. A DataSet can be synchronised with the database.

3. A DataSet can be converted to XML.

4. You can infer the schema from a DataSet

Question 47. (单选)

In Object Oriented Programming, how would you describe encapsulation?

1. The conversion of one type of object to another.

2. The runtime resolution of method calls.

3. The exposition of data.

4. The separation of interface and implementation.

Question 48. (单选)

How does assembly versioning in .NET prevent DLL Hell?

1. The runtime checks to see that only one version of an assembly is on the machine at any one time.

2. .NET allows assemblies to specify the name AND the version of any assemblies they need to run.

3. The compiler offers compile time checking for backward compatibility.

4. It doesn’t.

Question 49. (单选)

三种常用的字符串判空串方法:

1: bool isEmpty = (str.Length == 0);

2: bool isEmpty = (str == String.Empty);

3: bool isEmpty = (str == "");

哪种方法最快?

1. 1

2. 2

3. 3

Question 50. (单选)

public sealed class SampleSingleton1

{

private int m_Counter = 0;

private SampleSingleton1()

{

Console.WriteLine(""初始化SampleSingleton1。"");

}

public static readonly SampleSingleton1 Singleton = new SampleSingleton1();

public void Counter()

{

m_Counter ++;

}

}

以上代码实现了设计模式中的哪种模式?

1. 原型

2. 抽象工厂

3. 单键

4. 生成器

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Misc ,

几个我常去的.net学习网站

14. 四月 2009

英文:

CodeProject      C# Corner      DevX

中文:

博客园    CSDN

搜索:

www.Google.com     www.Baidu.com

 呵呵,先加这些,以后如果有什么好的网站,网址,我也会发上来,吼吼~

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Misc ,

向容器(PlaceHolder)中动态添加多个用户控件(UserControl)

10. 四月 2009

问题是这样的:

我在页面里有一个PlaceHolder容器,然后有一个Button;

    <form id="form1" runat="server">
    
<div>
    
<asp:PlaceHolder ID="ucHolder" runat="server"></asp:PlaceHolder>
    
</div>
    
<div>
        
<asp:Button ID="btnAddUC" runat="server" Text="Add User Control" />
    
</div>
    
</form>

当我点击Button的时候,PlaceHolder中动态加载一个UserControl,每点击一次按钮,多加载一个UserControl,如果已经加载的UserControl有值,需要保留原来的值。

好了,下面开始具体的实现

首先,我新建一个Aspx的页面和一个Ascx的用户控件,然后在Aspx页面的Page_Load事件中为Button添加Click事件;


btnAddUC.Click += new EventHandler(btnAddUC_Click);

还需要定义一个变量变量 Count,保存到 ViewState 中,记录 UserControl 的个数


    int Count
    {
        
get
        {
            
if (ViewState["ControlCount"== null)
                ViewState[
"ControlCount"= 1;
            
return (int)ViewState["ControlCount"];
        }
        
set
        {
            ViewState[
"ControlCount"= value;
        }
    }

按钮点击方法如下


    void btnAddUC_Click(object sender, EventArgs e)
    {
        Count
++;
        LoadUserControl(Count);
    }

加载用户控件的方法


    void LoadUserControl(int index)
    {
        Control ctl 
= this.LoadControl("~/WebUserControl.ascx");
        ctl.ID 
= string.Format("userControl_{0}", index);
        
this.ucHolder.Controls.Add(ctl);
    }

这里注意,因为Asp.Net 的页面有一个Element Tree结构,会保存控件的状态的,所以加载的UserControl的ID要固定,就向上面 ctl.ID = string.Format("userControl_{0}", index); 每次加载控件的ID 都固定的

然后由于Asp.Net保存控件状态用的是ViewState,所以我们加载控件的实现需要在ViewState之后,我们放在页面的Page_Load事件中


        for (int i = 1; i <= Count; i++)
        {
            LoadUserControl(i);
        }

OK,这样就完成了

 

附:源代码

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Asp.net , ,

最近精神状态很差

9. 四月 2009

也许是晚上睡觉太迟,又或者是其它什么原因,最近感觉精神很不好,做事总是心不在焉的,总感觉头脑发热,很不舒服...

第一个打分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5