Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                Cart = HttpContext.Current.Session["Cart"] as ShoppingCart;
                if (Cart == null)
                {
                    Cart = new ShoppingCart("ProductsGrid");
                    HttpContext.Current.Session["Cart"] = Cart;
                }

                ProductsGrid.DataSource = Cart.ToTable();
                ProductsGrid.DataBind();

                if (ProductsGrid.Rows.Count > 0)
                {
                    CartTotal.Text = "<p class='total'>Grand Total: "  String.Format("{0:c}", Cart.Total)  "</p>";
                }
                else
                {
                    CartBody.Text = "<p>Your cart is empty!</p>";
                }
            }
            catch (Exception ex)
            {
                CartBody.Text = "<p>Error: "  ex.Message  "</p>";
            }
        }
    }
Ejemplo n.º 2
0
    public void BindProducts()
    {
        int pageNumber = WebUtility.LoadInt32FromQueryString("Page");

        if (pageNumber == -1)
        {
            pageNumber = 0;
        }
        string keyword = WebUtility.LoadStringFromQueryString("Keyword", 200, true);
        string tag     = WebUtility.LoadStringFromQueryString("Tag", 200, true);

        if (string.IsNullOrEmpty(keyword) && string.IsNullOrEmpty(tag))
        {
            Response.Redirect("Default.aspx");
        }

        ProductsGrid.PageNumber = pageNumber;
        ProductsGrid.PageSize   = 4;
        ProductsGrid.Columns    = 3;
        Products products = new Products();

        if (!string.IsNullOrEmpty(keyword))
        {
            ProductsGrid.DataSource = products.SearchProducts(keyword, pageNumber, ProductsGrid.PageSize);
        }
        else if (!string.IsNullOrEmpty(tag))
        {
            ProductsGrid.DataSource = products.GetProductsByTags(tag, pageNumber, ProductsGrid.PageSize);
        }
        ProductsGrid.TotalRecords = products.ProductCount;
        ProductsGrid.DataBind();
    }
