Пример #1
0
        public async void refreshData(int whatData)
        {
            switch (whatData)
            {
            case 1:
                projects    = null;
                projectJson = null;
                pServer     = null;
                checkDataAsync(PROJECT_DATA);
                break;

            case 2:
                tasks = null;
                projectsWithTasks.Clear();
                taskJson.Clear();
                checkDataAsync(TASKS_DATA);
                break;

            case 3:
                timesheetPeriods = null;
                checkDataAsync(TIMESHEET_DATA);
                break;

            case 4:
                enterpriseResources = null;
                checkDataAsync(RESOURCES_DATA);
                break;

            case 5:
                clearFragment();
                oldFragment        = null;
                willSwitch         = false;
                refresh.Refreshing = true;

                offline = null;
                offline = await service.pullData(true, userName.Text);

                int count = 0;
                foreach (var item in offline)
                {
                    count++;
                }
                if (count != 0)
                {
                    switchFragment(savedTimesheetFragment);
                }
                else
                {
                    mText = "You don't have any timesheet saved";
                    switchFragment(new OfflineFragment());
                    fab.SetVisibility(ViewStates.Gone);
                }
                refresh.Refreshing = false;
                willSwitch         = true;
                break;
            }
        }
Пример #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View rootView = inflater.Inflate(Resource.Layout.empty_recycleview, null);

            main = (Activity as MainActivity);

            mRecyclerView  = rootView.FindViewById <RecyclerView>(Resource.Id.recyclerView);
            mLayoutManager = new LinearLayoutManager(rootView.Context);
            mRecyclerView.SetLayoutManager(mLayoutManager);


            mProjects      = new Projects();
            mProjectList   = main.getProjectList();
            mProjectServer = main.getProjectServerList();
            if (mProjectList != null)
            {
                for (int i = 0; i < mProjectList.D.Results.Count; i++)
                {
                    StringBuilder work = new StringBuilder();
                    work.Append(mProjectList.D.Results[i].ProjectWork.TrimEnd(new char[] { '0', '.' }));
                    if (work.ToString().Equals(""))
                    {
                        work.Append("0");
                    }

                    StringBuilder temp = new StringBuilder();
                    temp.Append(mProjectList.D.Results[i].ProjectDuration.TrimEnd(new char[] { '0', '.' }));
                    if (temp.ToString().Equals(""))
                    {
                        temp.Append("0");
                    }
                    int duration = Convert.ToInt32(temp.ToString()) / 8;
                    for (int j = 0; j < mProjectServer.D.Results.Count; j++)
                    {
                        if (mProjectServer.D.Results[j].Name.Equals(mProjectList.D.Results[i].ProjectName))
                        {
                            mProjects.addProjects(
                                mProjectList.D.Results[i].ProjectName,
                                mProjectList.D.Results[i].ProjectPercentCompleted.ToString(),
                                work.ToString() + "h",
                                duration.ToString() + "d",
                                mProjectServer.D.Results[j].IsCheckedOut,
                                mProjectList.D.Results[i].ProjectOwnerName);
                        }
                    }
                }
            }

            mProjectAdapter            = new ProjectAdapter(mProjects, main);
            mProjectAdapter.itemClick += Adapter_ItemClick;
            mRecyclerView.SetAdapter(mProjectAdapter);
            return(rootView);
        }
Пример #3
0
        public void fillDataAsync(int whatData)
        {
            clearFragment();
            oldFragment        = null;
            willSwitch         = false;
            refresh.Refreshing = true;
            //1 for projects
            //2 for tasks
            //3 for timesheet
            //4 for enterprise resources
            switch (whatData)
            {
            case 1:


                ThreadPool.QueueUserWorkItem(async state =>
                {
                    projectJson = await core.GetProjects();
                    var temp    = await core.GetProjectServer();
                    projects    = JsonConvert.DeserializeObject <ProjectModel.RootObject>(projectJson);
                    pServer     = JsonConvert.DeserializeObject <ProjectData.RootObject>(temp);
                    if (projects.D.Results.Count == 0 && pServer.D.Results.Count == 0)
                    {
                        projects = null;
                        pServer  = null;
                        mText    = "There are no projects in this site";
                        RunOnUiThread(() => { switchFragment(new OfflineFragment()); refresh.Refreshing = false; willSwitch = true; });
                    }
                    else
                    {
                        RunOnUiThread(() => { switchFragment(projectFragment); refresh.Refreshing = false; willSwitch = true; });
                    }
                    //CancellationToken tok = (CancellationToken)state;
                    //if (tok.IsCancellationRequested)
                    //{
                    //    projects = null;
                    //    pServer = null;
                    //    return;
                    //}
                });
                break;

            case 2:

                tasks = new List <Taskmodel.RootObject> {
                };
                tasksWithResource.Clear();
                if (pServer == null && projects == null)
                {
                    tasks = null;
                    mText = "There are no tasks assigned to you";
                    RunOnUiThread(() => { switchFragment(new OfflineFragment()); refresh.Refreshing = false; willSwitch = true; });
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(async state =>
                    {
                        for (int i = 0; i < pServer.D.Results.Count; i++)
                        {
                            string data  = await core.GetTasks(pServer.D.Results[i].Id);
                            string data2 = await core.GetResourceAssignment(pServer.D.Results[i].Id, userName.Text);
                            if (data.Length > 20)
                            {
                                taskJson.Add(data);
                                projectsWithTasks.Add(pServer.D.Results[i].Name);
                            }
                            if (data2.Length > 20)
                            {
                                var insides = JsonConvert.DeserializeObject <ProjectResourceAssignments.RootObject>(data2);
                                foreach (var item in insides.D.Results)
                                {
                                    if (item.ResourceName.Equals(userName.Text))
                                    {
                                        tasksWithResource.Add(item.TaskName);
                                    }
                                }
                            }
                        }

                        for (int i = 0; i < taskJson.Count; i++)
                        {
                            tasks.Add(JsonConvert.DeserializeObject <Taskmodel.RootObject>(taskJson[i]));
                        }

                        if (tasks.Count > 0 && tasksWithResource.Count > 0)
                        {
                            RunOnUiThread(() => { switchFragment(taskFragment); refresh.Refreshing = false; willSwitch = true; });
                        }
                        else
                        {
                            tasks = null;
                            mText = "There are no tasks assigned to you";
                            RunOnUiThread(() => { switchFragment(new OfflineFragment()); refresh.Refreshing = false; willSwitch = true; });
                        }
                    }, cts.Token);
                }
                break;

            case 3:

                ThreadPool.QueueUserWorkItem(async state =>
                {
                    var data         = await core.GetTimesheetPeriods();
                    timesheetPeriods = JsonConvert.DeserializeObject <TimesheetPeriod.RootObject>(data);
                    RunOnUiThread(() => {
                        switchFragment(timesheetFragment);
                        refresh.Refreshing = false;
                        willSwitch         = true;
                    });
                }, cts.Token);
                break;

            case 4:

                ThreadPool.QueueUserWorkItem(async state =>
                {
                    var data            = await core.GetEnterpriseResources();
                    enterpriseResources = JsonConvert.DeserializeObject <EnterpriseResources.RootObject>(data);
                    RunOnUiThread(() => {
                        switchFragment(enterpriseResourceFragment);
                        refresh.Refreshing = false;
                        willSwitch         = true;
                    });
                });

                break;
            }
        }