private void btpwd_Click(object sender, EventArgs e)
{ Form2 f = new Form2();
if(f.ShowDialog()==DialogResult.OK)
{
switch (f.power)
{
case 2:
ToolStripMenuItem1.Enabled = true;
ToolStripMenuItem2.Enabled = true;
ToolStripMenuItem3.Enabled = true;
ToolStripMenuItem4.Enabled = true;
ToolStripMenuItem5.Enabled = true;
ToolStripMenuItem6.Enabled = true;
break;
case 1:
ToolStripMenuItem1.Enabled = true;
break;
default:
MessageBox.Show("你没有使用本系统的权限");
}
} }貌似我主界面不是MenuItem菜单 然后不知道如何去引用FORM2的MenuItem菜单 求大神指点!!!!
还有就是Power 和colse的问题是一样的不知道怎么去添加方法或者是别的什么的初学C#求指点! private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'inventoryMgtDataSet10.pwd' table. You can move, or remove it, as needed.
this.pwdTableAdapter.Fill(this.inventoryMgtDataSet10.pwd);
// TODO: This line of code loads data into the 'inventoryMgtDataSet9.Dept' table. You can move, or remove it, as needed.
this.deptTableAdapter.Fill(this.inventoryMgtDataSet9.Dept);
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("请输入用户和密码,然后再登陆");
return;
}
string SQL = "select Power from Employee where EmployeeID=";
SQL += textBox1.Text + "and PassWord='" + textBox2.Text.Trim() + "'";
string myConStr = "Persist Security Info=False;Initial Catalog=FilmManager;";
myConStr += "Data Source=localhost;Integrated Security=SSPI;";
SqlCommand myCom = null;
SqlConnection myCon = null;
try
{
myCon = new SqlConnection(myConStr);
myCon.Open();
myCom = new SqlCommand(SQL, myCon);
SqlDataReader rd = myCom.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
power = Convert.ToInt32(rd[0]);
}
else
{
MessageBox.Show("没有这个用户或密码不正确,请重新登录!");
}
}
catch (SqlException oe)
{
MessageBox.Show(oe.Message, "Error");
}
finally
{
if (myCon.State == ConnectionState.Open)
myCon.close();
}
{ Form2 f = new Form2();
if(f.ShowDialog()==DialogResult.OK)
{
switch (f.power)
{
case 2:
ToolStripMenuItem1.Enabled = true;
ToolStripMenuItem2.Enabled = true;
ToolStripMenuItem3.Enabled = true;
ToolStripMenuItem4.Enabled = true;
ToolStripMenuItem5.Enabled = true;
ToolStripMenuItem6.Enabled = true;
break;
case 1:
ToolStripMenuItem1.Enabled = true;
break;
default:
MessageBox.Show("你没有使用本系统的权限");
}
} }貌似我主界面不是MenuItem菜单 然后不知道如何去引用FORM2的MenuItem菜单 求大神指点!!!!
还有就是Power 和colse的问题是一样的不知道怎么去添加方法或者是别的什么的初学C#求指点! private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'inventoryMgtDataSet10.pwd' table. You can move, or remove it, as needed.
this.pwdTableAdapter.Fill(this.inventoryMgtDataSet10.pwd);
// TODO: This line of code loads data into the 'inventoryMgtDataSet9.Dept' table. You can move, or remove it, as needed.
this.deptTableAdapter.Fill(this.inventoryMgtDataSet9.Dept);
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("请输入用户和密码,然后再登陆");
return;
}
string SQL = "select Power from Employee where EmployeeID=";
SQL += textBox1.Text + "and PassWord='" + textBox2.Text.Trim() + "'";
string myConStr = "Persist Security Info=False;Initial Catalog=FilmManager;";
myConStr += "Data Source=localhost;Integrated Security=SSPI;";
SqlCommand myCom = null;
SqlConnection myCon = null;
try
{
myCon = new SqlConnection(myConStr);
myCon.Open();
myCom = new SqlCommand(SQL, myCon);
SqlDataReader rd = myCom.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
power = Convert.ToInt32(rd[0]);
}
else
{
MessageBox.Show("没有这个用户或密码不正确,请重新登录!");
}
}
catch (SqlException oe)
{
MessageBox.Show(oe.Message, "Error");
}
finally
{
if (myCon.State == ConnectionState.Open)
myCon.close();
}
你大慨意思是说从登录窗口根据登录的用户来控制主窗体的菜单权限。
我们在登录窗品中设一个 static 字符串 strpower在主窗体登录时直接用if搞定private void MenuIsVisible()
{
if (Form1.strpower == "0")
{
// book0.Visible = true; 如果是设visible值就是看不到 设
//Enabled 的值是变灰
book0.Enabled = true; }
if (Form1.strpower == "1")
{
book1.Enabled = true;
}
if (Form1.strpower == "2")
{
book2.Enabled = true;
}
else{
Messagebox.show("你怎么搞个了什么权限都没有的人进来?");}
楼主要的是这个意思吗?