Data bind from network based XML file to class C#

  • Thread starter Thread starter Alex Jonas Jensen
  • Start date Start date
A

Alex Jonas Jensen

Guest
Hello.

I am trying to move my internal list to a network based XML file.

As i have tryed defrend things now i am stock at this code in my application:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Xml.Linq;


namespace HQ_Installer
{
public partial class Form1 : Form
{

public Form1()
{

InitializeComponent();

#region ComboBox1 indhold

Office OfficeList = new Office();
OfficeList.ReadXml(@"\\HQ\Software\att.xml");
//comboBox1.DataSource = OfficeList;
comboBox1.DisplayMember = "Program";
comboBox1.ValueMember = "sti";
comboBox1.ValueMember = "side";
OfficeList.Tables[0].DefaultView.Sort = "Program";
comboBox1.DataSource = OfficeList.Tables[0];

//var OfficeList = new[] {
//new Office {Program = "Office 2007", sti = @"\\HQ\Software\Microsoft\Office\12\x86\Suits\setup.exe", side = "http://www.google.com"},
//new Office {Program = "Office 2010", sti = @"\\HQ\Software\Microsoft\Office\14\x86\Suits\setup.exe", side = "http://www.microsoft.com"}

//};
//comboBox1.DataSource = OfficeList;
//comboBox1.DisplayMember = "Program";

#endregion

#region Start og slut af splash screen del 1
Thread t = new Thread(new ThreadStart(Startform));
t.Start();
Thread.Sleep(5000);
t.Abort();
#endregion

#region Tab navne
//Tab side navne
tabPage1.Text = "Start";
tabPage2.Text = "Microsoft Office";
tabPage3.Text = "Microsoft Windows";
tabPage4.Text = "Microsoft Windows Server";
tabPage5.Text = "Opdate";
#endregion

}

#region Start og slut af splash screen del 2
public void Startform()
{
Application.Run(new splash_screen());
}
#endregion

private void Form1_Load(object sender, EventArgs e)
{

//CPU clock speed
ManagementObject CPU_speed = new ManagementObject("Win32_Processor.DeviceID=CPU0");
uint speed = (uint)(CPU_speed["MaxClockSpeed"]);
CPU_speed.Dispose();
label6.Text = speed + " MHz".ToString();

string Query = "SELECT MaxCapacity FROM Win32_PhysicalMemoryArray";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(Query);
foreach (ManagementObject WniPART in searcher.Get())
{
UInt32 SizeinKB = Convert.ToUInt32(WniPART.Properties["MaxCapacity"].Value);
UInt32 SizeinMB = SizeinKB / 1024;
UInt32 SizeinGB = SizeinMB / 1024;
label8.Text = (SizeinGB + " GB");
}
#region Progress bar del 1
// Start the BackgroundWorker.
backgroundWorker1.RunWorkerAsync();
#endregion

#region Forbindelses til HQ server test
if (Directory.Exists(@"\\HQ\Software"))
{

}
else
{
MessageBox.Show("Der kan ikke oprettes forbindelse til \r\nSoftware mappen på HQ server.\r\n\r\nLøs problemet og prøv igen.",
"Test af forbindelse til HQ Server.",
MessageBoxButtons.OK,
//MessageBoxIcon.Warning // for Warning
MessageBoxIcon.Error // for Error
//MessageBoxIcon.Information // for Information
//MessageBoxIcon.Question // for Question
);
Application.Exit();

}
#endregion

#region Skal flyttes på senere
//Åbning af fil til tekst på start siden.
richTextBox1.Text = File.ReadAllText(@"\\HQ\Software\Start fil.txt", System.Text.Encoding.UTF7);

//Åbning af "web side" i web browser.
//this.webBrowser1.Navigate("http://www.microsoft.com");

}

#endregion

#region Progress bar Del 2
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress.
backgroundWorker1.ReportProgress(i);
}
}

private void backgroundWorker1_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
toolStripProgressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
#endregion

#region Menu strip
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutBox1 box = new AboutBox1();
box.ShowDialog();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion

//private void Load_comboBox1()
//{
//DataSet ds = new DataSet();
//DataTable dt = new DataTable("Office");
//ds.Tables.Add(dt);
//dt.Columns.Add("Program");
//dt.Columns.Add("sti");
//dt.Columns.Add("side");
//foreach (DataColumn dc in dt.Columns)
//{
//dc.ColumnMapping = MappingType.Attribute;
//}
//FileStream myFileStream = new FileStream("C:\\att.xml", FileMode.Open, FileAccess.Read);
//StreamReader myXmlStream = new StreamReader(myFileStream);
//ds.ReadXml(myXmlStream);
//myFileStream.Close();
//comboBox1.DataSource = ds.Tables[0];
//comboBox1.DataBind();
//}

#region Microsoft Office tab

//Ændring af info i webBrowser1.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Office c = comboBox1.SelectedItem as Office;
if (c != null)
{
string url = c.side;
webBrowser1.Navigate(url);
}

}

//Åbning af software installer.
private void button1_Click(object sender, EventArgs e)
{
Office c = comboBox1.SelectedItem as Office;
if (c != null)
{
string url = c.sti;
Process.Start(url);
}

}
#endregion

#region Microsoft Windows tab



#endregion

#region Microsoft Windows Server tab



#endregion

#region Update tab


#endregion
}

}

And this is my Office Class there are binds to and from:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Xml;
using System.IO;

namespace HQ_Installer
{
class Office
{
public string Program { get; set; }
public string sti { get; set; }
public string side { get; set; }

public XmlReadMode ReadXml(Stream stream);
}
}


And this is my XML file i am trying to open

<?xml version="1.0" encoding="UTF-8"?>
<OfficeList>
<Field side="http://www.google.com" sti="\\HQ\Software\Microsoft\Office\12\x86\Suits\setup.exe" Program="Office 2007"/>
</OfficeList>

The only thing there are working is the bind to comboBox1.
The rest of the binding to my Office Class does not work at all.

Is there a way to fix that in my codes?

Continue reading...
 
Back
Top