示例#1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        BillTotal();

        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            BillPayment bp = new BillPayment();
            // check which site it is coming from
            // get IP Address
            string ipAddress = GetIPAddress();
            //string ipAddress = GetLocalIPAddress();

            // set site venue
            string site = SetVenue(ipAddress);

            if (site.Equals("Check IP Address"))
            {
                alert.DisplayMessage("Check IP Address. Please contact administrator.");
                return;
            }

            bp.Site           = site;
            bp.MemberNo       = Int32.Parse(txtMemberNo.Text);
            bp.FirstName      = txtFirstName.Text;
            bp.LastName       = txtLastName.Text;
            bp.Biller         = txtBiller.Text;
            bp.ConfirmationId = txtConfirmationId.Text;
            bp.Cash           = cash;
            bp.EFTPOS         = eftpos;
            bp.Cheques        = cheques;
            bp.Points         = points;
            bp.Miscellaneous1 = misc1;
            bp.Miscellaneous2 = misc2;
            bp.TotalAmount    = totalAmount;
            bp.StaffId        = Int32.Parse(UserCredentials.StaffId);
            bp.Username       = UserCredentials.Username;
            bp.StaffName      = UserCredentials.DisplayName;
            DateTime currentDate = DateTime.Now, tradingDate = DateTime.Now;
            bp.EnteredDate = currentDate;

            if (currentDate.Hour == 0 || currentDate.Hour == 1 || currentDate.Hour == 2 || currentDate.Hour == 3 ||
                currentDate.Hour == 4 || currentDate.Hour == 5)
            {
                tradingDate = DateTime.Now.AddDays(-1);
            }
            bp.TradingDate = tradingDate;
            dc.BillPayments.InsertOnSubmit(bp);
            dc.SubmitChanges();
        }

        this.BindGrid();
        ResetFields();
    }
