Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyThread mt = new MyThread();
            Thread   t1 = new Thread(new ThreadStart(mt.Thread1));
            Thread   t2 = new Thread(new ThreadStart(mt.Thread1));

            connstring = "SERVER=65.19.141.67;PORT=3306;DATABASE=**********;UID=********; PASSWORD=*********;";
            if (!logl.Text.Equals(""))
            {
                if (!passl.Text.Equals(""))
                {
                    id   = logl.Text;
                    pass = passl.Text;

                    try
                    {
                        if (click == 1)
                        {
                            Console.WriteLine("Closing Connection");
                            conn.Close();
                            click = 0;
                            Console.WriteLine("Connection Closed");
                        }
                        if (click == 0)
                        {
                            try
                            {
                                t1.Start();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error");
                            }
                            conn = new MySqlConnection();
                            conn.ConnectionString = connstring;
                            Console.WriteLine("Connecting");
                            conn.Open();
                            click = 1;
                            Console.WriteLine("Success");
                            //t2.Start();
                            //t2.Abort();
                            try
                            {
                                t1.Abort();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error");
                            }
                        }

                        string          query      = "SELECT * FROM emp";
                        MySqlCommand    cmd        = new MySqlCommand(query, conn);
                        MySqlDataReader dataReader = cmd.ExecuteReader();
                        while (dataReader.Read())
                        {
                            if (id.Equals(dataReader["id" + ""]))
                            {
                                flag = 1;
                                break;
                            }
                        }

                        if (flag == 1)
                        {
                            if (pass.Equals(dataReader["pwd" + ""]))
                            {
                                name = (string)dataReader["name" + ""];

                                Upload v = new Upload(conn);
                                v.name1      = name;
                                v.namel.Text = name;
                                this.Hide();
                                v.ShowDialog();
                            }
                            else
                            {
                                MessageBox.Show("Password Mismatch", "Error");
                            }
                        }
                        else
                        {
                            MessageBox.Show("You are not authorised to access.", "Error");
                        }
                    }
                    catch (MySql.Data.MySqlClient.MySqlException ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                    }
                }
                else
                {
                    MessageBox.Show("Plaese Enter Password", "Error");
                }
            }
            else
            {
                MessageBox.Show("Please Enter Employee ID", "Error");
            }
        }