async void getQuestionAnswers()
        {
            nextButton.IsVisible        = false;
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;
            //Console.WriteLine("NUMBER OF QUESTIONS" + survey.surveyQuestions.Count());
            for (int i = 0; i < survey.surveyQuestions.Count(); i++)
            {
                string currentnumber = i.ToString();

                /*surveyQuestion surveyQuestion = new surveyQuestion();
                 * surveyQuestion.questionID = survey.surveyQuestions[i].questionID;
                 * surveyQuestion.questionTitle = survey.surveyQuestions[i].questionTitle;
                 * surveyQuestion.questionType = survey.surveyQuestions[i].questionType;
                 * surveyQuestion.surveyID = survey.surveyQuestions[i].surveyID;*/

                List <surveyOption> surveyOptions = new List <surveyOption>();

                /*if (survey.surveyQuestions[i].questionType == "shortsentence")
                 * {
                 *  survey.surveyQuestions.Add(surveyQuestion);
                 * }else if(survey.surveyQuestions[i].questionType == "longsentence")
                 * {
                 *  survey.surveyQuestions.Add(surveyQuestion);
                 * }else*/
                if (survey.surveyQuestions[i].questionType == "dropdown" || survey.surveyQuestions[i].questionType == "radiobuttons" || survey.surveyQuestions[i].questionType == "checkboxes")
                {
                    string httpTaskanswers = await Task.Run <string>(() => HttpRequestHandler.PostGetSurveyQuestionAnswers(survey.surveyQuestions[i].questionID));

                    while (httpTaskanswers == null)
                    {
                        httpTaskanswers = await Task.Run <string>(() => HttpRequestHandler.PostGetSurveyQuestionAnswers(survey.surveyQuestions[i].questionID));
                    }

                    //if survey question dropdown/radiobutton/checkbox is available, get the list of answers for this particular question
                    if (httpTaskanswers != null)
                    {
                        survey.surveyQuestions[i].surveyOptions = JsonConvert.DeserializeObject <List <surveyOption> >(httpTaskanswers.ToString());
                    }
                }
            }

            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
            nextButton.IsVisible        = true;
        }
        async void OnSubmitButtonClicked(object sender, EventArgs e)
        {
            if (adminAuth.Username == null)
            {
                Console.WriteLine("No username");
            }
            else
            {
                Console.WriteLine("Test Username:"******"TEST Password:"******"No PASSWORD");
            }

            if (adminAuth.Username != null && adminAuth.Password != null)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;

                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostAddAnnouncement(adminAuth.Username, adminAuth.Password, titleInput.Text, contentInput.Text));

                string httpResult = httpTask.ToString();

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;
                if (httpResult == "You have succesfully posted your announcement!")
                {
                    await DisplayAlert("Success", "Announcement has been successfully posted!", "OK");

                    var page             = App.Current.MainPage as rootPage;
                    var announcementPage = new announcementPage();
                    page.changePage(announcementPage);
                }
                else
                {
                    await DisplayAlert("Failed", httpResult, "OK");
                }
            }
            else
            {
                Console.WriteLine("User is not logged in");
            }
        }
Exemple #3
0
 private static string checkUserLogin()
 {
     if (String.IsNullOrEmpty(Settings.Username)) //user not logged in
     {
         Console.WriteLine("No username");
         return("false");
     }
     else
     {
         if (Settings.Role == "user")
         {
             //Send HTTP request to log user in
             Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.PostUserLogin(Settings.Username, Settings.Password));
             var           httpResult = httpTask.Result.ToString();
             Console.WriteLine("User runned");
             Console.WriteLine("HTTP Result: " + httpResult);
             if (httpResult == "Login successful!")
             {
                 Console.WriteLine("User returned");
                 return("user");
             }
             else
             {
                 return("false");
             }
         }
         else
         {
             //Login as admin
             Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.PostAdminLogin(Settings.Username, Settings.Password));
             var           httpResult = httpTask.Result.ToString();
             Console.WriteLine("HTTP Result for admin: " + httpResult);
             if (httpResult != "admin" && httpResult != "editor")
             {
                 return("false");
             }
             else
             {
                 adminAuth.saveCredentials(Settings.Username, Settings.Password);
                 userSession.adminRole = httpResult;
                 return("admin");
             }
         }
     }
 }
        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;
        }
        private async Task onUpdateBtnClicked(object sender, EventArgs e)
        {
            //Sending HTTP request to update Mailing Address
            Task <string> httpTask       = Task.Run <string>(() => HttpRequestHandler.EditCompanyProfileRequest("http://www2.sesco.com.my/etender/vendor/vendor_company_editSubmit.jsp", name, regno, mailingAddress.Text, coucode));
            var           httpTaskResult = httpTask.Result.ToString();

            Console.WriteLine(httpTaskResult);

            if (httpTaskResult == "OK")
            {
                await DisplayAlert("Success", "Company mailing address has been updated.", "OK");
            }

            var page         = App.Current.MainPage as rootPage;
            var userInfoPage = new userInfoPage();

            page.changePage(userInfoPage);
        }
        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;
        }
