[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

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

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
MSFanboy
Asked:
MSFanboy
  • 4
  • 4
1 Solution
 
magicdlfCommented:
I have several questions about your problem:
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
 
MSFanboyAuthor Commented:
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
 
magicdlfCommented:
How can 1 combobox indicate the rotate duration for both A and B?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
magicdlfCommented:
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++)
            {
                weeks.Add(new Week(i));
            }
            for (int i = 1; i <= 16; i++)
            {
                comboBox1.Items.Add(i);
                comboBox2.Items.Add(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)
                {
                    listBox1.Items.Add(wk);
                    if (cnt == (int)comboBox1.SelectedItem)
                    {
                        isWeekA = false;
                        cnt = 0;
                    }
                }
                else
                {
                    listBox2.Items.Add(wk);
                    if (cnt == (int)comboBox2.SelectedItem)
                    {
                        isWeekA = true;
                        cnt = 0;
                    }
                }
            }
        }
    }
}

Open in new window

0
 
MSFanboyAuthor Commented:
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
 
magicdlfCommented:
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
 
MSFanboyAuthor Commented:
yeah I do it for myself actually your code is already a solution just read from one combobox ;-)
0
 
MSFanboyAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now