Ejemplo n.º 3
0
        /// <summary>
        /// If overriding don't forget to call base.Load() or make sure to
        /// assign the WrappedElement.
        /// </summary>
        /// <returns></returns>
        public override ILoadableComponent Load()
        {
            base.Load();
            ProductsGrid.Load();

            return(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the new cross sell product.
        /// </summary>
        /// <param name="productName">Name of the product.</param>
        /// <returns></returns>
        public virtual CrossSellsComponent AddNewCrossSellProduct(string productName)
        {
            var currentPageHandle = WrappedDriver.CurrentWindowHandle;
            var windowHandles     = WrappedDriver.WindowHandles;
            var newWindowHandle   = default(string);

            AddNewCrossSellProductElement.Click();

            // Wait for the new window to appear.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => newWindowHandle = d.WindowHandles
                                          .Except(windowHandles)
                                          .FirstOrDefault());

            // Switch to the new window.
            WrappedDriver.SwitchTo().Window(newWindowHandle);

            SearchProductPopUp.Load();
            SearchProductPopUp.SearchForProduct(productName);

            // Switch back.
            WrappedDriver.SwitchTo().Window(currentPageHandle);

            // Wait for the grid to finish loading.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .UntilChain(d => ProductsGrid.IsBusy())
            .UntilChain(d => !ProductsGrid.IsBusy());

            return(this);
        }
 protected void Button4_Click(object sender, EventArgs e)
 {
     SpecificationRList1.ClearSelection();
     SpecificationRList2.ClearSelection();
     SpecificationRList3.ClearSelection();
     SpecificationRList4.ClearSelection();
     SpecificationRList5.ClearSelection();
     SpecificationRList6.ClearSelection();
     SpecificationRList7.ClearSelection();
     BrandList.SelectedIndex = 0;
     brandchanged            = false;
     conn = new MySqlConnection(GetConnectionString());
     try
     {
         conn.Open();
         MySqlCommand    comm = new MySqlCommand(mainquery + condition, conn);
         MySqlDataReader dr   = comm.ExecuteReader();
         ProductsGrid.DataSource = dr;
         ProductsGrid.DataBind();
         dr.Close();
     }
     catch (Exception ex)
     {
         Response.Write(ex.Message);
     }
     finally
     {
         conn.Close();
     }
 }
Ejemplo n.º 6
0
 protected void searchBtn_OnClick(object sender, EventArgs e)
 {
     try
     {
         string connectionString = ConfigurationManager.ConnectionStrings["productsGrid"].ConnectionString;
         statusL.Text = "Searching for " + searchTerm.Text;
         string   sqlQuery    = "SELECT  productID, productName, productPrice FROM dbo.products where 1=2";
         string[] searchTerms = searchTerm.Text.Replace(';', ' ').Replace("'", "").Split(' ');
         foreach (string term in searchTerms)
         {
             sqlQuery += " OR productID like '%" + term + "%' OR productName like '%" + term + "%' OR productPrice like '%" + term + "%' ;";
         }
         SqlDataAdapter productHistory = new SqlDataAdapter(sqlQuery, connectionString);
         // Create and fill a DataSet.
         DataSet maailmanloppu = new DataSet();
         productHistory.Fill(maailmanloppu);
         DataView source = new DataView(maailmanloppu.Tables[0]);
         ProductsGrid.DataSource = source;
         ProductsGrid.DataBind();
     }
     catch (Exception exc)
     {
         statusL.Text = exc.Message;
     }
 }
 private void BindProductsGrid()
 {
     SearchResultsPanel.Visible = true;
     ProductsGrid.Visible       = true;
     ProductsGrid.PageIndex     = 0;
     ProductsGrid.DataBind();
 }
Ejemplo n.º 8
0
    public void BindProducts()
    {
        int pageNumber = WebUtility.LoadInt32FromQueryString("Page");

        if (pageNumber == -1)
        {
            pageNumber = 0;
        }
        int categoryID = WebUtility.LoadInt32FromQueryString("CategoryID");

        if (categoryID == -1)
        {
            categoryID = 1;
        }
        SortOrder sortOrder = SortOrder.DontSort;

        Enum.TryParse <SortOrder>(WebUtility.LoadStringFromQueryString("Sort", 200, true), out sortOrder);

        ProductsGrid.PageNumber = pageNumber;
        ProductsGrid.PageSize   = 4;
        ProductsGrid.Columns    = 3;
        Products products = new Products();

        ProductsGrid.DataSource   = products.GetProducts(categoryID, pageNumber, ProductsGrid.PageSize, sortOrder);
        ProductsGrid.TotalRecords = products.ProductCount;
        ProductsGrid.DataBind();
    }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ProductID");
            dt.Columns.Add("ProductName");
            dt.Columns.Add("ProductPrice");
            dt.Columns.Add("ProductStock");
            dt.Columns.Add("ProductDescription");

            using (var reader = new StreamReader(@"C:\Visual Studio\ProgettoLiceo\ProgettoLiceo\data.csv"))
            {
                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(';');

                    DataRow row = dt.NewRow();
                    row["ProductID"]          = values[0];
                    row["ProductName"]        = values[1];
                    row["ProductPrice"]       = values[2] + " €";
                    row["ProductStock"]       = values[3];
                    row["ProductDescription"] = values[5];

                    dt.Rows.Add(row);
                }
            }

            ProductsGrid.DataSource = dt;
            ProductsGrid.DataBind();
        }
