web|控制項 全編輯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 初始化資料集
private void initDataSet(){……}
#endregion
#region 判斷是否是編輯列
private bool isEditCol(int i){……}
#endregion
#region 判斷是否是外鍵列
private bool isFkCol(int ii){……