Ejemplo n.º 1
0
        protected void AddProductButton_Click(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                Page.Validate("Add");
            }

            Boolean fileOK = false;
            String  path   = Server.MapPath("~/Catalog/Images/");

            if (ProductImage.HasFile)
            {
                String   fileExtension     = System.IO.Path.GetExtension(ProductImage.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }

            if (fileOK)
            {
                try
                {
                    // Save to Images folder.
                    ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                    // Save to Images/Thumbs folder.
                    ProductImage.PostedFile.SaveAs(path + "Thumbs/" + ProductImage.FileName);
                }
                catch (Exception ex)
                {
                    LabelAddStatus.Text = ex.Message;
                }

                // Add product data to DB.
                AddProducts products   = new AddProducts();
                bool        addSuccess = products.AddProduct(AddProductName.Text, AddProductDescription.Text,
                                                             AddProductPrice.Text, DropDownAddCategory.SelectedValue, ProductImage.FileName);
                if (addSuccess)
                {
                    // Reload the page.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ProductAction=add");
                }
                else
                {
                    LabelAddStatus.Text = "Unable to add new product to database.";
                }
            }
            else
            {
                LabelAddStatus.Text = "Unable to accept file type.";
            }
        }
Ejemplo n.º 2
0
        protected void AddProductBtn_Click(object sender, EventArgs e)
        {
            bool fileOk = false;
            string path = Server.MapPath("~/Catalog/Images/");
            if (ProductImage.HasFile)
            {
                string uploadedFileExt = Path.GetExtension(ProductImage.FileName).ToLower();
                string[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };

                fileOk = allowedExtensions.Any(ext => ext == uploadedFileExt);
            }

            if (!fileOk)
            {
                AlertBox.Attributes.Add("class", AlertBox.Attributes["class"].Replace("alert-success", "alert-danger"));
                AlertBox.Visible = true;
                LabelAlertStatus.Text = "Unable to accept file type.";
                return;
            }
            else
            {
                try
                {
                    // Save to Images folder.
                    ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                    // Save to Images/Thumb folder.
                    ProductImage.PostedFile.SaveAs(path + "Thumbs/" + ProductImage.FileName);
                }
                catch(Exception ex)
                {
                    AlertBox.Attributes.Add("class", AlertBox.Attributes["class"].Replace("alert-success", "alert-danger"));
                    AlertBox.Visible = true;
                    LabelAlertStatus.Text = ex.Message;
                }

                // Add product data to DB.
                AddProducts products = new AddProducts();
                bool addSuccess = products.AddProduct(
                    AddProductName.Text, AddProductDescription.Text, AddProductPrice.Text,
                    DropDownAddCategory.SelectedValue, ProductImage.FileName
                );
                if(!addSuccess)
                {
                    AlertBox.Attributes.Add("class", AlertBox.Attributes["class"].Replace("alert-success", "alert-danger"));
                    AlertBox.Visible = true;
                    LabelAlertStatus.Text = "Unable to add new product to database.";
                    return;
                }
                else
                {
                    Response.Redirect($"{GetPageUrl()}?ProductAction=add");
                }
            }
        }
