Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Test1.Utilities util  = new Test1.Utilities();
            SqlConnection   conn  = new SqlConnection(util.GetConnectionString());
            string          query = "Select * From Users WHERE usern = '" + textBox1.Text + "'and passw='" + textBox2.Text + "'";
            SqlCommand      cmdq  = new SqlCommand(query, conn);
            SqlDataReader   rdr;

            try
            {
                conn.Open();
                Console.WriteLine("connected");
                rdr = cmdq.ExecuteReader();
                Console.WriteLine("tamam");
                while (rdr.Read())
                {
                    int id = (Int32)rdr.GetValue(0);
                    x = rdr.GetString(1);
                    y = rdr["passw"].ToString();

                    this.Hide();
                    Main mainmenu = new Main(id, x);
                    mainmenu.Show();

                    Console.WriteLine(id + x + y);
                }

                // Call Close when done reading.
                rdr.Close();
            }

            catch
            {
                MessageBox.Show("no");
            }
            finally
            {
                conn.Close();
            }

            //    SqlDataAdapter sd = new SqlDataAdapter("Select Count(*) From Users Where usern = '"+ textBox1.Text + " ' and passw= ' " + textBox2.Text + " ' ", conn);
            //    DataTable dt = new DataTable();
            //    sd.Fill(dt);
            //    DataRow drow = dt.Rows[1];
            //    string value = drow.Field<string>("Users");
            //    Console.WriteLine(value);


            //    if (dt.Rows[0][0].ToString() == "1")
            //        {
            //           this.Hide();
            //           Main mainmenu = new Main();
            //           mainmenu.Show();
            //        }
            //        else
            //        {
            //            MessageBox.Show("ERRRRRR!");
            //        }
            //    }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            user input = new user(999, textBox1.Text, textBox2.Text, textBox4.Text);

            if (textBox2.Text != textBox3.Text)
            {
                MessageBox.Show("Passwords don't match");
                return;
            }
            Test1.Utilities util = new Test1.Utilities();
            SqlConnection   conn = new SqlConnection(util.GetConnectionString());

            string query   = "Select * From Users";
            string command = "insert into Users (usern,passw,privileges) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox4.Text + "')";

            SqlCommand    cmdq = new SqlCommand(query, conn);
            SqlCommand    cmdw = new SqlCommand(command, conn);
            SqlDataReader rdr;

            try
            {
                conn.Open();

                rdr = cmdq.ExecuteReader();

                while (rdr.Read())
                {
                    users.Add(new user((Int32)rdr.GetInt32(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3)));
                }

                if (users.Exists(r => r.name.ToLower() == input.name.ToLower()))
                {
                    MessageBox.Show("Duplicate user");
                    return;
                }
                rdr.Close();
                conn.Close();
                conn.Open();
                cmdw.ExecuteNonQuery();

                MessageBox.Show("User added successfully");
                this.Close();
            }
            catch
            {
                MessageBox.Show("A7a");
            }
        }