Exemple #7
0
        async void RelogUserAsync()
        {
            logoutStatus.Text = "";

            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;

            var httpTask = await Task.Run <string>(() => HttpRequestHandler.PostUserLogout());

            var httpResult = httpTask.ToString();

            if (httpResult == "Success")
            {
                //Clear user session
                userSession.userLoginCookie = "";
                userSession.username        = "";
                Settings.Username           = string.Empty;
                Settings.Password           = string.Empty;
                logoutStatus.Text           = "Please re-login with your new password.";
                logoutStatus.TextColor      = Color.Default;
                logoutStatus.FontAttributes = FontAttributes.None;

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;
                await Task.Delay(3000);

                //App.Current.MainPage = new rootPage { Detail = new NavigationPage(new loginPage())
                App.Current.MainPage = new rootPage();
                var page      = App.Current.MainPage as rootPage;
                var loginPage = new loginPage();
                page.changePage(loginPage);
            }
            else
            {
                logoutStatus.TextColor      = Color.Red;
                logoutStatus.FontAttributes = FontAttributes.None;
                logoutStatus.Text           = "Error: Logout Unsuccessful, " + httpResult;
            }

            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
        }
Exemple #8
0
        async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            var answer = await DisplayAlert("Delete", "Are you sure you want to delete the announcement?", "Yes", "No");

            if (answer)
            {
                string username = "";
                username = adminAuth.Username;
                //Send HTTP request to check user exists
                Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.deleteAnnouncement(announcementid, username));
                var           httpResult = httpTask.Result;

                if (httpResult == "deletesuccess")
                {
                    await DisplayAlert("Success", "Announcement successfully deleted", "OK");

                    var page             = App.Current.MainPage as rootPage;
                    var announcementPage = new announcementPage();
                    page.changePage(announcementPage);
                }
                else
                {
                    int count = 0;
                    while (count < 3 && httpResult != "deletesuccess")
                    {
                        Console.WriteLine("Looping for failure delete");
                        httpTask   = Task.Run <string>(() => HttpRequestHandler.deleteAnnouncement(announcementid, username));
                        httpResult = httpTask.Result;
                        count++;
                    }

                    if (httpResult != "deletesuccess")
                    {
                        await DisplayAlert("Failed", "Failed to delete announcement. Please try again later.", "OK");

                        var page             = App.Current.MainPage as rootPage;
                        var announcementPage = new announcementPage();
                        page.changePage(announcementPage);
                    }
                }
            }
        }
Exemple #9
0
        async void OnSubmitButtonClicked(object sender, EventArgs e)
        {
            if (selectedOption == "")
            {
                await DisplayAlert("Failed", "Please select an answer", "OK");
            }
            else
            {
                //Submit user's aswer for poll
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;
                string optionID = "";
                foreach (pollOption option in poll.pollOptions)
                {
                    if (selectedOption == option.optionTitle)
                    {
                        optionID = option.optionID;
                    }
                }
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostSubmitPollAnswer(poll.pollID, optionID, userSession.username, ""));

                string httpResult = httpTask.ToString();

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;

                if (httpResult == "Answer has been successfully submitted. Thank you for participating!")
                {
                    await DisplayAlert("Success", httpResult, "OK");

                    var page     = App.Current.MainPage as rootPage;
                    var pollPage = new pollPage();
                    page.changePage(pollPage);
                }
                else
                {
                    await DisplayAlert("Failed", httpResult, "OK");
                }
            }
        }
        async void onSubmitButtonClicked(object sender, EventArgs e)
        {
            if (userAnswer != "")
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;
                string jsonsurvey = JsonConvert.SerializeObject(survey);

                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostSurveyAnswers(jsonsurvey, userSession.username));

                while (httpTask == null)
                {
                    httpTask = await Task.Run <string>(() => HttpRequestHandler.PostSurveyAnswers(jsonsurvey, userSession.username));
                }
                string httpResult = httpTask.ToString();

                if (httpTask != null)
                {
                    activityIndicator.IsVisible = false;
                    activityIndicator.IsRunning = false;
                    if (httpResult == "Successfully submitted survey. Thank you for participating!")
                    {
                        await DisplayAlert("Success", "Successfully submitted survey. Thank you for participating!", "OK");
                    }
                    else
                    {
                        await DisplayAlert("Error", httpResult, "OK");
                    }
                    var page       = App.Current.MainPage as rootPage;
                    var surveyList = new surveyList();
                    page.changePage(surveyList);
                }
            }
            else
            {
                await DisplayAlert("Error", "Please select an answer", "OK");
            }
        }
        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;
        }
        async Task getUserList()
        {
            //Retrieve admin user list from database
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;

            string httpTask = await Task.Run <string>(() => HttpRequestHandler.getManageAdminUserList());

            var httpResult = httpTask;

            activityIndicator.IsVisible = false;
            activityIndicator.IsRunning = false;
            pageTitle.IsVisible         = true;
            if (httpResult != null)
            {
                if (httpResult == "No user found")
                {
                    errorMsg.IsVisible = true;
                }
                else if (httpResult == "Admin not logged in")
                {
                    errorMsg.Text      = httpResult;
                    errorMsg.IsVisible = true;
                }
                else
                {
                    List <adminUser> adminUsers = JsonConvert.DeserializeObject <List <adminUser> >(httpResult);
                    listView.ItemsSource = adminUsers;
                    upBtn.IsVisible      = true;
                }
            }
            else
            {
                errorMsg.IsVisible = true;
            }
        }
Exemple #13
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);
        }
