Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Convert Class list to XML file to import in program.

$
0
0

Okay... i have now been searching the web for about a week and can't seems to get how to make my current list to a XML file that i later can place on my network share so i can import it from there to my program.

Heres my code from my form1:

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];

            //Oprettelse af OfficeList
            var OfficeList = new[] {
            new Office {Program = "Office 2007", sti = @"\\HQ\Software\Microsoft\Office\12\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Office\2007\Tekst.html"},
            new Office {Program = "Office 2010 (x86)", sti = @"\\HQ\Software\Microsoft\Office\14\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            new Office {Program = "Office 2010 (x64)", sti = @"\\HQ\Software\Microsoft\Office\14\x64\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            new Office {Program = "Office 2013 (x86)", sti = @"\\HQ\Software\Microsoft\Office\15\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            new Office {Program = "Office 2013 (x64)", sti = @"\\HQ\Software\Microsoft\Office\15\x64\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            new Office {Program = "Office 2016 (x86)", sti = @"\\HQ\Software\Microsoft\Office\16\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            new Office {Program = "Office 2016 (x64)", sti = @"\\HQ\Software\Microsoft\Office\16\x64\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"}
            };
            comboBox1.DataSource = OfficeList;
            comboBox1.DisplayMember = "Program";
            comboBox1.ValueMember = "sti";
            comboBox1.ValueMember = "side";

            #endregion

            #region comboBow2 indhold

            //Oprettelse af ClientList
            var ClientList = new[] {
            new Client {Program = "Windows Vista (x86)", sti = @"\\HQ\Software\Microsoft\Windows\6.0\Vista\Vista x64 AIO.ISO", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            };
            comboBox2.DataSource = ClientList;
            comboBox2.DisplayMember = "Program";
            comboBox2.ValueMember = "sti";
            comboBox2.ValueMember = "side";

            #endregion

            #region comboBox3 indhold

            //Oprettelse af ClientList
            var ServerList = new[] {
            new Server {Program = "Windows Server 2008 R2 (x86)", sti = @"\\HQ\Software\Microsoft\Windows\6.1\Server 2008 R2\en-ru_windows_server_2008_r2_x64_with_update_aio_34in1_x64_v16.02.22_by_adguard.ISO", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
            };
            comboBox3.DataSource = ServerList;
            comboBox3.DisplayMember = "Program";
            comboBox3.ValueMember = "sti";
            comboBox3.ValueMember = "side";
            #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)
        {
            #region Hardware retrive
            //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();

            //Total mængde RAM
            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");
            }
            #endregion

            #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.
            this.webBrowser1.Navigate(@"\\HQ\Software\Server Software sider\Startside.html");

            //Åbning af fil til tekst på fanen updates.
            this.webBrowser5.Navigate(@"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html");

        }

        #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();
        }

        private void changeLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Change_log_viewer box = new Change_log_viewer();
            box.ShowDialog();
        }
        #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(@"\\HQ\Software\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;
                webBrowser2.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);
                Application.Exit();
            }

        }
        #endregion

        #region Microsoft Windows tab
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Client c = comboBox2.SelectedItem as Client;
            if (c != null)
            {
                string url = c.side;
                webBrowser3.Navigate(url);

            }

        }

        //Åbning af software installer.
        private void button2_Click(object sender, EventArgs e)
        {
            Client c = comboBox2.SelectedItem as Client;
            if (c != null)
            {
                string url = c.sti;
                Process.Start(url);
                Application.Exit();
            }

        }


        #endregion

        #region Microsoft Windows Server tab
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            Server c = comboBox3.SelectedItem as Server;
            if (c != null)
            {
                string url = c.side;
                webBrowser4.Navigate(url);

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Server c = comboBox3.SelectedItem as Server;
            if (c != null)
            {
                string url = c.sti;
                Process.Start(url);
                Application.Exit();
            }
        }

        #endregion

        #region Update tab

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {

        }


        private void button4_Click(object sender, EventArgs e)
        {

        }
        #endregion

    }

}


as you can see in my code have i tryed to implement it but whit bad results.

Heres the Classes it has to work with:

Office Class:

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;
using System.Xml.Linq;

namespace HQ_Installer
{
    class Office

    {
        public string Program { get; set; }
        public string sti { get; set; }
        public string side { get; set; }


        //public XmlReadMode ReadXml(XmlReader reader);
    }

}

Client Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

Server Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

and last but not least heres the XML file i have been using to testing:

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

Is there anyway to make this to work with my XML file?
And hopfely whit all 3 lists in one XML file.



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>