示例#2
0
    protected void btnUpdatePassword_Click(object sender, EventArgs e)
    {
        // once the new password is submitted, redirect them to the default url
        // update the password for this user
        RunStoredProcedure rsp = new RunStoredProcedure();
        // join these two methods together
        // encrypt password
        string encryptedPassword = rsp.EncryptPassword(txtNewPassword.Text);

        // update password stored in the database
        rsp.StoredProcedureUpdateString("Proc_UpdatePassword", "password", encryptedPassword, "username", txtUsername.Text);
        //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Password updated');location.href='/Web_Forms/Default.aspx';", true); // show alert textbox first then redirect to default url

        AlertMessage alert = new AlertMessage();

        alert.DisplayMessage("Password updated!");

        // hide the current objetcs displayed and display a textbox to write their new password
        divLogin.Visible       = true;
        divNewPassword.Visible = false;
        txtUsername.Focus();
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // show login prompt and hide header objects
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            // display the accordion when user has logged in
            accordion.Visible  = true;
            username.Visible   = true;
            imgBtnLogo.Visible = true;
        }
        else
        {
            // hide accordion on login page
            accordion.Visible  = false;
            username.Visible   = false;
            imgBtnLogo.Visible = false;
        }

        if (!IsPostBack)
        {
            // display an alert message if user has any existing unsigned report(s)
            if (UserCredentials.StaffId != "0")
            {
                if (Report.HasDisplayedUnsignedReport < 3)
                {
                    con.Open();
                    SqlCommand count = new SqlCommand("Proc_CountUserUnsignedReports", con);
                    count.CommandType = CommandType.StoredProcedure;
                    count.Parameters.Add("@StaffId", SqlDbType.VarChar).Value = UserCredentials.StaffId;
                    int numberOfReportsUnsigned = Int32.Parse(count.ExecuteScalar().ToString());
                    con.Close();

                    if (numberOfReportsUnsigned > 0)
                    {
                        alert.DisplayMessage("*Please ensure to sign all Awaiting Completion status reports. You have " + numberOfReportsUnsigned +
                                             " report(s) unsigned.");
                    }
                    Report.HasDisplayedUnsignedReport++;
                }
            }

            // populate dropdownlist based on user access
            if (!string.IsNullOrWhiteSpace(UserCredentials.Groups))
            {
                // hide or display the Report Version Button depending on the users group
                if (UserCredentials.Groups.Contains("SeniorManager") || UserCredentials.Groups.Contains("DutyManager") ||
                    UserCredentials.Groups.Contains("Supervisor"))
                {
                    acpDisplayVersion.Visible = true;

                    // hide or display the Log Viewer Button depending on the users group
                    if (UserCredentials.GroupsQuery.Contains("Log Viewer"))
                    {
                        btnLogViewer.Visible = true;
                    }
                }

                UserCredentials listReports = new UserCredentials();
                // populate into an int array a list of all reports available to the user
                int[] reportList = listReports.ListReports();

                if (!UserCredentials.Groups.Contains("MRReportsSeniorManagers"))
                {
                    // sort report list in order
                    Array.Sort(reportList);
                    bool incidentAdded1 = false, incidentAdded2 = false, covidAdded1 = false, covidAdded2 = false;
                    // display the reports in proper order, All MR Reports at the top followed by CU Reports
                    for (int i = 0; i < reportList.Length; i++)
                    {
                        // if Duty Manager or Supervisor or Reception or Contractor Staff - Merrylands
                        if (reportList[i] == 1 || reportList[i] == 2 || reportList[i] == 5 || reportList[i] == 8)
                        {
                            if (!incidentAdded1)
                            {
                                ddlCreateReport.Items.Add(new ListItem("MR Incident Report", "1"));
                                ddlSearchReport.Items.Add(new ListItem("MR Incident Report", "2"));
                                incidentAdded1 = true;
                            }
                        }
                        // if Duty Manager or Reception Staff - Umina
                        if (reportList[i] == 6 || reportList[i] == 7)
                        {
                            if (!incidentAdded2)
                            {
                                ddlCreateReport.Items.Add(new ListItem("CU Incident Report", "9"));
                                ddlSearchReport.Items.Add(new ListItem("CU Incident Report", "10"));
                                incidentAdded2 = true;
                            }
                        }
                        // MR Duty Manager
                        if (reportList[i] == 1)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Duty Managers", "2"));
                            ddlSearchReport.Items.Add(new ListItem("MR Duty Manager", "3"));
                        }
                        // MR Supervisor
                        else if (reportList[i] == 2)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Supervisors", "3"));
                            ddlSearchReport.Items.Add(new ListItem("MR Supervisor", "4"));
                        }
                        // if Duty Manager or Supervisor - Merrylands
                        if (reportList[i] == 1 || reportList[i] == 2)
                        {
                            if (!covidAdded1)
                            {
                                //ddlCreateReport.Items.Add(new ListItem("MR Covid Marshall", "10"));
                                //ddlSearchReport.Items.Add(new ListItem("MR Covid Marshall", "11"));
                                covidAdded1 = true;
                            }
                        }
                        // MR Function Supervisor
                        else if (reportList[i] == 3)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Function Supervisor", "4"));
                            ddlSearchReport.Items.Add(new ListItem("MR Function Supervisor", "5"));
                        }
                        // MR Reception Supervisor
                        else if (reportList[i] == 4)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Reception Supervisor", "5"));
                            ddlSearchReport.Items.Add(new ListItem("MR Reception Supervisor", "6"));
                        }
                        // MR Reception
                        else if (reportList[i] == 5)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Reception", "6"));
                            ddlSearchReport.Items.Add(new ListItem("MR Reception", "7"));
                        }
                        // CU Duty Manager
                        else if (reportList[i] == 6)
                        {
                            ddlCreateReport.Items.Add(new ListItem("CU Duty Managers", "7"));
                            ddlSearchReport.Items.Add(new ListItem("CU Duty Manager", "8"));
                            //ddlCreateReport.Items.Add(new ListItem("CU Covid Marshall", "11"));
                            //ddlSearchReport.Items.Add(new ListItem("CU Covid Marshall", "12"));
                        }
                        // CU Reception
                        else if (reportList[i] == 7)
                        {
                            ddlCreateReport.Items.Add(new ListItem("CU Reception", "8"));
                            ddlSearchReport.Items.Add(new ListItem("CU Reception", "9"));
                        }
                        // MR Customer Relations Customer
                        else if (reportList[i] == 9)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Customer Relations Officer", "12"));
                            ddlSearchReport.Items.Add(new ListItem("MR Customer Relations Officer", "13"));
                        }
                        // MR Caretaker
                        else if (reportList[i] == 10)
                        {
                            ddlCreateReport.Items.Add(new ListItem("MR Caretaker", "13"));
                            ddlSearchReport.Items.Add(new ListItem("MR Caretaker", "14"));
                        }
                    }
                }
                // if the user has Senior Managers access
                else
                {
                    // add all available reports - MR Duty Manager and MR/CU Incident Report
                    ddlCreateReport.Items.Add(new ListItem("MR Incident Report", "1"));
                    ddlSearchReport.Items.Add(new ListItem("MR Incident Report", "2"));
                    ddlCreateReport.Items.Add(new ListItem("CU Incident Report", "9"));
                    ddlSearchReport.Items.Add(new ListItem("CU Incident Report", "10"));
                    ddlCreateReport.Items.Add(new ListItem("MR Duty Managers", "2"));
                    ddlSearchReport.Items.Add(new ListItem("MR Duty Manager", "3"));
                    //ddlCreateReport.Items.Add(new ListItem("MR Covid Marshall", "10"));
                    //ddlSearchReport.Items.Add(new ListItem("MR Covid Marshall", "11"));
                    //ddlCreateReport.Items.Add(new ListItem("CU Covid Marshall", "11"));
                    //ddlSearchReport.Items.Add(new ListItem("CU Covid Marshall", "12"));
                    // MR Supervisor
                    ddlCreateReport.Items.Add(new ListItem("MR Supervisors", "3"));
                    ddlSearchReport.Items.Add(new ListItem("MR Supervisor", "4"));
                    // MR Function Supervisor
                    ddlCreateReport.Items.Add(new ListItem("MR Function Supervisor", "4"));
                    ddlSearchReport.Items.Add(new ListItem("MR Function Supervisor", "5"));
                    // MR Reception Supervisor
                    ddlCreateReport.Items.Add(new ListItem("MR Reception Supervisor", "5"));
                    ddlSearchReport.Items.Add(new ListItem("MR Reception Supervisor", "6"));
                    // MR Reception
                    ddlCreateReport.Items.Add(new ListItem("MR Reception", "6"));
                    ddlSearchReport.Items.Add(new ListItem("MR Reception", "7"));
                    // CU Duty Manager
                    ddlCreateReport.Items.Add(new ListItem("CU Duty Managers", "7"));
                    ddlSearchReport.Items.Add(new ListItem("CU Duty Manager", "8"));
                    // CU Reception
                    ddlCreateReport.Items.Add(new ListItem("CU Reception", "8"));
                    ddlSearchReport.Items.Add(new ListItem("CU Reception", "9"));
                    // MR Customer Relations Officer
                    ddlCreateReport.Items.Add(new ListItem("MR Customer Relations Officer", "12"));
                    ddlSearchReport.Items.Add(new ListItem("MR Customer Relations Officer", "13"));
                    // MR Caretaker
                    ddlCreateReport.Items.Add(new ListItem("MR Caretaker", "13"));
                    ddlSearchReport.Items.Add(new ListItem("MR Caretaker", "14"));
                }

                // populate the staff dropdownlist
                PopulateStaffList();

                // keeps the accordion set to the appropriate index (either Reports or Search Pane)
                if (!string.IsNullOrWhiteSpace(SearchReport.SetAccordion))
                {
                    acUserPanel.SelectedIndex = Int32.Parse(SearchReport.SetAccordion);
                }

                // sets the objects to filters selected by the user
                if (!string.IsNullOrWhiteSpace(Request.QueryString["ReportType"]))
                {
                    // current filters selected
                    ddlSearchReport.SelectedValue = Request.QueryString["ReportType"].ToString();
                    ddlDateGroup.SelectedValue    = Request.QueryString["DateGroup"].ToString();
                    ddlReportStat.SelectedValue   = Request.QueryString["ReportStatus"].ToString();

                    if (SearchReport.UnreadList)
                    {
                        cbUnreadList.Checked = true;
                    }
                    else
                    {
                        cbUnreadList.Checked = false;
                    }

                    if (SearchReport.CUOnly)
                    {
                        cbCUOnly.Checked = true;
                    }
                    else
                    {
                        cbCUOnly.Checked = false;
                    }

                    if (SearchReport.MROnly)
                    {
                        cbMROnly.Checked = true;
                    }
                    else
                    {
                        cbMROnly.Checked = false;
                    }

                    if (SearchReport.ArchivedStaff)
                    {
                        // populate the archived staff dropdownlist
                        cbArchivedStaff.Checked    = true;
                        SearchReport.ArchivedStaff = true;
                        PopulateArchivedStaffList();
                    }
                    else
                    {
                        // populate the staff dropdownlist
                        cbArchivedStaff.Checked    = false;
                        SearchReport.ArchivedStaff = false;
                        PopulateStaffList();
                    }

                    ddlStaffId.SelectedValue = Request.QueryString["Staff"].ToString();

                    // set keyword entered
                    if (Request.QueryString["Keyword"].ToString().Equals("0"))
                    {
                        txtKeyword.Text = "";
                    }
                    else
                    {
                        txtKeyword.Text = Request.QueryString["Keyword"].ToString();
                    }

                    if (string.IsNullOrWhiteSpace(SearchReport.ReportId))
                    {
                        txtReportId.Text = "";
                    }
                    else
                    {
                        txtReportId.Text = SearchReport.ReportId;
                    }

                    // if Custom Date is selected in Date Filter
                    if (ddlDateGroup.SelectedValue == "7")
                    {
                        txtStartDate.Text      = SearchReport.StartDate;
                        txtEndDate.Text        = SearchReport.EndDate;
                        txtStartDate.Visible   = true;
                        refvStartDate.Visible  = true;
                        regExStartDate.Visible = true;
                        txtEndDate.Visible     = true;
                        refvStartDate.Visible  = true;
                        regExEndDate.Visible   = true;
                        cmpValue.Visible       = true;
                    }

                    AdvancedFilter();
                    if (SearchReport.WhatHappened == "0")
                    {
                        ddlIncidentHappened.SelectedValue = SearchReport.WhatHappened;
                    }
                    else
                    {
                        // remove the last character (,)
                        ddlIncidentHappened.SelectedValue = SearchReport.WhatHappened.TrimEnd(',');
                    }
                    if (SearchReport.Location == "0")
                    {
                        ddlLocation.SelectedValue = SearchReport.Location;
                    }
                    else
                    {
                        ddlLocation.SelectedValue = SearchReport.Location.TrimEnd(',');
                    }
                    if (SearchReport.MemberNo.Equals("0"))
                    {
                        txtMemNo.Text = "";
                    }
                    else
                    {
                        txtMemNo.Text = SearchReport.MemberNo;
                    }
                    if (SearchReport.ActionTaken == "0")
                    {
                        ddlActionTaken.SelectedValue = SearchReport.ActionTaken;
                    }
                    else
                    {
                        ddlActionTaken.SelectedValue = SearchReport.ActionTaken.TrimEnd(',');
                    }
                    if (SearchReport.FirstName.Equals("0"))
                    {
                        txtFirstName.Text = "";
                    }
                    else
                    {
                        txtFirstName.Text = SearchReport.FirstName;
                    }
                    if (SearchReport.LastName.Equals("0"))
                    {
                        txtLastName.Text = "";
                    }
                    else
                    {
                        txtLastName.Text = SearchReport.LastName;
                    }
                    if (SearchReport.Alias.Equals("0"))
                    {
                        txtAlias.Text = "";
                    }
                    else
                    {
                        txtAlias.Text = SearchReport.Alias;
                    }
                }

                if (!string.IsNullOrEmpty(SearchReport.CreateReport))
                {
                    ddlCreateReport.SelectedValue = SearchReport.CreateReport;
                }

                if (SearchReport.RunOnStart == true)
                {
                    DefaultSearch();
                    // check if postback came from creating a report
                    if (SearchReport.FromCreateReport)
                    {
                        SearchReport.UnreadList       = false;
                        SearchReport.FromCreateReport = false;
                    }
                    else
                    {
                        SearchReport.UnreadList = true;
                    }
                    SearchReport.RunOnStart = false;
                }
            }
        }

        // when key is pressed on these objects and Enter key is selected, trigger btnSearchReport_Click method
        this.cbUnreadList.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");

        this.txtStartDate.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtEndDate.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");

        this.ddlStaffId.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtReportId.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.ddlReportStat.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtKeyword.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");

        this.ddlIncidentHappened.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.ddlLocation.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtFirstName.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtLastName.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtAlias.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.txtMemNo.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
        this.ddlActionTaken.Attributes.Add("onkeypress", "button_click(this,'" + this.btnSearchReport.ClientID + "')");
    }
示例#4
0
    public string[] RetrieveData(string sqlQuery, string data)
    {
        string[] returnData = new string[12];

        // read files from sql database
        SqlDataReader rdr = null;
        SqlCommand    cmd = new SqlCommand(sqlQuery, con);

        // set appropriate stored procedure (either Proc_KeywordSearchAllReports - any report other than Incidents
        if (sqlQuery.Equals("Proc_KeywordSearchAllReports"))
        {
            cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SqlCommandTimeOut"]);
            string keyword = SearchReport.Keyword.ToString().Replace("+", " ");
            cmd.CommandType = CommandType.StoredProcedure; // runs stored procedure Proc_KeywordSearchAllReports
            cmd.Parameters.Add("SearchStr", SqlDbType.VarChar).Value = keyword;
        }

        // Proc_KeywordSearchIncidentReports - Incidents ONLY)
        if (sqlQuery.Equals("Proc_KeywordSearchIncidentReports"))
        {
            cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SqlCommandTimeOut"]);
            string keyword = SearchReport.Keyword.Replace("+", " ");
            cmd.CommandType = CommandType.StoredProcedure; // runs stored procedure Proc_KeywordSearchIncidentReports
            cmd.Parameters.Add("SearchStr", SqlDbType.VarChar).Value    = keyword;
            cmd.Parameters.Add("MemNo", SqlDbType.VarChar).Value        = SearchReport.MemberNo;
            cmd.Parameters.Add("Location", SqlDbType.VarChar).Value     = SearchReport.Location;
            cmd.Parameters.Add("WhatHappened", SqlDbType.VarChar).Value = SearchReport.WhatHappened;
            cmd.Parameters.Add("ActionTaken", SqlDbType.VarChar).Value  = SearchReport.ActionTaken;
            cmd.Parameters.Add("FirstName", SqlDbType.VarChar).Value    = SearchReport.FirstName;
            cmd.Parameters.Add("LastName", SqlDbType.VarChar).Value     = SearchReport.LastName;
            cmd.Parameters.Add("Alias", SqlDbType.VarChar).Value        = SearchReport.Alias;
        }

        // List all reports related to selected Player Id
        if (sqlQuery.Equals("Proc_ListPriorIncidents"))
        {
            string playerId = "";
            switch (SearchReport.ListPlayerIdIncidents)
            {
            case "mr1":
                playerId = ReportIncidentMr.ViewPlayerId1;
                break;

            case "mr2":
                playerId = ReportIncidentMr.ViewPlayerId2;
                break;

            case "mr3":
                playerId = ReportIncidentMr.ViewPlayerId3;
                break;

            case "mr4":
                playerId = ReportIncidentMr.ViewPlayerId4;
                break;

            case "mr5":
                playerId = ReportIncidentMr.ViewPlayerId5;
                break;

            case "cu1":
                playerId = ReportIncidentCu.ViewPlayerId1;
                break;

            case "cu2":
                playerId = ReportIncidentCu.ViewPlayerId2;
                break;

            case "cu3":
                playerId = ReportIncidentCu.ViewPlayerId3;
                break;

            case "cu4":
                playerId = ReportIncidentCu.ViewPlayerId4;
                break;

            case "cu5":
                playerId = ReportIncidentCu.ViewPlayerId5;
                break;
            }
            cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SqlCommandTimeOut"]);
            cmd.CommandType    = CommandType.StoredProcedure; // runs stored procedure Proc_ListPriorIncidents
            cmd.Parameters.Add("PlayerId", SqlDbType.VarChar).Value = playerId;
        }

        try
        {
            con.Open();
            rdr = cmd.ExecuteReader();

            if (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    if (data.Equals("UpdateStaffSign")) // script written to revert Update mistake
                    {
                        Report.EntryDate         = rdr["ModifyDate"].ToString();
                        Report.SelectedStaffName = rdr["StaffName"].ToString();
                    }
                    if (data.Equals("SearchKeyword"))
                    {
                        // get table name and report id, save it as a string together with the sql query (adding a union) and make it look like the view from MRSLDB
                        // send the Table Name and Report ID to ReportSystem static class to create the query for searching the keyword
                        SearchReport.GlobalSearchId += rdr["ReportID"].ToString() + ", ";
                    }
                    if (data.Equals("CheckStaffExist"))
                    {
                        con1.Open(); // check whether or not the active name stored in the database is correct
                        SqlCommand checkExist = new SqlCommand("SELECT Name FROM [StaffName] WHERE [StaffId] = '" + rdr["StaffId"].ToString() + "' AND [Active] = 1", con1);
                        string     staffName  = (string)checkExist.ExecuteScalar();
                        con1.Close();

                        try
                        {
                            // store the Staff Id current Club Umina Manager to be used in ManagerSignQuery method in Report.cs and ManagerSignNotification method in Default.aspx.cs
                            con1.Open();
                            SqlCommand cuManager = new SqlCommand("SELECT StaffId FROM [Staff] WHERE GroupNames LIKE '%CUReportsClubManager%'", con1);
                            Report.ClubManagerUmina = cuManager.ExecuteScalar().ToString();
                            con1.Close();
                        }
                        catch { }

                        if (UserCredentials.DisplayName.Equals(staffName)) // if staff is up-to-date, continue
                        {
                            UserCredentials.StaffId     = rdr["StaffId"].ToString();
                            UserCredentials.StaffNameId = rdr["StaffNameId"].ToString();

                            UpdateStaffRoleAndPass();
                        }
                        else // if user has a different name in the Active Directory to the Database
                        {
                            con1.Open();
                            SqlCommand updateActiveName = new SqlCommand("UPDATE [StaffName] SET [Active]=0 WHERE Name='" + staffName + "'", con1); // update StaffName table and set Active field to false for this staff name
                            updateActiveName.ExecuteNonQuery();
                            con1.Close();

                            con1.Open();
                            SqlCommand checkNameExist = new SqlCommand("SELECT COUNT(*) FROM [StaffName] WHERE [Name] = '" + UserCredentials.DisplayName + "'", con1); // check if the name given already exist in the database
                            int        exist          = (int)checkNameExist.ExecuteScalar();
                            con1.Close();

                            if (exist > 0) // the name is already in the database, change the Active field to the right StaffNameId
                            {
                                con1.Open();
                                SqlCommand cmd3 = new SqlCommand("Update [StaffName] SET [Active]=1 WHERE Name='" + UserCredentials.DisplayName + "'", con1);
                                cmd3.ExecuteNonQuery();
                                con1.Close();

                                con1.Open();
                                SqlCommand checkExist3 = new SqlCommand("SELECT [StaffNameId] FROM [StaffName] WHERE [Name] = '" + UserCredentials.DisplayName + "' AND [ACTIVE]=1 ", con1);
                                int        staffNameId = (int)checkExist3.ExecuteScalar();
                                con1.Close();

                                con1.Open();
                                SqlCommand cmd4 = new SqlCommand("Update [Staff] SET [StaffNameId]='" + staffNameId + "' WHERE StaffId='" + rdr["StaffId"].ToString() + "'", con1);
                                cmd4.ExecuteNonQuery();
                                con1.Close();

                                UserCredentials.StaffId     = rdr["StaffId"].ToString();
                                UserCredentials.StaffNameId = staffNameId.ToString();
                                UserCredentials.Role        = rdr["StaffGroup"].ToString();

                                UpdateStaffRoleAndPass();
                            }
                            else // Name does not exist in the database, create a new StaffNameId and make it active
                            {
                                using (DataClassesDataContext dc = new DataClassesDataContext()) // add new staff name
                                {
                                    StaffName dm = new StaffName();
                                    dm.StaffId = Int32.Parse(rdr["StaffId"].ToString());
                                    dm.Name    = UserCredentials.DisplayName;
                                    dm.Active  = true;
                                    dc.StaffNames.InsertOnSubmit(dm);
                                    dc.SubmitChanges();
                                }

                                con1.Open();
                                SqlCommand checkExist4 = new SqlCommand("SELECT [StaffNameId] FROM [StaffName] WHERE [StaffId] = '" + rdr["StaffId"].ToString() + "' AND [Active] = 1", con1);
                                int        staffNameId = (int)checkExist4.ExecuteScalar();
                                con1.Close();

                                con1.Open();
                                SqlCommand cmd5 = new SqlCommand("Update [Staff] SET [StaffNameId]='" + staffNameId + "' WHERE StaffId='" + rdr["StaffId"].ToString() + "'", con1);
                                cmd5.ExecuteNonQuery();
                                con1.Close();

                                UserCredentials.StaffId     = rdr["StaffId"].ToString();
                                UserCredentials.StaffNameId = staffNameId.ToString();
                                UserCredentials.Role        = rdr["StaffGroup"].ToString();
                            }
                        }

                        break;                                         // the query only needs to run once, this stops it from looping a few times
                    }
                    if (data.Equals("HasReport"))                      // used for previous and next report selected
                    {
                        Report.Id    = rdr["ReportId"].ToString();     // set the selected ReportId
                        Report.Table = rdr["Report_Table"].ToString(); // set the selected Report_Table
                        try                                            // if report is from a Report Table                     // set the selected Report_Version
                        {
                            Report.Version = rdr["Report_Version"].ToString();
                        }
                        catch // if report is from ActionRequired Table
                        {
                            Report.Version = rdr["Version"].ToString();
                        }
                        Report.RowNumber    = rdr["RowNum"].ToString();       // set the selected Row Number
                        Report.AuditVersion = rdr["AuditVersion"].ToString(); // set the selected Audit Version
                        Report.Status       = rdr["ReportStat"].ToString();   // set the status of the selected report
                        Report.Name         = rdr["ReportName"].ToString();   // set the selected ReportName
                        try                                                   // if the report is written by the logged in user       // set the Staff ID selected in the report
                        {
                            Report.SelectedStaffId = rdr["StaffAuthor"].ToString();
                        }
                        catch // else someone else have written the report
                        {
                            Report.SelectedStaffId = rdr["StaffId"].ToString();
                        }
                        Report.SelectedStaffName = rdr["StaffName"].ToString();     // set the Staff selected in the report
                        Report.HasReport         = true;
                    }
                    if (data.Equals("ManagerSignOffRequired")) // check if report requires manager sign-off
                    {
                        Report.ManagerSignOffRequired = (bool)rdr["ManagerSignOffRequired"];
                    }
                    if (data.Equals("ReadList")) // get the list of users who read the report selected
                    {
                        Report.ReadList        = rdr["ReadBy"].ToString();
                        Report.ReadListStaffId = rdr["ReadByList"].ToString();
                    }
                    if (data.Equals("Comment")) // get the list of comments entered in the report selected
                    {
                        Report.Comment = rdr["Comments"].ToString();
                    }
                    if (data.Equals("HasManagerSign"))                           // check if report has already been signed by a manager
                    {
                        if (string.IsNullOrEmpty(rdr["ManagerSign"].ToString())) // if there is no manager sign in the selected report
                        {
                            Report.HasManagerSign = false;
                        }
                        else  // a manager has already signed the report
                        {
                            Report.HasManagerSign = true;
                        }
                    }
                    if (data.Equals("HasUserSign"))                            // check if report has already been signed by the user
                    {
                        if (string.IsNullOrEmpty(rdr["StaffSign"].ToString())) // user hasn't signed the selected report
                        {
                            Report.HasUserSign = false;
                        }
                        else // user has already signed the report
                        {
                            Report.HasUserSign = true;
                        }
                    }
                    if (data.Equals("HasPendingAction"))
                    {
                        if (Convert.ToBoolean(rdr["Completed"].ToString()) == false)
                        {
                            Report.HasPendingAction = true;
                        }
                    }
                    if (data.Equals("CheckUsername")) // get report owner's username
                    {
                        returnData[0] = rdr["Username"].ToString();
                    }
                }
            }
            else // if there is no data to read
            {
                if (data.Equals("HasReport")) // used for previous and next report selected
                {
                    Report.HasReport = false;
                    alert.DisplayMessage("End of list.");
                }
                if (data.Equals("ReadList")) // if no one has read the report yet
                {
                    Report.ReadList        = "";
                    Report.ReadListStaffId = "";
                }
                if (data.Equals("Comment")) // if no one has entered a comment on the report
                {
                    Report.Comment = "";
                }
                if (data.Equals("CheckStaffExist"))
                {
                    string staffRole = ""; // at any case, update the staff group details of the user (just in case there was a promotion that had happened)
                    if (UserCredentials.Groups.Contains("MRReportsSeniorManagers"))
                    {
                        staffRole = "MR Senior Managers";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsDutyManagers"))
                    {
                        staffRole = "MR Duty Managers";
                    }
                    else if (UserCredentials.Groups.Contains("CUReportsDutyManagers"))
                    {
                        staffRole = "CU Duty Managers";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsSupervisors"))
                    {
                        staffRole = "MR Supervisors";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsFunctionSupervisor"))
                    {
                        staffRole = "MR Function Supervisor";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsReceptionSupervisor"))
                    {
                        staffRole = "MR Reception Supervisor";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsReception"))
                    {
                        staffRole = "MR Reception";
                    }
                    else if (UserCredentials.Groups.Contains("CUReportsReception"))
                    {
                        staffRole = "CU Reception";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsIncident"))
                    {
                        staffRole = "MR Contractor";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsCustomerRelationsOfficer"))
                    {
                        staffRole = "MR Customer Relations Officer";
                    }
                    else if (UserCredentials.Groups.Contains("MRReportsCaretaker"))
                    {
                        staffRole = "MR Caretaker";
                    }

                    // get the last Staff Name ID stored in the database
                    con1.Open();
                    SqlCommand checkExist  = new SqlCommand("SELECT MAX(StaffNameId) FROM [StaffName]", con1);
                    int        staffNameId = (int)checkExist.ExecuteScalar();
                    con1.Close();

                    // store staffNameId as the next available variable
                    staffNameId += 1;
                    UserCredentials.StaffNameId = staffNameId.ToString();

                    // add the staff if not registered
                    using (DataClassesDataContext dc = new DataClassesDataContext())
                    {
                        Staff dm = new Staff();
                        dm.Username    = UserCredentials.Username;
                        dm.StaffGroup  = staffRole;
                        dm.StaffNameId = staffNameId;
                        dm.Active      = true;
                        dc.Staffs.InsertOnSubmit(dm);
                        dc.SubmitChanges();
                    }

                    // get the Staff ID of the created staff
                    con1.Open();
                    SqlCommand checkExist1 = new SqlCommand("SELECT MAX(StaffId) FROM [Staff] WHERE [StaffNameId] = '" + staffNameId + "'", con1);
                    int        staffId     = (int)checkExist1.ExecuteScalar();
                    con1.Close();

                    // add new staff name
                    using (DataClassesDataContext dc = new DataClassesDataContext())
                    {
                        StaffName dm = new StaffName();
                        dm.StaffId = staffId;
                        dm.Name    = UserCredentials.DisplayName;
                        dm.Active  = true;
                        dc.StaffNames.InsertOnSubmit(dm);
                        dc.SubmitChanges();
                    }
                }
                if (data.Equals("HasPendingAction"))
                {
                    Report.HasPendingAction = false;
                }
                if (data.Equals("CheckUsername"))
                {
                    Report.WrongUsername = true;
                }
            }
        }
        catch (Exception er)
        {
            alert.DisplayMessage(er.Message);
        }
        finally
        {
            if (rdr != null)
            {
                rdr.Close();
            }
            if (con != null)
            {
                con.Close();
            }
        }
        return(returnData);
    }