예제 #1
0
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        // log the print activity
        RunStoredProcedure rsp = new RunStoredProcedure();

        try
        {
            rsp.Log(3, Int32.Parse(Session["LinkRId"].ToString()));
        }
        catch { }

        ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( '/Web_Forms/PrintReport.aspx?LinkReport=1&ReportName=" + Request.QueryString["ReportName"].ToString() + "&Version=" + Request.QueryString["Version"].ToString() + "', null, 'height=2,width=2,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
        if (!string.IsNullOrEmpty(Session["LinkAuditVersion"].ToString()))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWindow", "closeWindow();", true);
        }
    }
예제 #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SearchReport.CreateReportReset(); // takes off the selected report in ddlCreateReport

        // get the last Report ID
        string   query = "SELECT MAX(ReportId) AS ReportId FROM dbo.Report_MerrylandsRSLReception";
        int      lastRId, result, returnFlag = 2;
        DateTime temp, date = DateTime.Parse(DateTime.Now.ToShortDateString());

        Report.ErrorMessage = "";

        con.Open();
        SqlCommand getRId = new SqlCommand(query, con);

        try
        {
            lastRId = (int)getRId.ExecuteScalar();
            // add plus one to the current report id to be used in this report
            lastRId += 1;
        }
        catch
        {
            lastRId = 6000001;
        }
        con.Close();

        Report.LastReportId = lastRId.ToString();

        if (txtDatePicker.Text == "")
        {
            Report.ErrorMessage = Report.ErrorMessage + "\\n* Shift Date shouldn't be empty.";
            txtDatePicker.Focus();
            returnFlag = 1;
        }
        else if (!DateTime.TryParse(txtDatePicker.Text, out temp))
        {
            Report.ErrorMessage = Report.ErrorMessage + "\\n* Shifts Date entry is not in date format please select an appropriate date.";
            txtDatePicker.Focus();
            returnFlag = 1;
        }
        else if (DateTime.TryParse(txtDatePicker.Text, out temp))
        {
            // compare selected date to current date
            result = DateTime.Compare(DateTime.Parse(DateTime.Parse(txtDatePicker.Text).ToShortDateString()), date);
            if (result > 0)
            {
                Report.ErrorMessage = Report.ErrorMessage + "\\n* DATE MUST BE BEFORE CURRENT DATE.";
                txtDatePicker.Focus();
                returnFlag = 1;
            }
        }

        //if (txtSpecialComments.Text == "")
        //{
        //    Report.ErrorMessage = Report.ErrorMessage + "\\n* COVID-19 section shouldn't be empty.";
        //    txtSpecialComments.Focus();
        //    returnFlag = 1;
        //}

        if (returnFlag == 1)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", "alert(\"" + Report.ErrorMessage + "\");", true);
            return;
        }

        // change the format of the shift date to timestamp format
        DateTime shift_date  = DateTime.Parse(txtDatePicker.Text);
        string   shift_tDate = shift_date.ToString("yyyyMMdd");

        // separate the shift date day of week value
        string shift_DOW = shift_date.DayOfWeek.ToString();

        // change the format of the entry date to timestamp format
        DateTime entry_date = DateTime.Now;

        // pop a message if shift is unchanged
        if (ddlShift.SelectedItem.Value == "-1")
        {
            showAlert("Please select Shift.");
            ddlShift.Focus();
            return;
        }

        // get staff's id
        string cmdText  = "SELECT StaffId FROM Staff WHERE Username = '******'",
               variable = "getStaff";

        readFiles(cmdText, variable);

        // insert data to table
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            Report_MerrylandsRSLReception dm = new Report_MerrylandsRSLReception();
            dm.ReportId        = Int32.Parse(Report.LastReportId);
            dm.RCatId          = 6; // MR Reception Category
            dm.StaffId         = Int32.Parse(Session["currentStaffId"].ToString());
            dm.StaffName       = UserCredentials.DisplayName;
            dm.ShiftId         = Int32.Parse(ddlShift.SelectedItem.Value);
            dm.ShiftDate       = shift_date.Date;
            dm.ShiftDOW        = shift_DOW;
            dm.EntryDate       = entry_date;
            dm.Report_Table    = "Report_MerrylandsRSLReception";
            dm.AuditVersion    = 1;
            dm.ReportStat      = "Awaiting Completion";
            dm.Report_Version  = 2; // current version
            dm.ReadByList      = "," + UserCredentials.StaffId + ",";
            dm.SignInSlip      = txtSignInSlip.Text.Replace("\n", "<br />").Replace("'", "^");
            dm.Refusals        = txtRefusals.Text.Replace("\n", "<br />").Replace("'", "^");
            dm.EventsField     = txtEventsField.Text.Replace("\n", "<br />").Replace("'", "^");
            dm.GeneralComments = txtGeneralComms.Text.Replace("\n", "<br />").Replace("'", "^");
            dm.SpecialComments = txtSpecialComments.Text.Replace("\n", "<br />").Replace("'", "^");
            dc.Report_MerrylandsRSLReceptions.InsertOnSubmit(dm);
            dc.SubmitChanges();
        }

        //log the create activity
        RunStoredProcedure rsp = new RunStoredProcedure();

        try
        {
            rsp.Log(4, Int32.Parse(Report.LastReportId));
        }
        catch { }

        //showAlert("Report Submitted.");
        //Response.Redirect("Default.aspx", false);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect",
                                            "alert('Report Submitted.'); window.location='" +
                                            Request.ApplicationPath + "Default.aspx';", true);
        SearchReport.SetAccordion     = "1";
        SearchReport.RunOnStart       = true;
        SearchReport.FromCreateReport = true;
    }
예제 #3
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string groups, displayName;

        string[]      groupArray;
        StringBuilder groupsList = new StringBuilder();

        AuthenticateUser authUser = new AuthenticateUser("LDAP://MRSLGROUP");

        try
        {
            using (HostingEnvironment.Impersonate())
            {
                if (true == authUser.IsAuthenticated("MRSLGROUP", txtUsername.Text, txtPassword.Text)) // check if login details are valid - checking from Active Directory User Account details
                {
                    groups                   = authUser.GetGroups(txtUsername.Text);                   // retrieve user groups + display name
                    groupArray               = groups.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                    Session["Username"]      = txtUsername.Text;
                    UserCredentials.Username = txtUsername.Text; // record username

                    displayName                 = groupArray[groupArray.Length - 1];
                    Session["DisplayName"]      = displayName;
                    UserCredentials.DisplayName = displayName;
                    groupArray = groupArray.Take(groupArray.Count() - 1).ToArray(); // delete the last array item (display name), to keep this array variable set to usr groups only
                    for (int i = 0; i < groupArray.Length; i++)
                    {
                        groupsList.Append(groupArray[i]); // store group name
                        groupsList.Append("|");           // add a back slash delimeter
                    }
                    groups = groupsList.ToString();       // set user groups
                    UserCredentials.Groups = groups;

                    SqlQuery sqlQuery = new SqlQuery();
                    string   query    = "SELECT * FROM Staff WHERE Username = '******'",
                             data     = "CheckStaffExist";
                    sqlQuery.RetrieveData(query, data); // check if staff is registered in the database

                    sqlQuery.RetrieveData(query, data); // run this method again just in case the Staff Name has just been created

                    RunStoredProcedure rsp = new RunStoredProcedure();
                    // encrypt password
                    string encryptedPassword = rsp.EncryptPassword(txtPassword.Text);
                    // update password stored in the database
                    rsp.UpdatePassword(txtUsername.Text, encryptedPassword);

                    // log the login activity
                    try
                    {
                        rsp.Log();
                    }
                    catch { }

                    bool isCookiePersistent = false; // Create the ticket, and add the groups.
                                                     // set expiration of the authentication ticket - current set: 720 minutes / 12 hours
                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(720), isCookiePersistent, groups);

                    string     encryptedTicket = FormsAuthentication.Encrypt(authTicket);                              //Encrypt the ticket.
                    HttpCookie authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); //Create a cookie, and then add the encrypted ticket to the cookie as data.

                    if (true == isCookiePersistent)
                    {
                        authCookie.Expires = authTicket.Expiration;
                    }

                    Response.Cookies.Add(authCookie);                                                      //Add the cookie to the outgoing cookies collection.
                    Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false), false); //You can redirect now.
                }
                else
                {
                    bool passwordGiven = CheckIfPasswordIsGiven();

                    if (!passwordGiven)
                    {
                        errorLabel.Text = "Invalid details. Please check your username and password.";
                    }
                }
            }
        }
        catch (Exception ex)
        {
            bool passwordGiven = CheckIfPasswordIsGiven();

            if (!passwordGiven)
            {
                errorLabel.Text = "Error logging in user. " + ex.Message;
            }
        }
    }
