예제 #1
0
        private void searchTool_Click(object sender, EventArgs e)
        {
            if (searchType.selectedValue.ToString() == "Director")
            {
                try
                {
                    con = new OracleConnection(ordb);
                    con.Open();
                    panel1.Controls.Clear();
                    con = new OracleConnection(ordb);

                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = " select movie.movie_name,movie.date_of_puplish , moviecategory.categoryname,movie.avg_rate,director.dir_name   from  movie inner join director on movie.director_id = director.dir_id inner join moviecategory ON moviecategory.categoryid = movie.category_id where director.dir_name= :name";
                    cmd.CommandType = CommandType.Text;

                    cmd.Parameters.Add("name", searchbox.Text.ToString());
                    con.Open();
                    OracleDataReader reader = cmd.ExecuteReader();
                    for (int i = 0; reader.Read(); i++)
                    {
                        string name     = reader[0].ToString();
                        string year     = reader[1].ToString();
                        string category = reader[2].ToString();
                        string rate     = reader[3].ToString();
                        string director = reader[4].ToString();
                        rate = get_avg_Rate(name);

                        if (rate == "null")
                        {
                            rate = "0";
                        }

                        update_rate(name, rate);

                        search s = new search(name, category, director, rate, year);
                        s.Visible  = true;
                        s.Location = new Point(70, 490 * i + 5);
                        panel1.Controls.Add(s);
                        s.BringToFront();
                    }
                    reader.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (searchType.selectedValue.ToString() == "Actor")
            {
                try
                {
                    panel1.Controls.Clear();
                    string cmdStr = "select movie.movie_name,movie.date_of_puplish , moviecategory.categoryname,movie.avg_rate,director.dir_name from  movie INNER JOIN movie_actor on movie_actor.movie_name=movie.movie_name INNER JOIN actor on movie_actor.actor_id=actor.actor_id inner join director on movie.director_id = director.dir_id  inner join moviecategory ON moviecategory.categoryid = movie.category_id where Actor.Actor_name=:actor_name";
                    adapter = new OracleDataAdapter(cmdStr, ordb);
                    adapter.SelectCommand.Parameters.Add("actor_name", searchbox.Text.ToString());
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        string name     = ds.Tables[0].Rows[i]["MOVIE_NAME"].ToString();
                        string year     = ds.Tables[0].Rows[i]["DATE_OF_PUPLISH"].ToString();
                        string category = ds.Tables[0].Rows[i]["categoryname"].ToString();
                        string rate     = ds.Tables[0].Rows[i]["AVG_RATE"].ToString();
                        string director = ds.Tables[0].Rows[i]["dir_name"].ToString();
                        if (rate == "")
                        {
                            rate = "0";
                        }

                        search s = new search(name, category, director, rate, year);
                        s.Visible  = true;
                        s.Location = new Point(70, 490 * i + 5);
                        panel1.Controls.Add(s);
                        s.BringToFront();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }



            else if (searchType.selectedValue.ToString() == "Title")
            {
                try
                {
                    OracleConnection conn;
                    string           ordb = "data source = orcl; user id =scott; password=tiger;";
                    con = new OracleConnection(ordb);
                    con.Open();
                    panel1.Controls.Clear();
                    con = new OracleConnection(ordb);

                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = " select movie.movie_name,movie.date_of_puplish , moviecategory.categoryname,movie.avg_rate,director.dir_name   from  movie inner join director on movie.director_id = director.dir_id inner join moviecategory ON moviecategory.categoryid = movie.category_id where movie.movie_name= :name";
                    cmd.CommandType = CommandType.Text;

                    cmd.Parameters.Add("name", searchbox.Text.ToString());
                    con.Open();
                    OracleDataReader reader = cmd.ExecuteReader();
                    for (int i = 0; reader.Read(); i++)
                    {
                        string name     = reader[0].ToString();
                        string year     = reader[1].ToString();
                        string category = reader[2].ToString();
                        string rate     = reader[3].ToString();
                        string director = reader[4].ToString();
                        rate = get_avg_Rate(name);

                        if (rate == "null")
                        {
                            rate = "0";
                        }

                        update_rate(name, rate);

                        search s = new search(name, category, director, rate, year);
                        s.Visible  = true;
                        s.Location = new Point(70, 490 * i + 5);
                        panel1.Controls.Add(s);
                        s.BringToFront();
                    }
                    reader.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            else if (searchType.selectedValue.ToString() == "Category")
            {
                try
                {
                    con = new OracleConnection(ordb);
                    con.Open();
                    panel1.Controls.Clear();
                    con = new OracleConnection(ordb);

                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection  = con;
                    cmd.CommandText = "SEARCH_CATEGORY";
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("cname", searchbox.Text.ToString());
                    cmd.Parameters.Add("c", OracleDbType.RefCursor, ParameterDirection.Output);
                    con.Open();
                    OracleDataReader reader = cmd.ExecuteReader();
                    for (int i = 0; reader.Read(); i++)
                    {
                        string name     = reader[0].ToString();
                        string year     = reader[1].ToString();
                        string category = reader[2].ToString();
                        string rate     = reader[3].ToString();
                        string director = reader[4].ToString();
                        rate = get_avg_Rate(name);

                        if (rate == "null")
                        {
                            rate = "0";
                        }

                        update_rate(name, rate);

                        search s = new search(name, category, director, rate, year);
                        s.Visible  = true;
                        s.Location = new Point(70, 490 * i + 5);
                        panel1.Controls.Add(s);
                        s.BringToFront();
                    }
                    reader.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }