1 Star 0 Fork 0

wyb/SlSoftSecond

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
OwnAdd.cs 3.87 KB
一键复制 编辑 原始数据 按行查看 历史
wyb 提交于 2024-03-30 17:56 . 个人信息的删除完成,全部完成
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;
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wyhwd/sl-soft-second.git
git@gitee.com:wyhwd/sl-soft-second.git
wyhwd
sl-soft-second
SlSoftSecond
master

搜索帮助