void AddMyReview(List <Review> reviews, List <Product> products) { int amount = reviews.Count; RectTransform content = body.GetChild(0).GetComponent <RectTransform>(); for (int i = 0; i < amount; i++) { Transform newMyReviewUnit = Instantiate(myReviewUnit); newMyReviewUnit.SetParent(content); MyReviewUnit myReviewUnitInfo = newMyReviewUnit.GetComponent <MyReviewUnit>(); myReviewUnits.Add(myReviewUnitInfo); } SortReviewPanels(0); for (int i = 0; i < amount; i++) { Transform unit = myReviewUnits[i].transform; Product product = products[i]; Review review = reviews[i]; ProductUnit productUnit = unit.GetChild(0).GetComponent <ProductUnit>(); productUnit.InfoChange(product, gameObject); ReviewUnit reviewUnit = unit.GetChild(1).GetComponent <ReviewUnit>(); reviewUnit.Change(review, gameObject); } }
public void ReadReviews() { int productID = product.id; int count = DbConnecter.instance.Count("productID", "review", "productID = " + productID + ";"); float anchorGap = 0.3f; float firstYMax = 0.75f; float lastYMax = 0; int maxRange = Mathf.Clamp(count - reviewUnits.Count, 0, count); int minRange = Mathf.Clamp(maxRange - oneLoadAmount, 0, maxRange); if (maxRange > 0) { string sql = "SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY(dateTime) DESC) AS id, email, productID, score, first, second, third, fourth, fifth FROM review WHERE productID = " + productID + ") newtable WHERE id <=" + maxRange + " AND id >" + minRange + "; "; /* * string sql = @"SELECT * * FROM ( * SELECT ROW_NUMBER() OVER(ORDER BY(dateTime) DESC) AS id, * * FROM review * WHERE productID = " + productID + * @") newtable * WHERE id <=" + maxRange + " AND id >" + minRange + "; "; */ MySql.Data.MySqlClient.MySqlDataReader reader = DbConnecter.instance.Reader(sql); while (reader.Read()) { Transform newReviewUnit = Instantiate(reviewUnit); newReviewUnit.SetParent(content.transform); RectTransform rectTransform = newReviewUnit.GetComponent <RectTransform>(); int reviewCount = reviewUnits.Count; float yMax = firstYMax - anchorGap * reviewCount; float yMin = yMax - anchorGap; lastYMax = yMin; rectTransform.anchorMax = new Vector2(1, yMax); rectTransform.anchorMin = new Vector2(0, yMin); rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; Review review = new Review(); review.id = (int)reader.GetInt64(0); review.email = reader.GetString(1); review.productID = reader.GetInt32(2); review.score = reader.GetInt32(3); review.first = reader.GetInt32(4); review.second = reader.GetInt32(5); review.third = reader.GetInt32(6); review.fourth = reader.GetInt32(7); review.fifth = reader.GetInt32(8); ReviewUnit reviewUnitInfo = newReviewUnit.GetComponent <ReviewUnit>(); reviewUnitInfo.Change(review, gameObject); reviewUnits.Add(reviewUnitInfo); } reader.Close(); DbConnecter.instance.CloseConnection(); } else { Debug.Log("불러올 리뷰가 없습니다"); } if (lastYMax < 0) { float contentSize = content.getInitialContentYSize() * (1 - (lastYMax)); content.ChangeSize(contentSize); } else { float contentSize = content.getInitialContentYSize(); content.ChangeSize(contentSize); } }