Ejemplo n.º 10
0
    protected void searchButton_OnClick(object sender, EventArgs e)
    {
        try
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["BenNotStallman"].ConnectionString;
            statusLabel.Text = "Searching for " + searchTerm.Text;
            string sqlQuery = "SELECT productNum, productName, productDesc, color, price "
                              + " FROM Product "
                              + " WHERE 1=2";

            string[] searchTerms = searchTerm.Text.Replace(';', ' ').Replace("'", "").Split(' ');

            foreach (string term in searchTerms)
            {
                sqlQuery += " OR productNum like '%" + term + "%' "
                            + " OR productName like '%" + term + "%' "
                            + " OR color like '%" + term + "%' "
                            + " OR productDesc like '%" + term + "%' "
                            + " OR price like '%" + term + "%' ";
            }
            SqlDataAdapter productRecords = new SqlDataAdapter(sqlQuery, ConnectionString);
            DataSet        ds             = new DataSet();
            productRecords.Fill(ds);
            DataView source = new DataView(ds.Tables[0]);
            ProductsGrid.DataSource = source;
            ProductsGrid.DataBind();
        }
        catch (Exception exc)
        {
            statusLabel.Text = exc.Message;
        }
    }
        /// <summary>
        /// If overridding this don't forget to call base.Load().
        /// NOTE: Will navigate to the pages url if the current drivers url
        /// is empty.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If the driver is an EventFiringWebDriver an event listener will
        /// be added to the 'Navigated' event and uses the url to determine
        /// if the page is 'stale'.
        /// </remarks>
        public override ILoadableComponent Load()
        {
            base.Load();
            basePage.Load();
            ProductsGrid.Load();
            SearchPanel.Load();

            return(this);
        }
 /// <summary>
 /// Gets the listed products.
 /// </summary>
 /// <returns></returns>
 /// <exception cref="NotImplementedException"></exception>
 public virtual IEnumerable <ListPageProductRowComponent> GetListedProducts()
 {
     foreach (var rowElement in ProductsGrid.EnumerateOverAllRows())
     {
         yield return(pageObjectFactory.PrepareComponent(
                          new ListPageProductRowComponent(
                              new ByElement(rowElement),
                              pageObjectFactory,
                              WrappedDriver)));
     }
 }
 protected void Page_Init(object sender, System.EventArgs e)
 {
     _AgreementId = AlwaysConvert.ToInt(Request.QueryString["AgreementId"]);
     _Agreement   = LicenseAgreementDataSource.Load(_AgreementId);
     if (_Agreement == null)
     {
         Response.Redirect("Default.aspx");
     }
     Caption.Text         = string.Format(Caption.Text, _Agreement.DisplayName);
     InstructionText.Text = string.Format(InstructionText.Text, _Agreement.DisplayName);
     BindAgreements();
     ProductsGrid.DataSource = _Agreement.DigitalGoods;
     ProductsGrid.DataBind();
 }
        protected void CategoryList_SelectedIndexChanged(object sender, EventArgs e)
        {
            String catid = CategoryList.SelectedValue.ToString();

            //Response.Write(catid);
            conn = new MySqlConnection(GetConnectionString());
            Specification1.Visible      = false;
            SpecificationRList1.Visible = false;

            Specification2.Visible      = false;
            SpecificationRList2.Visible = false;

            Specification3.Visible      = false;
            SpecificationRList3.Visible = false;

            Specification4.Visible      = false;
            SpecificationRList4.Visible = false;

            Specification5.Visible      = false;
            SpecificationRList5.Visible = false;

            Specification6.Visible      = false;
            SpecificationRList6.Visible = false;

            Specification7.Visible      = false;
            SpecificationRList7.Visible = false;
            try
            {
                conn.Open();
                MySqlCommand    comm = new MySqlCommand("Select Subcategory_Name,Subcategory_ID from Subcategory where Category_ID='" + catid + "'", conn);
                MySqlDataReader dr   = comm.ExecuteReader();
                SubcategoryList.DataSource = dr;

                SubcategoryList.DataTextField  = "Subcategory_Name";
                SubcategoryList.DataValueField = "Subcategory_ID";
                SubcategoryList.DataBind();
                dr.Close();
                comm.CommandText = mainquery + " and Category_ID='" + catid + "'" + condition;
                MySqlDataReader dr1 = comm.ExecuteReader();
                ProductsGrid.DataSource = dr1;
                ProductsGrid.DataBind();


                dr1.Close();
            }
            catch (Exception ex)
            { Response.Write("In category list"); Response.Write(ex.Message); }
            finally { conn.Close(); }
            SubcategoryList.Items.Insert(0, new ListItem("", "0"));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     _webpageId = AbleCommerce.Code.PageHelper.GetWebpageId();
     if (!Page.IsPostBack)
     {
         ProductPageList.DataBind();
         ListItem item = ProductPageList.Items.FindByValue(_webpageId.ToString());
         if (item != null)
         {
             item.Selected = true;
         }
         ProductsGrid.DataBind();
     }
 }
        protected void Update_Click(object sender, EventArgs e)
        {
            List <Object> dataKeys = ProductsGrid.GetSelectedDataKeyValues();

            foreach (Object dataKey in dataKeys)
            {
                int     productId = AlwaysConvert.ToInt(dataKey);
                Product product   = ProductDataSource.Load(productId);
                product.Webpage = WebpageDataSource.Load(AlwaysConvert.ToInt(ProductDisplayPages.SelectedValue));
                product.Save();
            }

            ProductsGrid.DataBind();
        }
        protected void Page_Init(object sender, System.EventArgs e)
        {
            _DigitalGoodId = AlwaysConvert.ToInt(Request.QueryString["DigitalGoodId"]);
            _DigitalGood   = DigitalGoodDataSource.Load(_DigitalGoodId);
            if (_DigitalGood == null)
            {
                Response.Redirect("Default.aspx");
            }
            Caption.Text            = string.Format(Caption.Text, _DigitalGood.Name);
            InstructionText.Text    = string.Format(InstructionText.Text, _DigitalGood.Name);
            ProductsGrid.DataSource = _DigitalGood.ProductDigitalGoods;
            ProductsGrid.DataBind();
            //GET ALL ORDER ITEMS ASSOCIATED WITH DIGITAL GOOD
            IList <OrderItemDigitalGood> oidgs = OrderItemDigitalGoodDataSource.LoadForDigitalGood(_DigitalGoodId);
            //BUILD DISTINCT LIST OF ORDERS
            List <CommerceBuilder.Orders.Order> orders = new List <CommerceBuilder.Orders.Order>();

            foreach (OrderItemDigitalGood oidg in oidgs)
            {
                CommerceBuilder.Orders.Order order = oidg.OrderItem.Order;
                if (orders.IndexOf(order) < 0)
                {
                    orders.Add(order);
                }
            }
            //BIND TO GRID
            OrderGrid.DataSource = orders;
            OrderGrid.DataBind();

            if (!String.IsNullOrEmpty(_DigitalGood.FileName))
            {
                ICriteria criteria = NHibernateHelper.CreateCriteria <DigitalGood>();
                criteria.Add(Restrictions.Eq("FileName", StringHelper.SafeSqlString(_DigitalGood.FileName)));
                IList <DigitalGood> dgc = DigitalGoodDataSource.LoadForCriteria(criteria);
                if (dgc != null && dgc.Count > 1)
                {
                    DeleteAllowedPanel.Visible   = false;
                    DeletePreventedPanel.Visible = true;
                    NoDeleteFileText.Text        = string.Format(NoDeleteFileText.Text, _DigitalGood.FileName);
                }
                else
                {
                    DeleteAllowedPanel.Visible   = true;
                    DeletePreventedPanel.Visible = false;
                    DeleteFile.Text = string.Format(DeleteFile.Text, _DigitalGood.FileName);
                }
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Cart = HttpContext.Current.Session["Cart"] as ShoppingCart;
            if (Cart == null)
            {
                Cart = new ShoppingCart("ProductsGrid");
                HttpContext.Current.Session["Cart"] = Cart;
            }

            if (int.TryParse(Request.QueryString["productID"], out productID))
            {
                try
                {
                    string retString = "Select productID, productName, productPrice from products where productID = @productID;";

                    using (SqlConnection dbConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["productsGrid"].ConnectionString))
                        using (SqlCommand sqlCmd = new SqlCommand(retString, dbConnection))
                        {
                            sqlCmd.Parameters.Add(new SqlParameter("@productID", System.Data.SqlDbType.Int)).Value = productID;

                            dbConnection.Open();
                            dbConnection.ChangeDatabase("productsGrid");
                            SqlDataAdapter productHistory = new SqlDataAdapter(sqlCmd);
                            DataSet        maailmanloppu  = new DataSet();
                            productHistory.Fill(maailmanloppu);
                            DataView source = new DataView(maailmanloppu.Tables[0]);
                            ProductsGrid.DataSource = source;
                            ProductsGrid.DataBind();

                            PageTitle.Text = "<h1>" + maailmanloppu.Tables[0].Rows[0][1] + "</h1>";
                        }
                }
                catch (Exception exc)
                {
                    statusL.Text = exc.Message;
                }
            }
            else
            {
                statusL.Text = "Invalid Product ID";
            }
        }
    }