Exemple #14
0
        async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            if (adminAuth.Username != null && adminAuth.Password != null)
            {
                var answer = await DisplayAlert("Delete", "Are you sure you want to delete the option?", "Yes", "No");

                Button deleteButton = (Button)sender;
                string optionID     = deleteButton.StyleId;
                if (answer)
                {
                    //If user confirm to delete the option, send the HTTP request
                    activityIndicator.IsVisible = true;
                    activityIndicator.IsRunning = true;

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostDeleteOption(adminAuth.Username, adminAuth.Password, optionID));

                    string httpResult = httpTask.ToString();

                    activityIndicator.IsVisible = false;
                    activityIndicator.IsRunning = false;

                    if (httpResult == "Poll option successfully deleted!")
                    {
                        await DisplayAlert("Success", "Poll option has been successfully deleted!", "OK");

                        var page     = App.Current.MainPage as rootPage;
                        var pollPage = new pollPage();
                        page.changePage(pollPage);
                    }
                    else
                    {
                        await DisplayAlert("Failed", httpResult, "OK");
                    }
                }
            }
        }
Exemple #15
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;
        }
        async void OnRegisterButtonClicked(object sender, EventArgs e)
        {
            bool   isErrorPresent = false;
            string errorMessage   = "";

            //Validate inputs
            if (confPasswordEntry.Text != passwordEntry.Text)
            {
                isErrorPresent = true;
                errorMessage   = "Confirm password does not match";
            }

            if (String.IsNullOrEmpty(passwordEntry.Text))
            {
                isErrorPresent = true;
                errorMessage   = "Please enter your Password";
            }
            else
            {
                if (!Regex.IsMatch(passwordEntry.Text, @"^[a-zA-Z0-9]*$"))
                {
                    isErrorPresent = true;
                    errorMessage   = "Wrong format for Password. Password may only contain alphabets and numbers.";
                }
            }

            if (String.IsNullOrEmpty(usernameEntry.Text))
            {
                isErrorPresent = true;
                errorMessage   = "Please enter your Username";
            }
            else
            {
                if (!Regex.IsMatch(usernameEntry.Text, @"^[a-zA-Z0-9]*$"))
                {
                    isErrorPresent = true;
                    errorMessage   = "Wrong format for Username. Username may only contain alphabets and numbers.";
                }
            }

            if (String.IsNullOrEmpty(emailEntry.Text))
            {
                isErrorPresent = true;
                errorMessage   = "Please enter your Email";
            }
            else
            {
                if (!Regex.IsMatch(emailEntry.Text, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
                {
                    isErrorPresent = true;
                    errorMessage   = "Wrong format for Email. e.g. [email protected]";
                }
            }

            if (String.IsNullOrEmpty(fullNameEntry.Text))
            {
                isErrorPresent = true;
                errorMessage   = "Please enter your Full Name";
            }
            else
            {
                if (!Regex.IsMatch(fullNameEntry.Text, @"^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$"))
                {
                    isErrorPresent = true;
                    errorMessage   = "Wrong format for Full Name. Full name must be alphabetic.";
                }
            }

            if (isErrorPresent)
            {
                //Display error message if inputs have error
                await DisplayAlert("Failed", errorMessage, "OK");
            }
            else
            {
                //Send HTTP request to register user
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;

                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostRegisterNewUser(fullNameEntry.Text, emailEntry.Text, usernameEntry.Text, passwordEntry.Text, confPasswordEntry.Text));

                string httpResult = httpTask.ToString();

                if (httpResult == "Registration successful")
                {
                    await DisplayAlert("Success", "You have successfully registered an account! Login now.", "OK");

                    var page      = App.Current.MainPage as rootPage;
                    var loginPage = new loginPage();
                    page.changePage(loginPage);
                }
            }
        }
Exemple #17
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);
            }
        }