예제 #4
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SearchReport.CreateReportReset(); // takes off the selected report in ddlCreateReport

        // get the last Report ID
        string   query = "SELECT MAX(ReportId) AS ReportId FROM dbo.Report_MerrylandsRSLCaretaker";
        int      lastRId, result, returnFlag = 2;
        DateTime temp, date = DateTime.Parse(DateTime.Now.ToShortDateString());

        Report.ErrorMessage = "";

        con.Open();
        SqlCommand getRId = new SqlCommand(query, con);

        try
        {
            lastRId = (int)getRId.ExecuteScalar();
            // add plus one to the current report id to be used in this report
            lastRId += 1;
        }
        catch
        {
            lastRId = 13000001;
        }
        con.Close();

        Report.LastReportId = lastRId.ToString();

        if (txtDatePicker.Text == "")
        {
            Report.ErrorMessage = Report.ErrorMessage + "\\n* Shift Date shouldn't be empty.";
            txtDatePicker.Focus();
            returnFlag = 1;
        }
        else if (!DateTime.TryParse(txtDatePicker.Text, out temp))
        {
            Report.ErrorMessage = Report.ErrorMessage + "\\n* Shifts Date entry is not in date format please select an appropriate date.";
            txtDatePicker.Focus();
            returnFlag = 1;
        }
        else if (DateTime.TryParse(txtDatePicker.Text, out temp))
        {
            // compare selected date to current date
            result = DateTime.Compare(DateTime.Parse(DateTime.Parse(txtDatePicker.Text).ToShortDateString()), date);
            if (result > 0)
            {
                Report.ErrorMessage = Report.ErrorMessage + "\\n* DATE MUST BE BEFORE CURRENT DATE.";
                txtDatePicker.Focus();
                returnFlag = 1;
            }
        }

        if (returnFlag == 1)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", "alert(\"" + Report.ErrorMessage + "\");", true);
            return;
        }

        // change the format of the shift date to timestamp format
        DateTime shift_date  = DateTime.Parse(txtDatePicker.Text);
        string   shift_tDate = shift_date.ToString("yyyyMMdd");

        // separate the shift date day of week value
        string shift_DOW = shift_date.DayOfWeek.ToString();

        // change the format of the entry date to timestamp format
        DateTime entry_date = DateTime.Now;

        // pop a message if shift is unchanged
        //if (ddlShift.SelectedItem.Value == "-1")
        //{
        //    showAlert("Please select Shift.");
        //    ddlShift.Focus();
        //    return;
        //}

        // get staff's id
        string cmdText  = "SELECT StaffId FROM Staff WHERE Username = '******'",
               variable = "getStaff";

        readFiles(cmdText, variable);

        // store in a string all the selected item in the checkboxlist
        // Create the list to store.
        List <String> YrStrList1 = new List <string>();

        // Loop through each item.
        foreach (ListItem item in List_Location.Items)
        {
            if (item.Selected)
            {
                // If the item is selected, add the value to the list.
                YrStrList1.Add(item.Value);
            }
        }
        // Join the string together using the ; delimiter.
        string Location = String.Join(",", YrStrList1.ToArray());

        if (!Location.Equals(""))
        {
            Location += ",";
        }


        // insert data to table
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            Report_MerrylandsRSLCaretaker dm = new Report_MerrylandsRSLCaretaker();
            dm.ReportId = Int32.Parse(Report.LastReportId);
            dm.RCatId   = 13; // Customer Relations Officer Category
            dm.StaffId  = Int32.Parse(Session["currentStaffId"].ToString());
            //dm.ShiftId = Int32.Parse(ddlShift.SelectedItem.Value);
            dm.StaffName       = UserCredentials.DisplayName;
            dm.ShiftDate       = shift_date.Date;
            dm.ShiftDOW        = shift_DOW;
            dm.EntryDate       = entry_date;
            dm.Report_Table    = "Report_MerrylandsRSLCaretaker";
            dm.AuditVersion    = 1;
            dm.ReportStat      = "Awaiting Completion";
            dm.Report_Version  = 1; // current version
            dm.ReadByList      = "," + UserCredentials.StaffId + ",";
            dm.Spare1          = Location;
            dm.Occupancy       = txtOccupancy.Text.Replace("\n", "<br />").Replace("'", "^");
            dm.Maintenance     = txtMaintenance.Text.Replace("\n", "<br />").Replace("'", "^");
            dm.GeneralComments = txtGeneralComments.Text.Replace("\n", "<br />").Replace("'", "^");
            dc.Report_MerrylandsRSLCaretakers.InsertOnSubmit(dm);
            dc.SubmitChanges();
        }

        //log the create activity
        RunStoredProcedure rsp = new RunStoredProcedure();

        try
        {
            rsp.Log(4, Int32.Parse(Report.LastReportId));
        }
        catch { }

        //showAlert("Report Submitted.");
        //Response.Redirect("Default.aspx", false);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect",
                                            "alert('Report Submitted.'); window.location='" +
                                            Request.ApplicationPath + "Default.aspx';", true);
        SearchReport.SetAccordion     = "1";
        SearchReport.RunOnStart       = true;
        SearchReport.FromCreateReport = true;
    }