-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathAccountForm.cs
120 lines (96 loc) · 3.42 KB
/
AccountForm.cs
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
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;
namespace JD_Get
{
/// <summary>
/// 京东会清除js 写入的账号信息 所以目前只做记录使用
/// </summary>
public partial class AccountForm : Form
{
Form1 form { set; get; }
public AccountForm(Form1 form)
{
InitializeComponent();
this.form = form;
this.textBox1.Text= AccountHelp.GetAccountsStr();
}
private void button1_Click(object sender, EventArgs e)
{
var account= (BindingList<AccountHelp.Account>)dataGridView1.DataSource;
AccountHelp.SaveAccountsStr(System.Text.Json.JsonSerializer.Serialize(account));
this.form.InitAccount();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
AccountHelp.GetAccounts();
}
private void Account_Load(object sender, EventArgs e)
{
InitData();
inport.Visible = AccountHelp.GetAccounts().Count()==0;
}
private void InitData()
{
var data = AccountHelp.GetAccounts();
BindingList<AccountHelp.Account> accounts = new BindingList<AccountHelp.Account>();
data.ForEach(n =>
{
accounts.Add(n);
});
dataGridView1.DataSource = accounts;
}
private void button2_Click_1(object sender, EventArgs e)
{
DialogResult result = MessageBox.
Show("从旧数据导入账号信息会导致现有账号丢失,请确认", "确认导入",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes) {
AccountHelp.FormatFromAccountsStr();
InitData();
}
}
private void button3_Click(object sender, EventArgs e)
{
var data = (BindingList<AccountHelp.Account>)dataGridView1.DataSource;
data.Add(new AccountHelp.Account()
{
Memo = "1",
Login = "2",
Password = "3"
});
}
private void button4_Click(object sender, EventArgs e)
{
// 检查是否有选中的行
if (dataGridView1.SelectedRows.Count > 0)
{
DialogResult result = MessageBox.Show("您确定要删除选中的行吗?", "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
for (int i = dataGridView1.SelectedRows.Count - 1; i >= 0; i--)
{
try
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i].Index);
}
catch
{
}
}
}
}
else
{
MessageBox.Show("没有选中任何行以供删除。", "无行选中", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}