Skip to content

Commit 3056720

Browse files
committed
新的名单管理界面,修复bug
1 parent 284f2e2 commit 3056720

File tree

8 files changed

+659
-385
lines changed

8 files changed

+659
-385
lines changed

RandomCall/AboutForm.Designer.cs

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RandomCall/CalledForm.Designer.cs

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RandomCall/CalledForm.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace RandomCall
12+
{
13+
public partial class CalledForm : Form
14+
{
15+
private List<string[]> originData;
16+
private List<string[]> excelData;
17+
private List<string[]> callData;
18+
private MainForm mainForm; // 保存 MainForm 的实例
19+
20+
public CalledForm(MainForm form, List<string[]> origin, List<string[]> data, List<string[]> called)
21+
{
22+
InitializeComponent();
23+
mainForm = form; // 初始化 MainForm 实例
24+
originData = origin;
25+
excelData = data;
26+
callData = called;
27+
}
28+
29+
private void CalledForm_Load(object sender, EventArgs e)
30+
{
31+
foreach (var item in excelData)
32+
{
33+
listBox1.Items.Add(string.Join(", ", item));
34+
}
35+
label3.Text = excelData.Count.ToString() + "人"; // 更新标签文本
36+
37+
foreach (var item in callData)
38+
{
39+
listBox2.Items.Add(string.Join(", ", item));
40+
}
41+
label4.Text = callData.Count.ToString() + "人"; // 更新标签文本
42+
}
43+
44+
private void button2_Click(object sender, EventArgs e)
45+
{
46+
if (listBox1.SelectedItems.Count == 0)
47+
{
48+
MessageBox.Show("请先选择要移出的人员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
49+
return;
50+
}
51+
52+
var selectedItem = listBox1.SelectedItem;
53+
54+
if (selectedItem.ToString() == "名单未加载" || selectedItem.ToString() == "名单已点完")
55+
{
56+
return;
57+
}
58+
59+
int selectedIndex = listBox1.SelectedIndex;
60+
61+
// 确保索引在有效范围内
62+
if (selectedIndex >= 0 && selectedIndex < excelData.Count)
63+
{
64+
listBox1.Items.Remove(selectedItem);
65+
excelData.RemoveAt(selectedIndex); // 从数据列表中移除对应项
66+
label3.Text = excelData.Count.ToString() + "人"; // 更新标签文本
67+
68+
listBox2.Items.Add(selectedItem);
69+
callData.Add(new string[] { selectedItem.ToString() }); // 将移出的人员添加到已点名名单中
70+
label4.Text = callData.Count.ToString() + "人"; // 更新标签文本
71+
}
72+
else
73+
{
74+
MessageBox.Show("索引超出范围,请检查数据同步。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
75+
}
76+
}
77+
78+
private void button1_Click(object sender, EventArgs e)
79+
{
80+
if (listBox2.SelectedItems.Count == 0)
81+
{
82+
MessageBox.Show("请先选择要移出的人员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
83+
return;
84+
}
85+
86+
var selectedItem = listBox2.SelectedItem;
87+
88+
if (selectedItem.ToString() == "暂无点名记录")
89+
{
90+
return;
91+
}
92+
93+
int selectedIndex = listBox2.SelectedIndex;
94+
95+
// 确保索引在有效范围内
96+
if (selectedIndex >= 0 && selectedIndex < callData.Count)
97+
{
98+
listBox2.Items.Remove(selectedItem);
99+
callData.RemoveAt(selectedIndex); // 从已点名数据列表中移除对应项
100+
label4.Text = callData.Count.ToString() + "人"; // 更新标签文本
101+
102+
listBox1.Items.Add(selectedItem);
103+
excelData.Add(new string[] { selectedItem.ToString() }); // 将移出的人员添加到剩余名单中
104+
label3.Text = excelData.Count.ToString() + "人"; // 更新标签文本
105+
}
106+
else
107+
{
108+
MessageBox.Show("索引超出范围,请检查数据同步。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
109+
}
110+
}
111+
112+
private void button3_Click(object sender, EventArgs e)
113+
{
114+
if (callData != null && callData.Count > 0)
115+
{
116+
callData.Clear();
117+
listBox1.Items.Clear();
118+
listBox2.Items.Clear();
119+
120+
excelData.Clear();
121+
excelData.AddRange(originData);
122+
123+
foreach (var item in excelData)
124+
{
125+
listBox1.Items.Add(string.Join(", ", item));
126+
}
127+
label3.Text = excelData.Count.ToString() + "人";
128+
129+
label4.Text = "0人"; // 更新标签文本
130+
131+
// 使用 MainForm 实例更新标签
132+
mainForm.label1.Text = "名单已重置";
133+
}
134+
else
135+
{
136+
MessageBox.Show("暂无点名记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
137+
}
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)