public ctrlDashBoardTaskItem(Task task) 
            : this()
        {
            _task = task;

            SetTaskData();
        }
        public void SetTaskState(Task task, int stateId)
        {
            var mctrl = TaskControls.FirstOrDefault(tc => tc.Task.Id == task.Id);

            if(mctrl?.Task == null || mctrl.Task.StateId == stateId)
                return;

            var mnewState = SimpleCache.GetAll<DictItem>()
                                       .FirstOrDefault(di => di.Id == stateId);

            if(mnewState == null)
                return;

            if (mnewState.Code == Task.States.TO_DO_CODE)
                mctrl.Parent = flwToDo;
            else if(mnewState.Code == Task.States.IN_PROGRESS_CODE)
                mctrl.Parent = flwInProgress;
            else if (mnewState.Code == Task.States.DONE_CODE)
                mctrl.Parent = flwDone;
            else if (mnewState.Code == Task.States.REMOVED_CODE)
                mctrl.Dispose();

            AfterTaskEdit();
        }
        public void AddTask(Task task)
        {
            var mc = CreateTaskControl(task);

            var mnewState = SimpleCache.GetAll<DictItem>()
                                       .FirstOrDefault(di => di.Id == task.StateId);

            if(mnewState == null)
                return;

            if (mnewState.Code == Task.States.TO_DO_CODE)
                flwToDo.Controls.Add(mc);
            else if (mnewState.Code == Task.States.IN_PROGRESS_CODE)
                flwInProgress.Controls.Add(mc);
            else if (mnewState.Code == Task.States.DONE_CODE)
                flwDone.Controls.Add(mc);

            AfterTaskEdit();
        }
        private static async Task<bool> ChangeTaskState(Task task, string newState)
        {
            if (task == null)
                return false;

            try
            {
                Logger.Log($"Change task {task.Id} state from {task.State?.Code} to {newState}");
                var mres = await WebCallFactory.ChangeTaskState(task.Id, newState);

                if (!mres.Error)
                {
                    Logger.Log("Success!");
                    task.State = SimpleCache.FirstOrDefault<DictItem>(di => di.IsType(DictItem.Types.TaskState) && di.Code == newState);
                }

                return !mres.Error;
            }
            catch (Exception mex)
            {
                Logger.Log("Error!");
                Logger.Log(mex);
                return false;
            }
        }
        private Control CreateTaskControl(Task task)
        {
            var mtsk = new ctrlDashBoardTaskItem(task)
            {
                Size = ctrlDashBoardTaskItem.DefaultSize,
                AllowDrop = true
            };

            mtsk.Click += (sender, args) =>
            {
                var mte = sender as ctrlDashBoardTaskItem;

                if (mte?.Task != null)
                    UIHelper.ShowTaskEditor(mte.Task, async t =>
                    {
                        mte.SetTask(t);
                        AfterTaskEdit();
                    }, parentForm:ParentForm);
            };

            mtsk.MouseMove += (sender, args) =>
            {
                if (args.Button == MouseButtons.Left)
                    DoDragDrop(sender, DragDropEffects.Move);
            };
            
            return mtsk;
        }
Exemplo n.º 6
0
        public ctrlTaskEditor(Task task)
            : this()
        {
            _taskId = task?.Id ?? 0;

            _task = task;
        }
Exemplo n.º 7
0
        private async Task<bool> TaskSave()
        {
            try
            {
                UIHelper.ShowLoader("Save task");

                var mvalid = ValidateGui();
                if (!string.IsNullOrEmpty(mvalid))
                {
                    UIHelper.ShowError(mvalid);
                    return false;
                }

                MakeBindingsToEntity();

                var mres = await WebCallFactory.SaveTask(Task);

                if (mres.Error)
                {
                    Logger.Log(mres.Exception);
                    UIHelper.ShowError(mres.Exception);
                    return false;
                }

                Logger.Log("Task saved");

                _task = mres.Task;
                SetTaskData();

                UIHelper.HideLoader();
                return true;
            }
            catch (Exception mex)
            {
                Logger.Log(mex);
                UIHelper.HideLoader();
                UIHelper.ShowError(mex);
                return false;
            }
            finally
            {
                UIHelper.HideLoader();
            }
        }
Exemplo n.º 8
0
        private async System.Threading.Tasks.Task LoadTask()
        {
            
            try
            {
                UIHelper.ShowLoader("LOAD TASK", ParentForm);

                if (_taskId == 0)
                {
                    if (ParentForm != null)
                        ParentForm.Text = "New task";
                }
                else
                {
                    if (ParentForm != null)
                        ParentForm.Text = $"Edit task {_taskId}";

                    var mres = await WebCallFactory.GetTask(_taskId);

                    if (mres.Error)
                        throw mres.Exception;

                    _task = mres.Task;
                }
                SetTaskData();
                UIHelper.HideLoader();
            }
            catch (Exception mex)
            {
                UIHelper.HideLoader();
                Logger.Log(mex);
                UIHelper.ShowError(mex);
            }
            finally
            {
                UIHelper.HideLoader();
            }
        }
        public void SetTask(Task task)
        {
            _task = task;

            SetTaskData();
        }