C#
0
Вклад в тег
static QuestionTypeCheckBox _obj;
public static QuestionTypeCheckBox Instance
{
get
{
if (_obj == null)
{
_obj = new QuestionTypeCheckBox();
}
return _obj;
}
}
public FlowLayoutPanel pnlView
{
get { return pnl_main; } // имя элемента
set { pnl_main = value; }
}
private void DeleteQuestionButton_Click(object sender, EventArgs e)
{
...
FlowLayoutPanel.Instance.pnlView.Controls.Clear(); // Удаление контролов
}
string connStr = "server=localhost; port=3306; username=root; password= root; database=bd;";
string sql = "SELECT * FROM `user` WHERE `Name` = @un and `Password`= @up";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
DataTable table = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand command = new MySqlCommand(sql, conn);
command.Parameters.Add("@un", MySqlDbType.VarChar, 25);
command.Parameters.Add("@up", MySqlDbType.VarChar, 25);
command.Parameters["@un"].Value = TextBox1.Text;
command.Parameters["@up"].Value = TextBox2.Text
adapter.SelectCommand = command;
adapter.Fill(table);
if (table.Rows.Count > 0)
{
userRole(); // метод, который будет открывать разные формы в зависимости от пользователя
}
conn.Close();
string UserName = TextBox1.Text;;
string connStr = "server=localhost; port=3306; username=root; password= root; database=bd;";
string sql = "SELECT User_Role FROM `user` WHERE `Name` = @un";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
MySqlParameter nameParam = new MySqlParameter("@un", UserName);
MySqlCommand command = new MySqlCommand(sql, conn);
command.Parameters.Add(nameParam);
string Form_Role = command.ExecuteScalar().ToString();
Switch(Form_Role)
{
case "Администратор": Form.ActiveForm.Close(); Form1 f1 = new Form1(); f1.Show(); break;
default: Form.ActiveForm.Close(); Form2 f2 = new Form2(); f2.Show();
}
conn.Close();