Ejemplo n.º 3
0
        protected void AddProductButton_Click(object sender, EventArgs e)
        {
            Boolean fOK  = false;
            String  path = Server.MapPath("~/Catalog/Images/");

            if (ProductImage.HasFile)
            {
                String   fileExtension     = System.IO.Path.GetExtension(ProductImage.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fOK = true;
                    }
                }
            }

            if (fOK)
            {
                try
                {
                    // Zapis obraz
                    ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                    // Zapis miniaturę obrazu.
                    ProductImage.PostedFile.SaveAs(path + "Thumbs/" + ProductImage.FileName);
                }
                catch (Exception ex)
                {
                    LabelAddStatus.Text = ex.Message;
                }

                // Dodaj produkt do bazy danych DB.
                AddProducts products   = new AddProducts();
                bool        addSuccess = products.AddProduct(AddProductName.Text, AddProductDescription.Text,
                                                             AddProductPrice.Text, DropDownAddCategory.SelectedValue, ProductImage.FileName);
                if (addSuccess)
                {
                    // Przeładuj stronę.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ProductAction=add");
                }
                else
                {
                    LabelAddStatus.Text = "Nie udało się dodać produktu do bazy danych.";
                }
            }
            else
            {
                LabelAddStatus.Text = "Zły fomat pliku z zdjeciem, użyj: .gif, .png, .jpeg, .jpg .";
            }
        }
        // Kada se klikne na AddProductButton, kod proverava HasFile svojstvo kontrole FileUpload.
        //Ako kontrola ima datoteku i ako je dozvoljen tip datoteke (na osnovu ekstenzije datoteke), slika se čuva u \
        //folderu Slike i folderu Images / Thumbs aplikacije.
        protected void AddProductButton_Click(object sender, EventArgs e)
        {
            Boolean fileOK = false;
            String  path   = Server.MapPath("~/Catalog/Images/");

            if (ProductImage.HasFile)
            {
                String   fileExtension     = System.IO.Path.GetExtension(ProductImage.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }

            if (fileOK)
            {
                try
                {
                    // Save to Images folder.
                    ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                    // Save to Images/Thumbs folder.
                    ProductImage.PostedFile.SaveAs(path + "Thumbs/" + ProductImage.FileName);
                }
                catch (Exception ex)
                {
                    LabelAddStatus.Text = ex.Message;
                }

                // Add product data to DB.
                AddProducts products   = new AddProducts();
                bool        addSuccess = products.AddProduct(AddProductName.Text, AddProductDescription.Text,
                                                             AddProductPrice.Text, DropDownAddCategory.SelectedValue, ProductImage.FileName);
                if (addSuccess)
                {
                    // Ponovo ucitajte stranicu.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ProductAction=add");
                }
                else
                {
                    LabelAddStatus.Text = "Nije moguce dodati novi proizvod u bazu podataka";
                }
            }
            else
            {
                LabelAddStatus.Text = "Nije moguce prihvatiti tip datoteke.";
            }
        }
Ejemplo n.º 5
0
        protected void AddProductButton_Click(object sender, EventArgs e)
        {
            var fileOk = false;
            var path   = Server.MapPath("~/Catalog/Images/");

            if (ProductImage.HasFile)
            {
                var      fileExtension     = Path.GetExtension(ProductImage.FileName).ToLower();
                string[] allowedExtensions = { ".gif", ".png", ".jpg", ".jpeg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOk = true;
                    }
                }
            }
            if (fileOk)
            {
                try {
                    // Save to Images folder
                    ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                    // Save to Images/Thumbs folder.
                    ProductImage.PostedFile.SaveAs($"{path}Thumbs/{ProductImage.FileName}");
                } catch (Exception ex) {
                    LabelAddStatus.Text = ex.Message;
                }

                // Add product data to db
                var products   = new AddProducts();
                var addSuccess = products.AddProduct(AddProductName.Text, AddProductDescription.Text, AddProductPrice.Text, ddlAddCategory.SelectedValue, ProductImage.FileName);
                if (addSuccess)
                {
                    // Reload the page
                    var pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect($"{pageUrl}?ProductAction=add");
                }
                else
                {
                    LabelAddStatus.Text = "Unable to add new product to database";
                }
            }
            else
            {
                LabelAddStatus.Text = "Unable to accept file type";
            }
        }
