Exemplo n.º 1
0
        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtenroll.Text) || string.IsNullOrWhiteSpace(txtpass.Text))
            {
                MessageBox.Show("Field Can't be empty......");
            }
            else
            {
                try

                {
                    enroll = txtenroll.Text;

                    //Check USER is valid or not
                    if (check_user() == true)
                    {
                        con.Open();
                        String           query1   = "SELECT * FROM student_info WHERE enrol = @name1 AND password = @pass1";
                        MySqlCommand     command1 = new MySqlCommand(query1, con);
                        MySqlDataAdapter da       = new MySqlDataAdapter(command1);
                        DataTable        dt       = new DataTable();
                        command1.Parameters.AddWithValue("@name1", txtenroll.Text);
                        command1.Parameters.AddWithValue("@pass1", txtpass.Text);
                        da.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            String en   = dt.Rows[0][1].ToString();
                            String name = dt.Rows[0][2].ToString();
                            this.Hide();

                            User_Info frm = new User_Info(en, name);
                            frm.ShowDialog();
                            //Process.Start(@"C:\Windows\System32\userinit.exe");
                        }
                        else
                        {
                            MessageBox.Show("Invalid Enrollment or password...!!!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have seat on wrong computer system or you have entered wrong enrollment number.....");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    panel1.Visible = false;
                    panel2.Visible = true;
                }
                finally
                {
                    con.Close();
                }
            }
        }
Exemplo n.º 2
0
        private void BtnGuest_Click_1(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtguestno.Text) || string.IsNullOrWhiteSpace(txtguestpass.Text))
            {
                MessageBox.Show("Field Can't be empty......");
            }
            else
            {
                con.Close();
                con.Open();
                MySqlCommand cmd = new MySqlCommand("select * from guest_user where enrol=@enrol and password = @pass ", con);
                cmd.Parameters.AddWithValue("@enrol", txtguestno.Text);
                cmd.Parameters.AddWithValue("@pass", txtguestpass.Text);
                MySqlDataReader dr2 = cmd.ExecuteReader();

                if (dr2.HasRows == true)
                {
                    string name = null;
                    try
                    {
                        while (dr2.Read())
                        {
                            name = dr2[1].ToString();
                        }

                        con.Close();
                        string mac1 = null, ip, pc_no;
                        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                        {
                            // Only consider Ethernet network interfaces
                            if ((nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
                                 nic.OperationalStatus == OperationalStatus.Up))
                            {
                                mac1 = nic.GetPhysicalAddress().ToString();
                            }
                        }

                        //string mac = mac1.Substring(0, 2) + "-" + mac1.Substring(2, 2) + "-" + mac1.Substring(4, 2) + "-" + mac1.Substring(6, 2) + "-" + mac1.Substring(8, 2) + "-" + mac1.Substring(10, 2);

                        string mac = "5C-26-0A-55-8F-46";
                        con.Open();
                        String           query1   = "SELECT * FROM not_use_pc WHERE mac_id = @enrol";
                        MySqlCommand     command1 = new MySqlCommand(query1, con);
                        MySqlDataAdapter da       = new MySqlDataAdapter(command1);
                        DataTable        dt       = new DataTable();
                        command1.Parameters.AddWithValue("@enrol", mac);
                        da.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            ip    = dt.Rows[0][0].ToString();
                            pc_no = dt.Rows[0][1].ToString();
                            con.Close();

                            con.Open();
                            String       query   = "INSERT INTO in_use_pc (mac_id, ip_address, enrol, pc_number, time_slot) VALUES ( @mac,@ip ,@enroll ,@pc_no, @time);";
                            MySqlCommand command = new MySqlCommand(query, con);
                            command.Parameters.AddWithValue("@mac", mac);
                            command.Parameters.AddWithValue("@ip", ip);
                            command.Parameters.AddWithValue("@enroll", txtguestno.Text);
                            command.Parameters.AddWithValue("@pc_no", pc_no);
                            command.Parameters.AddWithValue("@time", "01:00:00");
                            command.ExecuteNonQuery();
                            con.Close();

                            con.Open();
                            DataTable        dt1      = new DataTable();
                            MySqlCommand     command2 = new MySqlCommand("DELETE FROM not_use_pc WHERE mac_id=@Name1", con);
                            MySqlDataAdapter da1      = new MySqlDataAdapter(command2);
                            command2.Parameters.AddWithValue("@Name1", mac);
                            da1.Fill(dt1);
                            con.Close();
                            User_Info frm = new User_Info(txtguestno.Text, name);
                            this.Hide();
                            frm.Show();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("Wrong user Id or password");
                }
            }



            //if (txtguestno.Text == "1234" && txtguestpass.Text == "1234")
            //{
            //    ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;
            //    objKeyboardProcess = new LowLevelKeyboardProc(enable);
            //    ptrHook = SetWindowsHookEx(13, objKeyboardProcess, GetModuleHandle(objCurrentModule.ModuleName), 0);

            //    enroll = txtguestno.Text;
            //    this.Hide();
            //    Process.Start(@"C:\Windows\System32\userinit.exe");
            //}
            //else
            //{
            //    MessageBox.Show("Incorrect User Name or Password....");
            //}
        }