Ejemplo n.º 1
0
        private void btn_back_Click(object sender, EventArgs e)
        {
            string     id   = txt_id.Text;
            admin_form frm2 = new admin_form();

            frm2.MyProperty = id;
            frm2.Show();
            this.Hide();
        }
Ejemplo n.º 2
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            //login button checking for users table of faculty and students from tbl_user directing to user form
            String          sqlconstring = "Data Source = LOCALHOST; Initial Catalog = it_2d; username = root; password = ''";
            MySqlConnection sqlconnect   = new MySqlConnection(sqlconstring);

            MySqlDataAdapter sqlDataAdapter = new MySqlDataAdapter();
            DataSet          DS             = new DataSet();

            sqlconnect.Open();

            if (cmb_loginas.SelectedIndex == 1)
            {
                MySqlConnection  connection = new MySqlConnection("Data Source = LOCALHOST; Initial Catalog = it_2d; username = root; password = ''");
                MySqlDataAdapter adapter;
                DataTable        table = new DataTable();

                adapter = new MySqlDataAdapter("SELECT `u_un`, `u_pass` FROM `tbl_user` WHERE `u_un` = '" + txt_accno.Text + "' AND `u_pass` = '" + txt_pass.Text + "'", connection);
                adapter.Fill(table);

                if (table.Rows.Count <= 0)
                {
                    MessageBox.Show("Invalid Username or Password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                else
                {
                    //saving the login activity to tbl_activity
                    DateTime time   = DateTime.Now;
                    string   format = "yyyy-MM-dd HH:mm:ss";
                    var      mytime = time.ToString(format);

                    MySqlCommand sqlcommand = new MySqlCommand();
                    sqlcommand.CommandText = "INSERT INTO `tbl_activitylog` (`librarian_id`, `activity`,`account_no`,`date_activity`) VALUES ('" + txt_accno.Text + "',' Login' ,'" + txt_accno.Text + "' ,'" + mytime + "');";
                    sqlcommand.CommandType = CommandType.Text;
                    sqlcommand.Connection  = sqlconnect;
                    sqlcommand.ExecuteNonQuery();
                    sqlDataAdapter.SelectCommand = sqlcommand;
                    user_form uf = new user_form(txt_accno.Text);
                    uf.Show();
                    this.Hide();
                }
            }
            else
            {
                //login button checking for librarian's accounts from tbl_admin directing to admin/librarian form
                MySqlConnection  connection = new MySqlConnection("Data Source = LOCALHOST; Initial Catalog = it_2d; username = root; password = ''");
                MySqlDataAdapter adapter;
                DataTable        table = new DataTable();

                adapter = new MySqlDataAdapter("SELECT `a_un`, `a_pass` FROM `tbl_admin` WHERE `a_un` = '" + txt_accno.Text + "' AND `a_pass` = '" + txt_pass.Text + "'", connection);
                adapter.Fill(table);

                if (table.Rows.Count <= 0)
                {
                    MessageBox.Show("Invalid Username or Password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    DateTime time   = DateTime.Now;
                    string   format = "yyyy-MM-dd HH:mm:ss";
                    var      mytime = time.ToString(format);
                    //saving the login activity to tbl_activity
                    MySqlCommand sqlcommand = new MySqlCommand();
                    sqlcommand.CommandText = "INSERT INTO `tbl_activitylog`(`librarian_id`, `activity`,`account_no`,`date_activity`) VALUES ('" + txt_accno.Text + "',' Login' ,'" + txt_accno.Text + "' ,'" + mytime + "');";
                    sqlcommand.CommandType = CommandType.Text;
                    sqlcommand.Connection  = sqlconnect;
                    sqlcommand.ExecuteNonQuery();
                    sqlDataAdapter.SelectCommand = sqlcommand;

                    string     id = txt_accno.Text;
                    admin_form af = new admin_form();
                    af.MyProperty = id;
                    af.Show();
                    this.Hide();
                    this.Hide();
                }
            }
        }