Ejemplo n.º 6
0
        protected void AddProductButton_Click(object sender, EventArgs e)
        {
            string path = Server.MapPath("~/Catalog/Images/");

            if (ProductImage.HasFile)
            {
                string   fileExtension     = System.IO.Path.GetExtension(ProductImage.FileName).ToLower();
                string[] allowedextensions = { ".gif", ".png", ".jpeg", ".jpg" };
                if (allowedextensions.Contains(fileExtension))
                {
                    try
                    {
                        ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                        ProductImage.PostedFile.SaveAs(path + "Thumbs/" + ProductImage.FileName);
                    }
                    catch (Exception ex)
                    {
                        LabelAddStatus.Text = ex.Message;
                    }
                }
            }
            else
            {
                LabelAddStatus.Text = "Unable to accept file type.";
            }

            AddProducts products = new AddProducts();

            bool addSuccess = products.AddProduct(AddProductName.Text, AddProductDescription.Text, AddProductPrice.Text, DropDownAddCategory.SelectedValue, ProductImage.FileName);

            if (addSuccess)
            {
                string pageUrl = Request.Url.AbsoluteUri.Substring(0,
                                                                   Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                Response.Redirect(pageUrl + "?ProductAction=add");
            }
            else
            {
                LabelAddStatus.Text = "Unable to add new product to database.";
            }
        }
Ejemplo n.º 7
0
        protected void updateProductName_ServerValidate(object sender, ServerValidateEventArgs e)
        {
            //String connectionString = @"Data Source=DESKTOP-S3P3TBM\SQLEXPRESS;Initial Catalog=wingtiptoys.mdf;Integrated Security=True";
            string connectionString = "Data Source=MYLAPTOP\\SQLEXPRESS;Database=wingtiptoys.mdf;Integrated Security=True";
            string queryString      = "SELECT * FROM dbo.Products WHERE ProductName = '" + DropDownUpdateProductName.SelectedItem.Text + "'";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    if (reader.Read())
                    {
                        //update product record in database
                        e.IsValid = true;
                        System.Diagnostics.Debug.WriteLine(e.Value.ToString() + " Exists");
                        //update product in database
                        using (var _db = new WingtipToys.Models.ProductContext())
                        {
                            var myItem = (from c in _db.Products where c.ProductName == DropDownUpdateProductName.SelectedItem.Text select c).FirstOrDefault();
                            if (myItem != null)
                            {
                                System.Diagnostics.Debug.WriteLine(myItem.Description);
                                //remove product from database
                                _db.Products.Remove(myItem);
                                _db.SaveChanges();

                                // Add product data to DB.
                                AddProducts products = new AddProducts();
                                var         product  = new WingtipToys.Models.Product();
                                //update name, description, and price, but keep same category id and image file path for now
                                bool addSuccess = products.AddProduct(DropDownUpdateProductName.SelectedItem.Text, UpdateProductDescription.Text,
                                                                      UpdateProductPrice.Text, DropDownUpdateCategory.SelectedValue, myItem.ImagePath);
                                if (addSuccess)
                                {
                                    // Reload the page.
                                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                                    Response.Redirect(pageUrl + "?ProductAction=add");
                                }
                                else
                                {
                                    System.Diagnostics.Debug.WriteLine("Unable to add new product to database.");
                                }
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("Unable to locate product.");
                            }
                        }
                    }
                    else
                    {
                        //Throw validation error because product does not exist and cannot be updated
                        e.IsValid = false;
                        System.Diagnostics.Debug.WriteLine(e.Value.ToString() + " Does not exist");
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
        }
        protected void orderButton_Click(object sender, EventArgs e)
        {
            double total = 0.0;

            string size, crust, sauce;
            string topping = "";


            if (smallButton.Checked)
            {
                total = 10.0;
                size  = "Size :Small,";
            }
            else if (mediumButton.Checked)
            {
                total = 13.0;
                size  = "Size :Medium,";
            }

            else
            {
                total = 16.0;
                size  = "Size :Large,";
            }


            if (regularButton.Checked)
            {
                total += 2.0;
                crust  = "Crust :Regular,";
            }

            else if (thinButton.Checked)
            {
                total += 4.0;
                crust  = "Crust :Thin,";
            }

            else
            {
                total += 6.0;
                crust  = "Crust :Thick,";
            }

            if (bbqButton.Checked)
            {
                total += 2.0;
                sauce  = "BBQ,";
            }
            else
            {
                total += 1.75;
                sauce  = "Pesto,";
            }

            List <String> toppingList = new List <string>();

            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected)
                {
                    toppingList.Add(item.Value);
                    topping += item.Value + ",";
                    total   += 2.0;
                }
            }

            /*      if (pepperoniCheckbox.Checked)
             *    {
             *        total += 1.5;
             *        topping += "Pepperoni,";
             *    }
             *    else if (hamCheckbox.Checked)
             *    {
             *        total += 2.0;
             *        topping += "Ham,";
             *    }
             *    else if (freshgarlicCheckbox.Checked)
             *    {
             *        total += 0.75;
             *        topping += "Fresh Garlic,";
             *    }
             *    else if (onionCheckbox.Checked)
             *    {
             *        total += 0.75;
             *        topping += "Onion";
             *    }
             *    else if (mushroomCheckbox.Checked)
             *    {
             *        total += 0.75;
             *        topping += "Mushroom,";
             *    }
             *    else if (baconCheckbox.Checked)
             *    {
             *        total += 2.0;
             *        topping += "Bacon,";
             *    }
             *    else if (sausageCheckbox.Checked)
             *    {
             *        total += 1.5;
             *        topping += "Sausage";
             *
             *    }*/


            /* total = (pepperoniCheckbox.Checked) ? total + 1.5 : total;
             * total = (hamCheckbox.Checked) ? total + 2.0 : total;
             * total = (greenpepperCheckbox.Checked) ? total + 0.75 : total;
             * total = (freshgarlicCheckbox.Checked) ? total + 1.5 : total;
             * total = (onionCheckbox.Checked) ? total + 0.75 : total;
             * total = (mushroomCheckbox.Checked) ? total + 0.75 : total;
             * total = (baconCheckbox.Checked) ? total + 2.0 : total;
             * total = (sausageCheckbox.Checked) ? total + 1.5 : total;*/

            resultTotal.Text = total.ToString();
            resulttext.Text  = ("Size :" + size + "Crust :" + crust + "Sauce :" + sauce + "Topping :" + topping).ToString();
            Label1.Text      = "6";
            Label2.Text      = "pizzahotdog.jpg";

            AddProducts products = new AddProducts();

            products.AddProduct("Special :" + foodname.Text, resulttext.Text, resultTotal.Text, Label1.Text, Label2.Text);
            Status.Text = "Your Own Food Create Successfully :)";
        }
