Ejemplo n.º 1
0
        public void LoadMoreProductReviews(System.Web.HttpContext context)
        {
            StringBuilder      stringBuilder      = new StringBuilder();
            ProductReviewQuery productReviewQuery = new ProductReviewQuery();

            productReviewQuery.SortBy    = "ReviewDate";
            productReviewQuery.SortOrder = SortAction.Desc;
            productReviewQuery.PageIndex = int.Parse(context.Request["pageNumber"]);
            productReviewQuery.PageSize  = int.Parse(context.Request["size"]);
            productReviewQuery.productId = int.Parse(context.Request["ProductId"]);

            Globals.EntityCoding(productReviewQuery, true);
            DataTable dt = (DataTable)ProductCommentHelper.GetProductReviews(productReviewQuery).Data;

            stringBuilder.Append("{");
            if (dt.Rows.Count > 0)
            {
                stringBuilder.Append("\"Success\":1,");
                stringBuilder.Append("\"productcomments\":");
                IsoDateTimeConverter convert = new IsoDateTimeConverter();
                convert.DateTimeFormat = "yyyy-MM-dd";
                string strReviews = Newtonsoft.Json.JsonConvert.SerializeObject(dt, Formatting.None, convert);
                stringBuilder.Append(strReviews);
                stringBuilder.Append("}");
            }

            else
            {
                stringBuilder.Append("\"Success\":0");
                stringBuilder.Append("}");
            }

            context.Response.Write(stringBuilder.ToString());
            context.Response.End();
        }
Ejemplo n.º 2
0
        private DataGridViewModel <Dictionary <string, object> > GetDataList(ProductReviewQuery query)
        {
            DataGridViewModel <Dictionary <string, object> > dataGridViewModel = new DataGridViewModel <Dictionary <string, object> >();

            if (query != null)
            {
                DbQueryResult productReviews = ProductCommentHelper.GetProductReviews(query);
                dataGridViewModel.rows  = DataHelper.DataTableToDictionary(productReviews.Data);
                dataGridViewModel.total = productReviews.TotalRecords;
                foreach (Dictionary <string, object> row in dataGridViewModel.rows)
                {
                    ProductInfo       productById       = ProductHelper.GetProductById(row["ProductId"].ToInt(0));
                    ProductReviewInfo productReviewInfo = row.ToObject <ProductReviewInfo>();
                    row.Add("Type", query.havedReply);
                    if (productById.ProductName.Trim().Length > 22)
                    {
                        row.Add("ProductNameStr", productById.ProductName.Trim().Substring(0, 22) + "...");
                    }
                    else
                    {
                        row.Add("ProductNameStr", productById.ProductName.Trim());
                    }
                    if (productReviewInfo.ReviewText.Trim().Length >= 50)
                    {
                        row.Add("ReviewTextStr", productReviewInfo.ReviewText.Trim().Substring(0, 50) + "...");
                    }
                    else
                    {
                        row.Add("ReviewTextStr", productReviewInfo.ReviewText.Trim());
                    }
                    if (query.havedReply.ToBool())
                    {
                        if (productReviewInfo.ReplyText.Trim().Length >= 50)
                        {
                            row.Add("ReplyTextStr", productReviewInfo.ReplyText.Trim().Substring(0, 50) + "...");
                        }
                        else
                        {
                            row.Add("ReplyTextStr", productReviewInfo.ReplyText.Trim());
                        }
                    }
                }
            }
            return(dataGridViewModel);
        }
Ejemplo n.º 3
0
        private void BindPtReview()
        {
            ProductReviewQuery productReviewQuery = new ProductReviewQuery();

            productReviewQuery.Keywords    = this.keywords;
            productReviewQuery.CategoryId  = this.categoryId;
            productReviewQuery.ProductCode = this.productCode;
            productReviewQuery.PageIndex   = this.pager.PageIndex;
            productReviewQuery.PageSize    = this.pager.PageSize;
            productReviewQuery.SortOrder   = SortAction.Desc;
            productReviewQuery.SortBy      = "ReviewDate";
            Globals.EntityCoding(productReviewQuery, true);
            DbQueryResult productReviews = ProductCommentHelper.GetProductReviews(productReviewQuery);

            this.dlstPtReviews.DataSource = productReviews.Data;
            this.dlstPtReviews.DataBind();
            this.pager.TotalRecords = productReviews.TotalRecords;
        }
