Beispiel #1
0
        public tenderPage()
        {
            BindingContext = this;
            var label = new Label {
                Text = "text"
            };

            //StackLayout stackLayout = new StackLayout();
            //var childToRaise = stackLayout.Children.First();

            InitializeComponent();

            //Set "Previous" and "Next" hyperlink label.
            var previousLblTapRecognizer = new TapGestureRecognizer();

            previousLblTapRecognizer.Tapped += onPreviousPageTapped;
            previousPage.GestureRecognizers.Add(previousLblTapRecognizer);
            previousPage.IsVisible = false;  //"Previous" label is set to invisible for first page

            var nextLblTapRecognizer = new TapGestureRecognizer();

            nextLblTapRecognizer.Tapped += onNextPageTapped;
            nextPage.GestureRecognizers.Add(nextLblTapRecognizer);

            //Sending HTTP request to obtain the tender page data
            Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/notice/notice.jsp", false));
            var           httpResult = httpTask.Result.ToString();

            //Small data extraction to get "Next" and "Previous" page hyperlinks
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(httpResult);
            var aNodes = htmlDoc.DocumentNode.SelectNodes("//a");

            if (aNodes != null)
            {
                foreach (var aNode in aNodes)
                {
                    if (aNode.InnerHtml == "Previous")
                    {
                        previousUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                        isPreviousAvailable = true;
                    }
                    else if (aNode.InnerHtml == "Next")
                    {
                        nextUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                        isNextAvailable = true;
                    }
                }
            }


            //Extract tender data from the response
            var tenders = DataExtraction.getWebData(httpResult, "tender");
            List <tenderItem> tenderItems = (List <tenderItem>)tenders;

            listView.ItemsSource         = tenderItems;
            listView.SeparatorVisibility = SeparatorVisibility.None;
            listView.ItemSelected       += onItemSelected;
        }
