Example #1
0
        public EditPlanItem(EditItemMode mode, PlanGoal goal, PlanItem editing)
        {
            InitializeComponent();

            Mode = mode;
            Goal = goal;
            Editing = editing;

            TitleBox.Text = editing.Title;
            //StartTime.Value = editing.Start.ToLocalTime();
            //EndTime.Value = editing.End.ToLocalTime();
            CompletedHours.Text = editing.HoursCompleted.ToString();
            TotalHours.Text = editing.HoursTotal.ToString();
            DescriptionInput.InputBox.Text = editing.Description;

            if (Mode == EditItemMode.New)
                Text = "New Plan Item";

            if (Mode == EditItemMode.Edit)
                Text = "Edit Plan Item";

            if (Mode == EditItemMode.View)
            {
                Text = editing.Title;

                TitleBox.ReadOnly = true;
                //StartTime.Enabled = false;
                //EndTime.Enabled = false;
                CompletedHours.ReadOnly = true;
                TotalHours.ReadOnly = true;
                DescriptionInput.ReadOnly = true;
            }
        }
Example #2
0
 public void RemoveItem(PlanItem item)
 {
     if (ItemMap.ContainsKey(item.Ident))
     {
         if (ItemMap[item.Ident].Contains(item))
         {
             ItemMap[item.Ident].Remove(item);
         }
     }
 }
Example #3
0
        public static PlanItem Decode(G2Header root)
        {
            PlanItem item  = new PlanItem();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Ident:
                    item.Ident = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_BranchUp:
                    item.BranchUp = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Project:
                    item.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Title:
                    item.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Start:
                    item.Start = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_End:
                    item.End = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_Desc:
                    item.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_HoursCompleted:
                    item.HoursCompleted = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_HoursTotal:
                    item.HoursTotal = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;
                }
            }

            return(item);
        }
Example #4
0
        public PlanListItem(PlanItem item)
        {
            Item = item;
            Text = item.Title;

            // est time
            SubItems.Add(item.HoursTotal.ToString() + " Hours");

            // progress
            Progress.Total     = item.HoursTotal;
            Progress.Completed = item.HoursCompleted;

            SubItems.Add(Progress);
        }
Example #5
0
        public static PlanItem Decode(byte[] data)
        {
            G2Header root = new G2Header(data);

            if (!G2Protocol.ReadPacket(root))
            {
                return(null);
            }

            if (root.Name != PlanPacket.Item)
            {
                return(null);
            }

            return(PlanItem.Decode(root));
        }
Example #6
0
        private void AddItemLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PlanItem item = new PlanItem();

            item.Ident    = Head.Ident;
            item.Project  = Head.Project;
            item.BranchUp = Selected.BranchDown;
            //item.Start = Core.TimeNow.ToUniversalTime();
            //item.End = Selected.End;

            EditPlanItem form = new EditPlanItem(EditItemMode.New, Selected, item);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                Plans.LocalPlan.AddItem(form.Editing);
                View.ChangesMade();
            }
        }
Example #7
0
        public EditPlanItem(EditItemMode mode, PlanGoal goal, PlanItem editing)
        {
            InitializeComponent();

            Mode    = mode;
            Goal    = goal;
            Editing = editing;

            TitleBox.Text = editing.Title;
            //StartTime.Value = editing.Start.ToLocalTime();
            //EndTime.Value = editing.End.ToLocalTime();
            CompletedHours.Text            = editing.HoursCompleted.ToString();
            TotalHours.Text                = editing.HoursTotal.ToString();
            DescriptionInput.InputBox.Text = editing.Description;

            if (Mode == EditItemMode.New)
            {
                Text = "New Plan Item";
            }

            if (Mode == EditItemMode.Edit)
            {
                Text = "Edit Plan Item";
            }

            if (Mode == EditItemMode.View)
            {
                Text = editing.Title;

                TitleBox.ReadOnly = true;
                //StartTime.Enabled = false;
                //EndTime.Enabled = false;
                CompletedHours.ReadOnly   = true;
                TotalHours.ReadOnly       = true;
                DescriptionInput.ReadOnly = true;
            }
        }
