public void GetPhoto() { string sqlExpression = "SELECT product_photo FROM product WHERE product_id = '" + CustBag.prodSelected + "'"; using (SqlConnection connection = new SqlConnection(SignIn.connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { if (!reader.IsDBNull(0)) { Byte[] photo = (byte[])reader.GetValue(0); prodPic.Image = MainShop.ByteArrayToImage(photo); } } } connection.Close(); } }
public void GetStoreInfo() { string sqlExpression = "SELECT store_name, store_logo FROM store WHERE store_id = '" + CustBag.storeSelected + "'"; using (SqlConnection connection = new SqlConnection(SignIn.connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { if (!reader.IsDBNull(0)) { storeName = reader.GetValue(0).ToString(); } if (!reader.IsDBNull(1)) { storeLogo = (byte[])reader.GetValue(1); logoPreview.Image = MainShop.ByteArrayToImage(storeLogo); } } } connection.Close(); } }
public void GetDataForGrid() { for (int m = 0; m < numOfRows; m++) { if (m != numOfRows - 1) { temp += id[m] + ", "; } else { temp += id[m]; } } string sqlExpression = "SELECT DISTINCT dbo.product.product_code, dbo.product.product_name, dbo.product.product_info, " + "dbo.gender.gender_name, dbo.category.category_name, dbo.subcategory.subcategory_name, " + "dbo.product.product_photo, dbo.price.product_price, dbo.store.store_id, dbo.product.product_id " + "FROM dbo.product INNER JOIN " + "dbo.category_gender ON dbo.product.category_gender_id = dbo.category_gender.category_gender_id INNER JOIN " + "dbo.cat_subcategory ON dbo.category_gender.cat_subcat_id = dbo.cat_subcategory.cat_subcat_id INNER JOIN " + "dbo.category ON dbo.cat_subcategory.category_id = dbo.category.category_id INNER JOIN " + "dbo.subcategory ON dbo.cat_subcategory.subcategory_id = dbo.subcategory.subcategory_id INNER JOIN " + "dbo.gender ON dbo.category_gender.gender_id = dbo.gender.gender_id INNER JOIN " + "dbo.product_size ON dbo.product_size.product_id = dbo.product.product_id INNER JOIN " + "dbo.product_address ON dbo.product_address.product_size_id = dbo.product_size.product_size_id INNER JOIN " + "dbo.price ON dbo.price.product_id = dbo.product.product_id INNER JOIN " + "dbo.store_address ON dbo.store_address.store_address_id = dbo.product_address.store_address_id INNER JOIN " + "dbo.store ON dbo.store_address.store_id = dbo.store.store_id " + "WHERE (dbo.product.product_id IN (" + temp + ")) AND dbo.price.product_price IN " + "(SELECT product_price FROM price " + "WHERE version_date IN (SELECT MAX(version_date) FROM price GROUP BY product_id))" + extendSql + ""; prodInfo = new string[numOfRows, 9]; picArray = new List <Image>(); int i = 0; using (SqlConnection connection = new SqlConnection(SignIn.connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { prodInfo[i, 0] = reader.GetValue(0).ToString(); prodInfo[i, 1] = reader.GetValue(1).ToString(); prodInfo[i, 2] = reader.GetValue(2).ToString(); prodInfo[i, 3] = reader.GetValue(3).ToString(); prodInfo[i, 4] = reader.GetValue(4).ToString(); prodInfo[i, 5] = reader.GetValue(5).ToString(); prodInfo[i, 6] = reader.GetValue(7).ToString(); prodInfo[i, 7] = reader.GetValue(8).ToString(); prodInfo[i, 8] = reader.GetValue(9).ToString(); if (!reader.IsDBNull(6)) { prodPicByte = (byte[])reader.GetValue(6); picArray.Add(MainShop.ByteArrayToImage(prodPicByte)); } i++; } } reader.Close(); connection.Close(); } }