Exemple #1
0
        private void btn_bookList_Click(object sender, EventArgs e)
        {
            BookList obj = new BookList(id1, type1);

            obj.ShowDialog();
        }
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (combo_type.Text == "Admin")
            {
                if (text_id.Text != "" && text_pw.Text != "")
                {
                    try
                    {
                        string          connectionString = "datasource=localhost;port=3306;userid=root;password=1234;";
                        MySqlConnection connection       = new MySqlConnection(connectionString);

                        string       query = "SELECT password FROM lms.admin_login WHERE id ='" + text_id.Text + "'";
                        MySqlCommand cmd   = new MySqlCommand(query, connection);

                        connection.Open();
                        MySqlDataReader reader;
                        reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            if (text_pw.Text == reader.GetString(0))
                            {
                                MessageBox.Show("Login Successfull!");
                                this.Hide();
                                Admin obj = new Admin(text_id.Text, combo_type.Text);
                                obj.Show();
                            }

                            else
                            {
                                MessageBox.Show("Wrong Password!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        else
                        {
                            MessageBox.Show("Invalid ID!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        connection.Close();
                    }

                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Fields are empty!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else if (combo_type.Text == "Member")
            {
                if (text_id.Text != "" && text_pw.Text != "")
                {
                    try
                    {
                        string          connectionString = "datasource=localhost;port=3306;userid=root;password=1234;";
                        MySqlConnection connection       = new MySqlConnection(connectionString);

                        string       query = "SELECT m_password FROM lms.member_login WHERE m_id ='" + text_id.Text + "'";
                        MySqlCommand cmd   = new MySqlCommand(query, connection);

                        connection.Open();
                        MySqlDataReader reader;
                        reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            if (text_pw.Text == reader.GetString(0))
                            {
                                MessageBox.Show("Login Successfull!");
                                this.Hide();
                                Admin obj = new Admin(text_id.Text, combo_type.Text);
                                obj.Show();
                            }
                            else
                            {
                                MessageBox.Show("Wrong Password!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        else
                        {
                            MessageBox.Show("Invalid ID!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        connection.Close();
                    }

                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Fields are empty!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else if (combo_type.Text == "Guest")
            {
                BookList obj = new BookList(text_id.Text, combo_type.Text);
                obj.ShowDialog();
            }
        }