









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
To show the related information of the products such as Image, Name, Price and display it on the webpage based on category.
Typology: Assignments
1 / 16
This page cannot be seen from the preview
Don't miss anything!










1.0 Introduction..................................................................................................................................... 2 1.1 Objective...................................................................................................................................... 2
1.1 Objective
a) To develop a fully functional web application for customers to purchase fashion item conveniently. b) To show the related information of the products such as Image, Name, Price and display it
3.1.1 Users Column Data Type Remarks UserID Int NOT NULL, Increment by 1 Name Varchar(50) NULL Email Varchar(50) NULL Username Varchar(50) NULL Password Nvarchar(50) NULL RPassword Nvarchar(50) NULL Usertype Varchar(10) NULL 3.1.2 Products Column Data Type Remarks ProductID Int NOT NULL, Increment by 1 ProductName Varchar(50) NULL
ProductDescription Varchar(MAX) NULL Category Varchar(50) NULL Price Decimal(18.2) NULL PImage Varchar(50) NULL 3.1.3 Feedback Column Data Type Remarks Id Int NOT NULL, Increment by 1 Name Varchar(MAX) NULL Email Varchar(50) NULL Feedback Varchar(MAX) NULL
3.2.1 Storyboard
protected void btnAdd_Click(object sender, EventArgs e)
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].Connection String); try { con.Open(); string fileName = FileUpload1.PostedFile.FileName; FileUpload1.SaveAs(Server.MapPath("Img/" + fileName)); string query1 = "Insert into Products (ProductName, ProductDescription, Category, Price, PImage) values (@pName,@pDesc,@pCate,@pPrice,@pImage)"; SqlCommand cmd1 = new SqlCommand(query1, con); cmd1.Parameters.AddWithValue("@pName", txtProdName.Text); cmd1.Parameters.AddWithValue("@pDesc", txtProdDesc.Text); cmd1.Parameters.AddWithValue("@pCate", txtProdCategory.Text); cmd1.Parameters.AddWithValue("@pPrice", txtProdPrice.Text); cmd1.Parameters.AddWithValue("@pImage", "Img/"+ fileName); cmd1.ExecuteNonQuery(); lblMessage.ForeColor = System.Drawing.Color.ForestGreen; lblMessage.Text = "Product Added Successfully."; con.Close(); } catch (Exception ex) { Response.Write("Error :" + ex.ToString()); } } The code snippet above implemented a Create/ an Insert function for Add.aspx , which is a Web Form that’s allows admin to add product into the Product Database. The admin is necessary to fill in all the textbox and click the ‘btnAdd; button to fire the event for insert at the front end, required textbox included:
SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].Connection String); con.Open(); string query = "select * from Products"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); string desc = reader.GetString(2); string cate = reader.GetString(3); decimal price = reader.GetDecimal(4); string img = reader.GetString(5); htmlStr += "
cate (Product Category) price (Product Price) img (Product Image Path) htmlStr will be used to hold all these data that retrieved from the database, and combine as a command which can be able to create a table with data, it also included an Operation column with Edit button that will store the ProductID of the chosen Product and redirect the admin to the EditProduct.aspx. Con.Close() to close the Connection stream, and the htmlStr will be return to the fetchDat.
protected void btnEdit_Click1(object sender, EventArgs e) { con.Open(); string fileName = FileUpload1.PostedFile.FileName; if (fileName = “”)
path which is Img. An if-else condtion is used to declare which type of edit should be execute, with image changing or without image changing. If the filename = “” condition is fulfilled, the SQL statement for updating product data without Image Changing will be created, the target data is based on the chosen ProductID which is retrieved from the ViewAll.aspx , then the cmd.ExecuteNonQuery() will execute the query and perform the update process. Else, if the else condition is fulfilled, meaning that the admin request to change the image, the uploaded image will be saved in the _Img_ path and the SQL statement with image changing will be created and executed. Con.close() is necessary to close the connection stream, and the admin will be redirect to the ViewAll.aspx.
protected void btnDelete_Click(object sender, EventArgs e) { con.Open(); string query = "delete from Products where ProductID = '"+id+"'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close();
The code snippet above implemented a delete function for EditProduct.aspx which is the same webform for the Edit function. The delete event will be triggered whenever the admin clicked the btnDelete button. The connection stream will be opened and a SQL Query used to delete Product Data based on the ProductID retrieved from EditProduct.aspx will be created and executed. Con.Close() close the connection stream.
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].Connection String); con.Open(); SqlCommand cmd = new SqlCommand("select count(*) from Users where Username ='" + loginUsername.Text + "'and Password = '" + loginPassword.Text + "'", con);
Throughout this assignment, I have learnt how to create a functional website by using HTML, CSS, JS and ASP.NET Framework. In order to build a user-friendly interface, I tried to create the website with the help of Bootstrap, which caused me to save a lot of effort for designing, but also caused me to have trouble editing the design. I noticed that a website with bootstrap need to consume a lot of time and energy in order to understand the existing elements such as HTML, CSS and JavaScript, but fortunately I managed to edit the design based on my preference after much time. and efforts consumed. Database Connectivity allows me to gain more knowledge on how to connect a website to a database, which is necessary for a functional website to work instead of hard-coded website. In the future, I would like to develop a functional responsive website with WordPress, and also enhance my website coding skills and concept to develop a better website.