admin
2020-06-17 9d3d08ba960fc739498b0648d57eaf2c50a40fd1
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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 WindowsFormsApp1.utils;
using WindowsFormsApp1.entity.tb;
 
namespace WindowsFormsApp1
{
    public partial class Login : Form
    {
 
        public  static  Dictionary<int, TBLogin> loginContainer= new Dictionary<int, TBLogin> ();
 
        //获取登录表单
        private TBLogin GetLoginForm(int position) {
 
            if (loginContainer.ContainsKey(position))
            {
                return loginContainer[position];
            }
            loginContainer.Add(position,new TBLogin(position));
            return loginContainer[position];
        }
 
 
        public Login()
        {
            InitializeComponent();
            InitData();
        }
 
        private void setItemData(TBAccountLogin account,Button loginBtn,Label state,Label reLogin) {
            if (account != null)
            {
                loginBtn.Text = account.NickName;
                loginBtn.Enabled = false;
                if (account.Login)
                {
                    state.Text = "登录成功";
                    state.ForeColor = Color.Green;
                    reLogin.Visible = true;
                }
                else {
                    state.Text = "已失效";
                    state.ForeColor = Color.Red;
                    reLogin.Visible = true;
                }
            }
            else {
                loginBtn.Enabled = true;
                loginBtn.Text = "点击登录";
                state.Text = "未登录";
                reLogin.Visible =false;
                state.ForeColor = System.Drawing.SystemColors.ControlText;
            }
        }
 
        private void InitData() {
             Dictionary<int, TBAccountLogin> map=      Constant.tbAccountMap;
            //第一个淘宝号
            if (map.ContainsKey(1)&&map[1]!=null)//之前存在信息
            {
                setItemData(map[1],this.buttonLogin1, this.labelState1, this.labelReLogin1);
 
            }
 
            else {
                setItemData(null, this.buttonLogin1, this.labelState1, this.labelReLogin1);
            }
 
 
 
            if (map.ContainsKey(2) && map[2] != null)//之前存在信息
            {
                setItemData(map[2], this.buttonLogin2, this.labelState2, this.labelReLogin2);
 
            }
 
            else
            {
                setItemData(null, this.buttonLogin2, this.labelState2, this.labelReLogin2);
            }
 
            if (map.ContainsKey(3) && map[3] != null)//之前存在信息
            {
                setItemData(map[3], this.buttonLogin3, this.labelState3, this.labelReLogin3);
 
            }
 
            else
            {
                setItemData(null, this.buttonLogin3, this.labelState3, this.labelReLogin3);
            }
 
            if (map.ContainsKey(4) && map[4] != null)//之前存在信息
            {
                setItemData(map[4], this.buttonLogin4, this.labelState4, this.labelReLogin4);
 
            }
 
            else
            {
                setItemData(null, this.buttonLogin4, this.labelState4, this.labelReLogin4);
            }
 
            if (map.ContainsKey(5) && map[5] != null)//之前存在信息
            {
                setItemData(map[5], this.buttonLogin5, this.labelState5, this.labelReLogin5);
 
            }
 
            else
            {
                setItemData(null, this.buttonLogin5, this.labelState5, this.labelReLogin5);
            }
        }
 
        private void refresh() {
            InitData();
        }
 
 
        private void showLogin(int p) {
            TBLogin tbLogin= GetLoginForm(p);
            if (!tbLogin.HasShown)
            {
                TBLoginSuccessDelegate loginSuccess = refresh;
                tbLogin.SetTBLoginSuccess(loginSuccess);
                tbLogin.Show();
            }
            else {
                tbLogin.ReLogin();
            }
        }
 
        //登录
        private void login1_Click(object sender, EventArgs e)
        {
            showLogin(1);
 
        }
        private void login2_Click(object sender, EventArgs e)
        {
            showLogin(2);
        }
        private void login3_Click(object sender, EventArgs e)
        {
            showLogin(3);
        }
        private void login4_Click(object sender, EventArgs e)
        {
            showLogin(4);
        }
 
        private void login5_Click(object sender, EventArgs e)
        {
            showLogin(5);
        }
 
        //重新登录
        private void relogin1_Click(object sender, EventArgs e)
        {
            showLogin(1);
        }
        private void relogin2_Click(object sender, EventArgs e)
        {
            showLogin(2);
        }
        private void relogin3_Click(object sender, EventArgs e)
        {
            showLogin(3);
        }
        private void relogin4_Click(object sender, EventArgs e)
        {
            showLogin(4);
        }
 
        private void relogin5_Click(object sender, EventArgs e)
        {
            showLogin(5);
        }
 
    }
}