1 Star 0 Fork 1

LGF/随机点名器_C shap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Form1.cs 14.17 KB
一键复制 编辑 原始数据 按行查看 历史
薛江彬 提交于 2023-11-26 01:21 . 更新
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace suijidian
{
public partial class Form1 : Form
{
public static int numzu_man = 0; // 组的最大值属性
public static int numhao_max = 0; // 号的最大值属性
public static string buchongfuzu;
int mode = 0;
string filePath;
IniFile iniFile;
public string zum = "";
public string haom = "";
// 创建 Random 实例
Random random = new Random();
// 创建"Form2"窗口实例
Form2 form2 = new Form2();
public Form1()
{
InitializeComponent();
//配置文件读取
//string filePath = "example.ini";
//IniFile iniFile = new IniFile(filePath);
filePath = "./set.ini";
iniFile = new IniFile(filePath);
//string value1 = iniFile.GetValue("Section1", "Key1");
//string value2 = iniFile.GetValue("Section1", "Key2");
string zu = iniFile.GetValue("set", "zu");
string hao = iniFile.GetValue("set", "hao");
string buchongfuzu = iniFile.GetValue("set", "buchongfuzu");
string modet = iniFile.GetValue("set", "mode");
if (modet == null)
{
mode = 0;
不重复模式ToolStripMenuItem.Text = "不重复模式";
普通模式ToolStripMenuItem.Text = "(选中)普通模式";
}
else {
mode = int.Parse(modet);
if (mode == 0)
{
不重复模式ToolStripMenuItem.Text = "不重复模式";
普通模式ToolStripMenuItem.Text = "(选中)普通模式";
}
else
{
不重复模式ToolStripMenuItem.Text = "(选中)不重复模式";
普通模式ToolStripMenuItem.Text = "普通模式";
Thread thread = new Thread(new ThreadStart(cj));
thread.IsBackground = true; // 设置为后台线程,这样主线程不会等待它完成
thread.Start(); // 启动线程
}
}
bool success = int.TryParse(zu, out Form1.numzu_man);
bool success1 = int.TryParse(hao, out Form1.numhao_max);
if (success || success1)
{
}
else
{
MessageBox.Show("请转到设置,设置组数或号数");
form2.Show();
}
}
private void cj() {
for (int i = 1; i < numzu_man + 1; i++)
{
Console.WriteLine("创建组:" + i);
List<int> numbers = new List<int>();
Console.WriteLine("组内创建号:");
for (int j = 1; j < numhao_max + 1; j++)
{
numbers.Add(j);
Console.WriteLine(j);
}
listOfLists.Add(numbers);
}
}
List<int> zushu = new List<int>();
public void DisplayNumbers()
{
int number = 1;
int number1 = 1;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 2;//间隔时间
timer.Enabled = true;
timer.Tick += (sender, e) =>
{
Textboxzu.Text = number.ToString();
Textboxhao.Text = number.ToString();
number++;
number1++;
if (number > 9)
{
number = 1;
}
if (number1 > 30)
{
number = 1;
number1 = 0;
timer.Enabled = false;
try
{
Textboxzu.Text = random.Next(1, numzu_man+1).ToString();
if (buchongfuzu == "1") {
if (zushu.Count == 0)
{
for (int i = 1; i < numzu_man + 1; i++)
{
zushu.Add(i);
}
}
int texta;
while (true) {
texta = random.Next(1, numzu_man + 1);
if (zushu.Contains(texta))
{
zushu.RemoveAll(x => x == texta);
Console.WriteLine("本次:"+texta);
Textboxzu.Text = texta.ToString();
break;
}
}
}
foreach (int numbera in zushu)
{
Console.WriteLine(numbera);
}
//for (int i = 1; i < numzu_man; i++)
//{
// foreach (int numberb in listOfLists[i])
// {
// Console.WriteLine(numberb);
// }
//}
Console.WriteLine("组数:"+zushu);
Console.WriteLine("列表"+listOfLists);
if (checkBox1.Checked)
{
Textboxzu.Text = a.ToString();
a = a + 1;
if (a > numzu_man)
{
a = 1;
}
}
Textboxhao.Text = random.Next(1, numhao_max+1).ToString();
if (checkBox2.Checked)
{
Textboxhao.Text = b.ToString();
b = b + 1;
if (b > numhao_max)
{
b = 1;
}
}
}
catch (Exception ex)
{
MessageBox.Show("在随机时出现异常:" + ex.Message);
}
}
};
}
int a = 1;
int b = 1;
List<List<int>> listOfLists = new List<List<int>>();
int zu;
int hao;
public void buchongfu()
{
int number = 1;
int number1 = 1;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 2;//间隔时间
timer.Enabled = true;
timer.Tick += (sender, e) =>
{
Textboxzu.Text = number.ToString();
Textboxhao.Text = number.ToString();
number++;
number1++;
if (number > 9)
{
number = 1;
}
if (number1 > 30)
{
number = 1;
number1 = 0;
timer.Enabled = false;
try
{
if (zushu.Count == 0)
{
for (int i = 1; i < numzu_man + 1; i++)
{
zushu.Add(i);
}
}
int texta;
while (true)
{
texta = random.Next(1, numzu_man + 1);
if (zushu.Contains(texta))
{
zushu.RemoveAll(x => x == texta);
Console.WriteLine("本次:" + texta);
Textboxzu.Text = texta.ToString();
break;
}
}
foreach (int numbera in zushu)
{
Console.WriteLine(numbera);
}
while (true) {
zu = texta;
int zus = zu - 1;
if (listOfLists[zus].Count == 0)
{
for (int i = 1; i < numzu_man +1; i++)
{
listOfLists[zus].Add(i);
}
}
//Console.WriteLine("a本次抽到组:" + zu + "组内剩余:");
//foreach (int numbera in listOfLists[zus])
//{
// Console.WriteLine("a"+numbera);
//}
hao = random.Next(1, numhao_max + 1);
bool containsElement = listOfLists[zus].Contains(hao);
if (containsElement)
{
Textboxzu.Text = zu.ToString();
Textboxhao.Text = hao.ToString();
listOfLists[zus].Remove(hao);
if (listOfLists[zus].Count == 0)
{
for (int i = 1; i < numzu_man + 1; i++)
{
listOfLists[zus].Add(i);
}
}
Console.WriteLine("本次抽到组:" + zu + "组内剩余:");
foreach (int numbera in listOfLists[zus])
{
Console.WriteLine(numbera);
}
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show("在随机时出现异常:" + ex.Message);
}
}
};
}
private void button1_Click(object sender, EventArgs e)
{
if (mode == 0) {
DisplayNumbers();
}
if (mode == 1) {
buchongfu();
}
//// 用于在 UI 线程上执行的方法
//void SetText()
//{
// try
// {
// DisplayNumbers();
// Textboxzu.Text = random.Next(1, numzu_min).ToString();
// Textboxhao.Text = random.Next(1, numhao_max).ToString();
// }
// catch (Exception ex)
// {
// MessageBox.Show("在随机时出现异常:" + ex.Message);
// _ex = true;
// }
//}
//while (loop_times++ < target_times && !_ex)
//{
// // 使用 Control.Invoke 在 UI 线程上执行操作
// new Action(() =>
// {
// Thread.Sleep(interval_ms);
// this.Invoke(new Action(SetText));
// }).Invoke();
//}
}
private void 设置ToolStripMenuItem1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
private void 随即组ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3zu form3zu = new Form3zu();
form3zu.Show();
}
private void 随机号ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3hao form3hao = new Form3hao();
form3hao.Show();
}
private void 关于ToolStripMenuItem1_Click(object sender, EventArgs e)
{
about about = new about();
about.Show();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
a = 1;
}
private void 功能ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 不重复模式ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mode == 0)
{
不重复模式ToolStripMenuItem.Text = "(选中)不重复模式";
普通模式ToolStripMenuItem.Text = "普通模式";
mode = 1;
iniFile.SetValue("set", "mode", "1");
for (int i = 1; i < numzu_man + 1; i++)
{
Console.WriteLine("创建组:"+i);
List<int> numbers = new List<int>();
Console.WriteLine("组内创建号:");
for (int j = 1; j < numhao_max + 1; j++)
{
numbers.Add(j);
Console.WriteLine(j);
}
listOfLists.Add(numbers);
}
}
}
private void 普通模式ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (mode == 1)
{
不重复模式ToolStripMenuItem.Text = "不重复模式";
普通模式ToolStripMenuItem.Text = "(选中)普通模式";
mode = 0;
iniFile.SetValue("set", "mode", "0");
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/lgf-studio/random-roll-call-machine--c-shap.git
git@gitee.com:lgf-studio/random-roll-call-machine--c-shap.git
lgf-studio
random-roll-call-machine--c-shap
随机点名器_C shap
master

搜索帮助