Example #1
0
        private void Wybierz_Click(object sender, RoutedEventArgs e)
        {
            DataRowView wybrane = Mieszkania.SelectedItem as DataRowView;

            if (wybrane != null)
            {
                int        userhomeid = (int)wybrane.Row.ItemArray[3];
                Uzytkownik home       = new Uzytkownik(id, userhomeid);
                home.Show();
                this.Close();
            }
        }
Example #2
0
        private void Zaloguj_Click(object sender, RoutedEventArgs e)
        {
            string login    = UserLogin.Text;
            string password = Haslo.Password;

            try
            {
                var connstr = "server=remotemysql.com;uid=9eO1BYpNqH;pwd=Dcs0DDWGze;database=9eO1BYpNqH";
                using (var conn = new MySqlConnection(connstr))
                {
                    conn.Open();
                    DataTable        table   = new DataTable();
                    MySqlDataAdapter adapter = new MySqlDataAdapter();
                    String           query   = "Select * FROM login WHERE Login=@log AND Password=@pas";
                    MySqlCommand     command = new MySqlCommand(query, conn);
                    command.Parameters.Add("@log", MySqlDbType.VarChar).Value = login;
                    command.Parameters.Add("@pas", MySqlDbType.VarChar).Value = password;
                    adapter.SelectCommand = command;
                    adapter.Fill(table);
                    if (table.Rows.Count > 0)
                    {
                        DataTable        table3   = new DataTable();
                        MySqlDataAdapter adapter3 = new MySqlDataAdapter();
                        String           query3   = "Select * FROM login WHERE Login=@log";
                        MySqlCommand     command3 = new MySqlCommand(query3, conn);
                        command3.Parameters.Add("@log", MySqlDbType.VarChar).Value = login;
                        adapter3.SelectCommand = command;
                        adapter3.Fill(table3);
                        int ID       = table3.Rows[0].Field <int>(0);
                        int usertype = table3.Rows[0].Field <int>(3);
                        if (usertype == 0)
                        {
                            DataTable        table2   = new DataTable();
                            MySqlDataAdapter adapter2 = new MySqlDataAdapter();
                            String           query2   = "Select Ulica,NrBloku,NrMieszkania,IdMieszkania FROM Mieszkanie WHERE IdWlasciciela=@id";
                            MySqlCommand     command2 = new MySqlCommand(query2, conn);
                            command2.Parameters.Add("@id", MySqlDbType.Int16).Value = ID;
                            adapter2.SelectCommand = command2;
                            adapter2.Fill(table2);
                            if (table2.Rows.Count == 0)
                            {
                                DodajMieszkanie dodaj = new DodajMieszkanie(ID);
                                dodaj.Show();
                                this.Close();
                            }
                            if (table2.Rows.Count > 1)
                            {
                                WybierzMieszkanie wybierz = new WybierzMieszkanie(table2, ID);
                                wybierz.Show();
                                this.Close();
                            }
                            if (table2.Rows.Count == 1)
                            {
                                Uzytkownik home = new Uzytkownik(ID, table2.Rows[0].Field <int>(3));
                                home.Show();
                                this.Close();
                            }
                        }
                        if (usertype == 1)
                        {
                            Operator home = new Operator(ID);
                            home.Show();
                            this.Close();
                        }
                        if (usertype == 2)
                        {
                            Wspolnota home = new Wspolnota(ID);
                            home.Show();
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Błędna nazwa użytkownika lub hasło.");
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }