9 Replies - 1320 Views - Last Post: 15 April 2011 - 05:42 PM Rate Topic: -----

#1 Tara200   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 85
  • Joined: 13-October 07

Uni Module Selector Form

Posted 12 April 2011 - 12:55 AM

Hi,
I am building a timetable for university students, i have a basic windows form with two listboxxes side by side. The left one has listed all the available modules the student can enrol on and the right box is where the modules go once the student has selected the individual modules and clicked the select button (in the middle of the boxes)to transfer it over. I am not sure as to how to code the module class (is that get and set modules etc?) and how to get started on the algorithm for the click button.

i have designed a activity diagram (attached below with the full program)

I would be very grateful of any help you can give me with this....





Form.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModuleSelector.Entities;
using System.Xml;
using System.IO;

namespace ModuleSelector
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            int slot = (int)Timetable.timeSlots.Monday4_6;
            System.Console.WriteLine(slot);
           
        }

        private void listBoxModules_DragLeave(object sender, EventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
            //would need to draw the text to mouse now 
        }

        private void buttonAddModule_Click(object sender, EventArgs e)
        {
           //Not sure how to code this? 
        }
    }
}




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

namespace ModuleSelector.Entities
{
  class Timetable
    {
      /// <summary>
      /// enumarated weekly time slots
      /// </summary>
      public enum timeSlots
      {
          Monday9_11 = 0, Monday11_1, Monday2_4, Monday4_6,
          Tuesday9_11, Tuesday11_1, Tuesday2_4, Tuesday4_6,
          Wednesday9_11, Wednesday11_1,
          Thursday9_11, Thursday11_1, Thursday2_4,Thursday4_6
      }
    }
}



using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace ModuleSelector.Entities
{
    class Module
    {
        //Get and Set methods?

    }
       

      
}

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Uni Module Selector Form

#2 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Uni Module Selector Form

Posted 12 April 2011 - 05:00 AM

1. Don't use an Enum unless that is specifically what you want to use. If you need to get the names of each enumeration, it's much better to just use a collection of some sort.

2. In order to display items in a ListBox you can set it's .DataSource to a collection.

For example, I were to create a listbox for all the companies.

public class Company
{
    public int ID { get;set; }
    public string Name { get; set; }
}

List<Company> Companies = new List<Company>(){
    new Company(){ ID = 1, Name = "Microsoft",
    new Company(){ ID = 2, Name = "Adobe",
    new Company(){ ID = 3, Name = "Redbull"
};

listBoxCompanies.DisplayMember = "Name";
listBoxCompanies.ValueMember = "ID";
listBoxCompanies.DataSource = Companies;

This post has been edited by Sergio Tapia: 12 April 2011 - 05:00 AM

Was This Post Helpful? 0
  • +
  • -

#3 Tara200   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 85
  • Joined: 13-October 07

Re: Uni Module Selector Form

Posted 12 April 2011 - 12:09 PM

Hi, thankyou for your input, have to use an enum as its part of the spec, is your above code List referring to the module class?

This post has been edited by JackOfAllTrades: 14 April 2011 - 12:34 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#4 Tara200   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 85
  • Joined: 13-October 07

Re: Uni Module Selector Form

Posted 14 April 2011 - 11:27 AM

Hi all,

Hi i have a C# windows form that has two list boxes on it.the left one contains a list of 16 student module codes that are available to enrol onto. The user selects a module from the left to transfer to the right box.

I have it working up to this point, the module code transfers when the select button is clicked.

Once a module has been transferred i need to click on it and print out onto a label (placed to the right of it)the full module details that are held in an XML file.

I am able to read through the contents of the XML file and output that to the label (all contents) what i need it to do is just print out the "SELECTED module/modules" details to the label.

So i have to somehow use the XMLTextReader to read through the XML file and pick out the particular module/modules details that the user selects? So if he/she selects 8 modules then i just want the details of all of those to display on the label?

More simply the user transfers a module code to the second ListBox and when each is selected(clicked on) from there then the details of it(held in the XML file,module name, description etc etc)needs to display on the label next to the ListBox?

This is the relevant code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModuleSelector.Entities;
using System.Xml;
using System.IO;

namespace ModuleSelector
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        String mName, mCode, mDescription, mCapacity, mLectureSlot, mTutorialSlot;
        string workingDir = Directory.GetCurrentDirectory();
        /** private Module md;

         internal Module Md
         {
             get { return md; }
             set { md = value; }
         }  
         */
        private void FormMain_Load(object sender, EventArgs e)
        {
            int slot = (int)Timetable.timeSlots.Monday4_6;
            System.Console.WriteLine(slot);
        }
        private void listBoxModules_DragLeave(object sender, EventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }

        private void listBoxModules_DrawItem(object sender, EventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }
        private void buttonAddModule_Click(object sender, EventArgs e)
        {
            listBoxSelectedModules.Items.Add(listBoxModules.SelectedItem);

        }


        private void listBoxSelectedModules_DrawItem(object sender, DrawItemEventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }


        private void listBoxModules_DrawItem(object sender, DrawItemEventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }

        private void buttonRemoveModule_Click(object sender, EventArgs e)
        {
            listBoxSelectedModules.Items.Remove(listBoxModules.SelectedItem);
        }

        private void buttonsubmit_Click(object sender, EventArgs e)
        {

            XmlTextReader textReader = new XmlTextReader(workingDir + @"\XMLModules.xml");
            while (textReader.Read())
            {
                textReader.MoveToElement();
                //gets module name from XML file
                if (textReader.Name == "moduleName")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;

                    if (nType == XmlNodeType.Text)
                    {
                        mName += (" Module Name: " + textReader.Value.ToString());
                    }
                }
                //gets module code from XML file
                if (textReader.Name == "moduleCode")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;

                    if (nType == XmlNodeType.Text)
                    {
                        mCode += (" Module Code: " + textReader.Value.ToString());
                    }
                }
                //gets module description from XML file
                if (textReader.Name == "moduleDescription")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mDescription += (" Module Description: " + textReader.Value.ToString());
                    }
                }
                //Gets module capacity from XML file
                if (textReader.Name == "moduleCapacity")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mCapacity += (" Module Capacity: " + textReader.Value.ToString());
                    }

                }
                //Gets module Lecture slot from XML file
                if (textReader.Name == "lectureSlot")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mLectureSlot += (" Lecture Slot: " + textReader.Value.ToString());
                    }
                }

                //Gets tutorial slot from XML file
                if (textReader.Name == "tutorialSlot")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mTutorialSlot += (" Tutorial Slot: " + textReader.Value.ToString());
                    }
                }
                //Writes the data to the label
                this.formLabel.Text = mName +
                    "\n" + mCode +
                    "\n" + mDescription +
                    "\n" + mCapacity +
                    "\n" + mLectureSlot +
                    "\n" + mTutorialSlot;
            }
            textReader.Close();
        }

        
    }
}


This post has been edited by Tara200: 14 April 2011 - 11:29 AM

Was This Post Helpful? 0
  • +
  • -

#5 Tara200   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 85
  • Joined: 13-October 07

Re: Uni Module Selector Form

Posted 15 April 2011 - 01:33 PM

This is apart of another post i posted but it is a different subject so...and plus no one helped with my last post at all so thought i would try again....


I am able to read through the contents of an XML file and output that to a label (all contents) what i need it to do is just print out the "SELECTED module" details to the label. So i have to somehow read through the XML file and pick out the particular module/modules that the user selects? So if he/she selects 8 modules then i just want the details for those to display on the label?

I don't know how to select a particular group of nodes associated with a xml file any ideas??



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModuleSelector.Entities;
using System.Xml;
using System.IO;
using System.Xml.XPath;
using System.Xml.Linq;



namespace ModuleSelector
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        String mName, mCode, mDescription, mCapacity, mLectureSlot, mTutorialSlot;
        string workingDir = Directory.GetCurrentDirectory();

        private void FormMain_Load(object sender, EventArgs e)
        {

            int slot = (int)Timetable.timeSlots.Monday4_6;
            System.Console.WriteLine(slot);




        }

        private void listBoxModules_DragLeave(object sender, EventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }


        private void listBoxModules_DrawItem(object sender, EventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }

        private void buttonAddModule_Click(object sender, EventArgs e)
        {
            listBoxSelectedModules.Items.Add(listBoxModules.SelectedItem);

        }



        private void listBoxSelectedModules_DrawItem(object sender, DrawItemEventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }


        private void listBoxModules_DrawItem(object sender, DrawItemEventArgs e)
        {
            String module = (String)listBoxModules.SelectedItem;
        }

        private void buttonRemoveModule_Click(object sender, EventArgs e)
        {
            listBoxSelectedModules.Items.Remove(listBoxModules.SelectedItem);
        }

        private void buttonsubmit_Click(object sender, EventArgs e)
        {

        }
        private void listBoxSelectedModules_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Traverses through the Xml file reading each node
            XmlTextReader textReader = new XmlTextReader(workingDir + @"\XMLModules.xml");
            while (textReader.Read())
            {
                textReader.MoveToElement();
                if (textReader.Name == "moduleName")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;

                    if (nType == XmlNodeType.Text)
                    {
                        mName += (" Module Name: " + textReader.Value.ToString());
                    }
                }

                if (textReader.Name == "moduleCode")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;

                    if (nType == XmlNodeType.Text)
                    {
                        mCode += (" Module Code: " + textReader.Value.ToString());
                    }
                }

                if (textReader.Name == "moduleDescription")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mDescription += (" Module Description: " + textReader.Value.ToString());
                    }
                }

                if (textReader.Name == "moduleCapacity")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mCapacity += (" Module Capacity: " + textReader.Value.ToString());
                    }

                }

                if (textReader.Name == "lectureSlot")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mLectureSlot += (" Lecture Slot: " + textReader.Value.ToString());
                    }
                }


                if (textReader.Name == "tutorialSlot")
                {
                    textReader.Read();
                    XmlNodeType nType = textReader.NodeType;
                    if (nType == XmlNodeType.Text)
                    {
                        mTutorialSlot += (" Tutorial Slot: " + textReader.Value.ToString());
                    }
                }
                //Outputs the data to the label
                this.formLabel.Text = mName +
                    "\n" + mCode +
                    "\n" + mDescription +
                    "\n" + mCapacity +
                    "\n" + mLectureSlot +
                    "\n" + mTutorialSlot;
            }
            textReader.Close();
        }

        private void listBoxSelectedModules_MouseClick(object sender, MouseEventArgs e)
         {
             // Code needed here to select individual XML nodes?  
         }
    }
}       
            


Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,181
  • Joined: 12-June 08

Re: Uni Module Selector Form

Posted 15 April 2011 - 01:46 PM

They looked pretty similar to me. Try and limit the duplicate threads!
Was This Post Helpful? 1
  • +
  • -

#7 Tara200   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 85
  • Joined: 13-October 07

Re: Uni Module Selector Form

Posted 15 April 2011 - 01:53 PM

Yes they are similar!! That was my whole point....trying to draw attention to them for help, as my post was just getting ignored. The first part of the program is done so the second part is very different...only i added it to the first part originally and didn't get a response at all...so
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,181
  • Joined: 12-June 08

Re: Uni Module Selector Form

Posted 15 April 2011 - 02:23 PM

Quote

That was my whole point....trying to draw attention to them for help, as my post was just getting ignored.

...

didn't get a response at all...so


Just a friendly reminder this is a volunteer forum. Knowledgeable folk stop in and help out when they can. No one is entitled to answers; that is not a forward thinking attitude to have!

Clearly you were able to make some forward progress on your own so kudos to that.


Quote

So i have to somehow read through the XML file and pick out the particular module/modules that the user selects? So if he/she selects 8 modules then i just want the details for those to display on the label?

I don't know how to select a particular group of nodes associated with a xml file any ideas??


How are the XML files setup? usually there is an 'id node' - something that is unique to say that "this is nodeA and I am different from nodeB!". Do you have something like that in your setup? I would think that would be the "moduleCode" but I don't know. Can you put an example of the XML for a module out to look at?
Was This Post Helpful? 0
  • +
  • -

#9 Tara200   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 85
  • Joined: 13-October 07

Re: Uni Module Selector Form

Posted 15 April 2011 - 03:05 PM

Please dont misunderstand i am not thinking i am entitled to answers no more than the next person!I told you why i reposted it so no need for the attitude, and i also accept your friendly reminder there was no need to go any further with that :)

People volunteer on here because they want to and enjoy it and are enthusiastic about programming.Generally most posts are answered in some way of some sort....thats all, and i am just a bit anxious to get my work done as i have a tuesday deadline.

Anyway, thankyou for this, this is an example of a module:
<modules>
<module>
   <moduleCode>3SFE504</moduleCode>
   <moduleName>Algorithms and Data Structures</moduleName>
   <moduleCapacity>5</moduleCapacity>
   <semester>1</semester>
   <Prerequisite>none</Prerequisite>
   <lectureSlot>0</lectureSlot>
   <tutorialSlot>1</tutorialSlot>
   <moduleDescription>Data structures, ADT's and    implementations</moduleDescription>
</module>



Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6258
  • View blog
  • Posts: 24,026
  • Joined: 23-August 08

Re: Uni Module Selector Form

Posted 15 April 2011 - 05:42 PM

In case you missed it, we do have a tutorial that covers both XML files AND ListBoxes. That might be helpful for you to work through.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1