示例#1
0
        async Task <List <Job> > GetContent(int listStart, int listEnd, Connection cnx)
        {
            string jobKey = String.Format("/api/api/5?id=id$~{0}~cmd$~getjob~{1}~{2}", cnx.ID, listStart, listEnd);

            string jsonRaw = "";


            jsonRaw = await Client.GET(cnx.Token, jobKey);

            if (jsonRaw == "errorerrorerror")
            {
                await DisplayAlert("Http Request Error", "Please try again.\n\nIf this keeps happening, please contact us.", "Ok");

                //make sure that if you do return null here it doesnt break the app.
                return(null);
            }



            var        x    = JobsFromJson.FromJson(jsonRaw);
            List <Job> Jobs = JsonDictionaryToJob(x);

            return(Jobs);
        }
示例#2
0
        public async void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var cnx = Maincnx;


            var item = e.SelectedItem as JobCell;

            Job _item = new Job();

            _item = item.job;


            string jobKey = String.Format("/api/api/5?id=id$~{0}~cmd$~getjobdetails~{1}", cnx.ID, item.JobNumber);

            //List<MegaParser.groupitem> groupitems = MegaParser.ParseJobs(await GetJob(jobKey, cnx.Token));

            string rawJson = await GetJob(jobKey, cnx.Token);

            if (connected == false)
            {
                return;
            }

            if (rawJson == "no jobs" || string.IsNullOrEmpty(rawJson))
            {
                await DisplayAlert("No Info", "No Further Information", "ok");

                Console.WriteLine("RETURNED: no jobs");
                updateList(Maincnx, null);
            }
            else if (rawJson[0] != '[')
            {
                await DisplayAlert("No Info", "No Further Information", "ok");

                Console.WriteLine("RETURNED: Improper Format");
                updateList(Maincnx, null);
            }
            else
            {
                var x = JobsFromJson.FromJson(rawJson);

                List <SubJob> _subJobs = new List <SubJob>();

                foreach (Dictionary <string, string> i in x)
                {
                    SubJob sj = new SubJob();

                    if (i["subjob"] == "")
                    {
                        sj.Subjob = 0;
                    }
                    else
                    {
                        sj.Subjob = Convert.ToInt32(i["subjob"]);
                    }

                    if (i["esent"] == "")
                    {
                        sj.Sent = 0;
                    }
                    else
                    {
                        sj.Sent = Convert.ToInt32(i["esent"]);
                    }

                    sj.Status      = i["status"];
                    sj.Created     = i["created"];
                    sj.Description = i["description"];
                    sj.GrossValue  = i["grossValue"];
                    sj.NetValue    = i["netValue"];
                    sj.VatValue    = i["vatValue"];
                    sj.Notes       = i["notes"];

                    _subJobs.Add(sj);
                }

                List <Job> subjobs = new List <Job>();

                foreach (SubJob _sj in _subJobs)
                {
                    Job job = new Job();
                    if (_sj.Description == "none")
                    {
                        _sj.Description = "";
                    }

                    if (_sj.GrossValue == null || _sj.GrossValue == "")
                    {
                        if (_item.grossValue == null || _item.grossValue == 0)
                        {
                            _sj.GrossValue = "0.00";
                            job.grossValue = Convert.ToDouble(_sj.GrossValue);
                        }
                        else if (_sj.Subjob == 0)
                        {
                            job.grossValue = _item.grossValue;
                        }
                    }
                    else
                    {
                        job.grossValue = Convert.ToDouble(_sj.GrossValue);
                    }

                    if (_sj.NetValue == null || _sj.NetValue == "")
                    {
                        if (_item.netValue == null || _item.netValue == 0)
                        {
                            _sj.NetValue = "0.00";
                            job.netValue = Convert.ToDouble(_sj.NetValue);
                        }
                        else if (_sj.Subjob == 0)
                        {
                            job.netValue = _item.netValue;
                        }
                    }
                    else
                    {
                        job.netValue = Convert.ToDouble(_sj.NetValue);
                    }

                    if (_sj.VatValue == null || _sj.VatValue == "")
                    {
                        if (_item.vatValue == null || _item.vatValue == 0)
                        {
                            _sj.VatValue = "0.00";
                            job.vatValue = Convert.ToDouble(_sj.VatValue);
                        }
                        else if (_sj.Subjob == 0)
                        {
                            job.vatValue = _item.vatValue;
                        }
                    }
                    else
                    {
                        job.vatValue = Convert.ToDouble(_sj.VatValue);
                    }



                    job.job         = _item.job;
                    job.subjob      = _sj.Subjob;
                    job.status      = _sj.Status;
                    job.created     = Convert.ToDateTime(_sj.Created, System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"));
                    job.add1        = _item.add1;
                    job.add2        = _item.add2;
                    job.add3        = _item.add3;
                    job.add4        = _item.add4;
                    job.addpc       = _item.addpc;
                    job.awarded     = _item.awarded;
                    job.buildername = _item.buildername;
                    job.description = _sj.Description;
                    job.sentcount   = _sj.Sent;
                    job.Notes       = _sj.Notes;

                    subjobs.Add(job);
                }


                if (subjobs.Count == 1)
                {
                    JobCell _job = new JobCell
                    {
                        JobColor    = StatusSorter.JobNumberColor(subjobs[0]),
                        Status      = StatusSorter.StatusText(subjobs[0]),
                        StatusColor = StatusSorter.StatusColor(subjobs[0]),
                        CellColor   = StatusSorter.CellColor(subjobs[0]),
                        Add1        = subjobs[0].add1,
                        Add2        = subjobs[0].add2,
                        Add3        = subjobs[0].add3,
                        Add4        = subjobs[0].add4,
                        AddPC       = subjobs[0].addpc,
                        Awarded     = subjobs[0].awarded,
                        Builder     = subjobs[0].buildername,
                        Created     = subjobs[0].created,
                        Description = subjobs[0].description,
                        JobNumber   = subjobs[0].job.ToString(),
                        SentCount   = subjobs[0].sentcount,
                        GrossValue  = subjobs[0].grossValue,
                        NetValue    = subjobs[0].netValue,
                        VatValue    = subjobs[0].vatValue,
                        Notes       = subjobs[0].Notes,
                        noSubs      = true,

                        job = _item
                    };


                    await Navigation.PushAsync(new JobSpecific(cnx, _job, false));
                }
                else
                {
                    await Navigation.PushAsync(new Subjobs_List(cnx, subjobs, _item));
                }
            }
        }