Beispiel #2
0
        public async Task WaitAndExecuteUpdateTenders(int milisec)
        {
            await Task.Delay(milisec);


            //Sending HTTP request to obtain the tender page data
            string httpTask = await Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_tender_eligible.jsp", true));

            var httpResult = httpTask;

            //Extract tender data from the response
            var tenders = await DataExtraction.getWebData(httpResult, "eligibelTenderPage");

            List <tenderItem> tenderItems = (List <tenderItem>)tenders;

            //delete existing eligible tenders
            List <dbTenderItem> dbtenders0 = await App.Database.getTendersAsync(0);

            await deleteDatabaseEligibleTenders(dbtenders0);

            //save all eligible tenders to database
            await saveToTenderDb(tenderItems, 0);

            //Get bookmark details from database
            if (userSession.username != "")
            {
                //string httpTask = await Task.Run<string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_tender_eligible.jsp", true));
                //Task<List<tenderBookmark>> bookmarkHttpTask = Task.Run<List<tenderBookmark>>(() => retrieveBookmark());
                List <tenderBookmark> tenderBookmarks = await retrieveBookmark();

                if (tenderBookmarks != null)
                {
                    //List<tenderBookmark> tenderBookmarks = bookmarkHttpTask;
                    if (tenderBookmarks.Count > 0)
                    {
                        foreach (var tenderItem in tenderItems)
                        {
                            foreach (var tenderBookmark in tenderBookmarks)
                            {
                                if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                {
                                    tenderItem.BookmarkImage = "bookmarkfilled.png";
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            await DisplayAlert("Update Tenders", "Refresh Tenders", "Okay");

            listView.ItemsSource = tenderItems;



            await WaitAndExecuteUpdateTenders(10800000);
        }
        public tenderEligiblePage()
        {
            BindingContext = this;
            InitializeComponent();
            var items = Enumerable.Range(0, 10);

            //Sending HTTP request to obtain the tender page data
            Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_tender_eligible.jsp", true));
            var           httpResult = httpTask.Result.ToString();

            //Extract tender data from the response
            var tenders = DataExtraction.getWebData(httpResult, "eligibelTenderPage");
            List <tenderItem> tenderItems = (List <tenderItem>)tenders;

            listView.ItemsSource         = tenderItems;
            listView.SeparatorVisibility = SeparatorVisibility.None;
            listView.ItemSelected       += onItemSelected;
        }
        public editContactPerson()
        {
            BindingContext = this;
            InitializeComponent();

            //Sending HTTP request to obtain the company profile data
            Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_contact_edit.jsp", true));
            var           httpResult = httpTask.Result.ToString();

            //Extract company profile data from the response
            //var profileData = DataExtraction.getWebData(httpResult, "userContactPerson");
            var           profileData = Task.Run <Object>(() => DataExtraction.getWebData(httpResult, "userContactPerson"));
            ContactPerson profile     = (ContactPerson)profileData.Result;

            name.Text         = profile.Name;
            telephoneNo.Text  = profile.TelephoneNo;
            faxNo.Text        = profile.FaxNo;
            emailAddress.Text = profile.EmailAddress;
        }
        public editCompanyProfile()
        {
            BindingContext = this;
            InitializeComponent();

            //Sending HTTP request to obtain the company profile data
            Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_company_edit.jsp", true));
            var           httpResult = httpTask.Result.ToString();

            //Extract company profile data from the response
            var profileData = Task.Run <Object>(() => DataExtraction.getWebData(httpResult, "userCompanyProfile"));
            //var profileData = DataExtraction.getWebData(httpResult, "userCompanyProfile");
            CompanyProfile profile = (CompanyProfile)profileData.Result;

            companyName.Text           = profile.CompanyName;
            companyRegistrationNo.Text = profile.CompanyRegistrationNo;
            mailingAddress.Text        = profile.MailingAddress;
            country.Text = profile.Country;

            name    = profile.CompanyName;
            regno   = profile.CompanyRegistrationNo;
            coucode = profile.Country;
        }
Beispiel #6
0
        async Task <string> getPageData(string url)
        {
            string httpTask = await Task.Run <string>(() => HttpRequestHandler.GetRequest(url, false));

            var httpResult = httpTask.ToString();

            //Small data extraction to get "Next" and "Previous" page hyperlinks
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(httpResult);
            var aNodes = htmlDoc.DocumentNode.SelectNodes("//a");

            isNextAvailable     = false;
            isPreviousAvailable = false;

            if (aNodes != null)
            {
                foreach (var aNode in aNodes)
                {
                    if (aNode.InnerHtml == "Previous")
                    {
                        previousUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                        isPreviousAvailable = true;
                    }
                    else if (aNode.InnerHtml == "Next")
                    {
                        nextUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                        isNextAvailable = true;
                    }
                }
            }



            return(httpResult);
        }
Beispiel #7
0
        public searchTenderPage()
        {
            BindingContext = this;
            InitializeComponent();

            //Send Http request to retrieve search page originating station drop down
            Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/notice/notice_search.jsp", false));
            var           httpResult = httpTask.Result.ToString();

            //--------Station Picker Control Section---------------------------------------------
            //Small data extraction to extract Station dropdown selects/options to fill Picker
            HtmlDocument htmlDoc = new HtmlDocument();

            HtmlNode.ElementsFlags.Remove("option");
            htmlDoc.LoadHtml(httpResult);
            var stationList = new List <string>();

            foreach (HtmlNode node in htmlDoc.DocumentNode.SelectNodes("//select[@name='SchStation']//option"))
            {
                stationList.Add(node.InnerText);
            }


            stationPicker.ItemsSource = stationList;
            //set default origin station Picker value
            //stationPicker.SelectedIndex = 0;
            stationPicker.SelectedIndexChanged += OnPickerSelectedIndexChanged;
            //---------End Station Picker Control Section-----------------------------------------

            //---------DatePicker Control Section---------------
            //set datepicker text color to light gray to simulate not-filled
            closingdateFrom.TextColor    = Color.LightGray;
            closingdateTo.TextColor      = Color.LightGray;
            bidclosingdateFrom.TextColor = Color.LightGray;
            bidclosingdateTo.TextColor   = Color.LightGray;

            closingdateFrom.DateSelected    += DatePicker_DateSelected;
            closingdateTo.DateSelected      += DatePicker_DateSelected;
            bidclosingdateFrom.DateSelected += DatePicker_DateSelected;
            bidclosingdateTo.DateSelected   += DatePicker_DateSelected;
            //---------End DatePicker Control Section---------------------------------------------

            searchButton.Clicked += OnSubmitButtonClicked;
            clearButton.Clicked  += OnClearButtonClicked;

            //Event Handler Arguments
            void OnPickerSelectedIndexChanged(object sender, EventArgs e)
            {
                Picker picker = (Picker)sender;

                if (picker.SelectedIndex > 0)
                {
                    selectedStation = stationPicker.Items[stationPicker.SelectedIndex];
                }
                else
                {
                    selectedStation = null;
                }
                Console.WriteLine("Selected station: " + selectedStation);
            }

            void DatePicker_DateSelected(object sender, DateChangedEventArgs e)
            {
                if (sender == closingdateFrom)
                {
                    closingdatefrom           = e.NewDate.ToString();
                    closingdateFrom.TextColor = Color.Black;
                }
                else if (sender == closingdateTo)
                {
                    closingdateto           = e.NewDate.ToString();
                    closingdateTo.TextColor = Color.Black;
                }
                else if (sender == bidclosingdateFrom)
                {
                    bidclosingdatefrom           = e.NewDate.ToString();
                    bidclosingdateFrom.TextColor = Color.Black;
                }
                else if (sender == bidclosingdateTo)
                {
                    bidclosingdateto           = e.NewDate.ToString();
                    bidclosingdateTo.TextColor = Color.Black;
                }
            }

            async void OnSubmitButtonClicked(object sender, EventArgs e)
            {
                if (sender == searchButton)
                {
                    /*Console.WriteLine("Ref: " + tenderReferenceInput.Text);
                     * Console.WriteLine("Title: " + tenderTitleInput.Text);
                     * Console.WriteLine("Station: " + selectedStation);
                     * Console.WriteLine("closingdatefrom: " + closingdatefrom);
                     * Console.WriteLine("closingdateto: " + closingdateto);
                     * Console.WriteLine("bidclosingdatefrom: " + bidclosingdatefrom);
                     * Console.WriteLine("bidclosingdateto: " + bidclosingdateto);*/

                    if (String.IsNullOrEmpty(tenderReferenceInput.Text) && String.IsNullOrEmpty(tenderTitleInput.Text) && selectedStation == "" && closingdatefrom == "" && closingdateto == "" &&
                        bidclosingdatefrom == "" && bidclosingdateto == "")
                    {
                        DisplayAlert("Error", "Please enter at least one search field", "Okay");
                    }
                    else
                    {
                        //Sending HTTP request to obtain the tender page search result data
                        Task <string> httpSearchTask   = Task.Run <string>(() => HttpRequestHandler.SearchPostRequest("http://www2.sesco.com.my/etender/notice/notice.jsp", tenderReferenceInput.Text, tenderTitleInput.Text, selectedStation, closingdatefrom, closingdateto, bidclosingdatefrom, bidclosingdateto));
                        var           httpSearchResult = httpSearchTask.Result.ToString();
                        //Console.WriteLine(httpSearchResult);
                        await Navigation.PushAsync(new tenderSearchResultPage(httpSearchResult));
                    }
                }
            }

            void OnClearButtonClicked(object sender, EventArgs e)
            {
                if (sender == clearButton)
                {
                    tenderReferenceInput.Text   = "";
                    tenderTitleInput.Text       = "";
                    stationPicker.SelectedIndex = 0;
                    selectedStation             = "";
                    closingdatefrom             = "";
                    closingdateto                = "";
                    bidclosingdatefrom           = "";
                    bidclosingdateto             = "";
                    closingdateFrom.TextColor    = Color.LightGray;
                    closingdateTo.TextColor      = Color.LightGray;
                    bidclosingdateFrom.TextColor = Color.LightGray;
                    bidclosingdateTo.TextColor   = Color.LightGray;
                }
            }
        }
Beispiel #8
0
        async void onPreviousPageTapped(object sender, EventArgs eventArgs)
        {
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;
            //Sending HTTP request to obtain the second tender page data
            string httpTask = await Task.Run <string>(() => HttpRequestHandler.GetRequest(previousUrl, false));

            var httpResult = httpTask.ToString();

            //Small data extraction to get "Next" and "Previous" page hyperlinks
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(httpResult);
            var aNodes = htmlDoc.DocumentNode.SelectNodes("//a");

            isNextAvailable     = false;
            isPreviousAvailable = false;

            foreach (var aNode in aNodes)
            {
                if (aNode.InnerHtml == "Previous")
                {
                    previousUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                    isPreviousAvailable = true;
                }
                else if (aNode.InnerHtml == "Next")
                {
                    nextUrl         = "http://www2.sesco.com.my/etender/notice/" + aNode.Attributes["href"].Value;
                    isNextAvailable = true;
                }
            }

            //Extract tender data from the response
            var tenderItems = await Task.Run <Object>(() => DataExtraction.getTenderPage(htmlDoc));

            //var tenders = DataExtraction.getWebData(httpResult, "tender");
            //List<tenderItem> tenderItems = (List<tenderItem>)tenders;

            listView.ItemsSource  = (List <tenderItem>)tenderItems;
            listView.ItemTemplate = dataTemplate;

            if (isPreviousAvailable)
            {
                previousPage.IsVisible = true;
            }
            else
            {
                previousPage.IsVisible = false;
            }

            if (isNextAvailable)
            {
                nextPage.IsVisible = true;
            }
            else
            {
                nextPage.IsVisible = false;
            }
            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
        }
Beispiel #9
0
        public static async Task <Object> getTenderPage(HtmlDocument htmlDocument)
        {
            var htmlNodes = htmlDocument.DocumentNode.SelectNodes("//tbody/tr");
            int rowCount  = 0;

            //List to store tender items
            List <tenderItem> tenderItems = new List <tenderItem>();

            //Loop through the tender items to get the tender details for each of the tenders
            foreach (var trNode in htmlNodes)
            {
                //If the row is not the first row, create the tender item
                if (rowCount > 0)
                {
                    //Get contact details of the tender
                    var tdNodes     = trNode.ChildNodes;
                    var tdNodeCount = tdNodes.Count;
                    int count       = 0;

                    tenderItem tender = new tenderItem();

                    foreach (var tdNode in tdNodes)
                    {
                        if (tdNodeCount > 3)
                        {
                            if (!String.IsNullOrWhiteSpace(tdNode.InnerHtml))
                            {
                                switch (count)
                                {
                                case 0:
                                    string aNodeString = tdNode.InnerHtml.Trim();
                                    var    htmlDoc     = new HtmlDocument();
                                    htmlDoc.LoadHtml(aNodeString);
                                    var aNode = htmlDoc.DocumentNode.SelectSingleNode("//a");

                                    tender.Reference = aNode.InnerHtml;
                                    break;

                                case 1:
                                    tender.Title = tdNode.FirstChild.InnerHtml;
                                    break;

                                case 2:
                                    tender.OriginatingStation = tdNode.InnerHtml;
                                    break;

                                case 3:
                                    tender.ClosingDate = "Closing date: " + tdNode.InnerHtml;
                                    break;

                                case 4:
                                    tender.BidClosingDate = tdNode.InnerHtml;
                                    break;

                                case 5:
                                    tender.FeeBeforeGST = tdNode.InnerHtml;
                                    break;

                                case 6:
                                    tender.FeeGST = tdNode.InnerHtml;
                                    break;

                                case 7:
                                    tender.FeeAfterGST = tdNode.InnerHtml;
                                    break;
                                }
                                count++;
                            }
                        }
                        else
                        {
                            if (!String.IsNullOrWhiteSpace(tdNode.InnerHtml))
                            {
                                tender.TendererClass = tdNode.InnerHtml;
                            }
                        }
                    }

                    if (tdNodeCount > 3)
                    {
                        //Get the ORIGINATOR details of the tender item
                        string url = "http://www2.sesco.com.my/etender/notice/notice_originator.jsp?Referno=" + WebUtility.UrlEncode(tender.Reference);

                        string httpTask = await Task.Run <string>(() => HttpRequestHandler.GetRequest(url, false));

                        var httpResult = httpTask.ToString();

                        var htmlDoc = new HtmlDocument();
                        htmlDoc.LoadHtml(httpResult);
                        var originatorTrNodes    = htmlDoc.DocumentNode.SelectNodes("//table/tr/td/table/tr");
                        int originatorTrRowCount = 0;

                        if (originatorTrNodes != null)
                        {
                            foreach (var originatorTrNode in originatorTrNodes)
                            {
                                var originatorTdNodes = originatorTrNode.ChildNodes;
                                foreach (var originatorTdNode in originatorTdNodes)
                                {
                                    if (!String.IsNullOrWhiteSpace(originatorTdNode.InnerHtml) && !originatorTdNode.FirstChild.HasChildNodes)
                                    {
                                        //The originator info starts on row 3, thus row 0,1,2 are skipped
                                        switch (originatorTrRowCount)
                                        {
                                        case 3:
                                            tender.Name = originatorTdNode.InnerHtml;
                                            break;

                                        case 4:
                                            tender.OffinePhone = originatorTdNode.InnerHtml;
                                            break;

                                        case 5:
                                            tender.Extension = originatorTdNode.InnerHtml;
                                            break;

                                        case 6:
                                            tender.MobilePhone = originatorTdNode.InnerHtml;
                                            break;

                                        case 7:
                                            tender.Email = originatorTdNode.InnerHtml;
                                            break;

                                        case 8:
                                            tender.Fax = originatorTdNode.InnerHtml;
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }
                                originatorTrRowCount++;
                            }
                        }


                        //Get the downloadable files of the tender item
                        string url2 = "http://www2.sesco.com.my/etender/notice/notice_tender.jsp?Referno=" + WebUtility.UrlEncode(tender.Reference);

                        string httpTask2 = await Task.Run <string>(() => HttpRequestHandler.GetRequest(url2, false));

                        var httpResult2 = httpTask2.ToString();

                        var htmlDoc2 = new HtmlDocument();
                        htmlDoc2.LoadHtml(httpResult2);

                        var filesTdNodes = htmlDoc2.DocumentNode.SelectNodes("//table/tr/td");

                        if (filesTdNodes != null)
                        {
                            var fileLinkNodes = filesTdNodes.Elements("a");


                            foreach (var fileLinkNode in fileLinkNodes)
                            {
                                if (fileLinkNode.NodeType == HtmlNodeType.Element)
                                {
                                    string   fileName  = fileLinkNode.InnerHtml;
                                    string   fileLink  = fileLinkNode.Attributes["href"].Value;
                                    string[] linkSplit = Regex.Split(fileLink, "noticeDoc/");
                                    string   link      = "http://www2.sesco.com.my/noticeDoc/" + Uri.EscapeUriString(linkSplit[1]);
                                    tender.FileLinks[fileName] = link;
                                }
                            }
                        }

                        tenderItems.Add(tender);
                    }

                    rowCount++;
                }
                else
                {
                    rowCount++;
                }
            }

            return(tenderItems);
        }
Beispiel #10
0
        async void retrieveEligibleTenders()
        {
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;

            //Show tenders from database first if exists, then clear database to make way for new tenders
            List <tenderItem> dbtenders0 = await Task.Run <List <tenderItem> >(() => retrieveTenderFromDatabase(0));

            if (dbtenders0.Count > 0)
            {
                //Get bookmark details from database
                if (userSession.username != "")
                {
                    //string httpTask = await Task.Run<string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_tender_eligible.jsp", true));
                    //Task<List<tenderBookmark>> bookmarkHttpTask = Task.Run<List<tenderBookmark>>(() => retrieveBookmark());
                    List <tenderBookmark> tenderBookmarks = await retrieveBookmark();

                    if (tenderBookmarks != null)
                    {
                        //List<tenderBookmark> tenderBookmarks = bookmarkHttpTask;
                        if (tenderBookmarks.Count > 0)
                        {
                            foreach (var tenderItem in dbtenders0)
                            {
                                foreach (var tenderBookmark in tenderBookmarks)
                                {
                                    if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                    {
                                        tenderItem.BookmarkImage = "bookmarkfilled.png";
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                listView.ItemsSource        = dbtenders0;
                pageTitle.IsVisible         = true;
                activityIndicator.IsRunning = false;
                activityIndicator.IsVisible = false;
                upBtn.IsVisible             = true;


                await WaitAndExecuteUpdateTenders(10000);
            }
            else
            {
                //Sending HTTP request to obtain the tender page data
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_tender_eligible.jsp", true));

                var httpResult = httpTask;

                //Extract tender data from the response
                var tenders = await DataExtraction.getWebData(httpResult, "eligibelTenderPage");

                List <tenderItem> tenderItems = (List <tenderItem>)tenders;


                //Get bookmark details from database
                if (userSession.username != "")
                {
                    //string httpTask = await Task.Run<string>(() => HttpRequestHandler.GetRequest("http://www2.sesco.com.my/etender/vendor/vendor_tender_eligible.jsp", true));
                    //Task<List<tenderBookmark>> bookmarkHttpTask = Task.Run<List<tenderBookmark>>(() => retrieveBookmark());
                    List <tenderBookmark> tenderBookmarks = await retrieveBookmark();

                    if (tenderBookmarks != null)
                    {
                        //List<tenderBookmark> tenderBookmarks = bookmarkHttpTask;
                        if (tenderBookmarks.Count > 0)
                        {
                            foreach (var tenderItem in tenderItems)
                            {
                                foreach (var tenderBookmark in tenderBookmarks)
                                {
                                    if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                    {
                                        tenderItem.BookmarkImage = "bookmarkfilled.png";
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                listView.ItemsSource = tenderItems;

                //save all eligible tenders to database
                await saveToTenderDb(tenderItems, 0);

                pageTitle.IsVisible         = true;
                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;
                //pageTitle.IsVisible = true;


                if (tenderItems.Count > 0)
                {
                    upBtn.IsVisible = true;
                }

                await WaitAndExecuteUpdateTenders(10800000);
            }
        }
Beispiel #11
0
        public async void retrieveAndDisplayFirstPageTenders()
        {
            activityIndicator.IsRunning = true;
            activityIndicator.IsVisible = true;

            //Retrieve originating sources from server
            string origSourceHttpTask = await Task.Run <string>(() => HttpRequestHandler.PostRetrieveOrigSources());

            while (origSourceHttpTask == null)
            {
                origSourceHttpTask = await Task.Run <string>(() => HttpRequestHandler.PostRetrieveOrigSources());
            }

            if (origSourceHttpTask != null)
            {
                if (origSourceHttpTask != "Originating sources not found")
                {
                    Console.WriteLine("HTTP TASK IS: " + origSourceHttpTask);
                    originatingSources = JsonConvert.DeserializeObject <List <string> >(origSourceHttpTask);
                    currentFilter      = originatingSources; //Default filter contain all sources
                }
            }

            //Show tenders from database first if exists, then clear database to make way for new tenders
            List <tenderItem> dbtenders1 = await Task.Run <List <tenderItem> >(() => retrieveTenderFromDatabase(1));

            //List<tenderItem> dbtenders2 = await Task.Run<List<tenderItem>>(() => retrieveTenderFromDatabase(2));
            if (dbtenders1.Count > 0)
            {
                if (userSession.username != "")
                {
                    List <tenderBookmark> bookmarkHttpTask = await Task.Run <List <tenderBookmark> >(() => retrieveBookmark());

                    List <tenderBookmark> tenderBookmarks = bookmarkHttpTask.ToList();
                    if (tenderBookmarks.Count > 0)
                    {
                        foreach (var tenderItem in dbtenders1)
                        {
                            foreach (var tenderBookmark in tenderBookmarks)
                            {
                                if (tenderItem.Reference != "" && tenderItem.Reference != null)
                                {
                                    if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                    {
                                        tenderItem.BookmarkImage = "bookmarkfilled.png";
                                        break;
                                    }
                                }
                                else
                                {
                                    if (tenderItem.Title == tenderBookmark.tenderTitle)
                                    {
                                        tenderItem.BookmarkImage = "bookmarkfilled.png";
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                tenderListing        = dbtenders1;
                listView.ItemsSource = dbtenders1;

                /*if (dbtenders2.Count > 0)
                 * {
                 *  nextPage.IsVisible = true;
                 * }*/
                filterButton.IsVisible      = true;
                sortButton.IsVisible        = true;
                activityIndicator.IsRunning = false;
                activityIndicator.IsVisible = false;
                await WaitAndExecuteUpdateTenders(10000);
            }
            else
            {
                //Sending HTTP request to obtain the SEB tender page data
                //string httpTask = await Task.Run<string>(() => getPageData("http://www2.sesco.com.my/etender/notice/notice.jsp"));
                //var httpResult = httpTask;

                //Extract tender data from the response
                //var tenders = await DataExtraction.getWebData(httpResult, "tender");

                //Retrieve Telekom tenders
                //string httpTaskTelekom = await Task.Run<string>(() => getPageData("https://www.tm.com.my/DoingBusinessWithTM/pages/notices.aspx?Year=2018"));
                //var httpResultTelekom = httpTaskTelekom;
                //Console.WriteLine("TELEKOM: " + httpTaskTelekom);
                //Extract tender data from the response
                //var tendersTelekom = await DataExtraction.getWebData(httpResultTelekom, "telekom");

                //List<tenderItem> tenderItems = (List<tenderItem>)tendersTelekom;
                //tenderItems.AddRange((List<tenderItem>)tenders);
                //Get bookmark details from online database

                List <scrapped_tender> scrappedTenders = new List <scrapped_tender>();
                List <tenderItem>      tenderItems     = new List <tenderItem>();
                //Retrieve tenders from server
                string url            = "https://pockettender.000webhostapp.com/process_getTenders.php";
                string httpTaskResult = await Task.Run <string>(() => HttpRequestHandler.GetRequest(url, false));

                if (httpTaskResult != null)
                {
                    if (httpTaskResult != "No tender found")
                    {
                        scrappedTenders = JsonConvert.DeserializeObject <List <scrapped_tender> >(httpTaskResult);

                        if (scrappedTenders != null)
                        {
                            Console.WriteLine("Number of scrapped tenders: " + scrappedTenders.Count);
                            //Convert scrapped tender item into tender item
                            foreach (scrapped_tender scrappedTender in scrappedTenders)
                            {
                                tenderItem tender = new tenderItem();
                                tender.Company            = scrappedTender.originatingSource;
                                tender.TenderSource       = scrappedTender.tenderSource;
                                tender.Reference          = scrappedTender.reference;
                                tender.Agency             = scrappedTender.agency;
                                tender.Title              = scrappedTender.title;
                                tender.Category           = scrappedTender.category;
                                tender.OriginatingStation = scrappedTender.originatingSource;
                                tender.ClosingDate        = scrappedTender.closingDate;

                                //{"bidCloseDate":"N\/A","feeBeforeGST":"RM 0.00","feeGST":"RM 0.00","feeAfterGST":"RM 0.00"}
                                //{ "name":"Francesca Lim","officePhone":"082-441188","extension":"1126","mobilePhone":null,"email":null,"fax":null}
                                //{"PMS106-14-Instruction.pdf":"http:\/\/www2.sesco.com.my\/noticeDoc\/PMS106-14-Instruction.pdf"}

                                if (scrappedTender.docInfoJson != null)
                                {
                                    dynamic docInfo = JsonConvert.DeserializeObject(scrappedTender.docInfoJson);
                                    if (docInfo != null)
                                    {
                                        if (docInfo.bidCloseDate != null)
                                        {
                                            tender.BidClosingDate = docInfo.bidCloseDate;
                                        }

                                        if (docInfo.feeBeforeGST != null)
                                        {
                                            tender.FeeBeforeGST = docInfo.feeBeforeGST;
                                        }

                                        if (docInfo.feeGST != null)
                                        {
                                            tender.FeeGST = docInfo.feeGST;
                                        }

                                        if (docInfo.feeAfterGST != null)
                                        {
                                            tender.FeeAfterGST = docInfo.feeAfterGST;
                                        }
                                    }
                                }

                                if (scrappedTender.originatorJson != null)
                                {
                                    dynamic originatorInfo = JsonConvert.DeserializeObject(scrappedTender.originatorJson);
                                    if (originatorInfo != null)
                                    {
                                        if (originatorInfo.name != null)
                                        {
                                            tender.Name = originatorInfo.name;
                                        }

                                        if (originatorInfo.officePhone != null)
                                        {
                                            tender.OffinePhone = originatorInfo.officePhone;
                                        }

                                        if (originatorInfo.extension != null)
                                        {
                                            tender.Extension = originatorInfo.extension;
                                        }

                                        if (originatorInfo.mobilePhone != null)
                                        {
                                            tender.MobilePhone = originatorInfo.mobilePhone;
                                        }

                                        if (originatorInfo.email != null)
                                        {
                                            tender.Email = originatorInfo.email;
                                        }

                                        if (originatorInfo.fax != null)
                                        {
                                            tender.Fax = originatorInfo.fax;
                                        }
                                    }
                                }

                                if (scrappedTender.fileLinks != null)
                                {
                                    Dictionary <string, string> fileLinks = JsonConvert.DeserializeObject <Dictionary <string, string> >(scrappedTender.fileLinks);
                                    tender.FileLinks = fileLinks;
                                    //{"Folder 1.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 1.zip","Folder 2.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 2.zip","Folder 3.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 3.zip","Folder 4.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 4.zip"}
                                }
                                tenderItems.Add(tender);
                            }
                        }

                        if (userSession.username != "")
                        {
                            List <tenderBookmark> bookmarkHttpTask = await Task.Run <List <tenderBookmark> >(() => retrieveBookmark());

                            List <tenderBookmark> tenderBookmarks = bookmarkHttpTask.ToList();
                            if (tenderBookmarks.Count > 0)
                            {
                                foreach (var tenderItem in tenderItems)
                                {
                                    foreach (var tenderBookmark in tenderBookmarks)
                                    {
                                        if (tenderItem.Reference != "" && tenderItem.Reference != null)
                                        {
                                            if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                            {
                                                tenderItem.BookmarkImage = "bookmarkfilled.png";
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            if (tenderItem.Title == tenderBookmark.tenderTitle)
                                            {
                                                tenderItem.BookmarkImage = "bookmarkfilled.png";
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        Console.WriteLine("Num of tender items: " + tenderItems.Count);
                        tenderListing        = tenderItems;
                        listView.ItemsSource = tenderItems;
                    }
                }

                //Save page 1 tenders to database
                await saveToTenderDb(tenderItems, 1);

                //save subsequent page tenders to database;
                //await storeAllTenders();
                filterButton.IsVisible      = true;
                sortButton.IsVisible        = true;
                activityIndicator.IsRunning = false;
                activityIndicator.IsVisible = false;

                await WaitAndExecuteUpdateTenders(10800000);
            }
        }
Beispiel #12
0
        public async Task WaitAndExecuteUpdateTenders(int milisec)
        {
            await Task.Delay(milisec);

            //Sending HTTP request to obtain the tender page data

            /*string httpTask = await Task.Run<string>(() => getPageData("http://www2.sesco.com.my/etender/notice/notice.jsp"));
             * var httpResult = httpTask;
             *
             * //Extract tender data from the response
             * var tenders = await DataExtraction.getWebData(httpResult, "tender");
             *
             * //Retrieve Telekom tenders
             * string httpTaskTelekom = await Task.Run<string>(() => getPageData("https://www.tm.com.my/DoingBusinessWithTM/pages/notices.aspx?Year=2018"));
             * var httpResultTelekom = httpTaskTelekom;
             * //Console.WriteLine("TELEKOM:" + httpResultTelekom);
             * //Extract tender data from the response
             * var tendersTelekom = await DataExtraction.getWebData(httpResultTelekom, "telekom");
             *
             * List<tenderItem> tenderItems = (List<tenderItem>)tendersTelekom;
             * tenderItems.AddRange((List<tenderItem>)tenders);
             * //List<tenderItem> tenderItems = (List<tenderItem>)tenders;
             */

            List <scrapped_tender> scrappedTenders = new List <scrapped_tender>();
            List <tenderItem>      tenderItems     = new List <tenderItem>();
            //Retrieve tenders from server
            string url            = "https://pockettender.000webhostapp.com/process_getTenders.php";
            string httpTaskResult = await Task.Run <string>(() => HttpRequestHandler.GetRequest(url, false));

            if (httpTaskResult != null)
            {
                if (httpTaskResult != "No tender found")
                {
                    scrappedTenders = JsonConvert.DeserializeObject <List <scrapped_tender> >(httpTaskResult);
                    Console.WriteLine("Number of scrapped tenders: " + scrappedTenders.Count + " yes");
                    //Convert scrapped tender item into tender item
                    if (scrappedTenders != null)
                    {
                        foreach (scrapped_tender scrappedTender in scrappedTenders)
                        {
                            tenderItem tender = new tenderItem();
                            tender.Company            = scrappedTender.originatingSource;
                            tender.TenderSource       = scrappedTender.tenderSource;
                            tender.Reference          = scrappedTender.reference;
                            tender.Agency             = scrappedTender.agency;
                            tender.Title              = scrappedTender.title;
                            tender.Category           = scrappedTender.category;
                            tender.OriginatingStation = scrappedTender.originatingSource;
                            tender.ClosingDate        = scrappedTender.closingDate;

                            //{"bidCloseDate":"N\/A","feeBeforeGST":"RM 0.00","feeGST":"RM 0.00","feeAfterGST":"RM 0.00"}
                            //{ "name":"Francesca Lim","officePhone":"082-441188","extension":"1126","mobilePhone":null,"email":null,"fax":null}
                            //{"PMS106-14-Instruction.pdf":"http:\/\/www2.sesco.com.my\/noticeDoc\/PMS106-14-Instruction.pdf"}

                            if (scrappedTender.docInfoJson != null)
                            {
                                dynamic docInfo = JsonConvert.DeserializeObject(scrappedTender.docInfoJson);
                                if (docInfo != null)
                                {
                                    if (docInfo.bidCloseDate != null)
                                    {
                                        tender.BidClosingDate = docInfo.bidCloseDate;
                                    }

                                    if (docInfo.feeBeforeGST != null)
                                    {
                                        tender.FeeBeforeGST = docInfo.feeBeforeGST;
                                    }

                                    if (docInfo.feeGST != null)
                                    {
                                        tender.FeeGST = docInfo.feeGST;
                                    }

                                    if (docInfo.feeAfterGST != null)
                                    {
                                        tender.FeeAfterGST = docInfo.feeAfterGST;
                                    }
                                }
                            }

                            if (scrappedTender.originatorJson != null)
                            {
                                dynamic originatorInfo = JsonConvert.DeserializeObject(scrappedTender.originatorJson);
                                if (originatorInfo != null)
                                {
                                    if (originatorInfo.name != null)
                                    {
                                        tender.Name = originatorInfo.name;
                                    }

                                    if (originatorInfo.officePhone != null)
                                    {
                                        tender.OffinePhone = originatorInfo.officePhone;
                                    }

                                    if (originatorInfo.extension != null)
                                    {
                                        tender.Extension = originatorInfo.extension;
                                    }

                                    if (originatorInfo.mobilePhone != null)
                                    {
                                        tender.MobilePhone = originatorInfo.mobilePhone;
                                    }

                                    if (originatorInfo.email != null)
                                    {
                                        tender.Email = originatorInfo.email;
                                    }

                                    if (originatorInfo.fax != null)
                                    {
                                        tender.Fax = originatorInfo.fax;
                                    }
                                }
                            }

                            if (scrappedTender.fileLinks != null)
                            {
                                Dictionary <string, string> fileLinks = JsonConvert.DeserializeObject <Dictionary <string, string> >(scrappedTender.fileLinks);
                                tender.FileLinks = fileLinks;
                                //{"Folder 1.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 1.zip","Folder 2.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 2.zip","Folder 3.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 3.zip","Folder 4.zip":"http:\/\/www2.sesco.com.my\/noticeDoc\/Folder 4.zip"}
                            }
                            tenderItems.Add(tender);
                        }
                    }

                    if (userSession.username != "")
                    {
                        List <tenderBookmark> bookmarkHttpTask = await Task.Run <List <tenderBookmark> >(() => retrieveBookmark());

                        List <tenderBookmark> tenderBookmarks = bookmarkHttpTask.ToList();
                        if (tenderBookmarks.Count > 0)
                        {
                            foreach (var tenderItem in tenderItems)
                            {
                                foreach (var tenderBookmark in tenderBookmarks)
                                {
                                    if (tenderItem.Reference != "" && tenderItem.Reference != null)
                                    {
                                        if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                        {
                                            tenderItem.BookmarkImage = "bookmarkfilled.png";
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        if (tenderItem.Title == tenderBookmark.tenderTitle)
                                        {
                                            tenderItem.BookmarkImage = "bookmarkfilled.png";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    tenderListing        = tenderItems;
                    listView.ItemsSource = tenderItems;
                }
            }
            DisplayAlert("Update Tenders", "Updating tender listing. Please wait while the update is running...", "Okay");
            //Display the activity indicator to show activity running in the background
            activityIndicator.IsRunning = true;
            activityIndicator.IsVisible = true;

            //Disable next page and previous page button to disallow user from navigating to other page while update is running
            //previousPage.IsEnabled = false;
            //nextPage.IsEnabled = false;

            //delete existing tenders from database
            deleteAllTenders();

            //Save page 1 tenders to database
            await saveToTenderDb(tenderItems, 1);

            //save subsequent page tenders to database;
            //await storeAllTenders();

            List <tenderItem> dbtenders1 = await Task.Run <List <tenderItem> >(() => retrieveTenderFromDatabase(1));


            //Get bookmark details from online database
            if (userSession.username != "")
            {
                List <tenderBookmark> bookmarkHttpTask = await Task.Run <List <tenderBookmark> >(() => retrieveBookmark());

                List <tenderBookmark> tenderBookmarks = bookmarkHttpTask.ToList();
                if (tenderBookmarks.Count > 0)
                {
                    foreach (var tenderItem in dbtenders1)
                    {
                        foreach (var tenderBookmark in tenderBookmarks)
                        {
                            if (tenderItem.Reference != "" && tenderItem.Reference != null)
                            {
                                if (tenderItem.Reference == tenderBookmark.tenderReferenceNumber)
                                {
                                    tenderItem.BookmarkImage = "bookmarkfilled.png";
                                    break;
                                }
                            }
                            else
                            {
                                if (tenderItem.Title == tenderBookmark.tenderTitle)
                                {
                                    tenderItem.BookmarkImage = "bookmarkfilled.png";
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            //await DisplayAlert("Update Tenders", "Refresh Tenders", "Okay");
            tenderListing        = tenderItems;
            listView.ItemsSource = tenderItems;

            activityIndicator.IsRunning = false;
            activityIndicator.IsVisible = false;
            //previousPage.IsEnabled = true;
            //nextPage.IsEnabled = true;

            await WaitAndExecuteUpdateTenders(10800000);
        }