admin
2020-06-19 84616e6d524a7df88ebcca4b74aca42461f34605
WindowsFormsApp1/Main.cs
@@ -14,6 +14,7 @@
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;
@@ -27,8 +28,10 @@
            InitializeComponent();
            InitSkin();
            InitDataGridView();
            InitLogListView();
            InitData();
            initTextBox();
            ShowLog();
        }
@@ -43,7 +46,97 @@
            this.sdljGoodsTimer.Interval = 1000*60*5;
            this.sdljGoodsTimer.Start();
            this.tabControl1.SendToBack();
            this.label11.BringToFront();
            //初始化账户登录,淘宝登录
            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();
        }
@@ -54,18 +147,7 @@
        }
        private void initTextBox() {
            setTextBoxPrompt(this.textBox1,"最小值");
            setTextBoxPrompt(this.textBox2, "最大值");
            setTextBoxPrompt(this.textBox3, "最小值");
            setTextBoxPrompt(this.textBox4, "最大值");
            setTextBoxPrompt(this.textBox5, "最小值");
            setTextBoxPrompt(this.textBox6, "最大值");
            setTextBoxPrompt(this.textBox7, "最小值");
            setTextBoxPrompt(this.textBox8, "最大值");
            setTextBoxPrompt(this.textBox9, "最小值");
            setTextBoxPrompt(this.textBox10, "最大值");
            setTextBoxPrompt(this.textBox11, "最小值");
            setTextBoxPrompt(this.textBox12, "最大值");
        }
        /**
@@ -100,18 +182,12 @@
            SetGoodsData((bool) hasMore, goodsList);
        }
        private void searchSuccess(String result)
        {
            JObject obj = JObject.Parse(result);
            this.BeginInvoke(new SetGoodsAndClassDataDelegate(setGoodsAndClassData), obj);
        }
        private void search(int page, SearchInfo info)
        {
            OnSuccess onSuccess = searchSuccess;
            ApiUtil.searchGoods( classType, info, page, onSuccess);
            ApiUtil.searchGoods( classType, info, page, new OnSuccess((String result)=> {
                JObject obj = JObject.Parse(result);
                this.BeginInvoke(new SetGoodsAndClassDataDelegate(setGoodsAndClassData), obj);
            }));
        }
        int page = 1;
@@ -122,16 +198,19 @@
            this.dataGridView1.Rows.Clear();
            foreach (FirstOrderSubInfo info in infoList) {
                int index = this.dataGridView1.Rows.Add();
                this.dataGridView1.Rows[index].Cells[0].Value = info.Index;
                //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.ZkPrice;
                this.dataGridView1.Rows[index].Cells[3].Value = info.CouponPrice;
                this.dataGridView1.Rows[index].Cells[4].Value = info.LijinAmount;
                this.dataGridView1.Rows[index].Cells[5].Value = info.ActualPrice;
                this.dataGridView1.Rows[index].Cells[6].Value = info.Commission;
                this.dataGridView1.Rows[index].Cells[7].Value = info.CommissionRate;
                this.dataGridView1.Rows[index].Cells[8].Value = "加入引单库";
                this.dataGridView1.Rows[index].Cells[9].Value = "加入实拍库";
                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)
@@ -164,6 +243,15 @@
            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;
        }
@@ -195,54 +283,38 @@
            }
            Console.WriteLine("分类:" + item.DataSource.Key);
            page = 1;
            SearchInfo searchInfo = getSearchFilter();
            SearchInfo searchInfo =this.kssdljSearchPannel1.getSearchFilter();
            classType = Convert.ToInt32(item.DataSource.Key);
            searchInfo.Key = this.ucTextBoxEx1.InputText;
            search(page, searchInfo);
        }
        private SearchInfo getSearchFilter()
        {
            SearchInfo info = new SearchInfo();
            info.MinCouponPrice = this.textBox1.Text;
            info.MaxCouponPrice = this.textBox2.Text;
            info.MinLiJin = this.textBox3.Text;
            info.MaxLiJin = this.textBox4.Text;
            info.MinActualPrice = this.textBox5.Text;
            info.MaxActualPrice = this.textBox6.Text;
            info.MinSalesNum = this.textBox7.Text;
            info.MinSalesNum = this.textBox8.Text;
            info.MinCommission = this.textBox9.Text;
            info.MaxCommission = this.textBox10.Text;
            info.MinCommissionRate = this.textBox11.Text;
            info.MaxCommissionRate = this.textBox12.Text;
            return info;
        }
        //筛选
        private void button1_Click_1(object sender, EventArgs e)
        {
            page = 1;
            SearchInfo searchInfo = getSearchFilter();
            classType = 0;
            search(page, searchInfo);
            Console.WriteLine(JsonConvert.SerializeObject(searchInfo));
            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 = getSearchFilter();
            SearchInfo searchInfo = this.kssdljSearchPannel1.getSearchFilter();
            searchInfo.Key = this.ucTextBoxEx1.InputText;
            search(page, searchInfo);
        }
@@ -251,8 +323,10 @@
        //下一页
        private void next_Click(object sender, EventArgs e)
        {
            if (!IsLogin())
                return;
            page++;
            SearchInfo searchInfo = getSearchFilter();
            SearchInfo searchInfo = this.kssdljSearchPannel1.getSearchFilter();
            searchInfo.Key = this.ucTextBoxEx1.InputText;
            search(page, searchInfo);
        }
@@ -260,8 +334,10 @@
        //上一页
        private void before_Click(object sender, EventArgs e)
        {
            if (!IsLogin())
                return;
            page--;
            SearchInfo searchInfo = getSearchFilter();
            SearchInfo searchInfo = this.kssdljSearchPannel1.getSearchFilter();
            searchInfo.Key = this.ucTextBoxEx1.InputText;
            search(page, searchInfo);
        }
@@ -335,20 +411,31 @@
        //设置用户信息
        private void setUserInfo(UserInfo user) {
            this.label37.Visible = true;
            if (user.SdljShareExpireTime == null || DateTime.Now > user.SdljShareExpireTime)
            { //过期
                this.button8.Text = "升级共享";
            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);
                this.button8.Click += new System.EventHandler(this.upgrade_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);//升级
            }
            this.button8.Text = "升级共享";
            this.label37.Visible = true;
            this.button8.Click -= new System.EventHandler(this.login_Click);
        }
@@ -361,26 +448,33 @@
                    setUserInfo(user);
                  
                }));
                }),user);
            });
            FormUtil.ShowDialog(loginNew);
        }
        private void upgrade_Click(object sender, EventArgs e)
        {
            LoginNew loginNew = new LoginNew((UserInfo user) => { //登录成功
                //UI线程
                this.BeginInvoke(new LoginSuccessDelegate((UserInfo user1) => { //登录
                    setUserInfo(user);
                }));
            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());
                }
            });
            FormUtil.ShowDialog(loginNew);
        }
        private void button5_Click(object sender, EventArgs e)
@@ -448,11 +542,6 @@
        }
        private void checkBox7_CheckedChanged(object sender, EventArgs e)
        {
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
@@ -483,13 +572,16 @@
        //推广软件
        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)
        {
            WXGroup pt = new WXGroup();
            Config config = SQLiteDataBaseUtil.getInstance().GetConfig("xianbao_group_picture");
            WXGroup pt = new WXGroup("扫码进群", config!=null?config.Value:"");
            FormUtil.ShowDialog(pt);
        }
@@ -497,6 +589,8 @@
        //发单机器人
        private void fadanRobot_Click(object sender, EventArgs e) {
            if (!IsLogin())
                return;
            FaDanRobot pt = new FaDanRobot();
            FormUtil.ShowDialog(pt);
        }
@@ -504,11 +598,15 @@
        //淘宝授权
        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);
        }
@@ -560,6 +658,8 @@
        //授权登录
        private void button10_Click(object sender, EventArgs e)
        {
            if (!IsLogin())
                return;
            Login login = new Login();
            FormUtil.ShowDialog(login);
        }
@@ -579,5 +679,22 @@
        {
            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);
        }
    }
}