Ejemplo n.º 19
0
 public void PopulateDatagrid()
 {
     try
     {
         SqlConnection dbConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["productsGrid"].ConnectionString);
         dbConnection.Open();
         dbConnection.ChangeDatabase("productsGrid");
         string         retString      = "Select productID, productName, productPrice from products order by productID";
         SqlDataAdapter productHistory = new SqlDataAdapter(retString, dbConnection);
         DataSet        maailmanloppu  = new DataSet();
         productHistory.Fill(maailmanloppu);
         DataView source = new DataView(maailmanloppu.Tables[0]);
         ProductsGrid.DataSource = source;
         ProductsGrid.DataBind();
         dbConnection.Close();
     }
     catch (Exception) { Response.Write("NO"); }
 }
        protected void Button5_Click(object sender, EventArgs e)
        {
            String pname = TextBox2.Text;

            conn = new MySqlConnection(GetConnectionString());

            try
            {
                conn.Open();
                String          sql  = " and Product_Name like '%" + pname + "%'";
                MySqlCommand    comm = new MySqlCommand(mainquery + sql + condition, conn);
                MySqlDataReader dr   = comm.ExecuteReader();
                ProductsGrid.DataSource = dr;

                ProductsGrid.DataBind();
                dr.Close();
            }
            catch (Exception ex)
            { Response.Write(ex.Message); }
            finally { conn.Close(); }
        }
        protected void ProductSearch_Click(object sender, EventArgs e)
        {
            String product_id = TextBox1.Text;

            conn = new MySqlConnection(GetConnectionString());

            try
            {
                conn.Open();
                String          sql  = mainquery + " and Product_ID='" + product_id + "'" + condition;
                MySqlCommand    comm = new MySqlCommand(sql, conn);
                MySqlDataReader dr   = comm.ExecuteReader();
                ProductsGrid.DataSource = dr;



                ProductsGrid.DataBind();
            }
            catch (Exception ex)
            { Response.Write(ex.Message); }
            finally { conn.Close(); }
        }
