299 lines
12 KiB
C#
299 lines
12 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.Cps;
|
|||
|
using Api.Framework.Enums;
|
|||
|
using Api.Framework.Model;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using DevExpress.XtraGrid.Views.Grid;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using UI.Framework.Forms;
|
|||
|
|
|||
|
namespace FLSystem.Forms
|
|||
|
{
|
|||
|
public partial class tb_adzone_group_form : BaseForm
|
|||
|
{
|
|||
|
public class view_alimama_form_select_tgw
|
|||
|
{
|
|||
|
public string name { get; set; }
|
|||
|
public string pid { get; set; }
|
|||
|
public string membernick { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
SqlSugarClient session = null;
|
|||
|
List<Tuiguangwei> tgws = null;
|
|||
|
public fl_adzone_group adzone_group = null;
|
|||
|
|
|||
|
public tb_adzone_group_form(long id = 0)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
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>();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (!this.IsDisposed) ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void simpleButton3_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.DialogResult = System.Windows.Forms.DialogResult.No;
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
|
|||
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("组名称不能为空");
|
|||
|
if (gridView2.RowCount == 0) throw new Exception("请选择推广位");
|
|||
|
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") || ex.Message.Contains("Duplicate entry"))
|
|||
|
ShowError("推广位组名称已经存在");
|
|||
|
else
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void tb_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.gridView1.CustomDrawRowIndicator += gridView1_CustomDrawRowIndicator;
|
|||
|
|
|||
|
this.pageControl1.Bind(delegate (int page, int pagesize)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var member = this.comboBoxEdit1.SelectedItem as fl_cps_member;
|
|||
|
if (member == null) throw new Exception("找不到,您选择的账号!");
|
|||
|
var api = CpsClient.CreateAlimamaRequest(member);
|
|||
|
var result = api.AdzoneManage(page, pagesize);
|
|||
|
this.Invoke(new Action(() =>
|
|||
|
{
|
|||
|
label6.Visible = false;
|
|||
|
}));
|
|||
|
var list = result["pagelist"] as ArrayList;
|
|||
|
var _list = new List<view_alimama_form_select_tgw>();
|
|||
|
foreach (Dictionary<string, object> item in list)
|
|||
|
{
|
|||
|
_list.Add(new view_alimama_form_select_tgw() { pid = item["adzonePid"].ToString(), membernick = member.usernick, name = item["name"].ToString() });
|
|||
|
}
|
|||
|
var paginator = result["paginator"] as Dictionary<string, object>;
|
|||
|
|
|||
|
gridControl1.DataSource = _list;
|
|||
|
#region 勾选已经选中的数据
|
|||
|
if (_list != null && tgws != null && tgws.Count != 0)
|
|||
|
{
|
|||
|
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.pid == _tgws[i].Pid)));
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = _list, Total = int.Parse(paginator["items"].ToString()) };
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (!this.IsDisposed)
|
|||
|
this.UpdateUI(() =>
|
|||
|
{
|
|||
|
label6.Visible = true;
|
|||
|
label6.Text = ex.Message;
|
|||
|
});
|
|||
|
}
|
|||
|
return null;
|
|||
|
|
|||
|
}, this.gridControl1, 40, true, true);
|
|||
|
|
|||
|
this.comboBoxEdit1.Properties.Items.Clear();
|
|||
|
this.comboBoxEdit1.Properties.Items.AddRange(members);
|
|||
|
this.comboBoxEdit1.SelectedIndex = 0;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (!this.IsDisposed) ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
|
|||
|
{
|
|||
|
if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
|||
|
}
|
|||
|
|
|||
|
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.pageControl1.GotoPage(1);
|
|||
|
}
|
|||
|
|
|||
|
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["pid"]);//获取群号
|
|||
|
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)
|
|||
|
{ }
|
|||
|
}
|
|||
|
|
|||
|
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)
|
|||
|
{ }
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
this.pageControl1.GotoPage(1);
|
|||
|
ShowSuccess("删除成功");
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void 删除全部推广位ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
tgws.Clear();
|
|||
|
gridControl2.DataSource = null;
|
|||
|
this.pageControl1.GotoPage(1);
|
|||
|
ShowSuccess("删除成功");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (e.ControllerRow < 0)
|
|||
|
{
|
|||
|
var member = this.comboBoxEdit1.SelectedItem as fl_cps_member;
|
|||
|
var tgw_temp = tgws.Where(f => f.Member.username == member.username).ToList();
|
|||
|
foreach (var item in tgw_temp)
|
|||
|
{
|
|||
|
tgws.Remove(item);
|
|||
|
}
|
|||
|
if (gridView1.SelectedRowsCount != 0)
|
|||
|
{
|
|||
|
var list = gridControl1.DataSource as List<view_alimama_form_select_tgw>;
|
|||
|
foreach (var item in list)
|
|||
|
{
|
|||
|
var _tgw = new Tuiguangwei()
|
|||
|
{
|
|||
|
Member = new fl_cps_member() { username = member.username, usernick = member.usernick },
|
|||
|
Name = item.name,
|
|||
|
Pid = item.pid
|
|||
|
};
|
|||
|
tgws.Add(_tgw);
|
|||
|
}
|
|||
|
}
|
|||
|
gridControl2.DataSource = null;
|
|||
|
gridControl2.DataSource = tgws;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|