private void LoginButton(object sender, EventArgs e) {//catalogu değiştir. connection = "Server=localhost;port=5432;Database =bikeBookv1;username=postgres;Password=locklock"; var conn = new NpgsqlConnection(connection); conn.Open(); var cmd = new NpgsqlCommand("select username,password,usertype from users where username ='******' and password='******';", conn); { var reader = cmd.ExecuteReader(); while (reader.Read()) { username = (String)reader.GetValue(0); password = (String)reader.GetValue(1); usertype = (String)reader.GetValue(2); } Console.WriteLine(username + " " + password + " " + usertype); if (username == "" && password == "") { MessageBox.Show("username and password must be valid ,try again later"); } else if (usertype == "admin") { AdminPanel adminPanel = new AdminPanel(username, password); adminPanel.Show(); // this.Close(); } else if (usertype == "client") { ClientPanel clientPanel = new ClientPanel(username, password); clientPanel.Show(); // this.Close(); } else { MessageBox.Show("user not found."); } } // kullanici admin ise admin panel goruntulenir // kullanici musteri ise musteri panel goruntulenir }
public void signButtoClicked(object sender, EventArgs e) { connection = "Server=localhost;port=5432;Database =bikeBookv1;username=postgres;Password=locklock"; NpgsqlConnection conn = new NpgsqlConnection(connection); conn.Open(); username = null; fname = FirstNametextBox.Text; lname = LastNameTextBox.Text; password = passwordTextBox.Text; if (usernamatextBox.Text == "" || fname == "" || lname == "" || password == "") { MessageBox.Show("mandatory fields required"); } else { NpgsqlCommand cmd = new NpgsqlCommand("select username from users where username ='******';", conn); { var reader = cmd.ExecuteReader(); while (reader.Read()) { username = (String)reader.GetValue(0); Console.WriteLine(username); } conn.Close(); Console.WriteLine("çıktı" + username); Console.WriteLine((username != null) && (username.Equals(usernamatextBox.Text))); Console.WriteLine(usernamatextBox.Text); if ((username != null))// kullanıcı adıın daha önce alınması durumu { usernamatextBox.ForeColor = Color.Red; importantLabel.Text = "username was took by another person ,please change username"; Console.WriteLine("dgffsrbfb"); } //alanların uzunluk kontrolü else if (password.Length > 20 || usernamatextBox.Text.Length > 9 || fname.Length > 50 || lname.Length > 50 || password.Length > 20)//kullanıcı kaydı yapılır. { MessageBox.Show("length of that field must be like that ;username:9 ,first name 50 ,last name 50 ,password 20 "); } else if (termRadioButton.Checked.Equals(true)) // user aggreementın kabul edilmasiyle kullanıcı kaydı yapılır. { conn.Open(); NpgsqlCommand insertusercmd = new NpgsqlCommand("insert into users values('" + usernamatextBox.Text + "','" + fname + "','" + lname + "','" + password + "','admin')", conn); NpgsqlCommand insertAdmncmd = new NpgsqlCommand("insert into admin values('" + usernamatextBox.Text + "')", conn); insertusercmd.ExecuteNonQuery(); conn.Close(); conn.Open(); insertAdmncmd.ExecuteNonQuery(); conn.Close(); AdminPanel newAdminPanel = new AdminPanel(usernamatextBox.Text, password); newAdminPanel.Show(); this.Close(); } else { MessageBox.Show("user aggrement must be read and accepted to use that system."); } conn.Close(); } } }