Answered by:
Access level against user login criteria

Question
-
Hello all ,
I have 3 forms in my c# winform app ,
- Login
- Data Entry
- Dashboard with Graphs
Now after login a user must only access data entry form , but after admin login he must get both the form access .How to do this .
For form opening i am using this ..but how to modify it i am not getting.as every time that "login not successful" is also showing
Data_Entry f = new Data_Entry(); f.Show();
And here is mu login form code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mechanical_Straightening_Dies { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.ActiveControl = comboBox1; comboBox1.Focus(); } private void Btnexit_Click(object sender, EventArgs e) { System.Windows.Forms.Application.Exit(); } private void Btnlogin_Click(object sender, EventArgs e) { string user = comboBox1.Text; string pass = textBox1.Text; if(user == "ADMIN" && pass == "admin") { MessageBox.Show("Login Successfull as ADMIN"); FrmDashBoard f = new FrmDashBoard(); f.Show(); this.Hide(); } if(user == "USER" && pass == "password") { MessageBox.Show("Login Successfull as USER"); FrmDataEntry f = new FrmDataEntry(); f.Show(); this.Hide(); } else { MessageBox.Show("Invalid Username or Password"); } } private void comboBox1_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter) { textBox1.Focus(); } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Btnlogin.PerformClick(); } } } }
- Edited by Ravi Kumar12233 Tuesday, August 4, 2020 11:41 AM form show code was not written
Tuesday, August 4, 2020 11:27 AM
Answers
-
To solve the problem of unwanted message, try adding an else:
}
else if( user == “USER” && . . .
To allow the administrator to access the forms, maybe add buttons like “Show Dashboard” and “Show Data Entry” to both forms, but hide them if the user is not an administrator; something like this:
FrmDataEntry f = new FrmDataEntry();
f.IsAdministrator = false;
f.Show( );
where IsAdministrator is a custom property. Use this value in Form_Load event of both forms to show or hide the buttons.
- Edited by Viorel_MVP Tuesday, August 4, 2020 4:48 PM
- Marked as answer by Ravi Kumar12233 Wednesday, August 5, 2020 3:20 AM
Tuesday, August 4, 2020 4:42 PM
All replies
-
To solve the problem of unwanted message, try adding an else:
}
else if( user == “USER” && . . .
To allow the administrator to access the forms, maybe add buttons like “Show Dashboard” and “Show Data Entry” to both forms, but hide them if the user is not an administrator; something like this:
FrmDataEntry f = new FrmDataEntry();
f.IsAdministrator = false;
f.Show( );
where IsAdministrator is a custom property. Use this value in Form_Load event of both forms to show or hide the buttons.
- Edited by Viorel_MVP Tuesday, August 4, 2020 4:48 PM
- Marked as answer by Ravi Kumar12233 Wednesday, August 5, 2020 3:20 AM
Tuesday, August 4, 2020 4:42 PM -
Thank you so much for your suggestion ..Wednesday, August 5, 2020 3:20 AM