1
我有一個包含相同的事件(驗證)多次,即日誌文件:創建動態控件,並綁定到數據集
ID:001 驗證結果:
認證啓動:05:42 :34
驗證結束:7時12分52秒
驗證結果:
驗證開始:12點38分01秒
驗證結束:14點05分12秒
我已經動態地創建了控件(一個標籤和一個TextBox或DateTimePicker),它將這些信息顯示給用戶;我想知道的是如何在這樣一種方式,當寫入數據庫,這些控件綁定到我的數據集,每個驗證與ID相關聯的一個新的行,即:
UID | ID | Start | End
1 | 001 | 05:42:34 | 07:12:52
2 | 001 | 12:38:01 | 14:05:12
Codewise:我點該程序是一個日誌目錄,顯示在一個清單框中。在SelectedIndex的變化,我所說的下面:
void ParseImagerLogs(string source)
{
int i = 0;
//Log fields are parsed to a key/value pair
if (key.Equals("LogID"))
{
logIdTextBox.Text = value
}
if (key.Equals("VerStarted"))
{
//Date format ddd MMM dd HH:mm:ss yyyy is parsed to a useable format and
//saved as timeStart
verStartedDateTimePicker.Value = verTimeStart;
}
if (key.Equals("VerEnded"))
{
//Same parsing technique
verEndedDateTimePicker.Value = verTimeEnd;
//Work out the elapsed time
verTime - timeEnd.Subtract(timeStart).ToString();
//Pass the fields to a new method which dynamically generates the
GenerateVerificationFields(i, verStartedDateTimePicker.Value, verEndeDateTimePicker.Value, verTime.TextBox
//I have my first verification instance, so i++ and look for the next one.
i++;
}
}
private void GenerateVerificationFields(int amount, DateTime verStartval, DateTime verEndval, string verTimeval)
{
int i = amount;
int j = i + 1;
//Create groupBox
GroupBox groupBox = new GroupBox();
groupBox.Name = "verGroup" + i.ToString();
groupBox.Width = 430;
groupBox.Height = 120;
groupBox.Left = 5;
groupBox.Top = 42 + (groupBox.Height * i) + (10 * i);
groupBox.Text = "Verification #" + j.ToString();
//Create VerStart
DateTimePicker verStart = new DateTimePicker();
verStart.Name = "verStart" + i.ToString();
verStart.Width = 224;
verStart.Height = 22;
verStart.Location = new Point(160, 25);
verStart.DataBindings.Add(new Binding("Value", acqreports_testDataSet, "verification.VerStarted"));
verStart.Value = verStartval;
//Create VerEnded
DateTimePicker verEnd = new DateTimePicker();
verEnd.Name = "verStart" + i.ToString();
verEnd.Width = 224;
verEnd.Height = 22;
verEnd.Location = new Point(160, 55);
verEnd.DataBindings.Add(new Binding("Value", acqreports_testDataSet, "verification.VerEnded"));
verEnd.Value = verEndval;
//Create VerTime
TextBox verTime = new TextBox();
verTime.Name = "verTime" + i.ToString();
verTime.Width = 224;
verTime.Height = 22;
verTime.Location = new Point(160, 85);
verTime.Text = verTimeval;
//Create Ver Start label
Label lblVerStart = new Label();
lblVerStart.Name = lblVerStart + i.ToString();
lblVerStart.Text = "Ver Started: ";
lblVerStart.Location = new Point(5, 25);
//Create Ver End label
Label lblVerEnd = new Label();
lblVerEnd.Name = lblVerEnd + i.ToString();
lblVerEnd.Text = "Ver Ended: ";
lblVerEnd.Location = new Point(5, 55);
//Create Ver Time label
Label lblVerTime = new Label();
lblVerTime.Name = lblVerTime + i.ToString();
lblVerTime.Text = "Ver Time: ";
lblVerTime.Location = new Point(5, 85);
//Add created controls to groupBox
groupBox.Controls.Add(verStart);
groupBox.Controls.Add(verEnd);
groupBox.Controls.Add(verTime);
groupBox.Controls.Add(lblVerStart);
groupBox.Controls.Add(lblVerEnd);
groupBox.Controls.Add(lblVerTime);
tabControl2.TabPages[2].Controls.Add(groupBox);
}
然後我想用DateTimePickers和VerTime.Text每個驗證事件更新表。
我有一些想法,但我需要一些更多的細節,我沒有得到很多你在做什麼。一些代碼會有幫助 – Luke 2011-02-07 17:19:24