628 lines
23 KiB
C#
628 lines
23 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using UI.Framework.Forms;
|
|
using CsharpHttpHelper;
|
|
using System.Collections;
|
|
using System.Reflection;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
|
|
namespace Grant.Framework
|
|
{
|
|
public partial class AuthorizationManage : BaseForm
|
|
{
|
|
public AuthorizationManage()
|
|
{
|
|
InitializeComponent();
|
|
|
|
//this.pageControl1.Bind(SerchData_Robot,this.gridControl1,1,true,true);
|
|
}
|
|
|
|
private UI.Framework.Controls.PageControl.SerchResult SerchData_Robot(int index, int pagesize)
|
|
{
|
|
try
|
|
{
|
|
string keyword = string.Empty;
|
|
this.UpdateUI(() =>
|
|
{
|
|
keyword = this.textEdit1.Text;
|
|
});
|
|
var rst = SendCoredata("search_customers", new
|
|
{
|
|
keyword = keyword,
|
|
page = index,
|
|
limit = pagesize,
|
|
}) as Dictionary<string, object>;
|
|
|
|
var data = rst["data"] as object[];
|
|
List<_TempCoustomer> list = new List<_TempCoustomer>();
|
|
foreach (Dictionary<string, object> item in data) list.Add(item.ConvertToObj<_TempCoustomer>());
|
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = list, Total = int.Parse(rst["total"].ToString()) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.UpdateUI(delegate ()
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public class _WebResult
|
|
{
|
|
public bool ok { get; set; }
|
|
public object message { get; set; }
|
|
public int time { get; set; }
|
|
public string method { get; set; }
|
|
public string req { get; set; }
|
|
|
|
}
|
|
|
|
public class _Member
|
|
{
|
|
public string aid { get; set; }
|
|
public string username { get; set; }
|
|
public string crttime { get; set; }
|
|
public string point { get; set; }
|
|
public string rmb { get; set; }
|
|
public string sumpoint { get; set; }
|
|
public string status { get; set; }
|
|
public string agio { get; set; }
|
|
public string phone { get; set; }
|
|
}
|
|
|
|
|
|
public class _TempCoustomer
|
|
{
|
|
//登录者的id
|
|
public int id { get; set; }
|
|
//机器人的账号
|
|
public string cardname { get; set; }
|
|
public string softid { get; set; }
|
|
public string softnick { get; set; }
|
|
public string accountsid { get; set; }
|
|
public DateTime crtTime { get; set; }
|
|
public DateTime endTime { get; set; }
|
|
public string remark { get; set; }
|
|
}
|
|
/// <summary>
|
|
/// 软件类型
|
|
/// </summary>
|
|
public class _SoftWare
|
|
{
|
|
public int id { get; set; }
|
|
public string softwarename { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 卡密信息
|
|
/// </summary>
|
|
public class _Card
|
|
{
|
|
public string id { get; set; }
|
|
public string cardid { get; set; }
|
|
public string crttime { get; set; }
|
|
public string endtime { get; set; }
|
|
public string robotname { get; set; }
|
|
public string software_type { get; set; }
|
|
public string day { get; set; }
|
|
public string usingname { get; set; }
|
|
public string usingid { get; set; }
|
|
public string remark { get; set; }
|
|
}
|
|
|
|
private string appid = "1";
|
|
|
|
|
|
private string token;
|
|
private Dictionary<string, object> LoginResult;
|
|
public object SendCoredata(string method, object data)
|
|
{
|
|
var obj = CsharpHttpHelper.HttpHelper.ObjectToJson(data);
|
|
var dic = CsharpHttpHelper.HttpExtend.JsonToDictionary(obj);
|
|
if (!string.IsNullOrEmpty(token)) dic["token"] = token;
|
|
dic["time"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
var http = new HttpHelper();
|
|
var send = $"appid={appid}&method={method}&data={System.Web.HttpUtility.UrlEncode(HttpHelper.ObjectToJson(dic), Encoding.UTF8)}";
|
|
var item = http.GetItem("http://core.api.52cmg.cn/api/open.asmx/send_data", "", send);
|
|
item.Timeout = item.ReadWriteTimeout = 30000;
|
|
var html = http.GetHtml(item).Html;
|
|
var rst = HttpHelper.JsonToObject<_WebResult>(html) as _WebResult;
|
|
if (rst == null) throw new Exception(html);
|
|
if (!rst.ok) throw new Exception(rst.message.ToString());
|
|
return rst.message;
|
|
}
|
|
List<_SoftWare> _software_list = new List<_SoftWare>() {
|
|
new _SoftWare(){ id = 1001,softwarename = "微信授权"},
|
|
new _SoftWare(){ id = 1002,softwarename = "QQ授权"}
|
|
};
|
|
|
|
private void AuthorizationManage_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//this.Size = new Size(487, 386);
|
|
comboBox1.DataSource = _software_list;
|
|
comboBox1.DisplayMember = "softwarename";
|
|
comboBox1.ValueMember = "id";
|
|
|
|
var acc = GrantClient.Get().accounts;
|
|
var rst = SendCoredata("login", new { username = acc.username, userpass = acc.userpass }) as Dictionary<string, object>;
|
|
this.token = rst["token"].ToString();
|
|
this.LoginResult = rst["user"] as Dictionary<string, object>;
|
|
var status = int.Parse(LoginResult["status"].ToString());
|
|
xtraTabControl1.TabPages[3].PageVisible = status > 0;//为代理显示
|
|
simpleButton6.Visible = status > 0;
|
|
|
|
var about = GrantClient.Get().About;
|
|
//if (status > 0 || (GrantClient.Get().About.ContainsKey("ispayform") && GrantClient.Get().About["ispayform"].ToString() == "1"))
|
|
if (status > 0 || (about.ContainsKey("ispayform") && about["ispayform"].ToString() == "1"))
|
|
xtraTabPage1.PageVisible = true;//为代理显示
|
|
|
|
|
|
this.pageControl1.Bind(SerchData_Robot, this.gridControl1, 60, false, true);
|
|
this.pageControl2.Bind(SerchData_Card, this.gridControl2, 60, false, true);
|
|
this.pageControl3.Bind(SerchData_Customer, this.gridControl3, 60, false, true);
|
|
this.pageControl4.Bind(SerchData_Members, this.gridControl4, 60, false, true);
|
|
this.xtraTabControl1_SelectedPageChanged(null, null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string mess = ex.Message;
|
|
if (mess == "请求被中止: 操作超时。")
|
|
mess = "系统繁忙,请稍后重试!";
|
|
BaseForm.ShowError(mess);
|
|
this.Close();
|
|
}
|
|
|
|
}
|
|
|
|
private UI.Framework.Controls.PageControl.SerchResult SerchData_Members(int index, int pagesize)
|
|
{
|
|
try
|
|
{
|
|
string keyword = string.Empty;
|
|
this.UpdateUI(() =>
|
|
{
|
|
keyword = this.textEdit3.Text;
|
|
});
|
|
var rst = SendCoredata("member_list", new
|
|
{
|
|
page = index,
|
|
limit = pagesize,
|
|
keyword = keyword
|
|
}) as Dictionary<string, object>;
|
|
var data = rst["data"] as object[];
|
|
List<_Member> list = new List<_Member>();
|
|
foreach (Dictionary<string, object> item in data) list.Add(item.ConvertToObj<_Member>());
|
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = list, Total = int.Parse(rst["total"].ToString()) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.UpdateUI(delegate ()
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private UI.Framework.Controls.PageControl.SerchResult SerchData_Customer(int index, int pagesize)
|
|
{
|
|
try
|
|
{
|
|
string keyword = string.Empty;
|
|
this.UpdateUI(() =>
|
|
{
|
|
keyword = this.textEdit2.Text;
|
|
});
|
|
|
|
Dictionary<string, object> rst = null;
|
|
if (textEdit2.Tag == null)
|
|
{
|
|
rst = SendCoredata("find_customer_goods_pros", new
|
|
{
|
|
page = index,
|
|
limit = pagesize,
|
|
keyword = keyword
|
|
}) as Dictionary<string, object>;
|
|
}
|
|
else
|
|
{
|
|
rst = SendCoredata("find_customer_pros", new
|
|
{
|
|
aid = textEdit2.Tag.ToString(),
|
|
page = index,
|
|
limit = pagesize,
|
|
keyword = string.Empty
|
|
}) as Dictionary<string, object>;
|
|
}
|
|
var data = rst["data"] as object[];
|
|
List<_TempCoustomer> list = new List<_TempCoustomer>();
|
|
foreach (Dictionary<string, object> item in data) list.Add(item.ConvertToObj<_TempCoustomer>());
|
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = list, Total = int.Parse(rst["total"].ToString()) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.UpdateUI(delegate ()
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
});
|
|
}
|
|
finally
|
|
{
|
|
textEdit2.Tag = null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
|
|
{
|
|
var view = sender as GridView;
|
|
|
|
var row = view.GetRow(e.ListSourceRowIndex) as _TempCoustomer;
|
|
if (row != null)
|
|
{
|
|
if (e.Column.Caption == "剩余时间")
|
|
{
|
|
var end = row.endTime - DateTime.Now;
|
|
if (end.TotalDays < 0) e.DisplayText = "已过期";
|
|
else e.DisplayText = Math.Ceiling(end.TotalDays) + "天";
|
|
}
|
|
//else if (e.Column.Caption == "类型")
|
|
// e.DisplayText = GETSoftName(row.softid);
|
|
}
|
|
}
|
|
|
|
private void 卡号续费ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int[] rows = null;
|
|
GridView view = null;
|
|
if (xtraTabControl1.SelectedTabPage.Text == "代理操作" && tabPane1.SelectedPage.Caption == "机器人授权")
|
|
view = gridView3;
|
|
else if (xtraTabControl1.SelectedTabPage.Text == "授权账号 - 管理")
|
|
view = gridView1;
|
|
rows = view.GetSelectedRows();
|
|
if (rows.Length != 0)
|
|
{
|
|
var row = view.GetRow(rows[0]) as _TempCoustomer;
|
|
if (row != null)
|
|
{
|
|
var cardForm = new GetCardForm();
|
|
if (cardForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var id = row.id.ToString();//登录者的id
|
|
var cardname = row.cardname;//机器人的账号
|
|
var card = cardForm.CardStr;//充值的卡号
|
|
|
|
var data = SendCoredata("card_authorize", new
|
|
{
|
|
id = id,
|
|
cardname = cardname,
|
|
card = card,
|
|
});
|
|
ShowSuccess(data.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private UI.Framework.Controls.PageControl.SerchResult SerchData_Card(int index, int pagesize)
|
|
{
|
|
try
|
|
{
|
|
int id = 0;
|
|
string keyword = string.Empty;
|
|
this.UpdateUI(() =>
|
|
{
|
|
id = (this.comboBox1.SelectedItem as _SoftWare).id;
|
|
keyword = this.textBox2.Text.Trim();
|
|
});
|
|
var rst = SendCoredata("find_cardlist", new
|
|
{
|
|
sid = id,//查询软件的授权类型
|
|
page = index,
|
|
limit = pagesize,
|
|
keyword = keyword
|
|
}) as Dictionary<string, object>;
|
|
var data = rst["data"] as object[];
|
|
List<_Card> list = new List<_Card>();
|
|
foreach (Dictionary<string, object> item in data) list.Add(item.ConvertToObj<_Card>());
|
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = list, Total = int.Parse(rst["total"].ToString()) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.UpdateUI(delegate ()
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
try
|
|
{
|
|
var rst = SendCoredata("online_addpoint", new
|
|
{
|
|
orderid = this.textBox1.Text
|
|
});
|
|
BaseForm.ShowSuccess("恭喜您,充值成功!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
|
|
{
|
|
if (this.xtraTabControl1.SelectedTabPage == this.xtraTabPage1) //充值
|
|
{
|
|
this.Size = new Size(487, 386);
|
|
}
|
|
else
|
|
{
|
|
this.Size = new Size(793, 514);
|
|
}
|
|
}
|
|
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|
{
|
|
this.pageControl1.GotoPage(1);
|
|
}
|
|
|
|
private void simpleButton3_Click(object sender, EventArgs e)
|
|
{
|
|
this.pageControl2.GotoPage(1);
|
|
}
|
|
|
|
private void simpleButton4_Click(object sender, EventArgs e)
|
|
{
|
|
this.pageControl3.GotoPage(1);
|
|
}
|
|
|
|
private void simpleButton5_Click(object sender, EventArgs e)
|
|
{
|
|
this.pageControl4.GotoPage(1);
|
|
}
|
|
|
|
private void simpleButton6_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var createCardForm = new CreateCardForm(GrantClient.Get().accounts.username, _software_list);
|
|
if (createCardForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var data = SendCoredata("create_cards", new
|
|
{
|
|
//username = System.Web.HttpUtility.UrlEncode(createCardForm.username, Encoding.GetEncoding("GBK")),
|
|
username = createCardForm.username,
|
|
sid = createCardForm.sid,
|
|
number = createCardForm.number,
|
|
type = createCardForm.type,
|
|
remark = createCardForm.remark
|
|
});
|
|
ShowSuccess(data.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void 在线续费ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int[] rows = null;
|
|
GridView view = null;
|
|
if (xtraTabControl1.SelectedTabPage.Text == "代理操作" && tabPane1.SelectedPage.Caption == "机器人授权")
|
|
view = gridView3;
|
|
else if (xtraTabControl1.SelectedTabPage.Text == "授权账号 - 管理")
|
|
view = gridView1;
|
|
rows = view.GetSelectedRows();
|
|
|
|
if (rows.Length != 0)
|
|
{
|
|
var row = gridView1.GetRow(rows[0]) as _TempCoustomer;
|
|
if (row != null)
|
|
{
|
|
var onlineRenewalForm = new OnlineRenewalForm(row.cardname);
|
|
if (onlineRenewalForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var data = SendCoredata("online_recharge", new
|
|
{
|
|
cardname = row.cardname,
|
|
sid = row.softid,
|
|
type = onlineRenewalForm.type
|
|
});
|
|
ShowSuccess(data.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
|
|
{
|
|
int[] rows = null;
|
|
if (xtraTabControl1.SelectedTabPage.Text == "代理操作" && tabPane1.SelectedPage.Caption == "机器人授权")
|
|
{
|
|
rows = gridView3.GetSelectedRows();
|
|
this.更换授权ToolStripMenuItem.Enabled = false;
|
|
}
|
|
else if (xtraTabControl1.SelectedTabPage.Text == "授权账号 - 管理")
|
|
{
|
|
rows = gridView1.GetSelectedRows();
|
|
this.更换授权ToolStripMenuItem.Enabled = true;
|
|
}
|
|
if (rows == null || 0 == rows.Length) e.Cancel = true;
|
|
}
|
|
|
|
private void 更换授权ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rows = gridView1.GetSelectedRows();
|
|
if (rows.Length != 0)
|
|
{
|
|
var row = gridView1.GetRow(rows[0]) as _TempCoustomer;
|
|
if (row != null)
|
|
{
|
|
var replaceAuthorizeForm = new ReplaceAuthorizeForm(row.cardname);
|
|
if (replaceAuthorizeForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var data = SendCoredata("replace_authorize", new
|
|
{
|
|
cardname1 = replaceAuthorizeForm.cardname1,
|
|
cardname2 = replaceAuthorizeForm.cardname2,
|
|
});
|
|
ShowSuccess(data.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void simpleButton7_Click(object sender, EventArgs e)
|
|
{
|
|
new SetOEM(this).ShowDialog();
|
|
}
|
|
|
|
private void 设置OEMToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rows = gridView4.GetSelectedRows();
|
|
if (rows.Length != 0)
|
|
{
|
|
var row = gridView4.GetRow(rows[0]) as _Member;
|
|
if (row != null)
|
|
new SetOEM(this, row.aid).ShowDialog();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void 搜索机器人账号ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rows = gridView4.GetSelectedRows();
|
|
if (rows.Length != 0)
|
|
{
|
|
var row = gridView4.GetRow(rows[0]) as _Member;
|
|
if (row != null)
|
|
{
|
|
textEdit2.Text = row.username;
|
|
textEdit2.Tag = row.aid;
|
|
tabPane1.SelectedPageIndex = 0;
|
|
this.pageControl3.GotoPage(1);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void gridView4_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Column.FieldName == "agio")
|
|
{
|
|
if (e.Value.ToString() == "1")
|
|
e.DisplayText = "无折扣";
|
|
else if (e.Value.ToString() == "0.4")
|
|
e.DisplayText = "4折";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
private void contextMenuStrip2_Opening(object sender, CancelEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var acc = GrantClient.Get().accounts;
|
|
var rst = SendCoredata("login", new { username = acc.username, userpass = acc.userpass }) as Dictionary<string, object>;
|
|
this.token = rst["token"].ToString();
|
|
this.LoginResult = rst["user"] as Dictionary<string, object>;
|
|
var status = int.Parse(LoginResult["status"].ToString());
|
|
if (status == 3)
|
|
this.充值积分ToolStripMenuItem.Visible = true;
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
private void 充值积分ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rows = gridView4.GetSelectedRows();
|
|
if (rows.Length != 0)
|
|
{
|
|
var row = gridView4.GetRow(rows[0]) as _Member;
|
|
if (row != null)
|
|
{
|
|
var rechargePointForm = new RechargePointForm(row.username);
|
|
if (rechargePointForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var data = SendCoredata("admin_recharge_point", new
|
|
{
|
|
username = rechargePointForm.username,
|
|
point = rechargePointForm.point,
|
|
});
|
|
ShowSuccess(data.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|