Example #1
0
        unsafe public void btnGetUID_Click(object sender, EventArgs e)
        {
            UInt32 uiLength, uiRead, uiResult, uiWritten;

            byte[] ReadBuffer  = new byte[0x40];
            byte[] WriteBuffer = new byte[] { 0x2, 0x2, 0x1, 0x1 }; //Command {STX, LEN, CMD, DATA1, DATA2.....}

            byte[] sResponse = null;
            sResponse = new byte[21];

            EasyPOD.VID = 0xe6a;
            EasyPOD.PID = 0x317;
            Index       = 1;
            uiLength    = 64;

            fixed(MW_EasyPOD *pPOD = &EasyPOD)
            {
                dwResult = PODfuncs.ConnectPOD(pPOD, Index);

                if ((dwResult != 0))
                {
                    MessageBox.Show("Not connected yet");
                }
                else
                {
                    EasyPOD.ReadTimeOut  = 200;
                    EasyPOD.WriteTimeOut = 200;

                    dwResult = PODfuncs.WriteData(pPOD, WriteBuffer, 4, &uiWritten);                         //Send a request command to reader
                    uiResult = PODfuncs.ReadData(pPOD, ReadBuffer, uiLength, &uiRead);                       //Read the response data from reader

                    txbGetUIDh.Text = BitConverter.ToString(ReadBuffer, 4, (Int32)uiRead).Replace("-", " "); //HEX
                    txbGetUIDd.Text = BitConverter.ToInt32(ReadBuffer, 4).ToString();                        //DEC
                }
                dwResult = PODfuncs.ClearPODBuffer(pPOD);
                dwResult = PODfuncs.DisconnectPOD(pPOD);
            }
        }
        unsafe public void btnGetUID_Click(object sender, EventArgs e)
        {
            UInt32 drResult, dwResult, Index, uiWritten, uiRead;

            byte[] WriteBuffer_SN = new byte[] { 0x02, 0x01, 0x0D };//Command {STX, LEN, CMD,.....}
            byte[] sResponse_SN   = null;
            sResponse_SN = new byte[10 + 2];


            EasyPOD.VID = 0xe6a;
            EasyPOD.PID = 0x317;
            Index       = 1;


            fixed(MW_EasyPOD *pPOD = &EasyPOD)
            {
                dwResult = PODfuncs.ConnectPOD(pPOD, Index);

                if ((dwResult != 0))
                {
                    MessageBox.Show("Not connected yet");
                }
                else
                {
                    EasyPOD.ReadTimeOut  = 200;
                    EasyPOD.WriteTimeOut = 200;

                    dwResult = PODfuncs.WriteData(pPOD, WriteBuffer_SN, Convert.ToUInt32(WriteBuffer_SN.Length), &uiWritten);
                    drResult = PODfuncs.ReadData(pPOD, sResponse_SN, Convert.ToUInt32(sResponse_SN.Length), &uiRead);

                    txbGetSNh.Text = BitConverter.ToString(sResponse_SN, 4).Replace("-", " ");                         //HEX
                    txbGetSNt.Text = System.Text.Encoding.Default.GetString(sResponse_SN, 4, sResponse_SN.Length - 4); //ASCII
                }
                dwResult = PODfuncs.ClearPODBuffer(pPOD);
                dwResult = PODfuncs.DisconnectPOD(pPOD);
            }
        }
