312 lines
12 KiB
C#
312 lines
12 KiB
C#
using Api.Framework;
|
|
using Api.Framework.Cps;
|
|
using Api.Framework.Enums;
|
|
using Api.Framework.Model;
|
|
using DevExpress.XtraEditors;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
using UI.Framework.Forms;
|
|
|
|
namespace FLSystem.Forms
|
|
{
|
|
public partial class jd_adzone_group_form : BaseForm
|
|
{
|
|
public class view_jingdong_form_select_tgw
|
|
{
|
|
public string name { get; set; }
|
|
public string p_id { get; set; }
|
|
public DateTime create_time { get; set; }
|
|
}
|
|
|
|
List<Tuiguangwei> tgws = null;
|
|
public fl_adzone_group adzone_group = null;
|
|
|
|
public jd_adzone_group_form(int id = 0)
|
|
{
|
|
InitializeComponent();
|
|
var session = ApiClient.GetSession();
|
|
if (id == 0)
|
|
tgws = new List<Tuiguangwei>();
|
|
else
|
|
{
|
|
adzone_group = session.Queryable<fl_adzone_group>().First(f => f.id == id);
|
|
if (adzone_group != null)
|
|
{
|
|
tgws = CsharpHttpHelper.HttpHelper.JsonToObject<List<Tuiguangwei>>(adzone_group.adzones) as List<Tuiguangwei>;
|
|
gridControl2.DataSource = tgws;
|
|
textBox1.Text = adzone_group.name;
|
|
}
|
|
else
|
|
tgws = new List<Tuiguangwei>();
|
|
}
|
|
}
|
|
|
|
private void jd_adzone_group_form_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var members = CpsClient.Members.Where(f => f.cpstype == CpsType.京东联盟).ToList();
|
|
if (members == null || members.Count == 0)
|
|
{
|
|
ShowError("对不起,当前未检测到您登录的京东账号!");
|
|
this.Close();
|
|
return;
|
|
}
|
|
this.comboBoxEdit1.Properties.Items.AddRange(members);
|
|
|
|
this.pageControl1.Bind(delegate (int index, int page)
|
|
{
|
|
try
|
|
{
|
|
var member = this.comboBoxEdit1.EditValue as fl_cps_member;
|
|
if (member == null) throw new Exception("找不到,您选择的账号!");
|
|
var api = CpsClient.CreateJingdongRequest(member);
|
|
var list = new List<view_jingdong_form_select_tgw>();
|
|
FindTGW(api, 1, member.usernick, member.username, list);
|
|
var _list = list.Skip((index - 1) * page).Take(page).ToList();
|
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = _list, Total = list.Count };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.UpdateUI(() =>
|
|
{
|
|
this.label6.Visible = true;
|
|
this.label6.Text = ex.Message;
|
|
});
|
|
}
|
|
return null;
|
|
}, this.gridControl1, 100, true, true);
|
|
|
|
this.comboBoxEdit1.SelectedIndex = 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取所有的推广位
|
|
/// </summary>
|
|
/// <param name="api"></param>
|
|
/// <param name="page"></param>
|
|
/// <param name="usernick"></param>
|
|
/// <param name="username"></param>
|
|
/// <param name="list"></param>
|
|
private void FindTGW(JingdongApi api, int page, string usernick, string username, List<view_jingdong_form_select_tgw> list)
|
|
{
|
|
try
|
|
{
|
|
var result = api.SendJingdong("jd.union.open.position.query", new { positionReq = new { unionType = 1, pageSize = 100, pageIndex = page, unionId = usernick, key = username } });
|
|
if (result.ContainsKey("data"))
|
|
{
|
|
var data = result["data"] as Dictionary<string, object>;
|
|
if (data.ContainsKey("result"))
|
|
{
|
|
var result2 = data["result"] as ArrayList;
|
|
this.label6.Visible = false;
|
|
foreach (Dictionary<string, object> item in result2)
|
|
{
|
|
list.Add(new view_jingdong_form_select_tgw { name = item["spaceName"].ToString(), p_id = $"{usernick}_{(item.ContainsKey("siteId") ? item["siteId"].ToString() : "0")}_{item["id"].ToString()}" });
|
|
}
|
|
}
|
|
if (data.ContainsKey("total"))
|
|
{
|
|
var total = long.Parse(data["total"].ToString());
|
|
var pageNo = int.Parse(data["pageNo"].ToString());
|
|
var pageSize = int.Parse(data["pageSize"].ToString());
|
|
if (total > (pageNo * pageSize))
|
|
{
|
|
page++;
|
|
FindTGW(api, page, usernick, username, list);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
}
|
|
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(this.textEdit1.Text)) throw new Exception("推广位名称不能留空!");
|
|
string pattern = "[\u4e00-\u9fbb]";
|
|
if (Regex.IsMatch(this.textEdit1.Text, pattern)) throw new Exception("推广位名称不能包含中文!");
|
|
|
|
if (XtraMessageBox.Show($"您确定要创建名为【{this.textEdit1.Text}】的推广位吗?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
var member = this.comboBoxEdit1.EditValue as fl_cps_member;
|
|
var api = CpsClient.CreateJingdongRequest(member);
|
|
api.SendJingdong("jd.union.open.position.create", new
|
|
{
|
|
positionReq = new
|
|
{
|
|
spaceNameList = new string[] { this.textEdit1.Text },
|
|
unionType = 1,
|
|
type = 4,
|
|
unionId = member.usernick,
|
|
key = member.username
|
|
}
|
|
});
|
|
this.pageControl1.GotoPage(1);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!this.IsDisposed)
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
this.pageControl1.GotoPage(1);
|
|
|
|
#region 勾选已经选中的数据
|
|
var _list = gridControl1.DataSource as List<view_jingdong_form_select_tgw>;
|
|
if (_list != null && tgws != null && tgws.Count != 0)
|
|
{
|
|
var member = this.comboBoxEdit1.SelectedItem as fl_cps_member;
|
|
var _tgws = tgws.Where(f => f.Member.username == member.username).ToList();
|
|
for (int i = 0; i < _tgws.Count; i++)
|
|
{
|
|
gridView1.SelectRow(_list.IndexOf(_list.FirstOrDefault(f => f.p_id == _tgws[i].Pid)));
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Column.AbsoluteIndex == -1)
|
|
{
|
|
var flag = e.CellValue.ToString().ToLower() != "true";
|
|
var pid = gridView1.GetRowCellDisplayText(gridView1.FocusedRowHandle, gridView1.Columns["p_id"]);//获取群号
|
|
if (string.IsNullOrEmpty(pid)) throw new Exception("您当前没有选中任何一行!");
|
|
var _tgw = tgws.FirstOrDefault(f => f.Pid == pid);
|
|
if (flag)//增加到集合中
|
|
{
|
|
if (_tgw == null)
|
|
{
|
|
var member = this.comboBoxEdit1.SelectedItem as fl_cps_member;
|
|
_tgw = new Tuiguangwei()
|
|
{
|
|
Member = new fl_cps_member() { username = member.username, usernick = member.usernick },
|
|
Name = gridView1.GetRowCellDisplayText(gridView1.FocusedRowHandle, gridView1.Columns["name"]),
|
|
Pid = pid
|
|
};
|
|
tgws.Add(_tgw);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_tgw != null)
|
|
tgws.Remove(_tgw);
|
|
}
|
|
gridControl2.DataSource = null;
|
|
gridControl2.DataSource = tgws;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
private void gridView2_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Column.FieldName == "Member")
|
|
{
|
|
var cps = e.Value as fl_cps_member;
|
|
e.DisplayText = cps.usernick;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("组名称不能为空");
|
|
//if (string.IsNullOrWhiteSpace(memoEdit1.Text)) throw new Exception("请选择推广位");
|
|
if (gridView2.RowCount == 0) throw new Exception("请选择推广位");
|
|
var session = ApiClient.GetSession();
|
|
if (adzone_group == null)
|
|
{
|
|
adzone_group = new fl_adzone_group() { adzones = CsharpHttpHelper.HttpHelper.ObjectToJson(tgws), cps_type = CpsType.京东联盟, name = textBox1.Text.Trim() };
|
|
}
|
|
else
|
|
{
|
|
adzone_group.adzones = CsharpHttpHelper.HttpHelper.ObjectToJson(tgws);
|
|
adzone_group.name = textBox1.Text.Trim();
|
|
}
|
|
adzone_group = session.Saveable(adzone_group).ExecuteReturnEntity();
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex.Message.Contains("UNIQUE constraint failed"))
|
|
ShowError("推广位组名称已经存在");
|
|
else
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void simpleButton3_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.No;
|
|
this.Close();
|
|
}
|
|
|
|
private void 删除勾选推广位ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rownumber = gridView2.GetSelectedRows().OrderByDescending(f => f).ToList();//获取选中行号;
|
|
if (rownumber != null & rownumber.Count != 0)
|
|
{
|
|
foreach (var item in rownumber)
|
|
{
|
|
var _tgw = gridView2.GetRow(item) as Tuiguangwei;
|
|
tgws.Remove(_tgw);
|
|
}
|
|
gridControl2.DataSource = null;
|
|
gridControl2.DataSource = tgws;
|
|
ShowSuccess("删除成功");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void 删除全部推广位ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
tgws.Clear();
|
|
gridControl2.DataSource = null;
|
|
ShowSuccess("删除成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
}
|
|
} |