Example #1
0
        /// <summary>
        /// Handles BtnSend event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSend_Click(object sender, EventArgs e)
        {
            string message = mTxtFeedback.Text.Trim();

            if (message.Length > 255)
            {
                string error = "Sorry, the feedback message is too long.";
                AlertGenerator.ShowError(error, this);
            }
            else
            {
                DisableEnableControls(false);

                Task.Factory.StartNew(() =>
                {
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        Feedback feedback = new Feedback()
                        {
                            Username = Intent.GetStringExtra("Username"),
                            Rating   = mRatingBar.Rating,
                            Message  = message,
                            Date     = DateTime.Now.Date
                        };

                        FeedbackDA feedbackDA = new FeedbackDA();
                        if (feedbackDA.InsertFeedback(feedback))
                        {
                            // Feedback was added successfully
                            Finish(); // Close this activity
                            OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                        }
                        else
                        {
                            string error = "There was a problem saving the record.";
                            RunOnUiThread(() =>
                            {
                                //Enabling the controls back
                                DisableEnableControls(true);
                                AlertGenerator.ShowError(error, this);
                            });
                        }
                    }
                    else
                    {
                        // Connection could not be opened
                        string error = "Connection to the database could not be established.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            DisableEnableControls(true);
                            AlertGenerator.ShowError(error, this);
                        });
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                });
            }
        }
        /// <summary>
        /// Method for populating the DataDridView
        /// </summary>
        public void populateDataGridView(int projectId)
        {
            this.projectId = projectId;
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ModuleDataAccess module = new ModuleDataAccess();
                dgvModule.AutoGenerateColumns = false; // To only show the columns needed
                dgvModule.DataSource          = module.GetAllModules(projectId);

                ProjectDataAccess project = new ProjectDataAccess();
                projectName = project.FindProject(projectId).ProjectName;
                for (int i = 0; i < dgvModule.RowCount; i++)
                {
                    dgvModule.Rows[i].Cells[2].Value = projectName;
                }
                txtSearchModules.Text = "";
                Modules_Tab_Child.getInstance().clearModuleText();
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for populating the DataDridView
        /// </summary>
        public void populateDataGridView()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                dgvDefect.AutoGenerateColumns = false; // To only show the columns needed
                if (FormProvider.Dashboard.role == "Tester")
                {
                    dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Tester");
                }
                else if (FormProvider.Dashboard.role == "Developer")
                {
                    dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Dev");
                }
                else
                {
                    dgvDefect.DataSource = defect.GetAllDefects();
                }
                txtSearchDefects.Text = "";
                Defects_Tab_Child.getInstance().clearDefectText();
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
Example #4
0
        /// <summary>
        /// Method for loading data into the listview
        /// </summary>
        private void LoadData()
        {
            mProgressBar = FindViewById <ProgressBar>(Resource.Id.leaderboardProgressBar);

            Task.Factory.StartNew(() =>
            {
                RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Visible);
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    PlayerStatsDA statsDA = new PlayerStatsDA();
                    mItems = statsDA.GetAllStats();

                    RunOnUiThread(() =>
                    {
                        // Refresh ListView
                        mAdapter          = new MyListViewAdapter(this, mItems);
                        mListView.Adapter = mAdapter;
                    });
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
                RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Gone);
            });
        }
        /// <summary>
        /// Method for generating the DRR chart
        /// </summary>
        private void generateDrrChart()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                ReportsGenerator reportGen = new ReportsGenerator();
                var chartValues            = new List <DRRAnalysis>();
                foreach (var d in reportGen.DrrAnalysis())
                {
                    if (d.Tester == txtSearchDRR.Text)
                    {
                        chartValues.Add(new DRRAnalysis
                        {
                            ProjectName = d.ProjectName,
                            DRR         = d.DRR
                        });
                    }
                }
                drrPointChart.DataSource = chartValues;
                drrPointChart.Series["DRR"].XValueMember  = "ProjectName";
                drrPointChart.Series["DRR"].YValueMembers = "DRR";
                drrPointChart.Series["DRR"].YValueType    = ChartValueType.Int32;
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Populate the datagridview with search result
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearchModules_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ModuleDataAccess module = new ModuleDataAccess();
                dgvModule.AutoGenerateColumns = false; // To only show the columns needed
                dgvModule.DataSource          = module.SearchModules(txtSearchModules.Text.Trim());

                if (dgvModule.RowCount != 0)
                {
                    ProjectDataAccess project = new ProjectDataAccess();
                    var result = project.FindProject(Convert.ToInt32(dgvModule.Rows[0].Cells[1].Value)).ProjectName;
                    for (int i = 0; i < dgvModule.RowCount; i++)
                    {
                        dgvModule.Rows[i].Cells[2].Value = result;
                    }
                }
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for setting the user data into the fields
        /// </summary>
        private void SetData()
        {
            mProgressBar.Visibility = ViewStates.Visible;

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    UserDA userDA   = new UserDA();
                    User resultUser = userDA.FindUser(Intent.GetStringExtra("Username"));
                    if (resultUser != null)
                    {
                        // User found
                        RunOnUiThread(() =>
                        {
                            if (resultUser.Pic != null)
                            {
                                mUserImg = BitmapFactory.DecodeByteArray(resultUser.Pic, 0, resultUser.Pic.Length);
                                mUserPic.SetImageBitmap(mUserImg);
                            }
                            else
                            {
                                mUserPic.SetImageResource(Resource.Drawable.default_pic);
                            }
                            mTxtUsername.Text       = resultUser.Username;
                            mTxtFullName.Text       = resultUser.FullName;
                            mTxtEmail.Text          = resultUser.Email;
                            mTxtDOB.Text            = resultUser.DOB.ToShortDateString();
                            mProgressBar.Visibility = ViewStates.Gone;
                        });
                    }
                    else
                    {
                        // User not found
                        string error = "There was a problem when trying to retrieve data.";
                        RunOnUiThread(() =>
                        {
                            mProgressBar.Visibility = ViewStates.Gone;
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        mProgressBar.Visibility = ViewStates.Gone;
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }
        /// <summary>
        /// Handles DataGridView button click events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvUser_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var Column = ((DataGridView)sender).Columns[e.ColumnIndex];

            if (Column is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                if (Column.Index == 6)                   // Update button
                {
                    if (DbConnector.OpenSQLConnection()) // Open connection to the database
                    {
                        // Connection opened
                        UserAdminDataAccess user = new UserAdminDataAccess();
                        var result = user.FindUser(dgvUser.Rows[e.RowIndex].Cells[0].Value.ToString());
                        if (result != null)
                        {
                            Users_Tab_Child.getInstance().BringToFront();
                            Users_Tab_Child.getInstance().changeView(result);
                        }
                    }
                    else
                    {
                        // Connection could not be opened
                        MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                }
                else if (Column.Index == 7)           // Delete button
                {
                    if (MessageBox.Show("Are you sure you want to delete this record?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (DbConnector.OpenSQLConnection()) // Open connection to the database
                        {
                            // Connection opened
                            UserAdminDataAccess user = new UserAdminDataAccess();
                            if (user.DeleteUser(dgvUser.Rows[e.RowIndex].Cells[0].Value.ToString()))
                            {
                                // Record deleted successfully
                                MessageBox.Show("Record has been deleted successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                populateDataGridView();
                            }
                            else
                            {
                                // Record was not deleted
                                MessageBox.Show("The record could not be deleted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            // Connection could not be opened
                            MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        DbConnector.CloseSQLConnection(); // Close connection to the database
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        /// Handles deletion of the user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DialogFrag_OnDeleteComplete(object sender, DeleteUserDialog.OnDeleteEventArgs e)
        {
            mProgressBar.Visibility = ViewStates.Visible;
            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    User user = new User()
                    {
                        Username = Intent.GetStringExtra("Username"),
                        Password = CryptoHasher.Hash(e.Password)
                    };

                    UserDA userDA = new UserDA();
                    if (userDA.DeleteUser(user))
                    {
                        // User deleted
                        RunOnUiThread(() => MyEventHandler.Trigger(this));
                        Finish(); // Close the activity
                        OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                    }
                    else
                    {
                        string error = "Invalid password.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            mProgressBar.Visibility = ViewStates.Gone;
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        mProgressBar.Visibility = ViewStates.Gone;
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }
        /// <summary>
        /// Populate the datagridview with search result
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearchUsers_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                UserAdminDataAccess user = new UserAdminDataAccess();
                dgvUser.AutoGenerateColumns = false; // To only show the columns needed
                dgvUser.DataSource          = user.SearchUsers(txtSearchUsers.Text.Trim());
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for populating the Charts
        /// </summary>
        public void populateCharts()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                ReportsGenerator      reportGen     = new ReportsGenerator();
                List <StatusAnalysis> statusAnalyis = reportGen.StatusAnalysis();

                barChart.DataSource = statusAnalyis.OrderBy(i => i.Status);
                barChart.Series["Defect Count"].XValueMember  = "Status";
                barChart.Series["Defect Count"].YValueMembers = "Count";
                barChart.Series["Defect Count"].YValueType    = ChartValueType.Int32;

                doughnutChart.DataSource = statusAnalyis.OrderBy(i => i.Status);
                doughnutChart.Series["Count"].XValueMember  = "Status";
                doughnutChart.Series["Count"].YValueMembers = "Count";
                doughnutChart.Series["Count"].YValueType    = ChartValueType.Int32;

                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                drePointChart.DataSource = defect.GetAllDefects();
                drePointChart.Series["DRE"].XValueMember  = "DefectId";
                drePointChart.Series["DRE"].YValueMembers = "DRE";
                drePointChart.Series["DRE"].YValueType    = ChartValueType.Int32;

                List <AgeAnalysis> ageAnalysis = new List <AgeAnalysis>();
                foreach (var d in defects.Zip(reportGen.calculateAge(defects), Tuple.Create))
                {
                    ageAnalysis.Add(new AgeAnalysis
                    {
                        DefectId = d.Item1.DefectId,
                        Age      = d.Item2
                    });
                }
                agePointChart.DataSource = ageAnalysis;
                agePointChart.Series["Age"].XValueMember  = "DefectId";
                agePointChart.Series["Age"].YValueMembers = "Age";
                agePointChart.Series["Age"].YValueType    = ChartValueType.Int32;
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        private void btnSearchDRE_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                dgvDREAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvDREAnalysis.DataSource          = defect.SearchDefectsAnalysis(txtSearchDRE.Text.Trim());
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
Example #13
0
        public static void RetrieveData(Activity activity)
        {
            Task.Factory.StartNew(() =>
            {
                #region Get age data
                if (DbConnector.OpenSQLConnection())
                {
                    List <int> ageGroups = new List <int>();
                    UserDA userDA        = new UserDA();
                    ageGroups            = userDA.GetAllUsersAge();
                    activity.RunOnUiThread(() => OnAgeDataComplete.Invoke(activity, new OnAgeEventArgs(ageGroups)));
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    activity.RunOnUiThread(() =>
                    {
                        AlertGenerator.ShowError(error, activity);
                    });
                }
                DbConnector.CloseSQLConnection();
                #endregion

                #region Get play time data
                if (DbConnector.OpenSQLConnection())
                {
                    List <TimeSpan> playTimes = new List <TimeSpan>();
                    PlayerStatsDA playerDA    = new PlayerStatsDA();
                    playTimes = playerDA.GetAllPlayTimes();
                    activity.RunOnUiThread(() => OnPlayTimeDataComplete.Invoke(activity, new OnPlayTimeEventArgs(playTimes)));
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    activity.RunOnUiThread(() =>
                    {
                        AlertGenerator.ShowError(error, activity);
                    });
                }
                DbConnector.CloseSQLConnection();
                #endregion
            });
        }
        /// <summary>
        /// Method for populating the DataDridViews
        /// </summary>
        public void populateDataGridDRRAnalysis()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ReportsGenerator reportGen = new ReportsGenerator();
                dgvDRRAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvDRRAnalysis.DataSource          = reportGen.DrrAnalysis();
                txtSearchDRE.Text = "";
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for populating the DataDridView
        /// </summary>
        public void populateDataGridView()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ProjectDataAccess project = new ProjectDataAccess();
                dgvProject.AutoGenerateColumns = false; // To only show the columns needed
                dgvProject.DataSource          = project.GetAllProjects();
                txtSearchProjects.Text         = "";
                Projects_Tab_Child.getInstance().clearProjectText();
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for populating the DataDridView
        /// </summary>
        public void populateDataGridView()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                UserAdminDataAccess user = new UserAdminDataAccess();
                dgvUser.AutoGenerateColumns = false; // To only show the columns needed
                dgvUser.DataSource          = user.GetAllUsers();
                txtSearchUsers.Text         = "";
                Users_Tab_Child.getInstance().clearUserText();
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Override OnCreate method
        /// </summary>
        /// <param name="savedInstanceState"></param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_achievements);

            // Set the activity back button on the actionbar
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            #region Initialization
            mProgressBar  = FindViewById <ProgressBar>(Resource.Id.achProgressBar);
            mRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            AchievementsDA achievementsDA = new AchievementsDA();

            Task.Factory.StartNew(() =>
            {
                RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Visible);
                if (DbConnector.OpenSQLConnection())
                {
                    mAchievementsCompl = achievementsDA.GetAllAchievements(Intent.GetStringExtra("Username"));
                }
                DbConnector.CloseSQLConnection();

                // Handle columns on orientation change
                if (Resources.Configuration.Orientation == Android.Content.Res.Orientation.Portrait)
                {
                    mLayoutManager = new GridLayoutManager(this, 1);
                }
                else
                {
                    mLayoutManager = new GridLayoutManager(this, 2);
                }

                // Load achievements into CardViews
                RunOnUiThread(() =>
                {
                    mRecyclerView.SetLayoutManager(mLayoutManager);
                    mAdapter = new RecyclerAdapter(mAchievementsCompl, this);
                    mRecyclerView.SetAdapter(mAdapter);
                    mProgressBar.Visibility = ViewStates.Gone;
                });
            });
            #endregion
        }
        /// <summary>
        /// Method for populating the DataDridViews
        /// </summary>
        public void populateDataGridDREAnalysis()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                dgvDREAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvDREAnalysis.DataSource          = defects;
                txtSearchDRE.Text = "";
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Populate the datagridview with search result
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearchDefects_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                dgvDefect.AutoGenerateColumns = false; // To only show the columns needed
                if (FormProvider.Dashboard.role == "Tester")
                {
                    if (txtSearchDefects.Text != "")
                    {
                        dgvDefect.DataSource = defect.SearchDefects(FormProvider.Dashboard.username, txtSearchDefects.Text.Trim(), "Tester");
                    }
                    else
                    {
                        dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Tester");
                    }
                }
                else if (FormProvider.Dashboard.role == "Developer")
                {
                    if (txtSearchDefects.Text != "")
                    {
                        dgvDefect.DataSource = defect.SearchDefects(FormProvider.Dashboard.username, txtSearchDefects.Text.Trim(), "Dev");
                    }
                    else
                    {
                        dgvDefect.DataSource = defect.FindDefects(FormProvider.Dashboard.username, "Dev");
                    }
                }
                else
                {
                    dgvDefect.DataSource = defect.SearchDefects(txtSearchDefects.Text.Trim());
                }
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                UserDataAccess user   = new UserDataAccess();
                var            result = user.Login(txtUsername.Text, txtPass.Text);
                if (result == null)
                {
                    // No user found for the input credentials
                    MessageBox.Show("Invalid Credentials", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (result.IsAccActive == "Inactive")
                {
                    // User's account is deactivated
                    MessageBox.Show("Account is not active", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    // User found
                    FormProvider.Dashboard.SetUpDashboard(result);
                    if (checkBoxRemember.Checked == false)
                    {
                        txtUsername.Text = "";
                        txtPass.Text     = "";
                    }
                    Hide();                              // Hide LoginForm instance
                    FormProvider.Dashboard.ShowDialog(); // Open Dashboard instance
                }
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Method for populating the DataDridViews
        /// </summary>
        public void populateDataGridAgeAnalysis()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                dgvAgeAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvAgeAnalysis.DataSource          = defects;
                txtSearchDefects.Text = "";
                for (int i = 0; i < defects.Count; i++)
                {
                    ReportsGenerator reportGen = new ReportsGenerator();
                    dgvAgeAnalysis.Rows[i].Cells[7].Value = reportGen.calculateAge(defects)[i];
                }
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        /// <summary>
        /// Handles BtnUpdate event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MBtnUpdate_Click(object sender, EventArgs e)
        {
            string fullname = mTxtFullName.Text.Trim();
            string email    = mTxtEmail.Text.Trim();

            #region Input validation
            if (fullname.Length < 1 || email.Length < 1 || mTxtDOB.Text.Length < 1 ||
                mTxtCurrentPwd.Text.Length < 1 || mTxtNewPwd.Text.Length < 1 || mTxtNewConfPwd.Text.Length < 1)
            {
                string error = "Please fill all the fields.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtNewPwd.Text.Length < 8)
            {
                string error = "Password must contain at least 8 characters.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtNewPwd.Text != mTxtNewConfPwd.Text)
            {
                string error = "Password and Confirm Password do not match.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            #endregion

            // Disabling controls while saving the record
            DisableEnableControls(false);

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    byte[] imgBytes = null;
                    if (mUserImg != null)
                    {
                        // Converting the bitmap into a byte array
                        MemoryStream memStream = new MemoryStream();
                        mUserImg.Compress(Bitmap.CompressFormat.Webp, 100, memStream);
                        imgBytes = memStream.ToArray();
                    }

                    User user = new User()
                    {
                        Username = mTxtUsername.Text.Trim(),
                        FullName = fullname,
                        Email    = email,
                        DOB      = DateTime.Parse(mTxtDOB.Text),
                        Password = CryptoHasher.Hash(mTxtNewPwd.Text),
                        Pic      = imgBytes
                    };

                    UserDA userDA = new UserDA();
                    if (userDA.UpdateUser(user, Intent.GetStringExtra("Username"), CryptoHasher.Hash(mTxtCurrentPwd.Text)))
                    {
                        // User details updated successfully
                        Intent intent = new Intent(this, typeof(LoginActivity));
                        StartActivity(intent);
                        OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                        Finish(); // Close this activity
                    }
                    else
                    {
                        string error = "Invalid Password.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            DisableEnableControls(true);
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        DisableEnableControls(true);
                        AlertGenerator.ShowError(error, this);
                    });
                }
                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }
Example #23
0
        /// <summary>
        /// Handles BtnSignUp click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSignUp_Click(object sender, EventArgs e)
        {
            string username = mTxtUsername.Text.Trim();
            string fullname = mTxtFullName.Text.Trim();
            string email    = mTxtEmail.Text.Trim();

            #region Input validation
            if (username.Length < 1 || fullname.Length < 1 || email.Length < 1 || mTxtDOB.Text.Length < 1 ||
                mTxtPwd.Text.Length < 1 || mTxtConfPwd.Text.Length < 1)
            {
                string error = "Please fill all the fields.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtPwd.Text.Length < 8)
            {
                string error = "Password must contain at least 8 characters.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtPwd.Text != mTxtConfPwd.Text)
            {
                string error = "Password and Confirm Password do not match.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            #endregion

            // Disabling controls while saving the record
            DisableEnableControls(false);

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    UserDA userDA = new UserDA();
                    if (userDA.IsUsernameExists(username))
                    {
                        string error = "The Username entered already exist.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            DisableEnableControls(true);
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                    else
                    {
                        byte[] imgBytes = null;
                        if (mUserImg != null)
                        {
                            // Converting the bitmap into a byte array
                            MemoryStream memStream = new MemoryStream();
                            mUserImg.Compress(Bitmap.CompressFormat.Webp, 100, memStream);
                            imgBytes = memStream.ToArray();
                        }

                        User user = new User()
                        {
                            Username = username,
                            FullName = fullname,
                            Email    = email,
                            DOB      = DateTime.Parse(mTxtDOB.Text),
                            Password = CryptoHasher.Hash(mTxtPwd.Text),
                            Pic      = imgBytes
                        };

                        DbConnector.CloseSQLConnection(); // Close connection to the database
                        if (DbConnector.OpenSQLConnection())
                        {
                            if (userDA.InsertUser(user))
                            {
                                // User was added successfully
                                // Add a record to leaderboard
                                PlayerStats stats = new PlayerStats()
                                {
                                    Username = username,
                                    XP       = 0,
                                    SR       = 0,
                                    PlayTime = TimeSpan.FromSeconds(0),
                                    Golds    = 0,
                                    Silvers  = 0,
                                    Bronzes  = 0
                                };

                                DbConnector.CloseSQLConnection(); // Close connection to the database
                                PlayerStatsDA statsDA = new PlayerStatsDA();
                                if (DbConnector.OpenSQLConnection())
                                {
                                    if (!statsDA.InsertStats(stats))
                                    {
                                        string error = "There was a problem updating your stats.";
                                        RunOnUiThread(() =>
                                        {
                                            AlertGenerator.ShowError(error, this);
                                        });
                                    }
                                }

                                // Add achievements
                                List <AchievementsCompleted> achievementsCompleted = new List <AchievementsCompleted>();
                                for (int i = 1; i < 20; i++)
                                {
                                    achievementsCompleted.Add(new AchievementsCompleted()
                                    {
                                        Username = username,
                                        Progress = 0,
                                        Status   = false
                                    });
                                }

                                DbConnector.CloseSQLConnection(); // Close connection to the database
                                if (DbConnector.OpenSQLConnection())
                                {
                                    AchievementsDA achievementsDA = new AchievementsDA();
                                    if (!achievementsDA.InsertAchievements(achievementsCompleted))
                                    {
                                        string error = "There was a problem updating your stats.";
                                        RunOnUiThread(() =>
                                        {
                                            AlertGenerator.ShowError(error, this);
                                        });
                                    }
                                }

                                // Navigate to Login activity
                                Intent intent = new Intent(this, typeof(LoginActivity));
                                StartActivity(intent);
                                OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                                Finish(); // Close this activity
                            }
                            else
                            {
                                string error = "There was a problem saving the record.";
                                RunOnUiThread(() =>
                                {
                                    //Enabling the controls back
                                    DisableEnableControls(true);
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                        else
                        {
                            // Connection could not be opened
                            string error = "Connection to the database could not be established.";
                            RunOnUiThread(() =>
                            {
                                //Enabling the controls back
                                DisableEnableControls(true);
                                AlertGenerator.ShowError(error, this);
                            });
                        }
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        DisableEnableControls(true);
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }
Example #24
0
        /// <summary>
        /// Handles btnLogin click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            // Validation
            string username = mTxtUsername.Text.Trim();

            if (username.Length < 1 || mTxtPwd.Text.Length < 1)
            {
                string error = "Please fill all the fields.";
                AlertGenerator.ShowError(error, this);
                return;
            }

            // Disabling controls while saving the record
            DisableEnableControls(false);

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    User user = new User()
                    {
                        Username = mTxtUsername.Text,
                        Password = CryptoHasher.Hash(mTxtPwd.Text)
                    };

                    UserDA userDA   = new UserDA();
                    User resultUser = userDA.LoginUser(user);
                    if (resultUser != null)
                    {
                        // User found
                        ISharedPreferences pref       = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
                        ISharedPreferencesEditor edit = pref.Edit();
                        if (mRememberMe.Checked)
                        {
                            // Save credentials in shared preferences
                            edit.PutString("Username", resultUser.Username);
                            edit.PutString("Password", resultUser.Password);
                            edit.Apply();
                        }
                        else
                        {
                            // Remove credentials from shared preferences
                            edit.Remove("Username");
                            edit.Remove("Password");
                            edit.Apply();
                        }

                        MyEventHandler.Trigger(this, resultUser.Username, resultUser.FullName, resultUser.Pic, true);
                        Finish(); // Close the activity
                        OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                    }
                    else
                    {
                        string error = "Invalid Username or Password.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            DisableEnableControls(true);
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        DisableEnableControls(true);
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }
Example #25
0
        /// <summary>
        /// Method for updating player stats and achievements once a puzzle is fixed
        /// </summary>
        /// <param name="scores"></param>
        private void UpdatePlayerStats(PlayerStats scores)
        {
            if (mUsername != String.Empty)
            {
                Task.Factory.StartNew(() =>
                {
                    PlayerStats stats = new PlayerStats();

                    #region Update Player Stats
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        PlayerStatsDA statsDA = new PlayerStatsDA();
                        if (statsDA.IsStatsExist(mUsername))
                        {
                            // Stats exist, therefore update
                            stats           = statsDA.FindStats(mUsername);
                            stats.XP       += scores.XP;
                            stats.SR       += scores.SR;
                            stats.PlayTime += TimeSpan.FromSeconds(mTimeInSeconds);
                            stats.Golds    += scores.Golds;
                            stats.Silvers  += scores.Silvers;
                            stats.Bronzes  += scores.Bronzes;

                            DbConnector.CloseSQLConnection(); // Close connection to the database
                            if (DbConnector.OpenSQLConnection())
                            {
                                if (!statsDA.UpdateStats(stats))
                                {
                                    string error = "There was a problem updating your stats.";
                                    RunOnUiThread(() =>
                                    {
                                        AlertGenerator.ShowError(error, this);
                                    });
                                }
                            }
                            else
                            {
                                // Connection could not be opened
                                string error = "Connection to the database could not be established.";
                                RunOnUiThread(() =>
                                {
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                        else
                        {
                            // Stats does not exist, therefore insert
                            stats.Username = mUsername;
                            stats.XP       = scores.XP;
                            stats.SR       = scores.SR;
                            stats.PlayTime = TimeSpan.FromSeconds(mTimeInSeconds);
                            stats.Golds    = scores.Golds;
                            stats.Silvers  = scores.Silvers;
                            stats.Bronzes  = scores.Bronzes;

                            if (!statsDA.InsertStats(stats))
                            {
                                string error = "There was a problem updating your stats.";
                                RunOnUiThread(() =>
                                {
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                    }
                    else
                    {
                        // Connection could not be opened
                        string error = "Connection to the database could not be established.";
                        RunOnUiThread(() =>
                        {
                            AlertGenerator.ShowError(error, this);
                        });
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                    #endregion

                    #region Update Achievements
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        AchievementsDA achievementsDA = new AchievementsDA();
                        List <AchievementsCompleted> achievementsCompleted = new List <AchievementsCompleted>();
                        achievementsCompleted = achievementsDA.GetAllAchievements(mUsername);
                        DbConnector.CloseSQLConnection(); // Close connection to the database

                        if (achievementsCompleted != null)
                        {
                            // Achievements exist, therefore update
                            achievementsCompleted = AchievementsTracker.UpdateAchievements(achievementsCompleted, mUsername, stats, mCurrentMode, sCurrentLvl);
                            for (int i = 0; i < 19; i++)
                            {
                                if (achievementsCompleted[i].Title != String.Empty)
                                {
                                    string title       = achievementsCompleted[i].Title;
                                    string description = achievementsCompleted[i].Description;
                                    string image       = achievementsCompleted[i].Image;

                                    // Pull up Achievement dialog
                                    FragmentTransaction transaction = FragmentManager.BeginTransaction();
                                    AchDialog dialogFrag            = new AchDialog(title, description, image);
                                    dialogFrag.Show(transaction, "dialog fragment");
                                }
                            }
                            if (DbConnector.OpenSQLConnection())
                            {
                                if (!achievementsDA.UpdateAchievements(achievementsCompleted))
                                {
                                    string error = "There was a problem updating your stats.";
                                    RunOnUiThread(() =>
                                    {
                                        AlertGenerator.ShowError(error, this);
                                    });
                                }
                            }
                            else
                            {
                                // Connection could not be opened
                                string error = "Connection to the database could not be established.";
                                RunOnUiThread(() =>
                                {
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                        else
                        {
                            // Achievements do not exist, therefore insert
                            achievementsCompleted = AchievementsTracker.InsertAchievements(achievementsCompleted, mUsername, mCurrentMode);

                            if (DbConnector.OpenSQLConnection())
                            {
                                if (!achievementsDA.InsertAchievements(achievementsCompleted))
                                {
                                    string error = "There was a problem updating your stats.";
                                    RunOnUiThread(() =>
                                    {
                                        AlertGenerator.ShowError(error, this);
                                    });
                                }
                            }
                        }
                    }
                    else
                    {
                        // Connection could not be opened
                        string error = "Connection to the database could not be established.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            AlertGenerator.ShowError(error, this);
                        });
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                    #endregion
                });
            }
        }
Example #26
0
        /// <summary>
        /// Override OnCreate method
        /// </summary>
        /// <param name="savedInstanceState"></param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_splash);

            Task.Factory.StartNew(() =>
            {
                // Load splash loading image
                ImageViewAsync splashGif = FindViewById <ImageViewAsync>(Resource.Id.splashImageView);
                ImageService.Instance.LoadCompiledResource("loading").Into(splashGif);

                // Read UserInfo for saved credentials if available
                ISharedPreferences pref = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
                string username         = pref.GetString("Username", String.Empty);
                string password         = pref.GetString("Password", String.Empty);

                if (username == String.Empty || password == String.Empty)
                {
                    // No saved credentials, take user to the access screen
                    DbConnector.OpenSQLConnection();
                    DbConnector.CloseSQLConnection();
                    Intent intent = new Intent(this, typeof(MainActivity));
                    intent.PutExtra("LoggingStatus", false);
                    StartActivity(intent);
                    OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                    Finish(); // Close this activity
                    RunOnUiThread(() => MyEventHandler.Trigger(this, "Player", "Player One", null, false));
                }
                else
                {
                    // Saved credentials found
                    // Validate credentials
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        User user = new User()
                        {
                            Username = username,
                            Password = password
                        };

                        UserDA userDA   = new UserDA();
                        User resultUser = userDA.LoginUser(user);
                        if (resultUser != null)
                        {
                            // User found
                            Intent resultIntent = new Intent(this, typeof(MainActivity));
                            resultIntent.PutExtra("LoggingStatus", true);
                            StartActivity(resultIntent);
                            OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                            Finish(); // Close this activity
                            RunOnUiThread(() => MyEventHandler.Trigger(this, resultUser.Username, resultUser.FullName, resultUser.Pic, true));
                        }
                        else
                        {
                            // Saved credentials are incorrect, take the user to access screen
                            ISharedPreferencesEditor edit = pref.Edit();
                            edit.Remove("Username");
                            edit.Remove("Password");
                            edit.Apply();

                            Intent intent = new Intent(this, typeof(MainActivity));
                            intent.PutExtra("LoggingStatus", false);
                            StartActivity(intent);
                            OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                            Finish(); // Close this activity
                            RunOnUiThread(() => MyEventHandler.Trigger(this, "Player", "Player One", null, false));
                        }
                    }
                    else
                    {
                        // Connection could not be opened, take the user to access screen
                        Intent intent = new Intent(this, typeof(MainActivity));
                        intent.PutExtra("LoggingStatus", false);
                        StartActivity(intent);
                        OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                        Finish(); // Close this activity
                        RunOnUiThread(() => MyEventHandler.Trigger(this, "Player", "Player One", null, false));
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                    GC.Collect();                     // Must call Garbage Collector
                }
            });
        }
        /// <summary>
        /// Handles DataGridView button click events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvProject_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var Column = ((DataGridView)sender).Columns[e.ColumnIndex];

            if (Column is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                if (Column.Index == 9) // Modules button
                {
                    Modules_Tab.getInstance().BringToFront();
                    Modules_Tab.getInstance().populateDataGridView(Convert.ToInt32(dgvProject.Rows[e.RowIndex].Cells[0].Value));
                }
                else if (Column.Index == 10)             // Update button
                {
                    if (DbConnector.OpenSQLConnection()) // Open connection to the database
                    {
                        // Connection opened
                        ProjectDataAccess project = new ProjectDataAccess();
                        var result = project.FindProject(Convert.ToInt32(dgvProject.Rows[e.RowIndex].Cells[0].Value));
                        if (result != null)
                        {
                            Projects_Tab_Child.getInstance().BringToFront();
                            Projects_Tab_Child.getInstance().changeView(result);
                        }
                    }
                    else
                    {
                        // Connection could not be opened
                        MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                }
                else if (Column.Index == 11)          // Delete button
                {
                    if (MessageBox.Show("Are you sure you want to delete this record?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (DbConnector.OpenSQLConnection()) // Open connection to the database
                        {
                            // Connection opened
                            ProjectDataAccess project = new ProjectDataAccess();
                            if (project.DeleteProject(Convert.ToInt32(dgvProject.Rows[e.RowIndex].Cells[0].Value)))
                            {
                                // Record deleted successfully
                                MessageBox.Show("Record has been deleted successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                populateDataGridView();
                            }
                            else
                            {
                                // Record was not deleted
                                MessageBox.Show("The record could not be deleted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            // Connection could not be opened
                            MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        DbConnector.CloseSQLConnection(); // Close connection to the database
                    }
                }
            }
        }