Click here to Skip to main content
14,932,748 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am currently working on a E-Learning project , and I'm kinda stuck in the weekly calendar part. I made a Week calendar with tablelayout and buttons. Program renames the labels on the tablelayout when I click a button.
Here is how it looks like:Image_Flickr

What I want to do is I want every day to have their own lessons with names ,monday.lesson1 = biology etc. , and I want all of those lessons to have their own specific properties , monday.lesson1.description , monday.lesson1.starttime etc.
I thought I could use get set strings for this but I couldn't figure how to get the values of the lessons
What should I use for this ? Thanks in advance.
I am sorry if I couldn't express my question good.

What I have tried:

I tried to use {get; set;} OOP
Posted
Updated 23-Dec-20 0:29am
Comments
BillWoodruff 22-Dec-20 21:04pm
   
I suggest you make a diagram/sketch of what you want the UI to look like in actual use, and post that.

Describe the Classes and the inheritance relationships.
Arda Güler 23-Dec-20 2:49am
   
I don't know how to do this on visual studio , I don't think I can make a diagram of it. Basically I want to use monday.lesson1.name and monday.lesson1.starttime.I am not sure what to call it but I think it's property of a property or something.
Thank you for your reply.
BillWoodruff 23-Dec-20 14:47pm
   
You don't need Visual Studio to make a diagram, an outline, a sketch, a list of inputs, outputs, required functions. You need to think !
Richard MacCutchan 23-Dec-20 5:58am
   
You need a Lesson class that contains the properties of the lessons. You can then use get/set to access them. Then for each day you create a new Lesson object, set its properties and link it to the relevant session. You probably also need some backing store (e.g. database) to save and restore all the lessons.

1 solution

Hold on and stop thinking about user interface!

Start thinking about classes (objects)... Let say you have a list of lessons (List<Lesson>). Every Lesson object (class) has its own properties, such as: Name, Description, StartTime:
C#
public class Lesson
{
	private string sName = string.Empty;
	private string sDescription = string.Empty;
	private DateTime dStartTime = DateTime.MinValue;
	
	public Lesson(string _Name, string _Description, DateTime _StartTime)
	{
		sName = _Name;
		sDescription = _Description;
		dStartTime = _StartTime;
	}
	
	public string Name 
	{
		get => sName;
		set => sName = value;
	}
	
	public string Description 
	{
		get => sDescription;
		set => sDescription = value;
	}
	
	public DateTime StartTime 
	{
		get => dStartTime;
		set => dStartTime = value;
	}
	
	public DateTime EndTime 
	{
		get => dStartTime.AddMinutes(45);
	}
	
}


Assuming that StartTime is properly set, you can find all lessons in every day of month based on that property. See:

C#
List<Lesson> mondaylessons = alllessons.Where(x=> x.StartTime.DayOfWeek == DayOfWeek.Monday).ToList();



Code sample:
C#
List<Lesson> alllessons = new List<Lesson>();
	//add sample data
	for(int i = 0; i<9; i++)
	{
		DateTime startDateTime = new DateTime(2021, 1, 2 + i, 8, 0, 0);
		int[] cnt = {3, 5};
		int c = i % 2 == 0 ? 0 : 1;
		DateTime lessonStart = startDateTime;
		for(int j = 0; j<cnt[c]; j++)
		{
			Lesson l = new Lesson(new string((char)(65+j), 5), $"description{j}", lessonStart);
			alllessons.Add(l);
			lessonStart = l.EndTime.AddMinutes(10);
		}
	}
	//get monday's lessons
	List<Lesson> mondaylessons = alllessons.Where(x=> x.StartTime.DayOfWeek == DayOfWeek.Monday).ToList();
	foreach(Lesson l in mondaylessons)
		Console.WriteLine($"{l.Name} {l.Description} {l.StartTime.ToString("HH:mm")} {l.EndTime.ToString("HH:mm")}");


Result:
AAAAA description0 08:00 08:45
BBBBB description1 08:55 09:40
CCCCC description2 09:50 10:35
   
Comments
Richard MacCutchan 23-Dec-20 6:55am
   
You should get paid for all that code. :)
Maciej Los 23-Dec-20 7:32am
   
If i do, i'd be a very richman.
Merry Christmas, Richard!
Richard MacCutchan 23-Dec-20 7:43am
   
Merry Christmas to you too. Although it will be a bit less merry for us as we are not allowed to mix with our families.
Maciej Los 23-Dec-20 8:07am
   
Sad, but true. We all struggling with effects of COVID-19. :(
Arda Güler 23-Dec-20 11:34am
   
Thank you.
But I don't understand how can I implement this to the labels.
I know I am asking too much , you don't have to do anything.
But can you give an example of that ?
BillWoodruff 23-Dec-20 14:50pm
   
Start studying the code Maciej generously provided you and THINK about it rather than talking about what you don't understand.
BillWoodruff 23-Dec-20 14:51pm
   
+5
Maciej Los 23-Dec-20 15:16pm
   
Thank you very much, Bill.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900