admin
2020-06-22 924bdf1c9fb74babf2438d5545db3594756625d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsFormsApp1.entity;
using WindowsFormsApp1.entity.tb;
 
namespace WindowsFormsApp1.utils
{
    class TBAccountManager
    {
        //获取账号信息
        public static List<TBAccountLogin> GetAccountList() {
            List<TBAccountLogin> list= SQLiteDataBaseUtil.getInstance().GetByTBUid(null);
            return list;
        }
 
        //登录成功
        public static void LoginSuccess(int position, TBAccountLogin account) {
            SQLiteDataBaseUtil.getInstance().TBOnLine(account);
            
            if (!WindowsFormsApp1.utils.Constant.tbAccountMap.ContainsKey(position)|| WindowsFormsApp1.utils.Constant.tbAccountMap[position].Login==false)
            {
                //淘宝未授权的才显示
                LogManager.AddLog(new LogInfo(DateTime.Now, "第" + position + "个淘宝账号(" + account.NickName + ")授权登录成功", LogInfo.TYPE_SAFE));
            }
            if (WindowsFormsApp1.utils.Constant.tbAccountMap.ContainsKey(position)) {
                WindowsFormsApp1.utils.Constant.tbAccountMap.Remove(position);
            }
 
            WindowsFormsApp1.utils.Constant.tbAccountMap.Add(position, account);
        }
 
        public static void OFFLine(int index) {
            SQLiteDataBaseUtil.getInstance().TBOffLine(index);
            if (Constant.tbAccountMap.ContainsKey(index) && Constant.tbAccountMap[index].Login)
            {
                Constant.tbAccountMap[index].Login = false;
                Constant.tbAccountMap[index].UpdateTime = new DateTime();
                LogManager.AddLog(new LogInfo(DateTime.Now, "第" + index + "个淘宝账号(" + Constant.tbAccountMap[index].NickName + ")授权登录失效", LogInfo.TYPE_SAFE));
            }
        }
 
        public static void Delete(int index) {
            if (Constant.tbAccountMap.ContainsKey(index)) {
                TBAccountLogin account = Constant.tbAccountMap[index];
                Constant.tbAccountMap.Remove(index);
                LogManager.AddLog(new LogInfo(DateTime.Now, "第" + index + "个淘宝账号(" + account.NickName + ")授权被删除", LogInfo.TYPE_NORMAL));
                SQLiteDataBaseUtil.getInstance().TBDelete(index);
            }
        }
 
 
        public static bool IsHaveOffLine() {
            foreach (int key in Constant.tbAccountMap.Keys) {
                if (Constant.tbAccountMap != null && Constant.tbAccountMap[key].Login == false && !StringUtil.isEmpty(Constant.tbAccountMap[key].NickName))
                    return true;
            }
            return false;
        }
 
 
            
 
    }
}