Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
The user needs to have an annual summary of the entitlements displayed. Rest periods are 6 days of work and 2 days of rest. Example if rest falls on Monday and Tuesday, the next ones will be Tuesday and Wednesday and so on. I have no idea how to start doing this, can you help me?


What I have tried:

I haven't tried anything because I have no idea how to start, I'm new to this field.
Posted
Updated 2-Feb-23 22:18pm
Comments
Richard Deeming 12-Jan-23 8:36am    
Then talk to your teacher. Nobody here is going to do your homework for you.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Member 15771242 12-Jan-23 13:05pm    
Thanks for the reply. In truth, I didn't want ready-made code, but an idea where to start. For me, computer science is a hobby and a personal study, without earnings. I've done so many other things, with the help of web search, but in this case I'm stuck, I have no idea where to start. What I'm asking for is just a starting point for what I've asked for. Anyway thanks all the same, I will abandon the project since I haven't found anything on the web. Best regards
Pete O'Hanlon 12-Jan-23 15:22pm    
Don't abandon it. It's a fun little challenge and one you should definitely do. Try breaking it down into smaller chunks and solve those.
OriginalGriff 12-Jan-23 15:25pm    
So follow the link and you'll get an idea how to start.
Don't give up because others haven't done the work for you - half the fun of this stuff is working out what you need to do - writing the actual code is the dull bit most of the time! :D
Initially, you can start by ignoring needing to know what day of the week you are looking at. Just use a loop and some simple DateTime arithmetic. If I were solving this using DateTime (or DateOnly in a grown up .NET version), I would consider the following:

  1. The date we start our calculation from is supplied to us as a parameter
  2. We are ending when the calculated start date of a shift is greater than 1 year from now

Knowing this, I would create a list of DateTime (DateOnly) that will contain the first day off.
In a loop, I would add 6 days to the start date. This date would be added to the list.
The new start date would be 2 days from this date.
Repeat the loop until we have past the end date

If I want to know the start dates of my days off, I simply loop over the list and look at the DayOfWeek. The last day of this time off is the item in the list + 1 day.

This isn't complicated code to write. Try it, and let us know how you get on.
 
Share this answer
 
Comments
BillWoodruff 13-Jan-23 0:33am    
special medal for helping homework shirkers/procrastinators who "haven't tried anything" ?
C#
 private void btnRiposi_Click(object sender, System.EventArgs e)
        {
            DateTime startDate = new DateTime(2023, 2, 2);
            DateTime endDate = new DateTime(2023, 12, 31);

            for (double loopDate = startDate.ToOADate(); loopDate <= endDate.ToOADate(); loopDate++)
            {
                DateTime selectedDate;
                selectedDate = DateTime.FromOADate(loopDate);
                rtbRiposi.Text = selectedDate.ToString();
            }
        }
    }
}


@Pete O'Hanlon, I tried this but it only saves me the last rest date in RichTextBox, how do I make a list of all rest in current year?
 
Share this answer
 
v2
Why are you doing it so complicated ?
It seams to me like a kind of a Shift-Modell.
So ... you take your StartDate (this is your Shift-begin) and add 6 Days to it (that is your Off-begin). Now you add 2 Days to it and you have your new Shift-begin.
Repeat that until you have reached your End-Date ...
I will not provide any code for that - I think this desciption is enough to start ...
Are you familiar with the Function AddDays for DateTime ?
 
Share this answer
 
Comments
Member 15771242 4-Feb-23 10:49am    
If I have to enter all the dates, what is the program and scheduling for? The work should be done by the code, otherwise I use the calendar, notepad and pen, which I do before, right?
Ralf Meier 4-Feb-23 11:57am    
I don't understand your reply - sorry ...
The work could be done by the code and if you read my answer carefully you could see that the sentences 3 and 4 describe the code you need.
Member 15771242 10-Feb-23 21:29pm    
I solved it with excel which is much more flexible than c#, however not having many notions of c#, I would be grateful if you would show me just a start of the code, because you have to believe me and forgive my ignorance about it, I didn't understand what to do , I just need a start code, I'll do the rest. Thanks anyway for the replies.
Ralf Meier 11-Feb-23 3:34am    
??? ... and how did you realized it in Excel ???
Member 15771242 14-Feb-23 20:45pm    
First I entered the starting date in cell B2 and in the one below which is cell B3, the formula is: =B2+6 so as to obtain the last day of work. Then in F3 the formula is: B3+1 so as to get the first rest and then in J3 the formula is: F3+1 so as to get the second rest. I dragged the cells with the + and here is magically all I need.

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