代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class OwnAdd : Form
{
public OwnAdd()
{
InitializeComponent();
}
String dir = AppDomain.CurrentDomain.BaseDirectory;
public List<string> readIds()
{
List<string> users = new List<string>();
string path = string.Format("{0}\\user.txt",dir);
using (StreamReader read = new StreamReader(path))
{
string line;
while((line = read.ReadLine()) != null)
{
string[] parts = line.Split(',');
string id = parts[0].Split('=')[1];
users.Add(id);
}
read.Close();
}
return users;
}
public List<string> readAccount()
{
List<string> users = new List<string>();
string path = string.Format("{0}\\user.txt", dir);
using (StreamReader read = new StreamReader(path))
{
string line;
while ((line = read.ReadLine()) != null)
{
string[] parts = line.Split(',');
string id = parts[1].Split('=')[1];
users.Add(id);
}
read.Close();
}
return users;
}
private void confirm_Click(object sender, EventArgs e)
{
List<string> ids = readIds();
string path = string.Format("{0}\\user.txt",dir);
int uid = int.Parse(this.textBox1.Text);
foreach (string user in ids)
{
if(uid == int.Parse(user))
{
MessageBox.Show("用户id不能重复!");
return;
}
}
string uaccount = this.textBox2.Text;
List<string> users = readAccount();
foreach (string user in users)
{
if (uaccount == user)
{
MessageBox.Show("用户账号不能重复!");
return;
}
}
if (uaccount == null || uaccount == "")
{
MessageBox.Show("账号不能为空");
}
string upassword = this.textBox3.Text;
if (upassword == null || upassword == "")
{
MessageBox.Show("密码不能为空");
}
string permissions = this.comboBox1.Text;
if (permissions == null || permissions == "")
{
MessageBox.Show("身份不能为空");
}
int pid = int.Parse(this.textBox5.Text);
if (pid.ToString() == null)
{
MessageBox.Show("用户id不能为空");
}
if (permissions.Equals("教师"))
{
using (StreamWriter write = File.AppendText(path))
{
write.WriteLine($"uid={uid},uaccount={upassword},upassword={upassword},permissions={permissions},tid={pid}");
this.DialogResult = DialogResult.OK;
write.Close();
}
return;
}
if (permissions.Equals("学生"))
{
using (StreamWriter write = File.AppendText(path))
{
write.WriteLine($"uid={uid},uaccount={upassword},upassword={upassword},permissions={permissions},sid={pid}");
this.DialogResult = DialogResult.OK;
write.Close();
}
return;
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。