C#程序解读

[复制链接]
查看11 | 回复2 | 2016-7-14 07:18:45 | 显示全部楼层 |阅读模式
由于基础比较差,麻烦详细点,谢谢,这是我之前提问的后面,字数有限,只能分开
protected bool exist()
//判断用户名密码是否正确

{



string str = "";

FileStream fs = new FileStream(@"\Application\user.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

StreamReader users = new StreamReader(fs);

string[] strings = null;

string id = null;

string name = null;

string pwd = null;

int sign = 0;

while ((str = users.ReadLine()) != null)

{

strings = str.Split(',');

id = strings[0].ToString();

name = strings[1].ToString();

pwd = strings[2].ToString();

if (this.txtName.Text.Trim() == id && this.txtPwd.Text == pwd)

{



loginInfo.userId = id;

loginInfo.pwd = pwd;

loginInfo.userName = name;

sign=1;

break;

}

else

{

sign=0;



}

}



users.Close();

fs.Close();

if (sign == 1)

{

return true;

}

else

{

return false;

}

}
protected void existUser()

{

string str = "";

FileStream fs = new FileStream(@"\Application\user.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

StreamReader users = new StreamReader(fs);

string[] strings = null;

string id = null;

string name = null;

while ((str = users.ReadLine()) != null)

{

strings = str.Split(',');

id = strings[0].ToString();

name = strings[1].ToString();

if (this.txtName.Text.Trim() == id)

{

users.Close();

this.labId.Text =name;

break;

}

}

}
private void txtName_TextChanged(object sender, EventArgs e) //数据验证

{

this.labId.Text = this.txtName.Text.Trim();

if (!Regex.IsMatch(this.txtName.Text.Trim(), @"^\d{0,100}$"))

{

MessageBox.Show("输入格式错误!");

this.txtName.Text="";

}

}

private void timer1_Tick(object sender, EventArgs e)

{

this.lbSystemTime.Text = System.DateTime.Now.ToString();

}
}
}
还是有些不明白的,protected bool exist()
protected void existUser() private void txtName_TextChanged(object sender, EventArgs e)
实现什么功能里面有些语句也不懂,最好给个全篇的注释,谢谢啦,小弟基础差,麻烦各位了

回复

使用道具 举报

千问 | 2016-7-14 07:18:45 | 显示全部楼层
protected bool exist()//判断用户名密码是否正确,是一个布尔函数
{
string str = "";
FileStream fs = new FileStream(@"\Application\user.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);//定义文件流,打开user.txt
StreamReader users = new StreamReader(fs);//定义读取文件流,读取user
回复

使用道具 举报

千问 | 2016-7-14 07:18:45 | 显示全部楼层
你是不明白读取文件操作,把你的文件读进文件流里你的文件里的 用户id,用户名,用户密码是以 ,区分的所以程序用到了
strings = str.Split(',');split 就是 以,分割 出你的id,name,pwd 为一个 数组下标[0] 就是你的id下标[1] 就是你的name下标[2] 就是你的pwd
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行