Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am in the process of creating an application/panel that will aide me in scheduling hours for my staff of ten or more. I am hoping to create a multi-tabbed grid within which I may collect data about my staff and ultimately create a final schedule based on their choices. I have started the code, but I find myself stuck in a couple places: creating a grid that pulls that data from the other grids to give an overview of the schedule (in order to find overlapping hours, holes in the schedule, etc.), saving the data in the input fields once entered, and counting the number of check boxes that are ticked on each tab. My code can be found below, any guidance, help, or thoughts would be very helpful at this point. Thank you.

Mathematica graphics

f = Enabled -> False;
m = ImageMargins -> 20;
week =
  Grid[{
    {"", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", 
     "Saturday", "Sunday"},
    {"8:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[f], Checkbox[f]},
    {"9:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"10:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"11:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"12:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"1:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"2:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"3:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"4:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"5:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"6:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"7:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"8:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"9:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"10:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"11:00 PM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"12:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"1:00 AM", Checkbox[m], Checkbox[m], Checkbox[m], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[m]},
    {"2:00 AM", Checkbox[f], Checkbox[f], Checkbox[f], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[f]},
    {"3:00 AM", Checkbox[f], Checkbox[f], Checkbox[f], Checkbox[m], 
     Checkbox[m], Checkbox[m], Checkbox[f]}
    }, Frame -> All];
Clear[ln, fn, ws, ln2, fn2, ws2, ln3, fn3, ws3]
input =
  Panel[
   Grid[{
     {""},
     {Style["Front Desk Assignment Preferences", 14, Bold], 
      SpanFromLeft, SpanFromLeft, SpanFromLeft},
     {""},
     {"Last Name:", InputField[Dynamic[ln], String], SpanFromLeft, 
      SpanFromLeft},
     {"First Name:", InputField[Dynamic[fn], String], SpanFromLeft, 
      SpanFromLeft},
     {"-----------------------------------------------", SpanFromLeft,
       SpanFromLeft, SpanFromLeft},
     {"Workstudy:", RadioButtonBar[2, {1 -> "Yes", 2 -> "No"}], 
      SpanFromLeft, SpanFromLeft},
     {"Workstudy Amount:  $", 
          InputField[Dynamic[n], Number, FieldSize -> 10], SpanFromLeft, 
          SpanFromLeft},
         {"-----------------------------------------------", SpanFromLeft,
           SpanFromLeft, SpanFromLeft},
         {"Weekend Preference:", 
          RadioButtonBar[3, {1 -> "A", 2 -> "B", 3 -> "Either"}], 
          SpanFromLeft, SpanFromLeft},
         {""},
         {"-----------------------------------------------", SpanFromLeft,
           SpanFromLeft, SpanFromLeft},
         {Style[
           "Please select the hours you are interested in working from \
    the table below:", Bold], SpanFromLeft, SpanFromLeft, SpanFromLeft},
         {week, SpanFromLeft, SpanFromLeft, SpanFromLeft},
         {""}
         }, Alignment -> Left]];
    input2 =
      Panel[
       Grid[{
         {""},
         {Style["Front Desk Assignment Preferences", 14, Bold], 
          SpanFromLeft, SpanFromLeft, SpanFromLeft},
         {""},
         {"Last Name:", InputField[Dynamic[ln2], String], SpanFromLeft, 
          SpanFromLeft},
         {"First Name:", InputField[Dynamic[fn2], String], SpanFromLeft, 
          SpanFromLeft},
         {"-----------------------------------------------", SpanFromLeft,
           SpanFromLeft, SpanFromLeft},
         {"Workstudy:", RadioButtonBar[2, {1 -> "Yes", 2 -> "No"}], 
          SpanFromLeft, SpanFromLeft},
         {"Workstudy Amount:  $", 
          InputField[Dynamic[n2], Number, FieldSize -> 10], SpanFromLeft, 
          SpanFromLeft},
         {"-----------------------------------------------", SpanFromLeft,
           SpanFromLeft, SpanFromLeft},
         {"Weekend Preference:", 
          RadioButtonBar[3, {1 -> "A", 2 -> "B", 3 -> "Either"}], 
          SpanFromLeft, SpanFromLeft},
         {""},
         {"-----------------------------------------------", SpanFromLeft,
           SpanFromLeft, SpanFromLeft},
         {Style[
           "Please select the hours you are interested in working from \
    the table below:", Bold], SpanFromLeft, SpanFromLeft, SpanFromLeft},
         {week, SpanFromLeft, SpanFromLeft, SpanFromLeft},
         {""}
         }, Alignment -> Left]];
    input3 =
      Panel[
       Grid[{
         {""},
         {Style["Front Desk Assignment Preferences", 14, Bold], 
          SpanFromLeft, SpanFromLeft, SpanFromLeft},
         {""},
         {"Last Name:", InputField[Dynamic[ln3], String], SpanFromLeft, 
          SpanFromLeft},
         {"First Name:", InputField[Dynamic[fn3], String], SpanFromLeft, 
          SpanFromLeft},
         {"-----------------------------------------------", SpanFromLeft,
           SpanFromLeft, SpanFromLeft},
         {"Workstudy:", RadioButtonBar[2, {1 -> "Yes", 2 -> "No"}], 
          SpanFromLeft, SpanFromLeft},
         {"Workstudy Amount:  $", 
      InputField[Dynamic[n3], Number, FieldSize -> 10], SpanFromLeft, 
      SpanFromLeft},
     {"-----------------------------------------------", SpanFromLeft,
       SpanFromLeft, SpanFromLeft},
     {"Weekend Preference:", 
      RadioButtonBar[3, {1 -> "A", 2 -> "B", 3 -> "Either"}], 
      SpanFromLeft, SpanFromLeft},
     {""},
     {"-----------------------------------------------", SpanFromLeft,
       SpanFromLeft, SpanFromLeft},
     {Style[
       "Please select the hours you are interested in working from \
the table below:", Bold], SpanFromLeft, SpanFromLeft, SpanFromLeft},
     {week, SpanFromLeft, SpanFromLeft, SpanFromLeft},
     {""}
     }, Alignment -> Left]];
final = TabView[{"Worker 1" -> input, "Worker 2" -> input2, 
   "Worker 3" -> input3}]
share|improve this question
2  
Just my opinion, but I think a spreadsheet is better for this sort of thing than Mathematica. –  m_goldberg Nov 23 '12 at 3:49
    
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign –  Sjoerd C. de Vries Nov 23 '12 at 8:23
    
@m_goldberg: Excel was my first thought, but I ran into serious problems when it came to finding a way to consolidate all the staff on the "All" sheet in a manner that gave me more information than just the sum of those interested in that particular time slot. Do you have any thoughts on how I could better accomplish what I'm attempting in Excel? If so, I'd be very interested. Thanks. –  MathRulesTheWorld Nov 23 '12 at 16:24

3 Answers 3

up vote 6 down vote accepted
 DynamicModule[{n = 3,
  prefTable = ConstantArray[0, {3, 20, 7}],
  lastName = ConstantArray["", {3}],
  firstName = ConstantArray["", {3}],
  ws = ConstantArray[0, {3}],
  wsAmount = ConstantArray[Null, {3}],
  wkndPref = ConstantArray[Null, {3}],
  tabLabel = Array["Worker " <> ToString[#] &, {3}],
  hours = DateString[DatePlus[{2012, 1, 1, 7, 0, 0}, {#, "Hour"}],
     {"Hour12", ":", "Minute", " ", "AMPM"}] & /@ Range[20],
 colLabels = {"", "Monday", "Tuesday", "Wednesday", "Thursday",
    "Friday", "Saturday", "Sunday"},
 sFL = SpanFromLeft, combined, prefs, infoTable },
prefs[index_] := Grid[Prepend[Transpose[Prepend[
  Transpose@
   Outer[Checkbox[Dynamic[prefTable[[index, #1, #2]]], {0, 1}] &,
    Range[20], Range[7]], hours]], colLabels], Frame -> All];
combined = Panel@Grid[Prepend[Transpose[Prepend[
   Transpose@Outer[Row[Join[{             
         Dynamic[
          Style[Total[prefTable[[All, #1, #2]]], "Subsection"]], 
         " "},
        Table[With[{i = i},
          Checkbox[Dynamic[prefTable[[i, #1, #2]]], {0, 1}]],
         {i, Length[prefTable]}]]] &,
     Range[20], Range[7]], hours]], colLabels], Frame -> All];
infoTable[index_] := Panel[Grid[{{""},
   {Style["Front Desk Assignment Preferences", 14, Bold],  sFL, sFL, sFL}, {""},
  {"Last Name:", InputField[Dynamic[lastName[[index]],
    ((lastName[[index]] = #; tabLabel[[index]] = lastName[[index]]) &)], String], 
     sFL, sFL}, 
  {"First Name:", 
     InputField[Dynamic[firstName[[index]]], String], sFL,  sFL}, 
      {"-----------------------------------------------", sFL, sFL, sFL},
  {"Workstudy:", RadioButtonBar[Dynamic[ws[[index]]], 
      {1 -> "Yes", 2 -> "No"}], sFL, sFL},
 {"Workstudy Amount: $", InputField[Dynamic[wsAmount[[index]]],
     Number, FieldSize -> 10, Enabled -> Dynamic[ws[[index]] == 1]], sFL, sFL},
 {"-----------------------------------------------", sFL, sFL, sFL}, 
 {"Weekend Preference:", 
  RadioButtonBar[Dynamic[wkndPref[[index]]],
   {1 -> "A", 2 -> "B", 3 -> "Either"}], sFL, sFL}, {""},
 {"-----------------------------------------------", sFL, sFL, sFL}, 
 {Style[
   "Please select the hours you are interested in working from the table below:",
      Bold],
  sFL, sFL, sFL}, {prefs[index], sFL, sFL, sFL}, {""}}, 
  Alignment -> Left]];
 Deploy@TabView[Join @@ {Dynamic[tabLabel[[#]]] -> infoTable[#] & /@ Range[n],
     {"All" -> combined}}, Alignment -> {Center, Center}]]

enter image description here

enter image description here

share|improve this answer
    
Thank you very much for your guidance and help in my endeavor! I was wondering how to cleanly increase the number of staff (as I have ten to fifteen at any given time of the year)? In this sense, I'm not worried about the width of the "All" tab, as this will greatly increase by adding more checkboxes. –  MathRulesTheWorld Nov 23 '12 at 16:28

Here is a smaller example

With[{dims = {5, 5}},
 DynamicModule[{w1, w2},
  w1 = w2 = ConstantArray[False, dims];
  Panel@Column[{
     TabView[{"Worker 1", "Worker 2", "Both"} -> Append[
         Function[i, 
           Grid@Array[Checkbox[Dynamic[i[[#1, #2]]]] &, dims], 
           HoldAll] /@ Unevaluated@{w1, w2},
         Dynamic@
          Grid@Map[Checkbox[#, Enabled -> False] &, 
            Thread /@ Thread[w1 || w2], {2}]] // Thread],
     Row[{"Total: ", Dynamic@Total@Boole@Flatten@{w1, w2}, 
       Spacer[50], 
       Button["Save", 
        Save[SystemDialogInput["FileSave", "workers.txt"], {w1, w2}], 
        Method -> "Queued"]}]}]
  ]
 ]

Mathematica graphics

Mathematica graphics

Mathematica graphics

share|improve this answer
    
This is definitely something I will implement in the final version of the application. I like how clean and simple the functionality behaves. And the "Total" counter was exactly what I was looking for. Thank you. –  MathRulesTheWorld Nov 23 '12 at 16:33

This is only a partial answer -- maybe only a fraction of a partial answer.

  1. You define only one grid,week, which appears on all three panels. This means each of your workers is entering his/her choices into the same checkboxes, effectively undoing each other's choices. You really need a function that will return a new copy of your grid each time it is called.

  2. Your checkboxes need to have a value holder as their first arguments. Each value holder needs to be unique. The function that generates your grid might take an array of value holders for the worker choices as an argument and insert the array elements into the checkboxes. You will need to associate a array of such value holders with each of the workers.

  3. Each worker needs to have a representation in your code. You will collect and store the data from the input panels in these representations.

share|improve this answer
1  
To save the data, use DynamicModule. For details, see this. –  Z-Y.L Nov 23 '12 at 5:10
3  
@Z-Y.L I wouldn't trust that. I'd go for an explicit save. –  Sjoerd C. de Vries Nov 23 '12 at 6:40
    
@m_goldberg: Thanks for the input, the items you bring up certainly crossed my mind, but I'm not incredibly experienced with Mathematica and was not able to find a way to do the prescribed items listed above. I am slowly learning though. I appreciate your time. –  MathRulesTheWorld Nov 23 '12 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.