Exemple #18
0
        async void onUpdateButtonClicked(object sender, EventArgs eventArgs)
        {
            errorLbl.Text      = "";
            errorLbl.IsVisible = true;
            string name = "", email = "", username = "";
            var    selectedRole = rolePicker.Items[rolePicker.SelectedIndex];

            if (selectedRole == "Administrator")
            {
                selectedRole = "admin";
            }
            else if (selectedRole == "Editor")
            {
                selectedRole = "editor";
            }

            //Input error checking
            bool isInputsValid = true;

            errorLbl.Text = "";

            if (String.IsNullOrEmpty(usernameInput.Text) || String.IsNullOrWhiteSpace(usernameInput.Text))
            {
                errorLbl.Text = "Please enter Username. ";
                isInputsValid = false;
            }
            else
            {
                username = usernameInput.Text;
                if (!username.All(Char.IsLetterOrDigit))
                {
                    errorLbl.Text = "Username must be alphanumeric. ";
                    isInputsValid = false;
                }
            }

            if (String.IsNullOrEmpty(emailInput.Text) || String.IsNullOrWhiteSpace(emailInput.Text))
            {
                errorLbl.Text = "Please enter Email. ";
                isInputsValid = false;
            }
            else
            {
                email = emailInput.Text;
            }

            if (String.IsNullOrEmpty(nameInput.Text) || String.IsNullOrWhiteSpace(nameInput.Text))
            {
                errorLbl.Text = "Please enter Name. ";
                isInputsValid = false;
            }
            else
            {
                name = nameInput.Text;
                if (!Regex.IsMatch(name, @"^[a-zA-Z ]*$"))
                {
                    errorLbl.Text = "Name must be alphabetic. ";
                    isInputsValid = false;
                }
            }

            if (isInputsValid)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;

                //Send HTTP request if inputs are valid
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.editAdmin(name, email, selectedRole, username));

                string httpResult = httpTask.ToString();

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;

                if (httpResult == "Successfully updated user information!")
                {
                    await DisplayAlert("Success", httpResult, "OK");

                    var page = App.Current.MainPage as rootPage;

                    if (isCurrentUser)
                    {
                        var pageToChange = new editUserPage();
                        page.changePage(pageToChange);
                    }
                    else
                    {
                        var pageToChange = new manageUserPage();
                        page.changePage(pageToChange);
                    }
                }
                else
                {
                    await DisplayAlert("Failed", httpResult, "OK");

                    errorLbl.Text = httpResult;
                }
            }
        }
        async void onRegisterButtonClicked(object sender, EventArgs eventArgs)
        {
            string name = "", email = "", username = "", password = "", confPassword = "";
            var    selectedRole = rolePicker.Items[rolePicker.SelectedIndex];

            if (selectedRole == "Administrator")
            {
                selectedRole = "admin";
            }
            else if (selectedRole == "Editor")
            {
                selectedRole = "editor";
            }

            //Input error checking
            bool isInputsValid = true;

            errorLbl.Text = "";
            if (String.IsNullOrEmpty(confPasswordInput.Text) || String.IsNullOrWhiteSpace(confPasswordInput.Text))
            {
                errorLbl.Text = "Please enter Confirm Password. ";
                isInputsValid = false;
            }
            else
            {
                confPassword = confPasswordInput.Text;
            }

            if (String.IsNullOrEmpty(passwordInput.Text) || String.IsNullOrWhiteSpace(passwordInput.Text))
            {
                errorLbl.Text = "Please enter Password. ";
                isInputsValid = false;
            }
            else
            {
                password = passwordInput.Text;
            }

            if (isInputsValid)
            {
                if (confPassword != password)
                {
                    errorLbl.Text = "Password does not match. ";
                    isInputsValid = false;
                }
            }

            if (String.IsNullOrEmpty(usernameInput.Text) || String.IsNullOrWhiteSpace(usernameInput.Text))
            {
                errorLbl.Text = "Please enter Username. ";
                isInputsValid = false;
            }
            else
            {
                username = usernameInput.Text;
                if (!username.All(Char.IsLetterOrDigit))
                {
                    errorLbl.Text = "Username must be alphanumeric. ";
                    isInputsValid = false;
                }
            }

            if (String.IsNullOrEmpty(emailInput.Text) || String.IsNullOrWhiteSpace(emailInput.Text))
            {
                errorLbl.Text = "Please enter Email. ";
                isInputsValid = false;
            }
            else
            {
                email = emailInput.Text;
            }

            if (String.IsNullOrEmpty(nameInput.Text) || String.IsNullOrWhiteSpace(nameInput.Text))
            {
                errorLbl.Text = "Please enter Name. ";
                isInputsValid = false;
            }
            else
            {
                name = nameInput.Text;
                if (!Regex.IsMatch(name, @"^[a-zA-Z ]*$"))
                {
                    errorLbl.Text = "Name must be alphabetic. ";
                    isInputsValid = false;
                }
            }

            if (isInputsValid)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;

                //Send HTTP request if inputs are valid
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.registerNewAdmin(name, email, selectedRole, username, password, confPassword));

                string httpResult = httpTask.ToString();

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;

                if (httpResult == "Account successfully registered!")
                {
                    await DisplayAlert("Success", "Account has been successfully registered!", "OK");

                    var page             = App.Current.MainPage as rootPage;
                    var announcementPage = new announcementPage();
                    page.changePage(announcementPage);
                }
                else
                {
                    await DisplayAlert("Failed", httpResult, "OK");

                    errorLbl.Text = httpResult;
                }
            }
        }
Exemple #20
0
        async void retrieveBookmarkTenderDetails(tenderBookmark tenderBookmark)
        {
            int currentGridRow;

            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;

            //Get tender details
            string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostGetBookmarkDetails(tenderBookmark.tenderReferenceNumber, tenderBookmark.tenderTitle));

            var httpResult = httpTask.ToString();

            //var htmlDoc = new HtmlDocument();
            //htmlDoc.LoadHtml(httpResult);

            //Extract tender data from the response
            //var tenders = await DataExtraction.getWebData(httpResult, "tender");
            if (httpResult != "Tender not found" && httpResult != "Missing parameter(s)")
            {
                scrapped_tender scrappedTender = JsonConvert.DeserializeObject <scrapped_tender>(httpResult);
                tenderItem      aTenderItem    = new tenderItem();

                //Copying tender details from scrapped_tender object to tender item object
                aTenderItem.Company            = scrappedTender.originatingSource;
                aTenderItem.TenderSource       = scrappedTender.tenderSource;
                aTenderItem.Reference          = scrappedTender.reference;
                aTenderItem.Agency             = scrappedTender.agency;
                aTenderItem.Title              = scrappedTender.title;
                aTenderItem.Category           = scrappedTender.category;
                aTenderItem.OriginatingStation = scrappedTender.originatingSource;
                aTenderItem.ClosingDate        = scrappedTender.closingDate;

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

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

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

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

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

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

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

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

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

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

                if (scrappedTender.fileLinks != null)
                {
                    Dictionary <string, string> fileLinks = JsonConvert.DeserializeObject <Dictionary <string, string> >(scrappedTender.fileLinks);
                    aTenderItem.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"}
                }
                //List<tenderItem> tenderItems = (List<tenderItem>)tenders;

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;

                //if (tenderItems.Count > 0)
                if (aTenderItem != null)
                {
                    tenderRefLbl.Text    = aTenderItem.Reference;
                    tenderTitleLbl.Text  = aTenderItem.Title;
                    oriStationLbl.Text   = aTenderItem.OriginatingStation;
                    closingDateLbl.Text  = aTenderItem.ClosingDate;
                    bidCloseDateLbl.Text = aTenderItem.BidClosingDate;
                    feeBeforeGSTLbl.Text = aTenderItem.FeeBeforeGST;
                    feeGSTLbl.Text       = aTenderItem.FeeGST;
                    feeAfterGSTLbl.Text  = aTenderItem.FeeAfterGST;

                    if (aTenderItem.Company == "Sarawak Energy")
                    {
                        nameLbl.Text        = aTenderItem.Name;
                        officePhoneLbl.Text = aTenderItem.OffinePhone;
                        extensionLbl.Text   = aTenderItem.Extension;
                        mobilePhoneLbl.Text = aTenderItem.MobilePhone;
                        emailLbl.Text       = aTenderItem.Email;
                        faxLbl.Text         = aTenderItem.Fax;
                    }
                    else
                    {
                        displayGrid.Children.Remove(bidCloseDateTitleLbl);
                        displayGrid.Children.Remove(bidCloseLayout);
                        displayGrid.Children.Remove(boxView11);
                        displayGrid.Children.Remove(docFeeTitleLbl);
                        displayGrid.Children.Remove(feeBeforeGSTLbl);
                        displayGrid.Children.Remove(boxView13);
                        displayGrid.Children.Remove(gstTitleLbl);
                        displayGrid.Children.Remove(feeGSTLbl);
                        displayGrid.Children.Remove(boxView15);
                        displayGrid.Children.Remove(feeAfterGSTTitleLbl);
                        displayGrid.Children.Remove(feeAfterGSTLbl);
                        displayGrid.Children.Remove(boxView17);

                        displayGrid.Children.Remove(originatorTitleLbl);
                        displayGrid.Children.Remove(nameTitleLbl);
                        displayGrid.Children.Remove(offPhoneTitleLbl);
                        displayGrid.Children.Remove(extTitleLbl);
                        displayGrid.Children.Remove(mobPhoneTitleLbl);
                        displayGrid.Children.Remove(emailTitleLbl);
                        displayGrid.Children.Remove(faxTitleLbl);

                        displayGrid.Children.Remove(nameLbl);
                        displayGrid.Children.Remove(officePhoneLbl);
                        displayGrid.Children.Remove(extensionLbl);
                        displayGrid.Children.Remove(mobilePhoneLbl);
                        //displayGrid.Children.Remove(emailLbl);
                        displayGrid.Children.Remove(emailLayout);
                        displayGrid.Children.Remove(faxLbl);

                        displayGrid.Children.Remove(boxView20);
                        displayGrid.Children.Remove(boxView22);
                        displayGrid.Children.Remove(boxView24);
                        displayGrid.Children.Remove(boxView26);
                        displayGrid.Children.Remove(boxView28);
                        displayGrid.Children.Remove(boxView30);

                        for (int i = 0; i < 21; i++)
                        {
                            displayGrid.RowDefinitions.RemoveAt(displayGrid.RowDefinitions.Count() - 1);
                        }
                    }

                    Console.WriteLine("Tender source is : " + aTenderItem.TenderSource);
                    if (aTenderItem.TenderSource == "1")
                    {
                        //If tender is from myProcurement, display its category and agency
                        currentGridRow = displayGrid.RowDefinitions.Count();

                        //Create labels for category and add into the grid
                        var categoryLabel = new Label {
                            Text = "Category: ", Margin = new Thickness(0, 5, 0, 0), FontAttributes = FontAttributes.Bold
                        };
                        var categoryDataLabel = new Label {
                            Text = aTenderItem.Category, Margin = new Thickness(0, 5, 0, 0)
                        };
                        displayGrid.RowDefinitions.Add(new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Auto)
                        });
                        displayGrid.Children.Add(categoryLabel, 0, currentGridRow);
                        displayGrid.Children.Add(categoryDataLabel, 1, currentGridRow);
                        currentGridRow++;

                        //Create boxView as separator
                        var categoryBoxView = new BoxView {
                            BackgroundColor = Color.LightGray, HeightRequest = 1, Margin = new Thickness(0, 5, 0, 0), VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.FillAndExpand
                        };
                        displayGrid.RowDefinitions.Add(new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Auto)
                        });
                        displayGrid.Children.Add(categoryBoxView, 0, currentGridRow);
                        Grid.SetColumnSpan(categoryBoxView, 2);
                        currentGridRow++;

                        //Create labels for agency and add into the grid
                        var agencyLabel = new Label {
                            Text = "Agency: ", Margin = new Thickness(0, 5, 0, 0), FontAttributes = FontAttributes.Bold
                        };
                        var agencyLayout = new StackLayout {
                            Margin = new Thickness(0, 5, 0, 0)
                        };
                        var agencyDataLabel = new Label {
                            Text = aTenderItem.Agency
                        };
                        agencyLayout.Children.Add(agencyDataLabel);

                        displayGrid.RowDefinitions.Add(new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Auto)
                        });
                        displayGrid.Children.Add(agencyLabel, 0, currentGridRow);
                        displayGrid.Children.Add(agencyLayout, 1, currentGridRow);
                        currentGridRow++;

                        //Create boxView as separator
                        var agencyBoxView = new BoxView {
                            BackgroundColor = Color.LightGray, HeightRequest = 1, Margin = new Thickness(0, 5, 0, 0), VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.FillAndExpand
                        };
                        displayGrid.RowDefinitions.Add(new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Auto)
                        });
                        displayGrid.Children.Add(agencyBoxView, 0, currentGridRow);
                        Grid.SetColumnSpan(agencyBoxView, 2);
                    }

                    //Create hyperlink labels for downloadable files
                    if (aTenderItem.FileLinks != null)
                    {
                        if (aTenderItem.FileLinks.Count > 0)
                        {
                            currentGridRow = displayGrid.RowDefinitions.Count();
                            Console.WriteLine("Current grid row : " + currentGridRow);
                            //<Label Text="Downloadable Files: " x:Name="downloadLbl" Grid.Row="31" Grid.Column="0" FontSize="16" Grid.ColumnSpan="2" FontAttributes="Bold" Margin="0,20,0,10"/>
                            var downloadLabel = new Label {
                                Text = "Downloadable Files: ", Margin = new Thickness(0, 20, 0, 10), FontSize = 16, FontAttributes = FontAttributes.Bold
                            };
                            displayGrid.RowDefinitions.Add(new RowDefinition {
                                Height = new GridLength(1, GridUnitType.Auto)
                            });
                            displayGrid.Children.Add(downloadLabel, 0, currentGridRow);
                            Grid.SetColumnSpan(downloadLabel, 2);
                            currentGridRow++;
                            foreach (KeyValuePair <string, string> file in aTenderItem.FileLinks)
                            {
                                Console.WriteLine("Key: " + file.Key + "row: " + currentGridRow);
                                //create the hyperlink label
                                var label = new Label {
                                    Text = file.Key, TextColor = Color.DodgerBlue, Margin = new Thickness(0, 0, 0, 5)
                                };
                                var tapGestureRecognizer = new TapGestureRecognizer();
                                tapGestureRecognizer.Tapped += (s, e) => { Device.OpenUri(new Uri(file.Value)); };
                                label.GestureRecognizers.Add(tapGestureRecognizer);

                                //add hyperlink label into grid
                                displayGrid.RowDefinitions.Add(new RowDefinition {
                                    Height = new GridLength(1, GridUnitType.Auto)
                                });

                                displayGrid.Children.Add(label, 0, currentGridRow);
                                Grid.SetColumnSpan(label, 2);
                                currentGridRow++;
                            }
                        }
                    }
                }
                else
                {
                    await DisplayAlert("Not found", "Tender '" + tenderBookmark.tenderReferenceNumber + "' is not available!", "OK");

                    var page = App.Current.MainPage as rootPage;
                    var tenderBookmarkPage = new tenderBookmarkPage();
                    page.changePage(tenderBookmarkPage);
                }
            }
            else
            {
                if (httpResult == "Tender not found")
                {
                    await DisplayAlert("Tender Not found", "Tender '" + tenderBookmark.tenderReferenceNumber + "' is not available!", "OK");

                    var page = App.Current.MainPage as rootPage;
                    var tenderBookmarkPage = new tenderBookmarkPage();
                    page.changePage(tenderBookmarkPage);
                }
                else
                {
                    await DisplayAlert("Failed", httpResult.ToString(), "OK");

                    var page = App.Current.MainPage as rootPage;
                    var tenderBookmarkPage = new tenderBookmarkPage();
                    page.changePage(tenderBookmarkPage);
                }
            }
        }