Ejemplo n.º 22
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         try
         {
             string ConnectionString = ConfigurationManager.ConnectionStrings["BenNotStallman"].ConnectionString;
             string sqlQuery         = "SELECT productNum, productName, productDesc, color, price "
                                       + " FROM Product; ";
             SqlDataAdapter productRecords = new SqlDataAdapter(sqlQuery, ConnectionString);
             DataSet        ds             = new DataSet();
             productRecords.Fill(ds);
             DataView source = new DataView(ds.Tables[0]);
             ProductsGrid.DataSource = source;
             ProductsGrid.DataBind();
         }
         catch (Exception exc)
         {
             statusLabel.Text += exc.Message;
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            brandchanged    = false;
            spec1changed    = false;
            spec2changed    = false;
            spec3changed    = false;
            spec4changed    = false;
            spec5changed    = false;
            spec6changed    = false;
            spec7changed    = false;
            Button4.Visible = false;

            // Label15.Text = DateTime.Now.ToString();
            if (!IsPostBack)
            {
                Specification1.Visible      = false;
                SpecificationRList1.Visible = false;

                Specification2.Visible      = false;
                SpecificationRList2.Visible = false;

                Specification3.Visible      = false;
                SpecificationRList3.Visible = false;

                Specification4.Visible      = false;
                SpecificationRList4.Visible = false;

                Specification5.Visible      = false;
                SpecificationRList5.Visible = false;

                Specification6.Visible      = false;
                SpecificationRList6.Visible = false;

                Specification7.Visible      = false;
                SpecificationRList7.Visible = false;



                conn = new MySqlConnection(GetConnectionString());


                try
                {
                    conn.Open();
                    MySqlCommand    comm = new MySqlCommand("Select Category_Name,Category_ID from Category", conn);
                    MySqlDataReader dr   = comm.ExecuteReader();
                    CategoryList.DataSource     = dr;
                    CategoryList.DataTextField  = "Category_Name";
                    CategoryList.DataValueField = "Category_ID";
                    CategoryList.DataBind();
                    dr.Close();

                    comm.CommandText = mainquery + condition;
                    MySqlDataReader dr1 = comm.ExecuteReader();
                    ProductsGrid.DataSource = dr1;
                    ProductsGrid.DataBind();
                    dr1.Close();
                }
                catch (Exception em)
                { Response.Write("in page load"); Response.Write(em.Message); }
                finally { conn.Close(); }
            }
            CategoryList.Items.Insert(0, new ListItem("", "0"));
        }
        protected void SpecificationRList7_SelectedIndexChanged(object sender, EventArgs e)
        {
            String catid    = CategoryList.SelectedValue.ToString();
            String subcatid = SubcategoryList.SelectedValue.ToString();
            String spec1    = SpecificationRList1.SelectedValue.ToString();
            String spec2    = SpecificationRList2.SelectedValue.ToString();
            String spec3    = SpecificationRList3.SelectedValue.ToString();
            String spec4    = SpecificationRList4.SelectedValue.ToString();
            String spec5    = SpecificationRList5.SelectedValue.ToString();
            String spec6    = SpecificationRList6.SelectedValue.ToString();
            String spec7    = SpecificationRList7.SelectedValue.ToString();

            String query1 = " and Sp10_Value='" + spec7 + "' and Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";

            if (!BrandList.SelectedValue.ToString().Equals("0"))
            {
                String brandname = BrandList.SelectedValue.ToString();
                query1 += "and Company_Name='" + brandname + "'";
            }
            //brandchanged = false;



            if (spec2 != "")
            {
                query1 += "and Sp5_Value='" + spec2 + "'";
            }

            if (spec3 != "")
            {
                query1 += "and Sp6_Value='" + spec3 + "'";
            }


            if (spec4 != "")
            {
                query1 += "and Sp7_Value='" + spec4 + "'";
            }


            if (spec5 != "")
            {
                query1 += "and Sp8_Value='" + spec5 + "'";
            }


            if (spec6 != "")
            {
                query1 += "and Sp9_Value='" + spec6 + "'";
            }


            if (spec1 != "")
            {
                query1 += "and Sp4_Value='" + spec1 + "'";
            }
            conn = new MySqlConnection(GetConnectionString());

            try
            {
                conn.Open();
                String          sql  = mainquery + query1 + condition;
                MySqlCommand    comm = new MySqlCommand(sql, conn);
                MySqlDataReader dr1  = comm.ExecuteReader();
                ProductsGrid.DataSource = dr1;

                ProductsGrid.DataBind();
                dr1.Close();
            }
            catch (Exception ex)
            { Response.Write(ex.Message); }
            finally { conn.Close(); }
            Button4.Visible = true;
        }
