예제 #1
0
    protected void scheduleMatch(object sender, EventArgs e)
    {
        //Validation on Dropdown
        if (HomeClubdDropdown.SelectedItem.Text == AwayClubDropdown.SelectedItem.Text)
        {
            ErrorOutput.Text = "Home and Away Cannot be same";
        }
        else
        {
            ErrorOutput.Text = "";

            //Validation on Calendar Selection
            if (DateSelectionCalander.SelectedDate == Convert.ToDateTime("1/1/0001 12:00:00 AM"))
            {
                ErrorOutput.Text = "Select Date";
            }
            else
            {
                //Insert into Database
                comm = new SqlCommand("INSERT INTO matches values(@box1, @box2, @date,@homeid,@awayid)", conn);
                comm.Parameters.Add("@date", System.Data.SqlDbType.VarChar);
                comm.Parameters["@date"].Value = DateSelectionCalander.SelectedDate.ToShortDateString();
                comm.Parameters.Add("@box1", System.Data.SqlDbType.VarChar);
                comm.Parameters["@box1"].Value = HomeClubdDropdown.SelectedItem.Text;
                comm.Parameters.Add("@box2", System.Data.SqlDbType.VarChar);
                comm.Parameters["@box2"].Value = AwayClubDropdown.SelectedItem.Text;
                comm.Parameters.Add("@homeid", System.Data.SqlDbType.VarChar);
                comm.Parameters["@homeid"].Value = HomeClubdDropdown.SelectedValue;
                comm.Parameters.Add("@awayid", System.Data.SqlDbType.VarChar);
                comm.Parameters["@awayid"].Value = AwayClubDropdown.SelectedValue;
                conn.Open();
                comm.ExecuteNonQuery();
                conn.Close();

                //Get Matches Again from Database after Insertion of a Match
                comm = new SqlCommand("SELECT * FROM matches", conn);
                conn.Open();
                reader = comm.ExecuteReader();
                GridViewFixtures.DataSource = reader;
                GridViewFixtures.DataBind();
                reader.Close();
                conn.Close();
            }
        }
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        BindList();

        // Do not Load DropDown Data if the Request is Postback
        if (!IsPostBack)
        {
            ErrorOutput.Text = "Both Home and Away Team Cannot be same";

            comm = new SqlCommand("SELECT * FROM Clubs ", conn);
            conn.Open();
            reader = comm.ExecuteReader();
            HomeClubdDropdown.DataSource     = reader;
            HomeClubdDropdown.DataValueField = "registration_number";
            HomeClubdDropdown.DataTextField  = "name";
            HomeClubdDropdown.DataBind();
            reader.Close();
            conn.Close();
            comm = new SqlCommand("SELECT * FROM Clubs", conn);
            conn.Open();
            reader = comm.ExecuteReader();
            AwayClubDropdown.DataSource     = reader;
            AwayClubDropdown.DataValueField = "registration_number";
            AwayClubDropdown.DataTextField  = "name";
            AwayClubDropdown.DataBind();
            reader.Close();
            conn.Close();
        }

        // Load Matches on Every Request
        comm = new SqlCommand("SELECT * FROM matches", conn);
        conn.Open();
        reader = comm.ExecuteReader();
        GridViewFixtures.DataSource = reader;
        GridViewFixtures.DataBind();
        reader.Close();
        conn.Close();
    }