307 lines
11 KiB
C#
307 lines
11 KiB
C#
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;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 赋值采集源
|
|
/// </summary>
|
|
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++;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取代运营朋友圈采集源头
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<CollectionSourceResult> 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<long>() != 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var list = new List<CollectionSourceResult>();
|
|
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<string>();
|
|
item.Nick = jToken["NickName"]?.Value<string>();
|
|
list.Add(item);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 朋友圈采集源头数据
|
|
/// </summary>
|
|
public class CollectionSourceResult
|
|
{
|
|
/// <summary>
|
|
/// 来源Id
|
|
/// </summary>
|
|
public string SourceId { get; set; }
|
|
|
|
/// <summary>
|
|
/// 昵称
|
|
/// </summary>
|
|
public string Nick { get; set; }
|
|
|
|
/// <summary>返回表示当前对象的字符串。</summary>
|
|
/// <returns>表示当前对象的字符串。</returns>
|
|
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_(?<cpsname>\d+)_(?<pid1>\d+)_(?<pid2>\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, @"(?<cpsname>\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, @"(?<pid>(?<cpsname>\d+)_\d+_\d+)_(?<key>.+)");
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |