Пример #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string query = "";

            if (DropDownList2.SelectedValue.Equals("Books"))
            {
                query = "select title ,description,city ,date ,province,price from adbook WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }
            else if (DropDownList2.SelectedValue.Equals("Cameras"))
            {
                query = "select title ,description,city ,date ,province,price from adcamera WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }
            else if (DropDownList2.SelectedValue.Equals("Home Appliances"))
            {
                query = "select title ,description,city ,date ,province,price from adhomeappliences WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }
            else if (DropDownList2.SelectedValue.Equals("LapTops"))
            {
                query = "select title ,description,city ,date ,province,price from adlaptop WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }
            else if (DropDownList2.SelectedValue.Equals("Mobiles"))
            {
                query = "select title ,description,city ,date ,province,price from admobile WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }
            else if (DropDownList2.SelectedValue.Equals("Pcs"))
            {
                query = "select title ,description,city ,date ,province,price from adpc WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }
            else if (DropDownList2.SelectedValue.Equals("Real Estates"))
            {
                query = "select title ,description,city ,date ,province,price from adRealEastate WHERE title ='" + TextBox1.Text + "' and price between '" + TextBox2.Text + "' and '" + TextBox3.Text + "' and city='" + DropDownList1.SelectedValue + "' ";
            }

            SqlConnection connection = Connection_Manger.getConnection();
            SqlCommand    cmd        = new SqlCommand(query, connection);



            try
            {
                //to call a SP from SqlCommand use this
                //cmd.CommandType = CommandType.StoredProcedure;
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                int           i      = 0;
                //we'll check if there is any data in reader? if so then proceed otherwise terminate
                //and inform user

                if (reader.HasRows)
                {
                    result_message.Text = "Search Results";
                    //looping through the fetched result set
                    while (reader.Read())
                    {
                        //for each record/touple/row we'll call a procedure
                        //that will load data dynamically into the Div Controls....
                        this.divz(reader["title"].ToString(), reader["price"].ToString(), reader["description"].ToString(), reader["date"].ToString(), reader["city"].ToString(), reader["province"].ToString(), i++);
                    }
                }

                else
                {
                    result_message.Text = "No Record Found";
                }
            }

            catch (Exception ex)
            {
                result_message.Text = "Can not open connection !" + ex.Message;
            }


            if (DropDownList2.SelectedValue.Equals("Eating Outlets"))
            {
                query = "select title ,description,city ,date ,province,user_name from adEatingOutlet WHERE title ='" + TextBox1.Text + "' and city='" + DropDownList1.SelectedValue + "' ";



                SqlConnection conn    = Connection_Manger.getConnection();
                SqlCommand    command = new SqlCommand(query, connection);



                try
                {
                    //to call a SP from SqlCommand use this
                    //cmd.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    int           i      = 0;
                    //we'll check if there is any data in reader? if so then proceed otherwise terminate
                    //and inform user

                    if (reader.HasRows)
                    {
                        result_message.Text = "Search Results";
                        //looping through the fetched result set
                        while (reader.Read())
                        {
                            //for each record/touple/row we'll call a procedure
                            //that will load data dynamically into the Div Controls....
                            this.divz(reader["title"].ToString(), reader["user_name"].ToString(), reader["description"].ToString(), reader["date"].ToString(), reader["city"].ToString(), reader["province"].ToString(), i++);
                        }
                    }

                    else
                    {
                        result_message.Text = "No Record Found";
                    }
                }

                catch (Exception ex)
                {
                    result_message.Text = "Can not open connection !" + ex.Message;
                }
            }


            if (DropDownList2.SelectedValue.Equals("Eating Outlets"))
            {
                query = "select title ,description,city ,date ,province,user_name from adEatingOutlet WHERE title ='" + TextBox1.Text + "' and city='" + DropDownList1.SelectedValue + "' ";



                SqlConnection conn    = Connection_Manger.getConnection();
                SqlCommand    command = new SqlCommand(query, connection);



                try
                {
                    //to call a SP from SqlCommand use this
                    //cmd.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    int           i      = 0;
                    //we'll check if there is any data in reader? if so then proceed otherwise terminate
                    //and inform user

                    if (reader.HasRows)
                    {
                        result_message.Text = "Search Results";
                        //looping through the fetched result set
                        while (reader.Read())
                        {
                            //for each record/touple/row we'll call a procedure
                            //that will load data dynamically into the Div Controls....
                            this.divz(reader["title"].ToString(), reader["user_name"].ToString(), reader["description"].ToString(), reader["date"].ToString(), reader["city"].ToString(), reader["province"].ToString(), i++);
                        }
                    }

                    else
                    {
                        result_message.Text = "No Record Found";
                    }
                }

                catch (Exception ex)
                {
                    result_message.Text = "Can not open connection !" + ex.Message;
                }
            }


            else if (DropDownList2.SelectedValue.Equals("Events"))
            {
                query = "select title ,location,city ,date ,province,event_datetime from adevent WHERE title ='" + TextBox1.Text + "' and city='" + DropDownList1.SelectedValue + "' ";



                SqlConnection conn    = Connection_Manger.getConnection();
                SqlCommand    command = new SqlCommand(query, connection);



                try
                {
                    //to call a SP from SqlCommand use this
                    //cmd.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    int           i      = 0;
                    //we'll check if there is any data in reader? if so then proceed otherwise terminate
                    //and inform user

                    if (reader.HasRows)
                    {
                        result_message.Text = "Search Results";
                        //looping through the fetched result set
                        while (reader.Read())
                        {
                            //for each record/touple/row we'll call a procedure
                            //that will load data dynamically into the Div Controls....
                            this.divz(reader["title"].ToString(), reader["location"].ToString(), reader["event_datetime"].ToString(), reader["date"].ToString(), reader["city"].ToString(), reader["province"].ToString(), i++);
                        }
                    }

                    else
                    {
                        result_message.Text = "No Record Found";
                    }
                }

                catch (Exception ex)
                {
                    result_message.Text = "Can not open connection !" + ex.Message;
                }
            }



            else if (DropDownList2.SelectedValue.Equals("Jobs"))
            {
                query = "select title ,description,city ,date ,province,company_id from adjob WHERE title ='" + TextBox1.Text + "' and city='" + DropDownList1.SelectedValue + "' ";



                SqlConnection conn    = Connection_Manger.getConnection();
                SqlCommand    command = new SqlCommand(query, connection);



                try
                {
                    //to call a SP from SqlCommand use this
                    //cmd.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    int           i      = 0;
                    //we'll check if there is any data in reader? if so then proceed otherwise terminate
                    //and inform user

                    if (reader.HasRows)
                    {
                        result_message.Text = "Search Results";
                        //looping through the fetched result set
                        while (reader.Read())
                        {
                            //for each record/touple/row we'll call a procedure
                            //that will load data dynamically into the Div Controls....
                            this.divz(reader["title"].ToString(), reader["company_id"].ToString(), reader["description"].ToString(), reader["date"].ToString(), reader["city"].ToString(), reader["province"].ToString(), i++);
                        }
                    }

                    else
                    {
                        result_message.Text = "No Record Found";
                    }
                }

                catch (Exception ex)
                {
                    result_message.Text = "Can not open connection !" + ex.Message;
                }
            }
            else if (DropDownList2.SelectedValue.Equals("Services"))
            {
                query = "select type ,description,city ,date ,province from adService WHERE title ='" + TextBox1.Text + "' and city='" + DropDownList1.SelectedValue + "' ";



                SqlConnection conn    = Connection_Manger.getConnection();
                SqlCommand    command = new SqlCommand(query, connection);



                try
                {
                    //to call a SP from SqlCommand use this
                    //cmd.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    int           i      = 0;
                    //we'll check if there is any data in reader? if so then proceed otherwise terminate
                    //and inform user

                    if (reader.HasRows)
                    {
                        result_message.Text = "Search Results";
                        //looping through the fetched result set
                        while (reader.Read())
                        {
                            //for each record/touple/row we'll call a procedure
                            //that will load data dynamically into the Div Controls....
                            this.divz(reader["type"].ToString(), "", reader["description"].ToString(), reader["date"].ToString(), reader["city"].ToString(), reader["province"].ToString(), i++);
                        }
                    }

                    else
                    {
                        result_message.Text = "No Record Found";
                    }
                }

                catch (Exception ex)
                {
                    result_message.Text = "Can not open connection !" + ex.Message;
                }
            }
        }
Пример #2
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            /*************************************************************************************/

            // Get the UserId of the just-added user
            MembershipUser newUser   = Membership.GetUser(RegisterUser.UserName);
            Guid           newUserId = (Guid)newUser.ProviderUserKey;

            // Insert a new record into UserProfiles
            //string connectionString = Connection_Manger.getConnection();
            //SqlConnection conn = Connection_Manger.getConnection();
            //ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
            MessageBox.Show(newUserId.ToString());
            //int a = Convert.ToInt32(newUserId.ToString());
            //string insertSql = "INSERT INTO custom_profile values('"+newUserId+"','firstname','lastname','mobile','address','city')";
            string insertSql = "INSERT INTO custom_profile(Userid, firstname,lastname,mobile,country,city,address,picture) VALUES(@UserId, @firstname,@lastname,@mobile,@country,@City,@address,@picture)";

            /*try
             * {
             *  conn.Open();
             *  SqlCommand command = new SqlCommand(insertSql, conn);
             *
             *  command.ExecuteNonQuery();
             * }
             * catch (Exception sqe)
             * {
             *
             *  MessageBox.Show(sqe.Message);
             *
             * }
             * conn.Close();
             */

            using (SqlConnection conn = Connection_Manger.getConnection())


            {
                conn.Open();
                SqlCommand myCommand = new SqlCommand(insertSql, conn);
                myCommand.Parameters.AddWithValue("@UserId", newUserId);
                myCommand.Parameters.AddWithValue("@firstname", DBNull.Value);
                myCommand.Parameters.AddWithValue("@lastname", DBNull.Value);
                myCommand.Parameters.AddWithValue("@mobile", DBNull.Value);
                myCommand.Parameters.AddWithValue("@country", DBNull.Value);
                myCommand.Parameters.AddWithValue("@city", DBNull.Value);
                myCommand.Parameters.AddWithValue("@address", DBNull.Value);
                myCommand.Parameters.AddWithValue("@picture", DBNull.Value);
                myCommand.ExecuteNonQuery();
                conn.Close();
            }



            /*************************************************************************************/


            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (String.IsNullOrEmpty(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }