1.在评分的时候,录入答案,如何强制转变成大写或者小写,或者用as码值比较可以么,不然虽然选的对但是大小写不对,会有评分误差2.在if-else之间如何密码输入三次错误自动关闭,我知道是定义一个变量然后判断等于三,可是就是加不好,这是这一小段的代码
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn;
OleDbCommand comm;
if (radioButtonGuanLiYuan.Checked)
{
conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb";
string sqlstring = "Select count(*) as num From 管理员表 where 用户名='"+textBoxYongHuMing .Text +" ' and 密码 = '" + textBoxMiMa.Text + " '";
comm = new OleDbCommand();
comm.CommandText = sqlstring;
comm.Connection = conn;
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
dr.Read();
textBoxMiMa.Text = "";
int cc = (int)(dr["num"]);
if (cc == 0)
{
MessageBox.Show("用户名或密码输入错误!请重新输入!");
textBoxMiMa.Focus();
}
else
{
Form1 form1 = new Form1();
form1.Show();
}
conn.Close();
}
if (radioButtonXueSheng.Checked)
{
conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb";
string sqlstring = "Select count(*) as num From 学生用户表 where 用户名='"+textBoxYongHuMing .Text +"' and 密码='" + textBoxMiMa.Text + "'";
comm = new OleDbCommand();
comm.CommandText = sqlstring;
comm.Connection = conn;
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
dr.Read();
textBoxMiMa.Text = "";
int cc = (int)(dr["num"]);
if (cc == 0)
{
MessageBox.Show("用户名或密码输入错误!请重新输入!");
}
else
{
Formdati formdati = new Formdati();
formdati.Show();
}
conn.Close();
}
}在哪加才能出效果呢?
3.this.close是关闭当前窗口,那么关闭所有窗口呢?4.怎样在打开一个新窗体时把前一个窗体关闭或者隐藏?5,软件编写运行成功后,怎么样可以打包变成一个可安装的文件,提供给别人使用呢?
请大家指教下
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn;
OleDbCommand comm;
if (radioButtonGuanLiYuan.Checked)
{
conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb";
string sqlstring = "Select count(*) as num From 管理员表 where 用户名='"+textBoxYongHuMing .Text +" ' and 密码 = '" + textBoxMiMa.Text + " '";
comm = new OleDbCommand();
comm.CommandText = sqlstring;
comm.Connection = conn;
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
dr.Read();
textBoxMiMa.Text = "";
int cc = (int)(dr["num"]);
if (cc == 0)
{
MessageBox.Show("用户名或密码输入错误!请重新输入!");
textBoxMiMa.Focus();
}
else
{
Form1 form1 = new Form1();
form1.Show();
}
conn.Close();
}
if (radioButtonXueSheng.Checked)
{
conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb";
string sqlstring = "Select count(*) as num From 学生用户表 where 用户名='"+textBoxYongHuMing .Text +"' and 密码='" + textBoxMiMa.Text + "'";
comm = new OleDbCommand();
comm.CommandText = sqlstring;
comm.Connection = conn;
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
dr.Read();
textBoxMiMa.Text = "";
int cc = (int)(dr["num"]);
if (cc == 0)
{
MessageBox.Show("用户名或密码输入错误!请重新输入!");
}
else
{
Formdati formdati = new Formdati();
formdati.Show();
}
conn.Close();
}
}在哪加才能出效果呢?
3.this.close是关闭当前窗口,那么关闭所有窗口呢?4.怎样在打开一个新窗体时把前一个窗体关闭或者隐藏?5,软件编写运行成功后,怎么样可以打包变成一个可安装的文件,提供给别人使用呢?
请大家指教下
2、加一个全局性的变量,开始等于1,确定一次就加1,加个if判断如果大于3就直接退出程序。
3、Application.Exit()方法关闭所有窗口,退出程序;
4、新建窗体后:
this.Hide()
新窗体.Show()
5、新建一个项目,选择“其它项目类型”下面的“安装与部署”里面的“安装项目”,之后搜索一下百度吧,有比较详细的说明。
.ToUpper();//全部转大写
如果是连续输入三次那就好说,,在登录的时候写if else
错误一次+1
private int i = 0;
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn;
OleDbCommand comm;
i = i++;
if (i <= 3)
{
if (radioButtonGuanLiYuan.Checked)
{
conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb";
string sqlstring = "Select count(*) as num From 管理员表 where 用户名='" + textBoxYongHuMing.Text + " ' and 密码 = '" + textBoxMiMa.Text + " '";
comm = new OleDbCommand();
comm.CommandText = sqlstring;
comm.Connection = conn;
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
dr.Read();
textBoxMiMa.Text = "";
int cc = (int)(dr["num"]);
if (cc == 0)
{
MessageBox.Show("用户名或密码输入错误!请重新输入!");
textBoxMiMa.Focus();
}
else
{
Form1 form1 = new Form1();
form1.Show();
}
conn.Close();
}
if (radioButtonXueSheng.Checked)
{
conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=score.mdb";
string sqlstring = "Select count(*) as num From 学生用户表 where 用户名='" + textBoxYongHuMing.Text + "' and 密码='" + textBoxMiMa.Text + "'";
comm = new OleDbCommand();
comm.CommandText = sqlstring;
comm.Connection = conn;
conn.Open();
OleDbDataReader dr = comm.ExecuteReader();
dr.Read();
textBoxMiMa.Text = "";
int cc = (int)(dr["num"]);
if (cc == 0)
{
MessageBox.Show("用户名或密码输入错误!请重新输入!");
}
else
{
Formdati formdati = new Formdati();
formdati.Show();
}
conn.Close();
}
}
else
{
MessageBox.Show("密码已经错误3次!");
Application.Exit();
}
}
private int m_Count=0;
private void button1_Click(object sender, EventArgs e)
{
if(m_Count<3)
{
//你之前的代码
//你每次连接数据库查询,没有查到对应的记录就m_Count++;
}
}