protected void Page_Load(object sender, EventArgs e) { int idAdmin = (int)Session["employeeId"]; string connStr = "Server=BT; Database=PhoneShop; User=sa; Password=12345678"; SqlConnection conn = new SqlConnection(connStr); conn.Open(); String queryStr = "SELECT shopId,Phones.phoneId, phoneName, manufacturer, phonePrice, imageLink, phoneDescrible, quantity FROM dbo.Phones, PhoneOfShop WHERE (PhoneOfShop.shopId=(SELECT TOP 1 shopId FROM Employees WHERE employeeId='" + idAdmin + "')) AND (Phones.phoneId=PhoneOfShop.phoneId)"; SqlCommand cmd = new SqlCommand(queryStr); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; SqlDataReader reader = cmd.ExecuteReader(); listPhone = new List <Phone>(); while (reader.Read()) { Phone phone = new Phone(); phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); phone.PhoneQuantity = Int32.Parse(reader["quantity"].ToString().Trim()); phone.ShopId = Int32.Parse(reader["shopId"].ToString().Trim()); listPhone.Add(phone); } conn.Close(); foreach (Phone phone in listPhone) { show += "<tr>"; show += "<td><a href='DetailPhone.aspx?id=" + phone.PhoneId + "'>" + phone.PhoneId + "</a></td>"; show += "<td>" + phone.PhoneName + "</td>"; show += "<td>" + FormatNumber.FormatPrice(phone.PhonePrice) + "</td>"; show += "<td>" + phone.PhoneQuantity + "</td>"; show += "<td>" + phone.Manufacturer + "</td>"; show += "<td>" + phone.ShopId + "</td>"; show += "<td><a href='AddAmountPhone.aspx?id=" + phone.PhoneId + "'>Thêm </a></td>"; show += "<td><a href='EditPhone.aspx?id=" + phone.PhoneId + "'>Sửa </a></td>"; show += "<td><a href='DeletePhone.aspx?id=" + phone.PhoneId + "'>Xóa </a></td>"; show += "</tr>"; } }
protected void Page_Load(object sender, EventArgs e) { showProduct = ""; showProductCat = ""; categories = ""; string connStr = "Server=BT; Database=PhoneShop; User=sa; Password=12345678"; SqlConnection conn = new SqlConnection(connStr); if (Session["area"] != null) { string area = (string)Session["area"]; if (Request.QueryString["category"] == null) { int perPage = 6; int page; if (Request.QueryString["page"] != null) { page = Int32.Parse(Request.QueryString["page"].Trim()); } else { page = 1; } conn.Open(); SqlCommand cmd = new SqlCommand("SELECT shopId,Phones.phoneId, phoneName, manufacturer, phonePrice, imageLink, phoneDescrible, quantity FROM dbo.Phones, PhoneOfShop WHERE (PhoneOfShop.shopId=(SELECT TOP 1 shopId FROM Shops WHERE shopAddress=@address) AND (Phones.phoneId=PhoneOfShop.phoneId))"); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; cmd.Parameters.Add("@address", SqlDbType.NVarChar, 100).Value = area; SqlDataReader reader = cmd.ExecuteReader(); listPhone = new List <Phone>(); while (reader.Read()) { Phone phone = new Phone(); phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); phone.PhoneQuantity = Int32.Parse(reader["quantity"].ToString().Trim()); phone.ShopId = Int32.Parse(reader["shopId"].ToString().Trim()); listPhone.Add(phone); } conn.Close(); //show listphone for (int i = ((page - 1) * perPage); i < page * perPage; i++) { if (listPhone.Count > ((page - 1) * perPage)) { showProduct += "<div class='col-md-4 col-sm-6 center-responsive'>"; showProduct += "<div class='product'>"; showProduct += "<a href='Detail.aspx?id=" + listPhone[i].PhoneId + "&quantity=" + listPhone[i].PhoneQuantity + "'>"; showProduct += "<img class='img-responsive' src='" + listPhone[i].ImageLink + "'>"; showProduct += "<div class='text'>"; showProduct += "<h3>" + listPhone[i].PhoneName + "</h3>"; showProduct += "<p class='price'>" + FormatNumber.FormatPrice(listPhone[i].PhonePrice) + " VNĐ</p>"; showProduct += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + listPhone[i].PhoneId + "&quantity=" + listPhone[i].PhoneQuantity + "'>" + "Xem chi tiết</a></p>"; showProduct += "</div>"; showProduct += "</a>"; showProduct += "</div>"; showProduct += "</div>"; } if (listPhone.Count == i + 1) { break; } } } if (Request.QueryString["category"] != null) { string manufacturer = Request.QueryString["category"].Trim(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones WHERE manufacturer=@manufacturer"); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; cmd.Parameters.Add("@manufacturer", SqlDbType.VarChar, 100).Value = manufacturer; SqlDataReader reader = cmd.ExecuteReader(); listPhone = new List <Phone>(); while (reader.Read()) { Phone phone = new Phone(); phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); listPhone.Add(phone); } conn.Close(); //show listphone if (listPhone.Count == 0) { showProductCat += "<div class='box'><h1> No Product Found In This Product Categories </h1></div>"; } else { showProductCat += "<div class='box'><h1>" + manufacturer + "</h1></div>"; } for (int i = 0; i < listPhone.Count; i++) { if (listPhone.Count > 0) { showProductCat += "<div class='col-md-4 col-sm-6 center-responsive'>"; showProductCat += "<div class='product'>"; showProductCat += "<a href='Detail.aspx?id=" + listPhone[i].PhoneId + "'>"; showProductCat += "<img class='img-responsive' src='" + listPhone[i].ImageLink + "'>"; showProductCat += "<div class='text'>"; showProductCat += "<h3>" + listPhone[i].PhoneName + "</h3>"; showProductCat += "<p class='price'>" + FormatNumber.FormatPrice(listPhone[i].PhonePrice) + " VNĐ</p>"; showProductCat += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + listPhone[i].PhoneId + "'>" + "Xem chi tiết</a></p>"; showProductCat += "</div>"; showProductCat += "</a>"; showProductCat += "</div>"; showProductCat += "</div>"; } if (listPhone.Count == i + 1) { break; } } } } else { if (Request.QueryString["category"] == null) { int perPage = 6; int page; if (Request.QueryString["page"] != null) { page = Int32.Parse(Request.QueryString["page"].Trim()); } else { page = 1; } conn.Open(); SqlCommand cmd = new SqlCommand("SELECT [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones"); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; SqlDataReader reader = cmd.ExecuteReader(); listPhone = new List <Phone>(); while (reader.Read()) { Phone phone = new Phone(); phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); phone.PhoneQuantity = -1; listPhone.Add(phone); } conn.Close(); //show listphone for (int i = ((page - 1) * perPage); i < page * perPage; i++) { if (listPhone.Count > ((page - 1) * perPage)) { showProduct += "<div class='col-md-4 col-sm-6 center-responsive'>"; showProduct += "<div class='product'>"; showProduct += "<a href='Detail.aspx?id=" + listPhone[i].PhoneId + "'>"; showProduct += "<img class='img-responsive' src='" + listPhone[i].ImageLink + "'>"; showProduct += "<div class='text'>"; showProduct += "<h3>" + listPhone[i].PhoneName + "</h3>"; showProduct += "<p class='price'>" + FormatNumber.FormatPrice(listPhone[i].PhonePrice) + " VNĐ</p>"; showProduct += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + listPhone[i].PhoneId + "'>" + "Xem chi tiết</a></p>"; showProduct += "</div>"; showProduct += "</a>"; showProduct += "</div>"; showProduct += "</div>"; } if (listPhone.Count == i + 1) { break; } } } if (Request.QueryString["category"] != null) { string manufacturer = Request.QueryString["category"].Trim(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones WHERE manufacturer=@manufacturer"); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; cmd.Parameters.Add("@manufacturer", SqlDbType.VarChar, 100).Value = manufacturer; SqlDataReader reader = cmd.ExecuteReader(); listPhone = new List <Phone>(); while (reader.Read()) { Phone phone = new Phone(); phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); listPhone.Add(phone); } conn.Close(); //show listphone if (listPhone.Count == 0) { showProductCat += "<div class='box'><h1> No Product Found In This Product Categories </h1></div>"; } else { showProductCat += "<div class='box'><h1>" + manufacturer + "</h1></div>"; } for (int i = 0; i < listPhone.Count; i++) { if (listPhone.Count > 0) { showProductCat += "<div class='col-md-4 col-sm-6 center-responsive'>"; showProductCat += "<div class='product'>"; showProductCat += "<a href='Detail.aspx?id=" + listPhone[i].PhoneId + "'>"; showProductCat += "<img class='img-responsive' src='" + listPhone[i].ImageLink + "'>"; showProductCat += "<div class='text'>"; showProductCat += "<h3>" + listPhone[i].PhoneName + "</h3>"; showProductCat += "<p class='price'>" + FormatNumber.FormatPrice(listPhone[i].PhonePrice) + " VNĐ</p>"; showProductCat += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + listPhone[i].PhoneId + "'>" + "Xem chi tiết</a></p>"; showProductCat += "</div>"; showProductCat += "</a>"; showProductCat += "</div>"; showProductCat += "</div>"; } if (listPhone.Count == i + 1) { break; } } } } //take categories from database conn.Open(); SqlCommand cmdCategories = new SqlCommand("SELECT DISTINCT [manufacturer] FROM Phones"); cmdCategories.CommandType = System.Data.CommandType.Text; cmdCategories.Connection = conn; SqlDataReader readerCategories = cmdCategories.ExecuteReader(); while (readerCategories.Read()) { categories += "<li>"; categories += "<a href='Shop.aspx?category=" + readerCategories["manufacturer"] + "'>" + readerCategories["manufacturer"] + "</a>"; categories += "<li>"; } conn.Close(); }
protected void Page_Load(object sender, EventArgs e) { showSimilarPhone = ""; showListPhone = ""; categories = ""; totalPayment = ""; total = 0; string connStr = "Server=BT; Database=PhoneShop; User=sa; Password=12345678"; SqlConnection conn = new SqlConnection(connStr); if (Session["cart"] != null) { List <ItemCart> listItem = new List <ItemCart>((List <ItemCart>)Session["cart"]); foreach (ItemCart item in listItem) { showListPhone += "<tr>"; showListPhone += "<td><img class='img-responsive' src='" + item.ItemImage + "' alt='' /></td>"; showListPhone += "<td>" + item.ItemName + "</a></td>"; showListPhone += "<td>" + item.Quantity + " </td>"; showListPhone += "<td>" + FormatNumber.FormatPrice(item.ItemPrice) + "</td>"; showListPhone += "<td>" + FormatNumber.FormatPrice(item.Quantity * item.ItemPrice) + "</td>"; showListPhone += "<td><a href='DeletePhoneFromCart.aspx?id=" + item.ItemId + "'>Xóa</td>"; showListPhone += "</tr>"; total += (item.ItemPrice * item.Quantity); } totalPayment = FormatNumber.FormatPrice(total); } else { Response.Write("Session null"); } //show similar phone conn.Open(); SqlCommand cmdSimilarPhone = new SqlCommand("SELECT TOP 4 [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones"); cmdSimilarPhone.CommandType = System.Data.CommandType.Text; cmdSimilarPhone.Connection = conn; SqlDataReader readerSimilarPhone = cmdSimilarPhone.ExecuteReader(); List <Phone> listPhone = new List <Phone>(); while (readerSimilarPhone.Read()) { Phone phoneSimilar = new Phone(); phoneSimilar.PhoneId = Int32.Parse(readerSimilarPhone["phoneId"].ToString().Trim()); phoneSimilar.PhoneName = readerSimilarPhone["phoneName"].ToString().Trim(); phoneSimilar.PhonePrice = Int32.Parse(readerSimilarPhone["phonePrice"].ToString().Trim()); phoneSimilar.Manufacturer = readerSimilarPhone["manufacturer"].ToString().Trim(); phoneSimilar.ImageLink = readerSimilarPhone["imageLink"].ToString().Trim(); phoneSimilar.PhoneDescrible = readerSimilarPhone["phoneDescrible"].ToString().Trim(); listPhone.Add(phoneSimilar); } conn.Close(); foreach (Phone phone1 in listPhone) { showSimilarPhone += "<div class='col-md-3 col-sm-6 center-responsive'>"; showSimilarPhone += "<div class='product same-height'>"; showSimilarPhone += "<a href='Detail.aspx?id=" + phone1.PhoneId + "' >"; showSimilarPhone += "<img class='img-responsive' src='" + phone1.ImageLink + "' alt='' />"; showSimilarPhone += "<div class='text'>"; showSimilarPhone += "<h3>"; showSimilarPhone += phone1.PhoneName; showSimilarPhone += "</h3>"; showSimilarPhone += "<p class='price'>" + FormatNumber.FormatPrice(phone1.PhonePrice) + " VNĐ" + "</p>"; showSimilarPhone += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + phone1.PhoneId + "'>" + "Xem chi tiết</a></p>"; showSimilarPhone += "</div>"; showSimilarPhone += "</a>"; showSimilarPhone += "</div>"; showSimilarPhone += "</div>"; } //take categories from database conn.Open(); SqlCommand cmdCategories = new SqlCommand("SELECT DISTINCT [manufacturer] FROM Phones"); cmdCategories.CommandType = System.Data.CommandType.Text; cmdCategories.Connection = conn; SqlDataReader readerCategories = cmdCategories.ExecuteReader(); while (readerCategories.Read()) { categories += "<li>"; categories += "<a href='Shop.aspx?category=" + readerCategories["manufacturer"] + "'>" + readerCategories["manufacturer"] + "</a>"; categories += "<li>"; } conn.Close(); }
protected void Page_Load(object sender, EventArgs e) { show = ""; categories = ""; string connStr = "Server=BT; Database=PhoneShop; User=sa; Password=12345678"; SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT TOP 8 [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones"); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; SqlDataReader reader = cmd.ExecuteReader(); listPhone = new List <Phone>(); while (reader.Read()) { Phone phone = new Phone(); phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); listPhone.Add(phone); } conn.Close(); foreach (Phone phone in listPhone) { show += "<div class='col-md-4 col-sm-6 single'>"; show += "<div class='product'>"; show += "<a href='Detail.aspx?id=" + phone.PhoneId + "' >"; show += "<img class='img-responsive' src='" + phone.ImageLink + "' alt='' />"; show += "<div class='text'>"; show += "<h3>"; show += phone.PhoneName; show += "</h3>"; show += "<p class='price'>" + FormatNumber.FormatPrice(phone.PhonePrice) + " VNĐ" + "</p>"; show += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + phone.PhoneId + "'>" + "Xem chi tiết</a></p>"; show += "</div>"; show += "</a>"; show += "</div>"; show += "</div>"; } //take categories from database conn.Open(); SqlCommand cmdCategories = new SqlCommand("SELECT DISTINCT [manufacturer] FROM Phones"); cmdCategories.CommandType = System.Data.CommandType.Text; cmdCategories.Connection = conn; SqlDataReader readerCategories = cmdCategories.ExecuteReader(); while (readerCategories.Read()) { categories += "<li>"; categories += "<a href='Shop.aspx?category=" + readerCategories["manufacturer"] + "'><b>" + readerCategories["manufacturer"] + "<b></a>"; categories += "<li>"; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["cart"] == null) { Session["cart"] = new List <ItemCart>(); } if (Request.QueryString["id"] != null) { showPricePhone = ""; categories = ""; showDetailPhone = ""; showSimilarPhone = ""; string connStr = "Server=BT; Database=PhoneShop; User=sa; Password=12345678"; SqlConnection conn = new SqlConnection(connStr); int phoneId = Int32.Parse(Request.QueryString["id"].Trim()); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones WHERE phoneId=@phoneId"); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; cmd.Parameters.Add("@phoneId", SqlDbType.Int).Value = phoneId; SqlDataReader reader = cmd.ExecuteReader(); phone = new Phone(); while (reader.Read()) { phone.PhoneId = Int32.Parse(reader["phoneId"].ToString().Trim()); phone.PhoneName = reader["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(reader["phonePrice"].ToString().Trim()); phone.Manufacturer = reader["manufacturer"].ToString().Trim(); phone.ImageLink = reader["imageLink"].ToString().Trim(); phone.PhoneDescrible = reader["phoneDescrible"].ToString().Trim(); break; } conn.Close(); //take categories from database conn.Open(); SqlCommand cmdCategories = new SqlCommand("SELECT DISTINCT [manufacturer] FROM Phones"); cmdCategories.CommandType = System.Data.CommandType.Text; cmdCategories.Connection = conn; SqlDataReader readerCategories = cmdCategories.ExecuteReader(); while (readerCategories.Read()) { categories += "<li>"; categories += "<a href='Shop.aspx?category=" + readerCategories["manufacturer"] + "'>" + readerCategories["manufacturer"] + "</a>"; categories += "<li>"; } conn.Close(); showDetailPhone += ShowPhone.showPhone(phone); showPricePhone += FormatNumber.FormatPrice(phone.PhonePrice) + " VNĐ"; //show similar phone conn.Open(); SqlCommand cmdSimilarPhone = new SqlCommand("SELECT [phoneId],[phoneName],[manufacturer],[phonePrice],[imageLink],[phoneDescrible] FROM Phones WHERE manufacturer=@manufacturer"); cmdSimilarPhone.CommandType = System.Data.CommandType.Text; cmdSimilarPhone.Connection = conn; cmdSimilarPhone.Parameters.Add("@manufacturer", SqlDbType.VarChar).Value = phone.Manufacturer; SqlDataReader readerSimilarPhone = cmdSimilarPhone.ExecuteReader(); List <Phone> listPhone = new List <Phone>(); while (readerSimilarPhone.Read()) { Phone phoneSimilar = new Phone(); phoneSimilar.PhoneId = Int32.Parse(readerSimilarPhone["phoneId"].ToString().Trim()); phoneSimilar.PhoneName = readerSimilarPhone["phoneName"].ToString().Trim(); phoneSimilar.PhonePrice = Int32.Parse(readerSimilarPhone["phonePrice"].ToString().Trim()); phoneSimilar.Manufacturer = readerSimilarPhone["manufacturer"].ToString().Trim(); phoneSimilar.ImageLink = readerSimilarPhone["imageLink"].ToString().Trim(); phoneSimilar.PhoneDescrible = readerSimilarPhone["phoneDescrible"].ToString().Trim(); listPhone.Add(phoneSimilar); } conn.Close(); foreach (Phone phone1 in listPhone) { showSimilarPhone += "<div class='col-md-3 col-sm-6 center-responsive'>"; showSimilarPhone += "<div class='product same-height'>"; showSimilarPhone += "<a href='Detail.aspx?id=" + phone1.PhoneId + "' >"; showSimilarPhone += "<img class='img-responsive' src='" + phone1.ImageLink + "' alt='' />"; showSimilarPhone += "<div class='text'>"; showSimilarPhone += "<h3>"; showSimilarPhone += phone1.PhoneName; showSimilarPhone += "</h3>"; showSimilarPhone += "<p class='price'>" + FormatNumber.FormatPrice(phone1.PhonePrice) + " VNĐ" + "</p>"; showSimilarPhone += "<p class='button' align = 'center'<a class='btn btn-primary' href='Detail.aspx?id=" + phone1.PhoneId + "'>" + "Xem chi tiết</a></p>"; showSimilarPhone += "</div>"; showSimilarPhone += "</a>"; showSimilarPhone += "</div>"; showSimilarPhone += "</div>"; } } else { Response.Redirect("Shop.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { //int idAdmin = (int)Session["employeeId"]; orderId = Int32.Parse(Request.QueryString["orderId"]); string connStr = "Server=BT; Database=PhoneShop; User=sa; Password=12345678"; SqlConnection conn = new SqlConnection(connStr); //take data of customer and employee conn.Open(); String queryStr = "SELECT employeeName, customerName FROM Customers, Employees, Orders WHERE Orders.orderId=@orderId AND Customers.customerId=Orders.customerId AND Employees.employeeId=Orders.employeeId; "; SqlCommand cmd = new SqlCommand(queryStr); cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = conn; cmd.Parameters.Add("@orderId", SqlDbType.Int).Value = orderId; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { customerName = reader["customerName"].ToString().Trim(); employeeName = reader["employeeName"].ToString().Trim(); } conn.Close(); //take data of PhoneOfOrder from database. conn.Open(); String queryStrPhone = "SELECT phoneName, phonePrice, quantity FROM Phones, PhoneOfOrder, Orders WHERE Orders.orderId=@orderId AND Phones.phoneId=PhoneOfOrder.phoneId AND Orders.orderId=PhoneOfOrder.orderId; "; SqlCommand cmdListPhone = new SqlCommand(queryStrPhone); cmdListPhone.CommandType = System.Data.CommandType.Text; cmdListPhone.Connection = conn; cmdListPhone.Parameters.Add("@orderId", SqlDbType.Int).Value = orderId; SqlDataReader readerListPhone = cmdListPhone.ExecuteReader(); listPhone = new List <Phone>(); while (readerListPhone.Read()) { Phone phone = new Phone(); phone.PhoneName = readerListPhone["phoneName"].ToString().Trim(); phone.PhonePrice = Int32.Parse(readerListPhone["phonePrice"].ToString().Trim()); phone.PhoneQuantity = Int32.Parse(readerListPhone["quantity"].ToString().Trim()); //phone.ShopId = Int32.Parse(reader["shopId"].ToString().Trim()); listPhone.Add(phone); } conn.Close(); int stt = 1; foreach (Phone phone in listPhone) { show += "<tr>"; show += "<td>" + stt + "</td>"; show += "<td>" + phone.PhoneName + "</a></td>"; show += "<td>" + phone.PhoneQuantity + "</td>"; show += "<td>" + FormatNumber.FormatPrice(phone.PhonePrice) + "</td>"; show += "<td>" + FormatNumber.FormatPrice(phone.PhoneQuantity * phone.PhonePrice) + "</td>"; show += "</tr>"; totalPayment += phone.PhonePrice * phone.PhoneQuantity; } }