Ejemplo n.º 25
0
    protected void ProductsGrid_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (searchTerm.Text == null) //This triggers if no search terms are entered
        {
            string sortExpression = e.SortExpression;
            string direction      = string.Empty;

            if (SortDirection == SortDirection.Ascending)
            {
                SortDirection = SortDirection.Descending;
                direction     = " DESC";
            }
            else
            {
                SortDirection = SortDirection.Ascending;
                direction     = " ASC";
            }

            try
            {
                string ConnectionString = ConfigurationManager.ConnectionStrings["BenNotStallman"].ConnectionString;
                string sqlQuery         = "SELECT productNum, productName, productDesc, color, price "
                                          + " FROM Product "
                                          + " ORDER BY " + sortExpression + " " + direction;
                SqlDataAdapter productRecords = new SqlDataAdapter(sqlQuery, ConnectionString);
                DataSet        ds             = new DataSet();
                productRecords.Fill(ds);
                DataView source = new DataView(ds.Tables[0]);
                ProductsGrid.DataSource = source;
                ProductsGrid.DataBind();
            }
            catch (Exception exc)
            {
                statusLabel.Text = exc.Message;
            }
        }
        else  //Keeps search query while allowing sorting
        {
            string sortExpression = e.SortExpression;
            string direction      = string.Empty;

            if (SortDirection == SortDirection.Ascending)
            {
                SortDirection = SortDirection.Descending;
                direction     = " DESC";
            }
            else
            {
                SortDirection = SortDirection.Ascending;
                direction     = " ASC";
            }

            try
            {
                string ConnectionString = ConfigurationManager.ConnectionStrings["BenNotStallman"].ConnectionString;
                string sqlQuery         = "SELECT productNum, productName, productDesc, color, price "
                                          + " FROM Product "
                                          + " WHERE 1=2";

                string[] searchTerms = searchTerm.Text.Replace(';', ' ').Replace("'", "").Split(' ');

                foreach (string term in searchTerms)
                {
                    sqlQuery += " OR productNum like '%" + term + "%' "
                                + " OR productName like '%" + term + "%' "
                                + " OR color like '%" + term + "%' "
                                + " OR productDesc like '%" + term + "%' "
                                + " OR price like '%" + term + "%' ";
                }
                sqlQuery += " ORDER BY " + sortExpression + " " + direction;
                SqlDataAdapter productRecords = new SqlDataAdapter(sqlQuery, ConnectionString);
                DataSet        ds             = new DataSet();
                productRecords.Fill(ds);
                DataView source = new DataView(ds.Tables[0]);
                ProductsGrid.DataSource = source;
                ProductsGrid.DataBind();
            }
            catch (Exception exc)
            {
                statusLabel.Text = exc.Message;
            }
        }
    }
        protected void SubcategoryList_SelectedIndexChanged(object sender, EventArgs e)
        {
            String catid    = CategoryList.SelectedValue.ToString();
            String subcatid = SubcategoryList.SelectedValue.ToString();

            //Response.Write(catid);
            //Response.Write(subcatid);
            conn = new MySqlConnection(GetConnectionString());

            Specification1.Visible      = false;
            SpecificationRList1.Visible = false;

            Specification2.Visible      = false;
            SpecificationRList2.Visible = false;

            Specification3.Visible      = false;
            SpecificationRList3.Visible = false;

            Specification4.Visible      = false;
            SpecificationRList4.Visible = false;

            Specification5.Visible      = false;
            SpecificationRList5.Visible = false;

            Specification6.Visible      = false;
            SpecificationRList6.Visible = false;

            Specification7.Visible      = false;
            SpecificationRList7.Visible = false;
            try
            {
                conn.Open();
                String          query1 = mainquery + " and Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'" + condition;
                MySqlCommand    comm   = new MySqlCommand(query1, conn);
                MySqlDataReader dr1    = comm.ExecuteReader();
                //ProductsList.ClearSelection();

                ProductsGrid.DataSource = dr1;
                ProductsGrid.DataBind();
                dr1.Close();

                comm.CommandText = "Select DISTINCT(Company_Name) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                MySqlDataReader dr2 = comm.ExecuteReader();
                BrandList.DataSource     = dr2;
                BrandList.DataTextField  = "Company_Name";
                BrandList.DataValueField = "Company_Name";
                BrandList.DataBind();
                dr2.Close();
                BrandList.Visible = true;
                Label4.Visible    = true;

                comm.CommandText = "Select Specification4,Specification5,Specification6,Specification7,Specification8,Specification9,Specification10 from Specifications where Category_ID='" + catid + "' and Subcategory_ID = '" + subcatid + "'";
                MySqlDataReader dr3   = comm.ExecuteReader();
                String[]        Specs = new String[7];
                dr3.Read();
                for (int i = 0; i < 7; i++)
                {
                    Specs[i] = dr3.GetValue(i).ToString();
                }

                dr3.Close();
                if (Specs[0] != "")
                {
                    Specification1.Text    = Specs[0];
                    Specification1.Visible = true;
                }
                if (Specs[1] != "")
                {
                    Specification2.Text    = Specs[1];
                    Specification2.Visible = true;
                }
                if (Specs[2] != "")
                {
                    Specification3.Text    = Specs[2];
                    Specification3.Visible = true;
                }

                if (Specs[3] != "")
                {
                    Specification4.Text    = Specs[3];
                    Specification4.Visible = true;
                }
                if (Specs[4] != "")
                {
                    Specification5.Text    = Specs[4];
                    Specification5.Visible = true;
                }

                if (Specs[5] != "")
                {
                    Specification6.Text    = Specs[5];
                    Specification6.Visible = true;
                }
                if (Specs[6] != "")
                {
                    Specification7.Text    = Specs[6];
                    Specification7.Visible = true;
                }



                if (Specification1.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp4_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();

                    SpecificationRList1.DataSource     = dr4;
                    SpecificationRList1.DataTextField  = "Sp4_Value";
                    SpecificationRList1.DataValueField = "Sp4_Value";
                    SpecificationRList1.DataBind();
                    SpecificationRList1.Visible = true;
                    dr4.Close();
                }

                if (Specification2.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp5_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();
                    SpecificationRList2.DataSource     = dr4;
                    SpecificationRList2.DataTextField  = "Sp5_Value";
                    SpecificationRList2.DataValueField = "Sp5_Value";
                    SpecificationRList2.DataBind();
                    SpecificationRList2.Visible = true;
                    dr4.Close();
                }


                if (Specification3.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp6_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();
                    SpecificationRList3.DataSource     = dr4;
                    SpecificationRList3.DataTextField  = "Sp6_Value";
                    SpecificationRList3.DataValueField = "Sp6_Value";
                    SpecificationRList3.DataBind();
                    SpecificationRList3.Visible = true;
                    dr4.Close();
                }


                if (Specification4.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp7_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();
                    SpecificationRList4.DataSource     = dr4;
                    SpecificationRList4.DataTextField  = "Sp7_Value";
                    SpecificationRList4.DataValueField = "Sp7_Value";
                    SpecificationRList4.DataBind();
                    SpecificationRList4.Visible = true;
                    dr4.Close();
                }

                if (Specification5.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp8_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();
                    SpecificationRList5.DataSource     = dr4;
                    SpecificationRList5.DataTextField  = "Sp8_Value";
                    SpecificationRList5.DataValueField = "Sp8_Value";
                    SpecificationRList5.DataBind();
                    SpecificationRList5.Visible = true;
                    dr4.Close();
                }

                if (Specification6.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp9_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();
                    SpecificationRList6.DataSource     = dr4;
                    SpecificationRList6.DataTextField  = "Sp9_Value";
                    SpecificationRList6.DataValueField = "Sp9_Value";
                    SpecificationRList6.DataBind();
                    SpecificationRList6.Visible = true;
                    dr4.Close();
                }

                if (Specification7.Visible)
                {
                    comm.CommandText = "Select DISTINCT(Sp10_Value) from Master_Products where Category_ID='" + catid + "' and Subcategory_ID='" + subcatid + "'";
                    MySqlDataReader dr4 = comm.ExecuteReader();
                    SpecificationRList7.DataSource     = dr4;
                    SpecificationRList7.DataTextField  = "Sp10_Value";
                    SpecificationRList7.DataValueField = "Sp10_Value";
                    SpecificationRList7.DataBind();
                    SpecificationRList7.Visible = true;
                    dr4.Close();
                }
            }
            catch (Exception ex)
            { Response.Write(ex.Message); }
            finally
            {
                conn.Close();
            }
            BrandList.Items.Insert(0, new ListItem("", "0"));
        }
Ejemplo n.º 27
0
        protected void Page_Init()
        {
            MetaTable table = MetaTable.GetTable(typeof(Product));

            ProductsGrid.SetMetaTable(table);
        }
 protected void ProductPageList_SelectedIndexChanged(object sender, EventArgs e)
 {
     ProductsGrid.DataBind();
 }