VARCHART XGantt用戶手冊(cè):數(shù)據(jù)表——?jiǎng)?chuàng)建和修改數(shù)據(jù)記錄(.NET版)
VARCHART XGantt是一個(gè)交互式的甘特圖控件,其模塊化的設(shè)計(jì)讓您可以創(chuàng)建滿足您和您的客戶所需求的應(yīng)用程序。(我們領(lǐng)先的甘特圖控件VARCHART XGantt可用于.NET,ActiveX和ASP.NET應(yīng)用程序。)除此之外,同時(shí)還具有一個(gè)穩(wěn)定可靠的甘特圖工具,在編寫第一行代碼之前,您就可以知道是否可以滿足客戶的需求。本文主要描述甘特圖數(shù)據(jù)表教程中的創(chuàng)建和修改數(shù)據(jù)記錄!內(nèi)容緊接上文(數(shù)據(jù)表——?jiǎng)?chuàng)建數(shù)據(jù)表)~
創(chuàng)建和修改數(shù)據(jù)記錄
定義數(shù)據(jù)表字段之后,您可以通過(guò)API將數(shù)據(jù)記錄添加到表中。有兩種向記錄中添加數(shù)據(jù)的方法。我們建議使用一種普通的做法來(lái)定義類型對(duì)象的數(shù)組,其對(duì)象的數(shù)量與數(shù)據(jù)表字段的數(shù)量相對(duì)應(yīng)。
示例代碼VB.NET
Dim dataTable As VcDataTable Dim dataRecCltn As VcDataRecordCollection Dim dataRecVal() As Object Dim dataRec1 As VcDataRecord Dim dataRec2 As VcDataRecord dataTable = VcGantt1.DataTableCollection.DataTableByName("Maindata") dataRecCltn = dataTable.DataRecordCollection ReDim dataRecVal(dataTable.DataTableFieldCollection.Count) dataRecVal(Main_ID) = "1" dataRecVal(Main_Name) = "Node 1" dataRecVal(Main_Start) = DateSerial(2013, 1, 8) dataRecVal(Main_Duration) = 8
示例代碼C#
VcDataTable dataTable = vcGantt1.DataTableCollection.DataTableByName("Maindata"); VcDataRecordCollection dataRecCltn = dataTable.DataRecordCollection; Object [] dataRecVal = new object[dataTable.DataTableFieldCollection.Count]; VcDataRecord dataRec1; VcDataRecord dataRec2; dataRecVal[Main_ID] = "1"; dataRecVal[Main_Name] = "Node 1"; dataRecVal[Main_Start] = "08.01.2013"; dataRecVal[Main_Duration] = 8
可以通過(guò)對(duì)象DataRecordCollection的Add()方法添加數(shù)據(jù)記錄,該對(duì)象數(shù)組作為參數(shù)傳遞。
示例代碼VB.NET
dataRec1 = dataRecCltn.Add(dataRecVal)
示例代碼C#
dataRec1 = dataRecCltn.Add(dataRecVal);
作為第二種方法,您可以使用由數(shù)據(jù)值組成的字符串,這些數(shù)據(jù)值由分號(hào)分隔。
示例代碼VB.NET
dataRecCltn.Add("2;Node 2;15.01.13;;9")
示例代碼C#
dataRec2.AllData = "2;Activity Y;15.01.13;;9";
如果數(shù)據(jù)值包含分號(hào),則字符串必須用雙引號(hào)引起來(lái)。
示例代碼VB.NET
dataRec2 = dataRecCltn.Add("2;""Node 2;"";15.01.13;;9")
示例代碼C#
dataRec2 = dataRecCltn.Add("2;\"Node 2;\";15.01.13;;9");
可以使用DataRecordByID()方法通過(guò)主鍵快速找到對(duì)數(shù)據(jù)庫(kù)對(duì)象的引用。
示例代碼VB.NET
dataRec1 = dataRecCltn.DataRecordByID("1") dataRec2 = dataRecCltn.DataRecordByID("2")
示例代碼C#
dataRec1 = dataRecCltn.DataRecordByID(1); dataRec2 = dataRecCltn.DataRecordByID(2);
通過(guò)使用索引屬性DataField(),可以輕松修改數(shù)據(jù)記錄的單個(gè)數(shù)據(jù)字段的內(nèi)容。為了替換記錄的所有數(shù)據(jù)字段內(nèi)容,可以使用屬性AllData。
示例代碼VB.NET
dataRec1.DataField(Main_ID) = 1 dataRec1.DataField(Main_Name) = "Activity X" dataRec1.DataField(Main_Start) = DateSerial(2013, 1, 4) dataRec1.DataField(Main_Duration) = 12 dataRec1.Update() dataRec2.AllData = "2;Activity Y;18.01.13;;5" dataRec2.Update()
示例代碼C#
dataRec1.set_DataField(Main_ID, 1); dataRec1.set_DataField(Main_Name, "Activity X"); dataRec1.set_DataField(Main_Start, "04.01.2014"); dataRec1.set_DataField(Main_Duration, 12); dataRec1.Update(); dataRec2.AllData = "2;Activity Y;18.01.14;;5"; dataRec2.Update();
記錄的修改只能在調(diào)用對(duì)象DataRecord的方法Update()之后顯示。
使用Alldata加載值適用于在設(shè)計(jì)時(shí)快速顯示所有數(shù)據(jù)值,以及將數(shù)據(jù)記錄內(nèi)容傳輸?shù)狡渌淼挠涗?。您也可以使用此?shù)據(jù)格式與OLE拖放進(jìn)行信息交換。
示例代碼VB.NET
Dim content As String content = dataRec1.AllData & vbCr & dataRec2.AllData & vbCr & dataRec1.DataField(Main_Name) MsgBox(content)
示例代碼C#
content = dataRec1.AllData + "\r\n" + dataRec2.AllData + "\r\n" + dataRec1.get_DataField(Main_Name); MessageBox.Show(content);
注意:為了提高數(shù)據(jù)字段訪問的可讀性,您可以定義具有名稱而不是索引號(hào)的全局常量,這些名稱更具描述性。請(qǐng)?jiān)谙旅嬲业狡渖舷挛闹械拇a:
示例代碼VB.NET
Const Main_ID = 0 Const Main_Name = 1 Const Main_Start = 2 Const Main_Duration = 4 '... Dim dataRec1 As VcDataRecord Dim dataRec2 As VcDataRecord Dim content As String VcGantt1.TimeScaleEnd = DateSerial(2014, 1, 1) VcGantt1.TimeScaleStart = DateSerial(2013, 1, 1) VcGantt1.ExtendedDataTablesEnabled = True dataTable = VcGantt1.DataTableCollection.DataTableByName("Maindata") dataRecCltn = dataTable.DataRecordCollection ReDim dataRecVal(dataTable.DataTableFieldCollection.Count) dataRecVal(Main_ID) = "1" dataRecVal(Main_Name) = "Node 1" dataRecVal(Main_Start) = DateSerial(2013, 1, 8) dataRecVal(Main_Duration) = 8 dataRec1 = dataRecCltn.Add(dataRecVal) dataRecCltn.Add("2;Node 2;15.01.13;;9") VcGantt1.EndLoading() '... dataRec1 = dataRecCltn.DataRecordByID("1") dataRec2 = dataRecCltn.DataRecordByID("2") dataRec1.DataField(Main_ID) = 1 dataRec1.DataField(Main_Name) = "Activity X" dataRec1.DataField(Main_Start) = DateSerial(2013, 1, 4) dataRec1.DataField(Main_Duration) = 12 dataRec1.Update() dataRec2.AllData = "2;Activity Y;18.01.13;;5" dataRec2.Update() content = dataRec1.AllData & vbCr & dataRec2.AllData & vbCr & dataRec1.DataField(Main_Name) MsgBox(content) '... dataRec2.AllData = "2;""Activity Y;Z"";18.01.13;;5" dataRec2.Update() content = dataRec1.AllData & vbCr & dataRec2.AllData MsgBox(content)
示例代碼C#
const int Main_ID = 0; const int Main_Name = 1; const int Main_Start = 2; const int Main_Duration = 4; //... VcDataRecord dataRec1; VcDataRecord dataRec2; string content; vcGantt1.TimeScaleEnd = Convert.ToDateTime("01.01.2014"); vcGantt1.TimeScaleStart = Convert.ToDateTime("01.01.2013"); vcGantt1.ExtendedDataTablesEnabled = true; VcDataTable dataTable = vcGantt1.DataTableCollection.DataTableByName("Maindata"); VcDataRecordCollection dataRecCltn = dataTable.DataRecordCollection; Object [] dataRecVal = new object[dataTable.DataTableFieldCollection.Count];) dataRecVal[Main_ID] = "1"; dataRecVal[Main_Name] = "Node 1"; dataRecVal[Main_Start] = "08.01.2013"; dataRecVal[Main_Duration] = 8; dataRec1 = dataRecCltn.Add(dataRecVal); dataRecCltn.Add("2;Node 2;15.01.13;;9"); vcGantt1.EndLoading(); //... dataRec1 = dataRecCltn.DataRecordByID(1); dataRec2 = dataRecCltn.DataRecordByID(2); dataRec1.set_DataField(Main_ID, 1); dataRec1.set_DataField(Main_Name, "Activity X"); dataRec1.set_DataField(Main_Start, "04.01.2013"); dataRec1.set_DataField(Main_Duration, 12); dataRec1.Update(); dataRec2.AllData = "2;Activity Y;18.01.13;;5"; dataRec2.Update(); content = dataRec1.AllData + "\r\n" + dataRec2.AllData + "\r\n" + dataRec1.get_DataField(Main_Name); MessageBox.Show(content); //... dataRec2.AllData = "2;Activity Y;Z;18.01.13;;5"; dataRec2.Update(); content = dataRec1.AllData + "\r\n" + dataRec2.AllData; MessageBox.Show(content);
將創(chuàng)建以下輸出:
相關(guān)內(nèi)容推薦:
想要購(gòu)買VARCHART XGantt正版授權(quán),或了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊“咨詢?cè)诰€客服”