Solved

# Weekly rotation every X weeks, how to get the week objects from week A and B ?

Posted on 2009-12-30
245 Views
Hello,

I have for example 211 days / 7 =  31 week object or List<Week> with 31 objects.

Now the user of my programm can set the tasks he will do for the next 2 weeks or 3 weeks or 4 weeks. This I call week A. After this 2,3 or 4 or X weeks it changes/rotates and he wants to set other tasks for week 5,6,7,8 and after this everything repeats.

The user must be able to set a weekly rotation from 1 week to 16 weeks. That means the tasks he is doing rotate every week or every 16 weeks...

now I have the 31 week objects and lets assume the user has set a 4 week roation. In the end I want to get 2 lists for week A/B containing 16 and 15 week objects.

How can I read that List<Week> with 31 objects and split it in a GENERIC way so I get 2 Lists with week A/B,

I bet the solution needs many if-clauses, surprise me ;-)
0
Question by:MSFanboy

LVL 9

Expert Comment

1. Is there only 2 kinds of week (A/B) in your requirement? Does that mean the user will either do tasks for A or B?
2. How do the user set the rotations? Can you show me the function signature?
3. if the user set week 1,2,3 for A, 4,5,6,7 for B. So in week 8,9,10 he will do A and 11,12,13,14 he will do B, am I right? Is that the only case that you want?
0

Author Comment

1.) yes 2 kind of weeks A and B which rotate by every XX week
2.) a combobox which contains integers from 1 - 16
3.) Yes
0

LVL 9

Expert Comment

How can 1 combobox indicate the rotate duration for both A and B?
0

LVL 9

Accepted Solution

See if this is working for you, I used 2 combo boxes.
``````using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace ShiftWeeks

{

public partial class Form1 : Form

{

class Week

{

private int _id;

public Week(int id)

{

_id = id;

}

public override string ToString()

{

return string.Format("Week {0}", _id);

}

}

private List<Week> weeks = new List<Week>();

public Form1()

{

InitializeComponent();

for (int i = 1; i <= 31; i++)

{

}

for (int i = 1; i <= 16; i++)

{

}

comboBox1.SelectedIndex = 0;

comboBox2.SelectedIndex = 0;

}

private void button1_Click(object sender, EventArgs e)

{

listBox1.Items.Clear();

listBox2.Items.Clear();

int cnt = 0;

bool isWeekA = true;

foreach (Week wk in weeks)

{

cnt++;

if (isWeekA)

{

if (cnt == (int)comboBox1.SelectedItem)

{

isWeekA = false;

cnt = 0;

}

}

else

{

if (cnt == (int)comboBox2.SelectedItem)

{

isWeekA = true;

cnt = 0;

}

}

}

}

}

}
``````
0

Author Comment

seems you misunderstood me. I explain again:

there is only ONE combobox with value 1 - 16 so the user can rotate 1-16 weeks like this

test with 4-weekly rotation
Week A: 1,2,3,4,9,10,11,12,17,18,19,20
Week B: 5,6,7,8,13,14,15,16,21,22,23,24

Hope you understand it now else a happy new year to you :P
0

LVL 9

Expert Comment

That's even easier. Do you want to try it yourself? One combobox is just a special case of my program (combobox1.value == combobox2.value).
Happy new year to you too! Let me know if you need further help.
0

Author Comment

yeah I do it for myself actually your code is already a solution just read from one combobox ;-)
0

Author Closing Comment

no time to test it yet but it looks right to me, thanks a bunch!

Changing the week a/b when the selected rotation is == counter that did the trick :)
0

## Featured Post

### Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…