예제 #1
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;
    }
예제 #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_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;
    }