Ejemplo n.º 9
0
        protected void UpdateProductButton_Click(object sender, EventArgs e)
        {
            Boolean fileOK = false;
            String  path   = Server.MapPath("~/Catalog/Images/");

            if (UpdateFileUpload.HasFile)
            {
                String   fileExtension     = System.IO.Path.GetExtension(UpdateFileUpload.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }

            if (fileOK)
            {
                try
                {
                    // Save to Images folder.
                    UpdateFileUpload.PostedFile.SaveAs(path + UpdateFileUpload.FileName);
                    // Save to Images/Thumbs folder.
                    UpdateFileUpload.PostedFile.SaveAs(path + "Thumbs/" + UpdateFileUpload.FileName);
                }
                catch (Exception ex)
                {
                    LabelAddStatus.Text = ex.Message;
                }

                // Add product data to DB.
                AddProducts products   = new AddProducts();
                var         ID         = Convert.ToInt16(DropDownRemoveProduct.SelectedValue);
                bool        addSuccess = false;
                using (var db = new ApplicationDbContext())
                {
                    if (db.Products.Any(p => p.ProductID == ID))
                    {
                        addSuccess = products.AddProduct(UpdateNameTextBox.Text, UpdateDescriptionTextBox.Text,
                                                         UpdatePriceTextBox.Text, UpdateCategoryDropDownList.SelectedValue, UpdateFileUpload.FileName, ID);
                    }
                    else
                    {
                        addSuccess = products.AddProduct(UpdateNameTextBox.Text, UpdateDescriptionTextBox.Text,
                                                         UpdatePriceTextBox.Text, UpdateCategoryDropDownList.SelectedValue, UpdateFileUpload.FileName);
                    }
                }

                if (addSuccess)
                {
                    // Reload the page.
                    Session["OutcomeMessage"] = ID == 0 ? "Added new product " + UpdateNameTextBox.Text : "Updated product " + UpdateNameTextBox.Text;
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl /*+ "?ProductAction=add"*/);
                }
                else
                {
                    LabelAddStatus.Text = "Unable to add new product to database.";
                }
            }
            else
            {
                LabelAddStatus.Text = "Unable to accept file type.";
            }
        }