Example #8
0
        public void SetDetails(PlanGoal goal, PlanItem item)
        {
            LastGoal = goal;
            LastItem = item;

            List <string[]> tuples = new List <string[]>();

            string          notes = null;
            DetailsModeType mode  = DetailsModeType.None;

            // get inof that needs to be set
            if (goal != null)
            {
                tuples.Add(new string[] { "title", goal.Title });
                tuples.Add(new string[] { "due", goal.End.ToLocalTime().ToString("D") });
                tuples.Add(new string[] { "person", Core.GetName(goal.Person) });
                tuples.Add(new string[] { "notes", goal.Description.Replace("\r\n", "<br>") });

                notes = goal.Description;
                mode  = DetailsModeType.Goal;
            }

            else if (item != null)
            {
                tuples.Add(new string[] { "title", item.Title });
                tuples.Add(new string[] { "progress", item.HoursCompleted.ToString() + " of " + item.HoursTotal.ToString() + " Hours Completed" });
                tuples.Add(new string[] { "notes", item.Description.Replace("\r\n", "<br>") });

                notes = item.Description;
                mode  = DetailsModeType.Item;
            }

            // set details button
            DetailsButton.ForeColor = Color.Black;

            if (splitContainer1.Panel2Collapsed && notes != null && notes != "")
            {
                DetailsButton.ForeColor = Color.Red;
            }



            if (mode != DetailsMode)
            {
                DetailsMode = mode;

                Details.Length = 0;

                if (mode == DetailsModeType.Goal)
                {
                    Details.Append(GoalPage);
                }
                else if (mode == DetailsModeType.Item)
                {
                    Details.Append(ItemPage);
                }
                else
                {
                    Details.Append(DefaultPage);
                }

                foreach (string[] tuple in tuples)
                {
                    Details.Replace("<?=" + tuple[0] + "?>", tuple[1]);
                }

                SetDisplay(Details.ToString());
            }
            else
            {
                foreach (string[] tuple in tuples)
                {
                    DetailsBrowser.SafeInvokeScript("SetElement", new String[] { tuple[0], tuple[1] });
                }
            }
        }
Example #9
0
        private void AddItemLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PlanItem item = new PlanItem();
            item.Ident = Head.Ident;
            item.Project = Head.Project;
            item.BranchUp = Selected.BranchDown;
            //item.Start = Core.TimeNow.ToUniversalTime();
            //item.End = Selected.End;

            EditPlanItem form = new EditPlanItem(EditItemMode.New, Selected, item);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                Plans.LocalPlan.AddItem(form.Editing);
                View.ChangesMade();
            }
        }
Example #10
0
 public PlanMenuItem(string caption, PlanItem item, Image icon, EventHandler onClick)
     : base(caption, icon, onClick)
 {
     Item = item;
 }
Example #11
0
        public void SimTest()
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { SimTest(); });
                return;
            }

            uint project = 0;

            // schedule
            PlanBlock block = new PlanBlock();

            block.ProjectID = project;
            block.Title = Core.TextGen.GenerateWords(1)[0];
            block.StartTime = Core.TimeNow.AddDays(Core.RndGen.Next(365)); // anytime in next year
            block.EndTime = block.StartTime.AddDays(Core.RndGen.Next(3, 90)); // half a week to 3 months
            block.Description = Core.TextGen.GenerateSentences(1)[0];
            block.Scope = -1;
            block.Unique = Core.RndGen.Next();

            // add to local plan
            LocalPlan.AddBlock(block);

            // goals

            // get  uplinks including self and scan all goals for  anything assigned to local
            List<ulong> uplinks = Core.Trust.GetUplinkIDs(Core.UserID, project);
            uplinks.Add(Core.UserID);

            List<PlanGoal> assignedGoals = new List<PlanGoal>();

            PlanMap.LockReading(delegate()
            {
                foreach (ulong uplink in uplinks)
                    if (PlanMap.ContainsKey(uplink) && PlanMap[uplink].GoalMap != null)
                        foreach (List<PlanGoal> list in PlanMap[uplink].GoalMap.Values)
                            foreach (PlanGoal goal in list)
                                if (goal.Person == Core.UserID)
                                    assignedGoals.Add(goal);
            });

            PlanGoal randGoal = null;
            if (assignedGoals.Count > 0)
                randGoal = assignedGoals[Core.RndGen.Next(assignedGoals.Count)];

            List<ulong> downlinks = Core.Trust.GetDownlinkIDs(Core.UserID, project, 3);

            if (downlinks.Count > 0)
            {
                // create new goal
                PlanGoal newGoal = new PlanGoal();

                newGoal.Project = project;
                newGoal.Title = GetRandomTitle();
                newGoal.End = Core.TimeNow.AddDays(Core.RndGen.Next(30, 300));
                newGoal.Description = Core.TextGen.GenerateSentences(1)[0];

                int choice = Core.RndGen.Next(100);

                // create new goal
                if (randGoal == null || choice < 10)
                {
                    newGoal.Ident = Core.RndGen.Next();
                    newGoal.Person = Core.UserID;
                }

                // delegate goal to sub
                else if (randGoal != null && choice < 50)
                {
                    PlanGoal head = randGoal;

                    // delegate down
                    newGoal.Ident = head.Ident;
                    newGoal.BranchUp = head.BranchDown;
                    newGoal.BranchDown = Core.RndGen.Next();
                    newGoal.Person = downlinks[Core.RndGen.Next(downlinks.Count)];
                }
                else
                    newGoal = null;

                if(newGoal != null)
                    LocalPlan.AddGoal(newGoal);
            }

            // add item to random goal
            if (randGoal != null)
            {
                PlanItem item = new PlanItem();

                item.Ident = randGoal.Ident;
                item.Project = randGoal.Project;
                item.BranchUp = randGoal.BranchDown;

                item.Title = GetRandomTitle();
                item.HoursTotal = Core.RndGen.Next(3, 30);
                item.HoursCompleted = Core.RndGen.Next(0, item.HoursTotal);
                item.Description = Core.TextGen.GenerateSentences(1)[0];

                LocalPlan.AddItem(item);
            }

            SaveLocal();
        }