Exemple #21
0
        /*void OnCartTapped(object sender, EventArgs args)
         * {
         *  var tenderSelected = ((TappedEventArgs)args).Parameter;
         *  tenderItem tender = (tenderItem)tenderSelected;
         *
         *  DisplayAlert("Success", tender.AddToCartQuantity + " Item " + tender.Reference + " has been successfully added to cart ", "OK");
         * }*/

        async void OnBookmarkTapped(object sender, EventArgs eventArgs)
        {
            //check if user is logged in
            if (userSession.userLoginCookie == "")
            {
                DisplayAlert("Login required", "Please login first to bookmark this item.", "OK");
            }
            else
            {
                var        tenderSelected = ((TappedEventArgs)eventArgs).Parameter;
                tenderItem tender         = (tenderItem)tenderSelected;
                //var image = sender as Image;
                Console.WriteLine("Image now is: " + ((Image)sender).Source.ToString());

                if (((Image)sender).Source.ToString() == "File: bookmarkfilled.png")
                {
                    ((Image)sender).Source = "bookmark.png";
                    DisplayAlert("Cancel bookmark", "Tender '" + tender.Reference + "' has been removed from bookmark!", "OK");

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "delete"));

                    var httpResult = httpTask.ToString();
                    Console.WriteLine(httpResult);
                    int count = 0;

                    while (count < 3 && httpResult != "Success")
                    {
                        Console.WriteLine("Looping for failure delete");
                        httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "delete"));

                        httpResult = httpTask.ToString();
                        count++;
                    }
                }
                else
                {
                    ((Image)sender).Source = "bookmarkfilled.png";
                    DisplayAlert("Add bookmark", "Tender '" + tender.Reference + "' has been successfully added to bookmark!", "OK");

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "add"));

                    var httpResult = httpTask.ToString();
                    Console.WriteLine(httpResult);
                    int count = 0;

                    while (count < 3 && httpResult != "Success")
                    {
                        Console.WriteLine("Looping for failure add");
                        httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "add"));

                        httpResult = httpTask.ToString();
                        count++;
                    }
                }
            }


            //Display tender list with or without bookmark

            //send request to database everyone user tap on bookmark
        }
        async void onLoginBtnClicked(object sender, EventArgs e)
        {
            errorLbl.Text = "";
            bool   isInputsValid = true;
            string username = "", password = "";

            if (String.IsNullOrEmpty(userIdEntry.Text) || String.IsNullOrWhiteSpace(userIdEntry.Text))
            {
                errorLbl.Text += "Please enter User Id. ";
                isInputsValid  = false;
            }

            if (String.IsNullOrEmpty(passwordEntry.Text) || String.IsNullOrWhiteSpace(passwordEntry.Text))
            {
                errorLbl.Text += "Please enter your password.";
                isInputsValid  = false;
            }

            if (isInputsValid)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;
                username = userIdEntry.Text;
                password = passwordEntry.Text;

                //Send HTTP request to log user in
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostAdminLogin(username, password));

                var httpResult = httpTask.ToString();

                //Data extraction to get admin login status from HTTP response
                //var extractionTask = await Task.Run<Object>(() => DataExtraction.getWebData(httpResult, "adminLoginPage"));
                //var status = await DataExtraction.getWebData(httpResult, "adminLoginPage");

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;

                //if login success, save the user account with Xamarin.Auth
                if (httpResult != "admin" && httpResult != "editor")
                {
                    errorLbl.Text = "Login failed! Please try again.";
                }
                else
                {
                    adminAuth.saveCredentials(username, password);
                    userSession.adminRole = httpResult;
                    Console.WriteLine("Admin login: "******"Login success! You will be redirected soon";
                    await Task.Delay(1000);

                    //errorLbl.TextColor = Color.Red;
                    //errorLbl.Text = "";

                    //await Navigation.PushAsync(new tenderPage());
                    //App.Current.MainPage = new rootPage { Detail = new NavigationPage(new tenderEligiblePage()) };
                    App.Current.MainPage = new rootPage(false);
                    //rootPage.changeDetailPage(typeof(tenderPage));
                }
            }
        }
