// 刷新QQ微信群 private void refreshSendButton_Click(object sender, EventArgs e) { List <WndInfo> wndList = _productQunfa.GetAllQQWechatWnd(); qunfaListBox.DisplayMember = "Name"; foreach (WndInfo item in wndList) { if (qunfaListBox.FindString(item.Name) == -1) { qunfaListBox.Items.Add(item); } } // 删除项 for (int i = qunfaListBox.Items.Count - 1; i >= 0; i--) { bool bFind = false; foreach (WndInfo curItem in wndList) { WndInfo item = qunfaListBox.Items[i] as WndInfo; if (curItem.Name == item.Name) { bFind = true; break; } } if (!bFind) { qunfaListBox.Items.RemoveAt(i); } } }
// 群发定时器 private void OnQunfaTimer(object sender, EventArgs e) { List <WndInfo> qunfaWndList = new List <WndInfo>(); for (int i = 0; i < qunfaListBox.CheckedItems.Count; i++) { WndInfo item = ((WndInfo)qunfaListBox.CheckedItems[i]); qunfaWndList.Add(item); } List <TranslateUrlResult> resultList = _productQunfa.GetTranslateResult(); foreach (TranslateUrlResult result in resultList) { //QQ群发 try { MemoryStream ms = new MemoryStream(System.Text.Encoding.Default.GetBytes(result.QQShowContent));// copy Clipboard.SetData("QQ_RichEdit_Format", ms); qunfaQQWnd(qunfaWndList); Clipboard.Clear(); } catch (Exception) { } //微信群发 try { int nMajor = System.Environment.Version.Major; int nMinor = System.Environment.Version.Minor; if (nMajor >= 6 && nMinor >= 2) { // win8及以上 Clipboard.SetData(DataFormats.Html, result.WechatShowContent);// copy qunfaWechatWnd(qunfaWndList); Clipboard.Clear(); } else { // win7 // 先粘贴图片 Image img = Image.FromFile(result.ImagePath); Clipboard.SetDataObject(img); qunfaWechatWnd(qunfaWndList); Clipboard.Clear(); // 再粘贴文字 Clipboard.SetDataObject(result.WechatShowContent); qunfaWechatWnd(qunfaWndList); Clipboard.Clear(); } } catch (Exception) { } ListViewItem lv = qunfaListView.Items.Add(result.ProductTitle); lv.SubItems.Add(DateTime.Now.ToString()); } }
// 开始采集 private void collectButton_Click(object sender, EventArgs e) { if (!collectProductTimer.Enabled) { if (collectListBox.CheckedItems.Count == 0) { MessageBox.Show("请至少选择一个QQ群窗口"); return; } List <int> monitorQQWndList = new List <int>(); for (int i = 0; i < collectListBox.CheckedItems.Count; i++) { WndInfo item = ((WndInfo)collectListBox.CheckedItems[i]); monitorQQWndList.Add(item.Wnd); } int startTime, endTime, interval; Configure conf = Database.loadConfigre(); startTime = conf.CollectStartTime; endTime = conf.CollectEndTime; interval = conf.CollectInterval; _collectAutoSync = conf.CollectAutoSync; _productCollector.StartMonitor(monitorQQWndList, startTime, endTime, interval); // 开始监控 collectProductTimer.Start(); collectButton.Text = "停止采集"; collectListBox.Enabled = false; refreshCollectButton.Enabled = false; if (_collectAutoSync) // 如果勾选了自动同步到自选库,则先把已采集商品同步到自选库中 { List <ProductInfo> selectedProductList = new List <ProductInfo>(); foreach (ListViewItem item in collectListView.Items) { selectedProductList.Add(new ProductInfo(item.SubItems[0].Text, "", item.SubItems[4].Text, item.SubItems[2].Text, item.SubItems[3].Text, item.SubItems[1].Text, item.Tag as string)); } Database.addProductList(selectedProductList); } } else { _productCollector.StopMonitor(); // 停止监控 collectProductTimer.Stop(); collectButton.Text = "开始采集"; collectListBox.Enabled = true; refreshCollectButton.Enabled = true; } }