Example #12
0
        public static PlanItem Decode(G2Header root)
        {
            PlanItem item = new PlanItem();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Ident:
                        item.Ident = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_BranchUp:
                        item.BranchUp = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Project:
                        item.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Title:
                        item.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Start:
                        item.Start = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_End:
                        item.End = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_Desc:
                        item.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_HoursCompleted:
                        item.HoursCompleted = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_HoursTotal:
                        item.HoursTotal = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;
                }
            }

            return item;
        }
Example #13
0
        public void LoadPlan(ulong id)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreBlocked(delegate() { LoadPlan(id); });
                return;
            }

            OpPlan plan = GetPlan(id, false);

            if (plan == null)
            {
                return;
            }

            // if local plan file not created yet
            if (plan.File.Header == null)
            {
                if (plan.UserID == Core.UserID)
                {
                    plan.Init();
                }

                return;
            }

            try
            {
                string path = Cache.GetFilePath(plan.File.Header);

                if (!File.Exists(path))
                {
                    return;
                }

                plan.Init();

                List <int> myjobs = new List <int>();

                using (TaggedStream file = new TaggedStream(path, Network.Protocol))
                    using (IVCryptoStream crypto = IVCryptoStream.Load(file, plan.File.Header.FileKey))
                    {
                        PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read);

                        G2Header root = null;

                        while (stream.ReadPacket(ref root))
                        {
                            if (root.Name == PlanPacket.Block)
                            {
                                PlanBlock block = PlanBlock.Decode(root);

                                if (block != null)
                                {
                                    plan.AddBlock(block);
                                }
                            }

                            if (root.Name == PlanPacket.Goal)
                            {
                                PlanGoal goal = PlanGoal.Decode(root);

                                if (goal != null)
                                {
                                    plan.AddGoal(goal);
                                }
                            }

                            if (root.Name == PlanPacket.Item)
                            {
                                PlanItem item = PlanItem.Decode(root);

                                if (item != null)
                                {
                                    plan.AddItem(item);
                                }
                            }
                        }
                    }

                plan.Loaded = true;


                // check if we have tasks for this person, that those jobs still exist
                //crit do check with plan items, make sure goal exists for them

                /*List<PlanTask> removeList = new List<PlanTask>();
                 * bool update = false;
                 *
                 * foreach(List<PlanTask> tasklist in LocalPlan.TaskMap.Values)
                 * {
                 *  removeList.Clear();
                 *
                 *  foreach (PlanTask task in tasklist)
                 *      if(task.Assigner == id)
                 *          if(!myjobs.Contains(task.Unique))
                 *              removeList.Add(task);
                 *
                 *  foreach(PlanTask task in removeList)
                 *      tasklist.Remove(task);
                 *
                 *  if (removeList.Count > 0)
                 *      update = true;
                 * }
                 *
                 * if (update)
                 *  SaveLocal();*/
            }
            catch (Exception ex)
            {
                Core.Network.UpdateLog("Plan", "Error loading plan " + ex.Message);
            }
        }