Exemple #23
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;
                }
            }
        }
Exemple #24
0
        async void OnPublishButtonClicked(object sender, EventArgs e)
        {
            bool   isErrorPresent = false;
            string errorMessage   = "";
            string pollQuestion   = "";

            //Validate inputs
            if (pollQuestionInput.Text == "")
            {
                isErrorPresent = true;
                errorMessage   = "Please enter poll question. ";
            }

            if (selectedOption == "")
            {
                isErrorPresent = true;
                errorMessage   = "Please enter number of poll option. ";
            }
            //Get option inputs
            string[] options = new string[optionListLayout.Children.Count()];
            int      count   = 0;

            //Obtain the option inputs
            foreach (StackLayout layout in optionListLayout.Children)
            {
                foreach (View view in layout.Children)
                {
                    if (view.GetType() == typeof(Frame))
                    {
                        if (((Frame)view).Content.GetType() == typeof(Entry))
                        {
                            Entry entry = (Entry)((Frame)view).Content;
                            options[count] = entry.Text;
                            count++;
                        }
                    }
                }
            }

            if (options.Count() <= 0)
            {
                isErrorPresent = true;
                errorMessage   = "Please enter poll option fields. ";
            }

            if (!isErrorPresent)
            {
                if (adminAuth.Username != null && adminAuth.Password != null)
                {
                    activityIndicator.IsVisible = true;
                    activityIndicator.IsRunning = true;

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostAddPoll(adminAuth.Username, adminAuth.Password, pollQuestionInput.Text, selectedOption, options));

                    string httpResult = httpTask.ToString();

                    activityIndicator.IsVisible = false;
                    activityIndicator.IsRunning = false;
                    if (httpResult == "You have succesfully published a poll!")
                    {
                        await DisplayAlert("Success", "Poll has been successfully published!", "OK");

                        var page     = App.Current.MainPage as rootPage;
                        var pollPage = new pollPage();
                        page.changePage(pollPage);
                    }
                    else
                    {
                        await DisplayAlert("Failed", httpResult, "OK");
                    }
                }
                else
                {
                    Console.WriteLine("User is not logged in");
                }
            }
            else
            {
                await DisplayAlert("Failed", errorMessage, "OK");
            }
        }
Exemple #25
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);
        }
Exemple #26
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);
            }
        }
