using HZH_Controls.Controls;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.CodeDom;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using WindowsFormsApp1.entity;
|
using WindowsFormsApp1.entity.tb;
|
using WindowsFormsApp1.utils;
|
using WindowsFormsApp1.utils.tb;
|
using WindowsFormsApp1.utils.ui;
|
|
namespace WindowsFormsApp1
|
{
|
public partial class Main : Form
|
{
|
public Main()
|
{
|
InitializeComponent();
|
InitSkin();
|
InitDataGridView();
|
InitLogListView();
|
InitData();
|
initTextBox();
|
ShowLog();
|
}
|
|
|
//初始化皮肤颜色
|
private void InitSkin()
|
{
|
//this.textBox
|
}
|
private void InitData()
|
{
|
this.ucHorizontalList1.SelectedItemEvent += new System.EventHandler(this.click_Class);
|
this.sdljGoodsTimer.Interval = 1000*60*5;
|
this.sdljGoodsTimer.Start();
|
this.tabControl1.SendToBack();
|
|
//初始化账户登录,淘宝登录
|
UserInfo user= LoginManager.GetLoginUser();
|
if (user != null) {//自动登录
|
LoginManager.LoginSuccess(user);
|
//设置登录状态
|
setUserInfo(user);
|
}
|
|
//初始化淘宝登录
|
List<TBAccountLogin> accountList= TBAccountManager.GetAccountList();
|
if (accountList != null) {
|
foreach (TBAccountLogin account in accountList) {
|
account.Login = false;
|
if (!Constant.tbAccountMap.ContainsKey(account.Index))//去重
|
Constant.tbAccountMap.Add( account.Index,account);
|
}
|
}
|
//开启日志显示
|
this.logTimer.Start();
|
//获取配置参数
|
ApiUtil.GetConfig((String result) =>
|
{
|
JObject obj= JObject.Parse(result);
|
if (Convert.ToInt32(obj["code"]) == 0) {
|
|
List<Config> configList= JsonConvert.DeserializeObject <List<Config>>(obj["data"].ToString());
|
if (configList != null)
|
foreach (Config cf in configList) {
|
SQLiteDataBaseUtil.getInstance().AddConfig(cf);
|
}
|
}
|
|
});
|
}
|
|
//验证登录
|
private bool IsLogin() {
|
if (LoginManager.GetLoginUser() != null)
|
return true;
|
MessageBox.Show("请登录");
|
return false;
|
}
|
|
|
//初始化listview
|
private void InitLogListView() {
|
this.listView1.GridLines = false;
|
this.listView1.View = View.Details;
|
this.listView1.HeaderStyle = ColumnHeaderStyle.None;
|
ColumnHeader ch = new ColumnHeader();
|
ch.Text = ""; //设置列标题
|
ch.Width = 0; //设置列宽度
|
ch.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
|
this.listView1.Columns.Add(ch);
|
ch = new ColumnHeader();
|
ch.Text = ""; //设置列标题
|
ch.Width = 120; //设置列宽度
|
ch.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
|
this.listView1.Columns.Add(ch);
|
|
ch = new ColumnHeader();
|
ch.Text = ""; //设置列标题
|
ch.Width = 300; //设置列宽度
|
ch.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
|
this.listView1.Columns.Add(ch);
|
}
|
|
//显示日志
|
private void ShowLog() {
|
List <LogInfo> logList= LogManager.GetLogList();
|
if (this.listView1.Items.Count >= logList.Count)
|
return;
|
this.listView1.BeginUpdate();
|
|
for (int i = this.listView1.Items.Count; i < logList.Count; i++) {
|
LogInfo log = logList[i];
|
ListViewItem lvi = new ListViewItem();
|
lvi.Font = new Font("微软雅黑", 9, FontStyle.Regular);
|
lvi.SubItems.Add(TimeUtil.GetGeneralTime(log.Time, "yyyy-MM-dd HH:mm"));
|
lvi.SubItems.Add(log.Content);
|
if (log.Type == LogInfo.TYPE_DENGER)
|
lvi.ForeColor = Color.Red;
|
else if (log.Type == LogInfo.TYPE_SAFE)
|
lvi.ForeColor = Color.Green;
|
else if (log.Type == LogInfo.TYPE_NORMAL)
|
lvi.ForeColor = Color.Gray;
|
this.listView1.Items.Add(lvi);
|
}
|
this.listView1.Items[this.listView1.Items.Count - 1].EnsureVisible();
|
this.listView1.EndUpdate();
|
}
|
|
|
|
private void setTextBoxPrompt(TextBoxEx ex,String text) {
|
ex.PromptFont = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
|
ex.PromptText = text;
|
}
|
|
private void initTextBox() {
|
|
}
|
|
/**
|
*
|
*
|
* 商品开始
|
*
|
*
|
*
|
*/
|
|
delegate void SetGoodsAndClassDataDelegate(JObject obj);
|
|
void setGoodsAndClassData(JObject obj) {
|
List<GoodsClass> goodsClassList = new List<GoodsClass>();
|
List<FirstOrderSubInfo> goodsList = new List<FirstOrderSubInfo>();
|
if (obj["code"].ToString() == "0")
|
{
|
//解析分类
|
var array = JArray.Parse(obj["data"]["goodsClass"].ToString());
|
goodsClassList = array.ToObject<List<GoodsClass>>();
|
|
//解析数据
|
array = JArray.Parse(obj["data"]["goods"].ToString());
|
goodsList = array.ToObject<List<FirstOrderSubInfo>>();
|
}
|
|
SetClassData(goodsClassList);
|
|
var hasMore= obj["data"]["hasMore"];
|
|
SetGoodsData((bool) hasMore, goodsList);
|
}
|
|
private void search(int page, SearchInfo info)
|
{
|
ApiUtil.searchGoods( classType, info, page, new OnSuccess((String result)=> {
|
JObject obj = JObject.Parse(result);
|
this.BeginInvoke(new SetGoodsAndClassDataDelegate(setGoodsAndClassData), obj);
|
}));
|
}
|
|
int page = 1;
|
private List<FirstOrderSubInfo> infoList;
|
//设置列表的数据
|
private void SetGoodsData(bool hasMore, List<FirstOrderSubInfo> infoList) {
|
this.infoList = infoList;
|
this.dataGridView1.Rows.Clear();
|
foreach (FirstOrderSubInfo info in infoList) {
|
int index = this.dataGridView1.Rows.Add();
|
//this.dataGridView1.Rows[index].Cells[0].Value = info.GoodsId;
|
this.dataGridView1.Rows[index].Cells[1].Value = info.Title;
|
this.dataGridView1.Rows[index].Cells[2].Value = info.SalesNum;
|
this.dataGridView1.Rows[index].Cells[3].Value = info.ZkPrice;
|
this.dataGridView1.Rows[index].Cells[4].Value = info.CouponAmount;
|
this.dataGridView1.Rows[index].Cells[5].Value = info.CouponPrice;
|
this.dataGridView1.Rows[index].Cells[6].Value = info.LijinAmount;
|
this.dataGridView1.Rows[index].Cells[7].Value = info.ActualPrice;
|
this.dataGridView1.Rows[index].Cells[8].Value = info.Commission;
|
this.dataGridView1.Rows[index].Cells[9].Value = info.CommissionRate;
|
this.dataGridView1.Rows[index].Cells[10].Value = info.Tmall == 1 ? "天猫" : "淘宝";
|
if(info.Mark)
|
this.dataGridView1.Rows[index].DefaultCellStyle.BackColor = Color.Red;
|
}
|
|
if (hasMore)
|
{
|
this.label36.ForeColor = ColorUtil.GetThemeColor();
|
}
|
else {
|
this.label36.ForeColor = ColorUtil.GetDefaultColor();
|
}
|
|
if (page <= 1)
|
{
|
this.label35.ForeColor = ColorUtil.GetDefaultColor();
|
}
|
else {
|
this.label35.ForeColor = ColorUtil.GetThemeColor();
|
}
|
|
}
|
|
|
private void InitDataGridView() {
|
this.dataGridView1.Columns[0].Width=40;
|
this.dataGridView1.Columns[1].Width = 280;
|
this.dataGridView1.Columns[2].Width = 70;
|
this.dataGridView1.Columns[3].Width = 70;
|
this.dataGridView1.Columns[4].Width = 75;
|
this.dataGridView1.Columns[5].Width = 70;
|
this.dataGridView1.Columns[6].Width = 55;
|
this.dataGridView1.Columns[7].Width = 65;
|
this.dataGridView1.Columns[8].Width = 75;
|
this.dataGridView1.Columns[9].Width = 75;
|
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Menu;
|
dataGridViewCellStyle1.Font = new System.Drawing.Font("微软雅黑", 9F);
|
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
|
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
|
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
|
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
|
}
|
|
|
|
|
private void SetClassData(List<GoodsClass> goodsClassList) {
|
List<KeyValuePair<string, string>> lstHL = new List<KeyValuePair<string, string>>();
|
int p = 0;
|
int i = 0;
|
foreach (GoodsClass goodsClass in goodsClassList)
|
{
|
|
lstHL.Add(new KeyValuePair<string, string>(goodsClass.Id+"", goodsClass.Name));
|
if (goodsClass.Selected)
|
p = i;
|
i++;
|
}
|
this.ucHorizontalList1.DataSource = lstHL;
|
this.ucHorizontalList1.SetSelect(lstHL[p].Key);
|
}
|
|
int classType = 0;
|
|
private void click_Class(object sender, EventArgs e) {
|
KS_Controls.Controls.KSHorizontalListItem item = (KS_Controls.Controls.KSHorizontalListItem) sender;
|
int key= Convert.ToInt32(item.DataSource.Key);
|
if (classType == key) {
|
return;
|
}
|
Console.WriteLine("分类:" + item.DataSource.Key);
|
page = 1;
|
SearchInfo searchInfo =this.kssdljSearchPannel1.getSearchFilter();
|
classType = Convert.ToInt32(item.DataSource.Key);
|
searchInfo.Key = this.ucTextBoxEx1.InputText;
|
search(page, searchInfo);
|
}
|
|
//筛选
|
private void button1_Click_1(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
|
InputDialog input = new InputDialog("应用筛选命名", "应用筛选是自动生成文案云发单必要设置", new OnSuccess((String result)=> {
|
|
//TODO 插入引单组合
|
FormUtil.ShowDialog(new YingDanSelect());
|
|
|
}));
|
|
FormUtil.ShowDialog(input);
|
}
|
|
|
//搜索
|
private void button5_Click_2(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
classType = 0;
|
page = 1;
|
SearchInfo searchInfo = this.kssdljSearchPannel1.getSearchFilter();
|
searchInfo.Key = this.ucTextBoxEx1.InputText;
|
search(page, searchInfo);
|
}
|
|
|
//下一页
|
private void next_Click(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
page++;
|
SearchInfo searchInfo = this.kssdljSearchPannel1.getSearchFilter();
|
searchInfo.Key = this.ucTextBoxEx1.InputText;
|
search(page, searchInfo);
|
}
|
|
//上一页
|
private void before_Click(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
page--;
|
SearchInfo searchInfo = this.kssdljSearchPannel1.getSearchFilter();
|
searchInfo.Key = this.ucTextBoxEx1.InputText;
|
search(page, searchInfo);
|
}
|
|
//选中某一行
|
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
{
|
int index= e.RowIndex;
|
if (index > -1&& this.infoList!=null)
|
{
|
if (this.infoList.Count > index)
|
{
|
|
}
|
}
|
}
|
|
|
/**
|
*
|
*
|
* 商品结束
|
*
|
*
|
*/
|
|
private void getSDLJGoods(object sender, EventArgs e) {
|
Console.WriteLine("getSDLJGoods");
|
if (Login.loginContainer != null)
|
foreach (int key in Login.loginContainer.Keys)
|
{
|
String baseUrl = null;
|
if (Constant.sdljBaseUrl.ContainsKey(key))
|
{
|
baseUrl = Constant.sdljBaseUrl[key];
|
}
|
if (baseUrl == null || baseUrl.Trim().Length == 0)
|
continue;
|
|
Thread thread = new Thread(()=> {
|
Console.WriteLine("执行线程");
|
new SDLJGoodsManager().StartRequestGoods(baseUrl, key);
|
});
|
thread.Start();
|
}
|
}
|
|
|
/*
|
*
|
*刷新Cookie结束
|
*
|
*/
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
/*
|
*淘宝登录
|
*/
|
private void tbLogin_Click(object sender, EventArgs e)
|
{
|
TBLogin tbLogin = new TBLogin();
|
tbLogin.Tag = "http://www.taobao.com";
|
tbLogin.ShowDialog();
|
}
|
|
//设置用户信息
|
private void setUserInfo(UserInfo user) {
|
if (user != null)
|
{
|
|
this.label37.Visible = true;
|
if (user.SdljShareExpireTime == null)
|
{ //过期
|
this.button8.Text = "升级共享";
|
this.button8.Click -= new System.EventHandler(this.login_Click);
|
this.button8.Click += new System.EventHandler(this.upgrade_Click);//升级
|
}
|
else
|
{
|
this.button8.Text = "共享续期";
|
this.button8.Click -= new System.EventHandler(this.login_Click);
|
this.button8.Click += new System.EventHandler(this.upgrade_Click);//升级
|
}
|
this.label37.Visible = true;
|
this.button8.Click -= new System.EventHandler(this.login_Click);
|
}
|
else {
|
this.label37.Visible = false;
|
this.button8.Text = "登录";
|
this.button8.Click += new System.EventHandler(this.login_Click);
|
this.button8.Click -= new System.EventHandler(this.upgrade_Click);//升级
|
}
|
|
}
|
|
|
//用户登录
|
private void login_Click(object sender, EventArgs e) {
|
LoginNew loginNew = new LoginNew((UserInfo user)=> { //登录成功
|
//UI线程
|
this.BeginInvoke(new LoginSuccessDelegate((UserInfo user1)=> { //登录
|
|
setUserInfo(user);
|
|
}),user);
|
|
});
|
FormUtil.ShowDialog(loginNew);
|
}
|
|
|
private void upgrade_Click(object sender, EventArgs e)
|
{
|
ApiUtil.GetUserInfo((String result) =>
|
{
|
JObject obj= JObject.Parse(result);
|
if (Convert.ToInt32(obj["code"]) == 0)
|
{
|
UserInfo user= JsonConvert.DeserializeObject<UserInfo>(obj["data"].ToString());
|
//到期时间
|
this.BeginInvoke(new LoginSuccessDelegate((UserInfo user1)=> {
|
CardPwd cardPwd = new CardPwd(user1.SdljShareExpireTime);
|
FormUtil.ShowDialog(cardPwd);
|
}), user);
|
}
|
else {
|
MessageBox.Show(obj["msg"].ToString());
|
}
|
});
|
|
|
}
|
|
private void button5_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void groupBox3_Enter(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label9_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label13_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label7_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label12_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label14_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void textBox5_TextChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void textBox6_TextChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void label24_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void radioButton9_CheckedChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void radioButton7_CheckedChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void radioButton8_CheckedChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void checkBox6_CheckedChanged(object sender, EventArgs e)
|
{
|
|
}
|
|
private void button6_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
private void button5_Click_1(object sender, EventArgs e)
|
{
|
|
}
|
|
|
private void label3_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
|
//推广软件
|
private void promotion_Click(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
Promotion pt = new Promotion();
|
FormUtil.ShowDialog(pt);
|
}
|
//微信群
|
private void wxGroup_Click(object sender, EventArgs e)
|
{
|
Config config = SQLiteDataBaseUtil.getInstance().GetConfig("xianbao_group_picture");
|
WXGroup pt = new WXGroup("扫码进群", config!=null?config.Value:"");
|
FormUtil.ShowDialog(pt);
|
}
|
|
//
|
|
//发单机器人
|
private void fadanRobot_Click(object sender, EventArgs e) {
|
if (!IsLogin())
|
return;
|
FaDanRobot pt = new FaDanRobot();
|
FormUtil.ShowDialog(pt);
|
}
|
|
//淘宝授权
|
private void tbAuth_Click(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
TBAuth login = new TBAuth();
|
FormUtil.ShowDialog(login);
|
}
|
//发单库
|
private void fadanKu_Click(object sender, EventArgs e) {
|
if (!IsLogin())
|
return;
|
FaDanKu login = new FaDanKu();
|
FormUtil.ShowDialog(login);
|
}
|
|
|
|
private void groupBox9_Enter(object sender, EventArgs e)
|
{
|
|
}
|
|
private void Main_Load(object sender, EventArgs e)
|
{
|
|
|
}
|
|
private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
|
private void tabPage1_Click(object sender, EventArgs e)
|
{
|
|
|
|
}
|
|
private void button9_Click(object sender, EventArgs e)
|
{
|
//文案编辑
|
DocEdit doc=new DocEdit();
|
FormUtil.ShowDialog(doc);
|
}
|
|
/**////是否符合指定的正则表达式
|
static public bool Validate(string str, string regexStr)
|
{
|
Regex regex = new Regex(regexStr);
|
Match match = regex.Match(str);
|
if (match.Success)
|
return true;
|
else
|
return false;
|
}
|
|
//授权登录
|
private void button10_Click(object sender, EventArgs e)
|
{
|
if (!IsLogin())
|
return;
|
Login login = new Login();
|
FormUtil.ShowDialog(login);
|
}
|
|
//刷新Cookie
|
//TODO
|
private void ReFreshCookie() {
|
|
if (Login.loginContainer != null)
|
foreach (int key in Login.loginContainer.Keys) {
|
//刷新Cookie
|
Login.loginContainer[key].RefeshCookie();
|
}
|
}
|
|
private void groupBox4_Paint(object sender, PaintEventArgs e)
|
{
|
e.Graphics.Clear(this.BackColor);
|
}
|
|
private void logTimer_Tick(object sender, EventArgs e)
|
{
|
ShowLog();
|
}
|
|
private void Main_FormClosed(object sender, FormClosedEventArgs e)
|
{
|
this.logTimer.Stop();
|
}
|
|
//退出登录
|
private void label37_Click(object sender, EventArgs e)
|
{
|
LoginManager.ExitLogin();
|
setUserInfo(null);
|
}
|
}
|
}
|