Example #3
0
        unsafe private void button2_Click_1(object sender, EventArgs e)
        {
            UInt32 uiLength, uiRead, uiResult, uiWritten;

            byte[] ReadBuffer  = new byte[0x40];
            byte[] WriteBuffer = new byte[] { 0x2, 0x2, 0x1, 0x1 }; //Command {STX, LEN, CMD, DATA1, DATA2.....}

            byte[] sResponse = null;
            sResponse = new byte[21];

            EasyPOD.VID = 0xe6a;
            EasyPOD.PID = 0x317;
            Index       = 1;
            uiLength    = 64;

            fixed(MW_EasyPOD *pPOD = &EasyPOD)
            {
                dwResult = PODfuncs.ConnectPOD(pPOD, Index);

                if ((dwResult != 0))
                {
                    MessageBox.Show("Ligue o leitor de cartões");
                }
                else
                {
                    EasyPOD.ReadTimeOut  = 200;
                    EasyPOD.WriteTimeOut = 200;

                    dwResult = PODfuncs.WriteData(pPOD, WriteBuffer, 4, &uiWritten);                         //Send a request command to reader
                    uiResult = PODfuncs.ReadData(pPOD, ReadBuffer, uiLength, &uiRead);                       //Read the response data from reader

                    textBoxHex.Text = BitConverter.ToString(ReadBuffer, 4, (Int32)uiRead).Replace("-", " "); //HEX
                    textBoxDe.Text  = BitConverter.ToInt32(ReadBuffer, 4).ToString();                        //DEC
                                                                                                             //textBox1.PasswordChar = '*';


                    string           conexao    = "Server=localhost;Database=Scholendar;Uid=root";
                    var              connection = new MySqlConnection(conexao);
                    var              command    = connection.CreateCommand();
                    MySqlDataAdapter adapter    = new MySqlDataAdapter();

                    //QUERY'S
                    MySqlCommand queryAl   = new MySqlCommand("select * from Aluno where Hex = '" + textBoxHex.Text + "' or De = '" + textBoxDe.Text + "'", connection);
                    MySqlCommand queryAd   = new MySqlCommand("select * from Admin where Hex = '" + textBoxHex.Text + "' or De = '" + textBoxDe.Text + "'", connection);
                    MySqlCommand queryProf = new MySqlCommand("select * from Professor where Hex = '" + textBoxHex.Text + "' or De = '" + textBoxDe.Text + "'", connection);

                    connection.Open();

                    //DATATABLES
                    DataTable dataTable1 = new DataTable();
                    DataTable dataTable2 = new DataTable();
                    DataTable dataTable3 = new DataTable();

                    //ADAPATERS
                    MySqlDataAdapter daAl   = new MySqlDataAdapter(queryAl);
                    MySqlDataAdapter daAd   = new MySqlDataAdapter(queryAd);
                    MySqlDataAdapter daProf = new MySqlDataAdapter(queryProf);

                    daAl.Fill(dataTable1);
                    daAd.Fill(dataTable2);
                    daProf.Fill(dataTable3);

                    connection.Close();


                    foreach (DataRow list in dataTable1.Rows) // Aluno
                    {
                        if (Convert.ToInt32(list.ItemArray[0]) > 0)
                        {
                            textBoxVar.Text = "1";
                        }
                        else
                        {
                            MessageBox.Show("Teste");
                        }
                    }

                    foreach (DataRow list in dataTable2.Rows) // Admin
                    {
                        if (Convert.ToInt32(list.ItemArray[0]) > 0)
                        {
                            textBoxVar.Text = "2";
                        }
                        else
                        {
                            MessageBox.Show("Teste");
                        }
                    }

                    foreach (DataRow list3 in dataTable3.Rows) //Professor
                    {
                        if (Convert.ToInt32(list3.ItemArray[0]) > 0)
                        {
                            textBoxVar.Text = "3";
                        }
                        else
                        {
                            MessageBox.Show("Teste");
                        }
                    }



                    if (textBoxVar.Text == "1")//ALUNO
                    {
                        connection.Open();
                        string          Hex       = textBoxHex.Text;
                        string          query     = "select * from Aluno where Hex = '" + Hex + "' ";
                        MySqlCommand    MyCommand = new MySqlCommand(query, connection);
                        MySqlDataReader MyReader;
                        MyReader = MyCommand.ExecuteReader();
                        while (MyReader.Read())
                        {
                            textBoxID_Aluno.Text = MyReader["ID_Aluno"].ToString();
                        }
                        connection.Close();

                        try
                        {
                            string ID_Aluno = textBoxID_Aluno.Text;
                            connection.Open();

                            string sql = "Update VAR set var = ('" + ID_Aluno + "') where ID_Var = 1;";
                            adapter.InsertCommand = new MySqlCommand(sql, connection);
                            adapter.InsertCommand.ExecuteNonQuery();
                            connection.Close();

                            connection.Open();
                            string          query1     = "select * from Aluno where ID_Aluno = '" + ID_Aluno + "' ;";
                            MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                            MySqlDataReader MyReader1;
                            MyReader1 = MyCommand1.ExecuteReader();
                            while (MyReader1.Read())
                            {
                                textBoxVarPass.Text = MyReader1["var"].ToString();
                            }
                            connection.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }

                        try
                        {
                            connection.Open();

                            string sql = "Update VAR set var = '1' where ID_Var = 2;";
                            adapter.InsertCommand = new MySqlCommand(sql, connection);
                            adapter.InsertCommand.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }

                        if (textBoxVarPass.Text == "1")
                        {
                            this.Hide();
                            MudarPass newform1 = new MudarPass();
                            newform1.Show();
                            form.textBoxUtilizador.Text = "Aluno";
                        }
                        else
                        {
                            this.Hide();
                            Aluno newform = new Aluno();
                            newform.Show();
                        }
                    }
                    else if (textBoxVar.Text == "2")//ADMIN
                    {
                        connection.Open();
                        string          Hex       = textBoxHex.Text;
                        string          query     = "select * from Admin where Hex = '" + Hex + "' ";
                        MySqlCommand    MyCommand = new MySqlCommand(query, connection);
                        MySqlDataReader MyReader;
                        MyReader = MyCommand.ExecuteReader();
                        while (MyReader.Read())
                        {
                            textBoxID_Admin.Text = MyReader["ID_Admin"].ToString();
                        }
                        connection.Close();

                        try
                        {
                            string ID_Admin = textBoxID_Admin.Text;
                            connection.Open();

                            string sql = "Update VAR set var = ('" + ID_Admin + "') where ID_Var = 1;";
                            adapter.InsertCommand = new MySqlCommand(sql, connection);
                            adapter.InsertCommand.ExecuteNonQuery();

                            connection.Close();

                            connection.Open();
                            string          query1     = "select * from Admin where ID_Admin = '" + ID_Admin + "' ;";
                            MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                            MySqlDataReader MyReader1;
                            MyReader1 = MyCommand1.ExecuteReader();
                            while (MyReader1.Read())
                            {
                                textBoxVarPass.Text = MyReader1["var"].ToString();
                            }
                            connection.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }

                        try
                        {
                            connection.Open();

                            string sql = "Update VAR set var = '2' where ID_Var = 2;";
                            adapter.InsertCommand = new MySqlCommand(sql, connection);
                            adapter.InsertCommand.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }

                        if (textBoxVarPass.Text == "1")
                        {
                            this.Hide();
                            MudarPass newform = new MudarPass();
                            newform.Show();
                            form.textBoxUtilizador.Text = "Administrador";
                        }
                        else if (textBoxVarPass.Text == "0")
                        {
                            this.Hide();
                            Admin Form = new Admin();
                            Form.Show();
                        }
                    }
                    else if (textBoxVar.Text == "3")//PROFESSOR
                    {
                        connection.Open();
                        string          Hex       = textBoxHex.Text;
                        string          query     = "select * from Professor where Hex = '" + Hex + "' ";
                        MySqlCommand    MyCommand = new MySqlCommand(query, connection);
                        MySqlDataReader MyReader;
                        MyReader = MyCommand.ExecuteReader();
                        while (MyReader.Read())
                        {
                            textBoxIDProf.Text = MyReader["ID_Professor"].ToString();
                        }
                        connection.Close();
                        string ID_Prof = textBoxIDProf.Text;
                        try
                        {
                            connection.Open();

                            string sql = "Update VAR set var = ('" + ID_Prof + "') where ID_Var = 1;";
                            adapter.InsertCommand = new MySqlCommand(sql, connection);
                            adapter.InsertCommand.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }

                        connection.Open();
                        string          query1     = "select * from Professor where ID_Professor = '" + ID_Prof + "' ;";
                        MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                        MySqlDataReader MyReader1;
                        MyReader1 = MyCommand1.ExecuteReader();
                        while (MyReader1.Read())
                        {
                            textBoxVarPass.Text = MyReader1["var"].ToString();
                        }
                        connection.Close();

                        try
                        {
                            connection.Open();

                            string sql = "Update VAR set var = '3' where ID_Var = 2;";
                            adapter.InsertCommand = new MySqlCommand(sql, connection);
                            adapter.InsertCommand.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }

                        if (textBoxVarPass.Text == "1")
                        {
                            this.Hide();
                            MudarPass newform = new MudarPass();
                            newform.Show();
                            form.textBoxUtilizador.Text = "Professor";
                        }
                        else if (textBoxVarPass.Text == "0")
                        {
                            this.Hide();
                            Professor Form = new Professor();
                            Form.Show();
                        }
                    }
                    else if (textBoxDe.Text == "0")
                    {
                    }
                    else
                    {
                        MessageBox.Show("Cartão não registado");
                    }
                }
                dwResult = PODfuncs.ClearPODBuffer(pPOD);
                dwResult = PODfuncs.DisconnectPOD(pPOD);
            }
        }