当前位置:首页 > Oracle课程设计报告(简易点歌台系统)
主要代码如下(注释说明了各部分代码的作用):
//重载构造函数,传入窗口1的用户名
public Form5(string str) {
InitializeComponent(); user = str;
//设置回车的默认按钮
this.AcceptButton = button_commit; }
private void button_commit_Click(object sender, EventArgs e) {
string connstr = \; //搜索已有的管理员信息
string selectstr = \;
OracleConnection orclConn = new OracleConnection(connstr); OracleCommand selectcomd = orclConn.CreateCommand(); OracleCommand insertcomd=orclConn.CreateCommand(); selectcomd.CommandText = selectstr; selectcomd.Connection = orclConn; orclConn.Open();
OracleDataReader ord = selectcomd.ExecuteReader(); string[] ans = new string[100]; int i = 0; bool ok=true;
//将管理员的用户名存到ans字符串数组中 while (ord.Read()) {
ans[i++] = ord[0].ToString(); }
//密码为空时不创建新用户
if(textBox_password.Text==\) ok=false; //若用户名已存在则不创建 for(int k=0;k
if(textBox_user.Text.Equals(ans[k])) {
ok=false; break; } }
//判断是否创建新用户 if (ok)
{
//创建新用户
string insertstr = \ + textBox_user.Text + \ + textBox_password.Text + \;
insertcomd.CommandText = insertstr; insertcomd.Connection = orclConn; insertcomd.ExecuteNonQuery();
MessageBox.Show(\添加新用户成功\, \添加成功\); this.Close(); } else {
//跳出输入有误的提示
MessageBox.Show(\该用户已存在或者未输入密码\, \添加失败\); textBox_user.Clear(); textBox_password.Clear(); } }
private void button_cancel_Click(object sender, EventArgs e) {
this.Close(); }
管理员操作
验证用户名和密码通过后可以添加歌曲或者删除歌曲:
若信息不完整,则不能添加歌曲:
歌曲ID已存在,同样添加失败:
否则添加成功:
共分享92篇相关文档