Exemplo n.º 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string reqID1 = Request.Url.Query.ToString().Substring(1);
        string delete = "DELETE FROM RequestFacility WHERE (RequestID = " + reqID1 + ")";

        InsertNewBooking.DeleteCommand = delete;
        InsertNewBooking.Delete();
        delete = "DELETE FROM RequestTime WHERE (RequestID = " + reqID1 + ")";
        InsertNewBooking.DeleteCommand = delete;
        InsertNewBooking.Delete();
        delete = "DELETE FROM RequestRoom WHERE (RequestID = " + reqID1 + ")";
        InsertNewBooking.DeleteCommand = delete;
        InsertNewBooking.Delete();
        delete = "DELETE FROM Request WHERE (RequestID = " + reqID1 + ")";
        InsertNewBooking.DeleteCommand = delete;
        InsertNewBooking.Delete();
        string status = "";

        if (Button1.Text == "Submit Instant Request")
        {
            status = "Allocated";
        }

        if (Button1.Text == "Submit Request")
        {
            status = "Pending";
        }

        string insertstring = "INSERT INTO Request (ModuleID, RoundID, UserID, NoStudents, Status, ParkOnly, BuildingID, NoRooms) VALUES('" + ListBoxModCodes.SelectedItem.Text + "'," + DropDownList3.SelectedValue + ",@UserID," + TextBoxStudents.Text + ",'" + status + "',";

        if (DropDownListPark.SelectedItem.Text == "All" || RoomBox1.SelectedIndex != -1)
        {
            insertstring += "null,";
        }
        else
        {
            insertstring += "'" + DropDownListPark.SelectedItem.Text + "',";
        }
        if (DropDownList4.SelectedItem.Text == "All" || RoomBox1.SelectedIndex != -1)
        {
            insertstring += "null,";
        }
        else
        {
            insertstring += "'" + DropDownList4.SelectedValue + "',";
        }
        insertstring += " " + DropDownList2.SelectedValue + ")";

        InsertNewBooking.InsertCommand = insertstring;
        InsertNewBooking.Insert();
        System.Data.SqlClient.SqlConnection MyConnection;
        System.Data.SqlClient.SqlCommand    MyCommand;
        System.Data.SqlClient.SqlDataReader MyDataReader;
        MyConnection = new System.Data.SqlClient.SqlConnection("Data Source=co-web-3.lboro.ac.uk;Initial Catalog=team17;User ID=team17;Password=g6g88fcv");
        MyConnection.Open();
        MyCommand             = new System.Data.SqlClient.SqlCommand();
        MyCommand.Connection  = MyConnection;
        MyCommand.CommandText = "SELECT RequestID FROM REQUEST";
        MyDataReader          = MyCommand.ExecuteReader();
        string reqID = "";

        while (MyDataReader.Read())
        {
            reqID = MyDataReader.GetSqlValue(0).ToString();
        }
        MyDataReader.Close();
        MyDataReader = null;

        for (int d = 0; d <= DropDownList2.SelectedIndex; d++)
        {
            if (d == 0 && RoomBox1.SelectedIndex != -1)
            {
                MyCommand.CommandText = "INSERT INTO RequestRoom (RequestID, RoomID) VALUES('" + reqID + "', '" + RoomBox1.SelectedValue + "')";
                MyDataReader          = MyCommand.ExecuteReader();
                MyDataReader.Close();
                MyDataReader = null;
            }

            if (d == 1 && RoomBox2.SelectedIndex != -1)
            {
                MyCommand.CommandText = "INSERT INTO RequestRoom (RequestID, RoomID) VALUES('" + reqID + "', '" + RoomBox2.SelectedValue + "')";
                MyDataReader          = MyCommand.ExecuteReader();
                MyDataReader.Close();
                MyDataReader = null;
            }

            if (d == 2 && RoomBox3.SelectedIndex != -1)
            {
                MyCommand.CommandText = "INSERT INTO RequestRoom (RequestID, RoomID) VALUES('" + reqID + "', '" + RoomBox3.SelectedValue + "')";
                MyDataReader          = MyCommand.ExecuteReader();
                MyDataReader.Close();
                MyDataReader = null;
            }

            if (d == 3 && RoomBox4.SelectedIndex != -1)
            {
                MyCommand.CommandText = "INSERT INTO RequestRoom (RequestID, RoomID) VALUES('" + reqID + "', '" + RoomBox4.SelectedValue + "')";
                MyDataReader          = MyCommand.ExecuteReader();
                MyDataReader.Close();
                MyDataReader = null;
            }
        }

        if (DropDownListRoomType.SelectedValue != "All")
        {
            MyCommand.CommandText = "INSERT INTO RequestFacility (RequestID, FacilityID) VALUES(" + reqID + ", " + DropDownListRoomType.SelectedValue + ") ";
            MyDataReader          = MyCommand.ExecuteReader();
            MyDataReader.Close();
            MyDataReader = null;
        }

        if (DropDownListRoomStyle.SelectedValue != "All")
        {
            MyCommand.CommandText = "INSERT INTO RequestFacility (RequestID, FacilityID) VALUES(" + reqID + ", " + (DropDownListRoomStyle.SelectedValue + 3) + ") ";
            MyDataReader          = MyCommand.ExecuteReader();
            MyDataReader.Close();
            MyDataReader = null;
        }

        int noFacilities = CheckBoxListFacilities.Items.Count;

        for (int x = 0; x < noFacilities; x++)
        {
            if (CheckBoxListFacilities.Items[x].Selected == true)
            {
                MyCommand.CommandText = "INSERT INTO RequestFacility (RequestID, FacilityID) VALUES(" + reqID + ", " + (x + 5) + ") ";
                MyDataReader          = MyCommand.ExecuteReader();
                MyDataReader.Close();
                MyDataReader = null;
            }
        }
        for (int z = 0; z < CheckBoxList1.Items.Count; z++)
        {
            if (CheckBoxList1.Items[z].Selected == true)
            {
                for (int b = 0; b < CheckBoxList2.Items.Count; b++)
                {
                    if (CheckBoxList2.Items[b].Selected == true)
                    {
                        MyCommand.CommandText = "INSERT INTO RequestTime (RequestID, Week, TimeID) VALUES(" + reqID + ", " + (z + 1) + ", " + b + ") ";
                        MyDataReader          = MyCommand.ExecuteReader();
                        MyDataReader.Close();
                        MyDataReader = null;
                    }
                }
            }
        }
        MyCommand = null;
        MyConnection.Close();
        MyConnection = null;
        Response.Redirect("~/Secure/booked.aspx?" + reqID);
    }
Exemplo n.º 2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string status = "";

        if (Button1.Text == "Submit Instant Request")
        {
            status = "Allocated";
        }

        if (Button1.Text == "Submit Request")
        {
            status = "Pending";
        }

        string insertstring = "INSERT INTO Request (ModuleID, RoundID, UserID, NoStudents, Status, NoRooms) VALUES('" + ListBoxModCodes.SelectedItem.Text + "'," + DropDownList3.SelectedValue + ",@UserID," + TextBoxStudents.Text + ",'" + status + "',1) ";

        InsertNewBooking.InsertCommand = insertstring;
        InsertNewBooking.Insert();
        System.Data.SqlClient.SqlConnection MyConnection;
        System.Data.SqlClient.SqlCommand    MyCommand;
        System.Data.SqlClient.SqlDataReader MyDataReader;
        MyConnection = new System.Data.SqlClient.SqlConnection("Data Source=co-web-3.lboro.ac.uk;Initial Catalog=team17;User ID=team17;Password=g6g88fcv");
        MyConnection.Open();
        MyCommand             = new System.Data.SqlClient.SqlCommand();
        MyCommand.Connection  = MyConnection;
        MyCommand.CommandText = "SELECT RequestID FROM REQUEST";
        MyDataReader          = MyCommand.ExecuteReader();
        string reqID = "";

        while (MyDataReader.Read())
        {
            reqID = MyDataReader.GetSqlValue(0).ToString();
        }
        MyDataReader.Close();
        MyDataReader = null;

        MyCommand.CommandText = "INSERT INTO RequestRoom (RequestID, RoomID) VALUES('" + reqID + "', '" + Label2.Text + "')";
        MyDataReader          = MyCommand.ExecuteReader();
        MyDataReader.Close();
        MyDataReader = null;

        for (int z = 0; z < CheckBoxList1.Items.Count; z++)
        {
            if (CheckBoxList1.Items[z].Selected == true)
            {
                for (int b = 0; b < CheckBoxList2.Items.Count; b++)
                {
                    if (CheckBoxList2.Items[b].Selected == true)
                    {
                        MyCommand.CommandText = "INSERT INTO RequestTime (RequestID, Week, TimeID) VALUES(" + reqID + ", " + (z + 1) + ", " + b + ") ";
                        MyDataReader          = MyCommand.ExecuteReader();
                        MyDataReader.Close();
                        MyDataReader = null;
                    }
                }
            }
        }
        MyCommand = null;
        MyConnection.Close();
        MyConnection = null;
        Response.Redirect("~/Secure/booked.aspx?" + reqID);
    }