using Api.Framework; using Api.Framework.Cps; using Api.Framework.Enums; using Api.Framework.Tools; using DevExpress.XtraEditors; using ProductClient.Properties; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Windows.Forms; using CsharpHttpHelper; using DevExpress.Utils.Filtering.Internal; using Newtonsoft.Json.Linq; using UI.Framework.Forms; using static Api.Framework.ApiClient; namespace ProductClient { public partial class MainForm : BaseForm { public MainForm() { InitializeComponent(); this.Text = Resources.MainFormTitle; } public void CloseForm() { try { if (!this.IsDisposed) { this.Invoke(new Action(delegate { this.Close(); this.Dispose(); })); } } catch (Exception ex) { ShowError(ex.Message); } } private void MainForm_Load(object sender, EventArgs e) { textEdit1.Text = Class1.Config.tbPid; textEdit2.Text = Class1.Config.pddPid; textEdit3.Text = Class1.Config.jdPid; textEdit4.Text = Class1.Config.actionLink; numericUpDown1.Value = Class1.Config.Monitor_Interval; checkBox1.Checked = Class1.Config.isPyTkl; checkBox2.Checked = Class1.Config.isPl; this.comboBoxEdit2.Properties.Items.AddRange(Enum.GetNames(typeof(DwzType))); comboBoxEdit2.SelectedIndex = (int)Class1.Config.dwzType; SetComboBox_GetCollectionSource(); comboBoxEdit1.SelectedIndex = (int)Class1.Config.qrImageType; memoEdit1.Text = Class1.Config.appendComment; } /// /// 赋值采集源 /// private void SetComboBox_GetCollectionSource() { if (Class1.Config.sourceId == null) { Class1.Config.sourceId = "129505086429724672"; } var collectionSources = GetCollectionSourceAll(); if (collectionSources != null) { int index = 0; foreach (var item in collectionSources) { this.comboBoxEdit3.Properties.Items.Add(item); this.comboBoxEdit3.SelectedText = item.Nick; if (Class1.Config.sourceId == item.SourceId) { comboBoxEdit3.SelectedIndex = index; } index++; } } } /// /// 获取代运营朋友圈采集源头 /// /// public List GetCollectionSourceAll() { //http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/GetCollectionSourceAll //{"Code":0,"Result":[{"Id":"129505086429724672","NickName":"壮壮"}]} var html = new HttpHelper().GetHtml( "http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/GetCollectionSourceAll").Html; var jObj = JObject.Parse(html); if (jObj["Code"]?.Value() != 0) { return null; } var list = new List(); var jArr = jObj["Result"]?.ToArray(); if (jArr != null && jArr.Length > 0) { foreach (var jToken in jArr) { var item = new CollectionSourceResult(); item.SourceId = jToken["Id"]?.Value(); item.Nick = jToken["NickName"]?.Value(); list.Add(item); } } return list; } /// /// 朋友圈采集源头数据 /// public class CollectionSourceResult { /// /// 来源Id /// public string SourceId { get; set; } /// /// 昵称 /// public string Nick { get; set; } /// 返回表示当前对象的字符串。 /// 表示当前对象的字符串。 public override string ToString() { return Nick; } } private void hyperlinkLabelControl_Click(object sender, EventArgs e) { try { var label = sender as HyperlinkLabelControl; if (label == null) return; var session = ApiClient.GetSession(); var cps = (CpsType)Enum.ToObject(typeof(CpsType), int.Parse(label.Name.ToLower().Replace("hyperlinklabelcontrol", ""))); switch (cps) { case CpsType.阿里妈妈: { var tgwObj = CpsClient.SelectTuiguangwei(CpsType.阿里妈妈); if (tgwObj != null) { var tgw = tgwObj as Tuiguangwei; textEdit1.Text = tgw.Pid; Class1.Config.tbPid = tgw.Pid; } } break; case CpsType.多多进宝: { var tgwObj = CpsClient.SelectTuiguangwei(CpsType.多多进宝); if (tgwObj != null) { var tgw = tgwObj as Tuiguangwei; textEdit2.Text = tgw.Pid; Class1.Config.pddPid = tgw.Pid; } } break; case CpsType.京东联盟: { var tgwObj = CpsClient.SelectTuiguangwei(CpsType.京东联盟); if (tgwObj != null) { var tgw = tgwObj as Tuiguangwei; textEdit3.Text = tgw.Pid + "_" + tgw.Member.username; Class1.Config.jdPid = textEdit3.Text; } } break; default: break; } } catch (Exception ex) { ShowError(ex); } } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { comboBoxEdit1.Focus(); Class1.Config.qrImageType = (QrImageType)comboBoxEdit1.SelectedIndex; Class1.Config.Monitor_Interval = (int)numericUpDown1.Value; Class1.Config.dwzType = (DwzType)comboBoxEdit2.SelectedIndex; if (comboBoxEdit3.SelectedItem != null) { Class1.Config.sourceId = ((CollectionSourceResult)comboBoxEdit3.SelectedItem)?.SourceId; } Class1.Config.isPyTkl = checkBox1.Checked; Class1.Config.isPl = checkBox2.Checked; Class1.Config.appendComment = memoEdit1.Text; Class1.Config.actionLink = textEdit4.Text; Util.Save(Class1.Config); } private void textEdit_Leave(object sender, EventArgs e) { try { var text = sender as TextEdit; if (text == null) return; var session = ApiClient.GetSession(); var cps = (CpsType)Enum.ToObject(typeof(CpsType), int.Parse(text.Name.ToLower().Replace("textedit", ""))); switch (cps) { case CpsType.阿里妈妈: { //mm_28592081_118450408_105567700447 var pidstr = text.Text.Trim(); if (!string.IsNullOrWhiteSpace(pidstr)) { var reg = Regex.Match(pidstr, @"mm_(?\d+)_(?\d+)_(?\d+)"); if (reg.Success) Class1.Config.tbPid = pidstr; } } break; case CpsType.多多进宝: { //1929015_26838864 var pidstr = text.Text.Trim(); if (!string.IsNullOrWhiteSpace(pidstr)) { var reg = Regex.Match(pidstr, @"(?\d+)_(\d+)"); if (reg.Success) Class1.Config.pddPid = pidstr; } } break; case CpsType.京东联盟: { //1000858402_0_1843753459_xxxxxxxxxxxxxxxxxxxxxxxxx var pidstr = text.Text.Trim(); if (!string.IsNullOrWhiteSpace(pidstr)) { var reg = Regex.Match(pidstr, @"(?(?\d+)_\d+_\d+)_(?.+)"); if (reg.Success) Class1.Config.jdPid = pidstr; } } break; default: break; } } catch (Exception ex) { ShowError(ex); } } private void hyperlinkLabelControl_Click_1(object sender, EventArgs e) { try { var label = sender as HyperlinkLabelControl; if (label == null) return; var cps = (CpsType)Enum.ToObject(typeof(CpsType), int.Parse(label.Name.ToLower().Replace("hyperlinklabelcontrol_", ""))); switch (cps) { case CpsType.阿里妈妈: { textEdit1.Text = Class1.Config.tbPid = string.Empty; } break; case CpsType.多多进宝: textEdit2.Text = Class1.Config.pddPid = string.Empty; break; case CpsType.京东联盟: textEdit3.Text = Class1.Config.jdPid = string.Empty; break; default: break; } } catch (Exception ex) { ShowError(ex); } } } }