日期:2012-09-05  浏览次数:20738 次

全编辑WebGrid控件LrcGrid(3)——整体结构

资源文件:

LrcGrid使用两个引用文件:一个css样式表文件MyFSheet.css,一个js脚本库文件UpdArray_LRC.js。

样式表文件中存放着应用于文本框的样式表类,用于文本框处于不同模式(浏览、编辑、焦点)时的样式

1.隐藏(浏览)样式:

.lrc_txt_hid
{
border-style:none;
width:95;
background:url(images/txt_back.gif);
}



2.编辑样式:

.lrc_txt_show
{
border-style:groove;
background-color:#ffffff;
width:95;
}


3.焦点样式:

.lrc_txt_edit
{
border-width:medium;
border-style:groove;
font-weight:bolder;
background-color:Yellow;
width:95;
}


脚本库:包含了控件客户端操作的函数.包括:

将表格行切换到编辑模式的函数:chgEditRow(rowIndex,tab)()
将表格列切换到编辑模式的函数:chgEdit(colIndex,tab)
在客户端构造更新数据库的sql语句: BuildSql(tabName)
添加新记录的函数:AddRow(tab)
移除新添加行的函数:  RemoveRow(tab) :
将在以后贴出全部代码,如果贴在这里太长了.

LrcGrid类结构:

LrcGrid包含三个类和一个枚举
VirtualRecordCount类:记录分页信息
PageChangedEventArgs类:继承自EventArgs 换页事件
PagerStyle枚举:分页导航条的形式枚举
LrcGrid类:继承自System.Web.UI.WebControls.Table,实现INamingContainer接口。
前几个都比较简单,我把代码直接贴出来。
#region VirtualRecordCount class 记录分页信息的类

public class VirtualRecordCount

{

public int RecordCount;

public int PageCount;

public int RecordsInLastPage;

}

#endregion



#region PagerStyle enum 分页导航条的形式枚举

public enum PagerStyle

{

NextPrev,

NumericPages

}

#endregion



#region PageChangedEventArgs class 换页事件类

public class PageChangedEventArgs : EventArgs

{

public int OldPageIndex;

public int NewPageIndex;

}

#endregion


LrcGrid类就比较复杂了,1000多行吧,大体结构如下(在后面的章节中将陆续贴出全部源码!):
[

ToolboxData("<{0}:LrcGrid runat=server></{0}:LrcGrid>"),

DefaultProperty("SelSql")

]

public class LrcGrid : System.Web.UI.WebControls.Table,INamingContainer

{



public LrcGrid() : base(){…… }

#region 私有变量

private……

#endregion



#region 和分页有关的私有变量

private……

#endregion



#region 公共属性

/// <summary>

/// 外键指示

/// </summary>

[

Category("关键"),

Description("外键.格式:本表列名|外键列名|要显示的外键列名|外键表名,.....")

]

public string FkCol

{

get{return _fkCol;}

set{_fkCol = value;}

}

……

#endregion

#region 和分页有关的公共成员

#endregion


#region 公共方法 重建

/// <summary>

/// 重新构造控件

/// </summary>

public void ReBuild(){……}

#endregion



#region Override过程

protected override void CreateChildControls()

{this.ReBuild();}

protected override void OnPreRender(EventArgs e){……}

#endregion



#region 排序

private void lk_Command(object sender, CommandEventArgs e){……}

#endregion

#region 创建标题行

private void buildTitle(){……}

#endregion

#region 创建数据行

private void buildCol(){……}

#endregion

#region 创建操作行

private void buildOper(){……}

#endregion

#region