Example #14
0
        public void SimTest()
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { SimTest(); });
                return;
            }

            uint project = 0;

            // schedule
            PlanBlock block = new PlanBlock();

            block.ProjectID   = project;
            block.Title       = Core.TextGen.GenerateWords(1)[0];
            block.StartTime   = Core.TimeNow.AddDays(Core.RndGen.Next(365));      // anytime in next year
            block.EndTime     = block.StartTime.AddDays(Core.RndGen.Next(3, 90)); // half a week to 3 months
            block.Description = Core.TextGen.GenerateSentences(1)[0];
            block.Scope       = -1;
            block.Unique      = Core.RndGen.Next();

            // add to local plan
            LocalPlan.AddBlock(block);


            // goals

            // get  uplinks including self and scan all goals for  anything assigned to local
            List <ulong> uplinks = Core.Trust.GetUplinkIDs(Core.UserID, project);

            uplinks.Add(Core.UserID);

            List <PlanGoal> assignedGoals = new List <PlanGoal>();

            PlanMap.LockReading(delegate()
            {
                foreach (ulong uplink in uplinks)
                {
                    if (PlanMap.ContainsKey(uplink) && PlanMap[uplink].GoalMap != null)
                    {
                        foreach (List <PlanGoal> list in PlanMap[uplink].GoalMap.Values)
                        {
                            foreach (PlanGoal goal in list)
                            {
                                if (goal.Person == Core.UserID)
                                {
                                    assignedGoals.Add(goal);
                                }
                            }
                        }
                    }
                }
            });


            PlanGoal randGoal = null;

            if (assignedGoals.Count > 0)
            {
                randGoal = assignedGoals[Core.RndGen.Next(assignedGoals.Count)];
            }


            List <ulong> downlinks = Core.Trust.GetDownlinkIDs(Core.UserID, project, 3);

            if (downlinks.Count > 0)
            {
                // create new goal
                PlanGoal newGoal = new PlanGoal();

                newGoal.Project     = project;
                newGoal.Title       = GetRandomTitle();
                newGoal.End         = Core.TimeNow.AddDays(Core.RndGen.Next(30, 300));
                newGoal.Description = Core.TextGen.GenerateSentences(1)[0];

                int choice = Core.RndGen.Next(100);

                // create new goal
                if (randGoal == null || choice < 10)
                {
                    newGoal.Ident  = Core.RndGen.Next();
                    newGoal.Person = Core.UserID;
                }

                // delegate goal to sub
                else if (randGoal != null && choice < 50)
                {
                    PlanGoal head = randGoal;

                    // delegate down
                    newGoal.Ident      = head.Ident;
                    newGoal.BranchUp   = head.BranchDown;
                    newGoal.BranchDown = Core.RndGen.Next();
                    newGoal.Person     = downlinks[Core.RndGen.Next(downlinks.Count)];
                }
                else
                {
                    newGoal = null;
                }


                if (newGoal != null)
                {
                    LocalPlan.AddGoal(newGoal);
                }
            }


            // add item to random goal
            if (randGoal != null)
            {
                PlanItem item = new PlanItem();

                item.Ident    = randGoal.Ident;
                item.Project  = randGoal.Project;
                item.BranchUp = randGoal.BranchDown;

                item.Title          = GetRandomTitle();
                item.HoursTotal     = Core.RndGen.Next(3, 30);
                item.HoursCompleted = Core.RndGen.Next(0, item.HoursTotal);
                item.Description    = Core.TextGen.GenerateSentences(1)[0];

                LocalPlan.AddItem(item);
            }

            SaveLocal();
        }
Example #15
0
        public void AddItem(PlanItem item)
        {
            if (!ItemMap.ContainsKey(item.Ident))
                ItemMap[item.Ident] = new List<PlanItem>();

            ItemMap[item.Ident].Add(item);
        }
Example #16
0
 public PlanMenuItem(string caption, PlanItem item, Image icon, EventHandler onClick)
     : base(caption, icon, onClick)
 {
     Item = item;
 }
Example #17
0
        public PlanListItem(PlanItem item)
        {
            Item = item;
            Text = item.Title;

            // est time
            SubItems.Add(item.HoursTotal.ToString() + " Hours");

            // progress
            Progress.Total = item.HoursTotal;
            Progress.Completed = item.HoursCompleted;

            SubItems.Add(Progress);
        }
Example #18
0
 public void RemoveItem(PlanItem item)
 {
     if (ItemMap.ContainsKey(item.Ident))
         if (ItemMap[item.Ident].Contains(item))
             ItemMap[item.Ident].Remove(item);
 }