public CommentDetail(ReviewDataSoruce ds) { InitializeComponent(); bs.DataSource = ds; this.Load += CommentDetail_Load; _context = new Service.ServiceContext(); }
/// <summary> /// 初始化tagPage1 /// </summary> void InitPage1() { this.txtUrl.SetHintText("在这里输入要添加评价的创业赚钱商品链接"); this.txtLog.Focus(); this.txtJson.TextChanged += (s, e) => { btnAddComments.Enabled = cbIsUploadReviewImg.Enabled = txtJson.Text.Trim().Length > 0; }; //复制天猫脚本 this.btnTmall.Click += (s, e) => { try { Clipboard.SetText(ConstParams.PRODUCT_COMMENT); SM("复制脚本成功"); } catch (Exception ex) { AppendLogError(txtLog, "[异常]" + ex.Message); } }; //解析商品事件 this.btnGetProductInfo.Click += async(s, e) => { var url = txtUrl.Text.Trim(); #region 验证URL if (string.IsNullOrEmpty(url)) { SM("哎呀你逗我呢,没连接你给谁评价去O(∩_∩)O~"); return; } if (!_urlReg.IsMatch(url)) { SM("仔细瞅瞅,商品链接不对吧!"); return; } #endregion #region 验证商品 try { var productId = Convert.ToInt64(_urlReg.Match(url).Groups[1].Value); AppendLogWarning(txtLog, "开始验证商品信息..."); _productInfo = await _context.ProductService.GetProductInfo(productId); if (_productInfo != null) { AppendLogWarning(txtLog, "商品验证通过,信息如下:"); AppendLog(txtLog, "商品{0}品名:{1}", _productInfo.product[0].product_id , _productInfo.product[0].product_name); AppendLog(txtLog, "共识别出{0}个SKU,提交评价会随机匹配SKU作为购买规格评价使用!请知悉...", _productInfo.property.Count); for (int i = 0; i < _productInfo.property.Count; i++) { AppendLog(txtLog, "第{0}个SKU={1}", i + 1, _productInfo.property[i].json_info); } //绑定到page2属性combobox上 cbProperty.DataSource = _productInfo.property; //启用 tcReviews.Enabled = true; } else { AppendLogError(txtLog, "暂无此商品,请核对"); } } catch (Exception ex) { AppendLogError(txtLog, "[异常]" + ex.Message); } #endregion }; //解析json评价并展示 var isProcessData = false; //当前评价是否处理过 this.btnAddComments.Click += async(s, e) => { var json = txtJson.Text.Trim(); #region 验证URL if (string.IsNullOrEmpty(json)) { SM("干嘛呢,输入评价数据啊!"); return; } #endregion #region 提交评价 批量 try { btnAddComments.Enabled = false; if (!isProcessData) { _reviewList = JsonConvert.DeserializeObject <List <ReviewInfo> >(json); AppendLog(txtLog, "共识别出{0}条评价...", _reviewList.Count); } if (_reviewList.Count > 0) { if (!isProcessData) { #region 处理评价 for (int i = 0; i < _reviewList.Count; i++) { _reviewList[i].ProductId = _productInfo.product[0].product_id; _reviewList[i].AddUserId = _context.Session.Token.userid; _reviewList[i].PropertyName = _productInfo.property[_random.Next(0, _productInfo.property.Count)] .json_info; //处理头像 //AppendLog(txtLog, "开始处理第[{0}]个评价的头像...", i + 1); _reviewList[i].HeadPic = GetHeadPic(_reviewList[i].HeadPic); AppendLog(txtLog, "第[{0}]个评价的头像处理完成...", i + 1); //循环处理评价图片 if (_isUploadReviewImg && !string.IsNullOrEmpty(_reviewList[i].ReviewImgs)) { var imgList = _reviewList[i].ReviewImgs.Split(','); var updateImglist = new List <string>(); for (int j = 0; j < imgList.Length; j++) { //AppendLog(txtLog, "开始处理第[{0}]个评价的第[{1}]张图片...", i + 1, j + 1); updateImglist.Add(await _context.ImageService.UploadImg(imgList[j], 4)); AppendLog(txtLog, "第[{0}]个评价的第[{1}]张图片处理完成...", i + 1, j + 1); } _reviewList[i].ReviewImgs = string.Join(",", updateImglist); } else { _reviewList[i].ReviewImgs = ""; } } #endregion isProcessData = true; } ReviewDataSoruce rds = new ReviewDataSoruce(); rds.AddRange(_reviewList); _commentDetail = new CommentDetail(rds); _commentDetail.IsUploadData += async(sender, arge) => { _reviewList = sender as List <ReviewInfo>; if (await SubmintReview(_reviewList)) { txtJson.Text = ""; isProcessData = false; } }; _commentDetail.ShowDialog(this); btnAddComments.Enabled = true; } } catch (Exception ex) { AppendLogError(txtLog, "[异常]" + ex.Message); } #endregion }; //url输入框点击事件 主要用来自动粘贴 this.txtUrl.Click += (s, e) => { if (string.IsNullOrEmpty((s as TextBox).Text)) { string getTxt = Clipboard.GetText(); if (_urlReg.IsMatch(getTxt)) { (s as TextBox).Text = getTxt; } } else { (s as TextBox).SelectAll(); } }; //是否上传图片 this.cbIsUploadReviewImg.Click += (s, e) => { _isUploadReviewImg = cbIsUploadReviewImg.Checked; }; }