Exemple #27
0
        async void retrievePoll()
        {
            activityIndicator.IsVisible = true;
            activityIndicator.IsRunning = true;

            string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollQuestion());

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

            if (httpTask != null)
            {
                if (httpTask != "There is no poll for now.")
                {
                    List <Poll> pollList = JsonConvert.DeserializeObject <List <Poll> >(httpTask.ToString());

                    //If poll is available, get the poll details, else display the error message
                    if (pollList != null)
                    {
                        if (pollList.Count > 0)
                        {
                            //Get poll details
                            poll = pollList[0];
                            Console.WriteLine("Poll question is: " + poll.pollQuestion);
                            string pollID       = poll.pollID;
                            string pollQuestion = poll.pollQuestion;

                            //Get poll options
                            string httpOptionTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollOptions(pollID));

                            while (httpOptionTask == null)
                            {
                                httpOptionTask = await Task.Run <string>(() => HttpRequestHandler.PostGetPollOptions(pollID));
                            }

                            if (httpOptionTask != null)
                            {
                                List <pollOption> pollOptionList = JsonConvert.DeserializeObject <List <pollOption> >(httpOptionTask.ToString());
                                poll.pollOptions = pollOptionList;
                                List <string> pollOptionStrings = new List <string>();
                                foreach (pollOption option in poll.pollOptions)
                                {
                                    pollOptionStrings.Add(option.optionTitle);
                                }
                                if (pollOptionList != null)
                                {
                                    if (pollOptionList.Count > 0)
                                    {
                                        //Display poll details and options
                                        isPollPresent = true;
                                        Console.WriteLine("YES TESTING IF ISPRESENT " + isPollPresent);
                                        pollQuestionLbl.Text         = pollQuestion;
                                        pollOptionPicker.ItemsSource = pollOptionStrings;
                                        pollQuestionLbl.IsVisible    = true;
                                        optionFrame.IsVisible        = true;
                                        //submitButton.IsVisible = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            errorMsg.IsVisible = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Poll Task is null ");
                        errorMsg.IsVisible = true;
                    }
                }
                else
                {
                    errorMsg.IsVisible = true;
                }
            }
            //await Task.Run(() => checkAdminLoginStatus());
            checkAdminLoginStatus();
            //activityIndicator.IsVisible = false;
            //activityIndicator.IsRunning = false;
        }
        async void onUpdateBtnClick(object sender, EventArgs e)
        {
            if (updateTitleError == true)
            {
                await DisplayAlert("Invalid Title", "Title cannot be empty.", "OK");
            }

            if (updateContentError == true)
            {
                await DisplayAlert("Invalid Content", "Content cannot be empty.", "OK");
            }

            if (updateTitleError == false && updateContentError == false)
            {
                updatedTitle   = editTitle.Text;
                updatedContent = editContent.Text;

                if (adminAuth.Username == null)
                {
                    Console.WriteLine("No username");
                }
                else
                {
                    Console.WriteLine("Test Username:"******"TEST Password:"******"No PASSWORD");
                }

                if (adminAuth.Username != null && adminAuth.Password != null)
                {
                    activityIndicator.IsVisible = true;
                    activityIndicator.IsRunning = true;

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostEditAnnouncement(adminAuth.Username, adminAuth.Password, editID, updatedTitle, updatedContent));

                    string httpResult = httpTask.ToString();

                    activityIndicator.IsVisible = false;
                    activityIndicator.IsRunning = false;

                    if (httpResult == "You have succesfully edited the announcement post!")
                    {
                        await DisplayAlert("Success", httpResult, "OK");

                        var page             = App.Current.MainPage as rootPage;
                        var announcementPage = new announcementPage();
                        page.changePage(announcementPage);
                    }
                    else
                    {
                        await DisplayAlert("Failed", httpResult, "OK");
                    }
                }
                else
                {
                    Console.WriteLine("User is not logged in");
                }
            }
        }
        async void onUpdateBtnClicked(object sender, EventArgs e)
        {
            string oldPassword = "", newPassword = "", confPassword = "";
            bool   isInputsValid = true;

            errorLbl.Text = "";

            //Inputs validation
            if (String.IsNullOrEmpty(confPasswordInput.Text) || String.IsNullOrWhiteSpace(confPasswordInput.Text))
            {
                errorLbl.Text = "Please enter Confirm Password. ";
                isInputsValid = false;
            }
            else
            {
                confPassword = confPasswordInput.Text;
            }

            if (String.IsNullOrEmpty(newPasswordInput.Text) || String.IsNullOrWhiteSpace(newPasswordInput.Text))
            {
                errorLbl.Text = "Please enter New Password. ";
                isInputsValid = false;
            }
            else
            {
                newPassword = newPasswordInput.Text;
            }

            //if new password and confirm password are not empty, check if they matches
            if (isInputsValid)
            {
                if (confPassword != newPassword)
                {
                    errorLbl.Text = "Confirm Password does not match. ";
                    isInputsValid = false;
                }
                else
                {
                    if (String.IsNullOrEmpty(oldPasswordInput.Text) || String.IsNullOrWhiteSpace(oldPasswordInput.Text))
                    {
                        errorLbl.Text = "Please enter Old Password. ";
                        isInputsValid = false;
                    }
                    else
                    {
                        oldPassword = oldPasswordInput.Text;
                    }

                    if (isInputsValid)
                    {
                        activityIndicator.IsVisible = true;
                        activityIndicator.IsRunning = true;

                        //Send HTTP request to update password
                        string httpTask = await Task.Run <string>(() => HttpRequestHandler.adminChangePassword(oldPassword, newPassword, confPassword));

                        string httpResult = httpTask.ToString();

                        activityIndicator.IsVisible = false;
                        activityIndicator.IsRunning = false;

                        if (httpResult == "Successfully changed password!")
                        {
                            await DisplayAlert("Success", "Password has been successfully changed! You will be logged out now.", "OK");

                            adminAuth.DeleteCredentials();

                            App.Current.MainPage = new rootPage();
                            var page      = App.Current.MainPage as rootPage;
                            var loginPage = new loginPage();
                            page.changePage(loginPage);
                        }
                        else
                        {
                            await DisplayAlert("Failed", httpResult, "OK");

                            errorLbl.Text = httpResult;
                        }
                    }
                }
            }
        }
Exemple #30
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);
        }