Ejemplo n.º 4
0
        private void BindPtReview()
        {
            ProductReviewQuery entity = new ProductReviewQuery {
                Keywords    = this.keywords,
                CategoryId  = this.categoryId,
                ProductCode = this.productCode,
                PageIndex   = this.pager.PageIndex,
                PageSize    = this.pager.PageSize,
                SortOrder   = SortAction.Desc,
                SortBy      = "ReviewDate"
            };

            Globals.EntityCoding(entity, true);
            DbQueryResult productReviews = ProductCommentHelper.GetProductReviews(entity);

            this.dlstPtReviews.DataSource = productReviews.Data;
            this.dlstPtReviews.DataBind();
            this.pager.TotalRecords = productReviews.TotalRecords;
        }
Ejemplo n.º 5
0
        private void BindPtReview()
        {
            ProductReviewQuery entity = new ProductReviewQuery();

            entity.Keywords    = this.keywords;
            entity.CategoryId  = this.categoryId;
            entity.ProductCode = this.productCode;
            entity.PageIndex   = this.pager.PageIndex;
            entity.PageSize    = this.pager.PageSize;
            entity.SortOrder   = SortAction.Desc;
            entity.SortBy      = "ReviewDate";
            Globals.EntityCoding(entity, true);
            int     total          = 0;
            DataSet productReviews = ProductCommentHelper.GetProductReviews(out total, entity);

            this.dlstPtReviews.DataSource = productReviews.Tables[0].DefaultView;
            this.dlstPtReviews.DataBind();
            this.pager.TotalRecords  = total;
            this.pager1.TotalRecords = total;
        }
Ejemplo n.º 6
0
        public void GetProductReviews(System.Web.HttpContext context)
        {
            string producId = context.Request["ProductId"];
            int    Id       = 0;

            int.TryParse(producId, out Id);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("{");
            if (!int.TryParse(producId, out Id))
            {
                stringBuilder.Append("\"Success\":-1");
                stringBuilder.Append("}");
                context.Response.Write(stringBuilder.ToString());
                context.Response.End();
                return;
            }

            //处理平均数和总数
            DataTable dt = ProductCommentHelper.GetReviewsCountAndAvg(Id);

            if (dt.Rows.Count > 0)
            {
                ProductReviewQuery productReviewQuery = new ProductReviewQuery();
                productReviewQuery.SortBy    = "ReviewDate";
                productReviewQuery.SortOrder = SortAction.Desc;
                productReviewQuery.PageIndex = int.Parse(context.Request["pageNumber"]);
                productReviewQuery.PageSize  = int.Parse(context.Request["size"]);
                productReviewQuery.productId = int.Parse(context.Request["ProductId"]);

                Globals.EntityCoding(productReviewQuery, true);
                DataTable dtcomments = (DataTable)ProductCommentHelper.GetProductReviews(productReviewQuery).Data;

                if (dtcomments.Rows.Count <= 0)
                {
                    stringBuilder.Append("\"Success\":0");
                    stringBuilder.Append("}");
                    context.Response.Write(stringBuilder.ToString());
                    context.Response.End();
                    return;
                }
                else
                {
                    int amount = 0;
                    try
                    {
                        int.TryParse(dt.Rows[0]["Amount"].ToString(), out amount);
                    }
                    catch
                    {
                        amount = 0;
                    }
                    stringBuilder.Append("\"Success\":1,");
                    stringBuilder.AppendFormat("\"Amount\":{0},", amount);
                    stringBuilder.Append("\"data\":");
                    for (int i = 0; i < dtcomments.Rows.Count; i++)
                    {
                        dtcomments.Rows[i]["UserName"] = ReplaceStr(dtcomments.Rows[i]["UserName"].ToString());
                    }

                    IsoDateTimeConverter convert = new IsoDateTimeConverter();
                    convert.DateTimeFormat = "yyyy-MM-dd";
                    string strReviews = Newtonsoft.Json.JsonConvert.SerializeObject(dtcomments, Formatting.None, convert);
                    stringBuilder.Append(strReviews);

                    stringBuilder.Append(",");
                    //stringBuilder.AppendFormat("\"Avg\":{0}", Math.Round((1.0 * count / list.Count), 1));
                    double avg = 0;
                    try{
                        double.TryParse(dt.Rows[0]["avg"].ToString(), out avg);
                    }
                    catch
                    {
                        avg = 0;
                    }

                    stringBuilder.AppendFormat("\"Avg\":{0}", avg.ToString("0.0"));
                    stringBuilder.Append("}");
                    context.Response.Write(stringBuilder.ToString());
                    context.Response.End();
                    return;
                }
            }

            else
            {
                stringBuilder.Append("\"Success\":0");
                stringBuilder.Append("}");
                context.Response.Write(stringBuilder.ToString());
                context.Response.End();
                return;
            }
        }