--- dao/DaoMqPump2/DaoMqGUI/MainForm.cs 2013/07/05 08:43:21 1994 +++ dao/DaoMqPump2/DaoMqGUI/MainForm.cs 2013/08/28 06:45:20 2058 @@ -64,9 +64,18 @@ return result; } + public int getSelectedTransportIndex() + { + if (transports.SelectedIndices.Count == 0) + return -1; + else + return transports.SelectedIndices[0]; + } + public void loadTransports() { - int selected = transports.SelectedIndex; + + int selected = getSelectedTransportIndex(); if (selected == -1) //er der ikke valgt - vælger vi den første selected = 0; @@ -77,29 +86,34 @@ foreach (string t in transportNames) { transportNameList.Add(t); - - bool enabled = client.GetTransportEnabled(t); + StatusData statusData = client.GetTransportStatus(t); + bool enabled = statusData.transportEnabled; string status = ""; - + Color bgColor; if (enabled) { - bool lastOk = client.GetTransportLastrunOk(t); + bool lastOk = statusData.lastrunOk; if (lastOk) { - status = "running"; + status = "running"; + bgColor = Color.Green; } else { status = "error"; + bgColor = Color.Red; } } else { status = "stopped"; + bgColor = Color.DarkOrange; } - transports.Items.Add(t + " - " + status); + ListViewItem item = new ListViewItem(t + " - " + status); + item.ForeColor = bgColor; + transports.Items.Add(item); } @@ -111,7 +125,10 @@ selected = -1; } - transports.SelectedIndex = selected; + transports.SelectedIndices.Clear(); + if (selected != -1) + transports.SelectedIndices.Add(selected); + //transports.SelectedIndices[0] = selected; } @@ -153,38 +170,33 @@ private void transports_SelectedIndexChanged(object sender, EventArgs e) { - loadFormData(); + showData(); } - private void loadFormData() + private void loadStatusData() { - if (transports.SelectedIndex == -1) + if (getSelectedTransportIndex() == -1) return; - string transportName = transportNameList[transports.SelectedIndex]; - - bool enabled = client.GetTransportEnabled(transportName); - bool lastOk = client.GetTransportLastrunOk(transportName); + string transportName = transportNameList[getSelectedTransportIndex() ]; - string lastokTime = client.GetTransportLastOkTime(transportName); - string lastErrorTime = client.GetTransportLastErrorTime(transportName); + StatusData statusData = client.GetTransportStatus(transportName); - string errorMsg = client.GetTransportLastErrorMessage(transportName); - - int counter = client.GetTransportCounter(transportName); + bool enabled = statusData.transportEnabled; txtTransport.Text = transportName; txtEnabled.Text = "" + enabled; - txtLastOK.Text = "" + lastOk; - - txtOkTime.Text = lastokTime; - txtErrorTime.Text = lastErrorTime; + txtLastOK.Text = "" + statusData.lastrunOk; - txtErrorMsg.Text = errorMsg; + txtOkTime.Text = statusData.lastOkTime; + txtErrorTime.Text = statusData.lastErrorTime; + txtTransferTime.Text = statusData.lastTransferTime; - txtCounter.Text = "" + counter; + txtErrorMsg.Text = statusData.lastErrorMessage; + txtCounter.Text = "" + statusData.counter; + txtDiscarded.Text = "" + statusData.discardedCounter; btnDisableOne.Enabled = enabled; btnEnableOne.Enabled = (!enabled); @@ -193,22 +205,19 @@ private void refreshTimer_Tick(object sender, EventArgs e) { - loadTransports(); - - if (transports.SelectedIndex == -1) - return; + loadTransports(); - if (tabControl1.SelectedIndex != 0) //0 er status siden + if (getSelectedTransportIndex() == -1) return; - loadFormData(); + showData(); } private void loadLog() { - if (transports.SelectedIndex == -1) + if (getSelectedTransportIndex() == -1) return; - string transportName = transportNameList[transports.SelectedIndex]; + string transportName = transportNameList[getSelectedTransportIndex()]; string[] logEntries = client.GetTransportLog(transportName); @@ -223,9 +232,9 @@ private void loadConfig() { - if (transports.SelectedIndex == -1) + if (getSelectedTransportIndex() == -1) return; - string transportName = transportNameList[transports.SelectedIndex]; + string transportName = transportNameList[getSelectedTransportIndex()]; string direction = client.GetTransportDirection(transportName); string queue = client.GetTransportQueueName(transportName); @@ -241,15 +250,15 @@ } - private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + private void showData() { - if (transports.SelectedIndex == -1) + if (getSelectedTransportIndex() == -1) return; switch (tabControl1.SelectedIndex) { case 0: - loadFormData(); + loadStatusData(); break; case 1: loadLog(); @@ -260,6 +269,11 @@ } } + private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + showData(); + } + private void lnkServer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string tmp_hostname = Microsoft.VisualBasic.Interaction.InputBox("Indtast servernavn/ip", "MQ Gui", hostname); @@ -278,6 +292,9 @@ private void MainForm_Shown(object sender, EventArgs e) { + lnkServer.Text = "Connecting ..."; + this.Refresh(); //force a redraw now () before we do the heavy work + initClient(); loadTransports(); }