Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd   = new Random();
            long   pesel = LongRandom(50000000000, 45000000000, rnd);

            addedPESEL         = "" + pesel;
            addedLogin         = textBoxLogin.Text;
            addedPassword      = textBoxPassword.Text;
            addedPasswordAgain = textBoxPasswordRepeat.Text;


            //DataTable doesUserExists = ourDB.getData("SELECT * FROM Uzytkownik WHERE PESELpracownika = '" + addedPESEL + "'");
            DataTable doesThisLoginExists = ourDB.getData("SELECT * FROM Uzytkownik WHERE LoginUsera = '" + addedLogin + "'");

            //DataTable isAnyEmployeePESEL = ourDB.getData("SELECT * FROM Pracownik WHERE PESEL = '" + addedPESEL + "'");

            // if (isAnyEmployeePESEL.Rows.Count == 0)
            //     MessageBox.Show("Brak pracownika o podanym PESELu, bledny PESEL!");
            // else if (doesUserExists.Rows.Count != 0)
            //     MessageBox.Show("Pracownik o danym PESELu ma juz konto uzytkownika!");
            // else
            if (doesThisLoginExists.Rows.Count != 0)
            {
                MessageBox.Show("Taki login jest juz w uzyciu, wybierz inny!");
            }
            else if (addedPassword != addedPasswordAgain)
            {
                MessageBox.Show("Hasla sa niezgodne!");
            }
            else
            {
                string query = pracownikGenerator();
                if (ourDB.executeSettingData(new SqlCommand(query, ourDB.connection)) == false)
                {
                    return;
                }
                addedPassword = LogForm.Szyfruj(addedPassword);

                string adminPesel = ourDB.getData("SELECT PESEL FROM Pracownik WHERE Stanowisko = 'admin'").Rows[0][0].ToString();

                query  = "INSERT INTO Uzytkownik values ('" + addedLogin + "','" + addedPassword + "','" + addedPESEL + "',1);";  //(@LoginUsera, @HasloUsera, @PESELpracownika, 1)";
                query += "INSERT INTO Historia  values ('admin', '" + addedLogin + "', 'stworzenie konta', '', '', '', '', 1,0)"; //"+ adminPesel + ",', '', 1,0)";
                ourDB.executeSettingData(new SqlCommand(query, ourDB.connection));

                userComboBox.Items.Add(addedLogin);
                mainInfoLabel.Text = "Utworzono nowego \n użytkownika";
                MessageBox.Show("Utworzono nowego użytkownika");
            }


            infoLabel.Visible = true;
            //textBoxID.Text = "";
            textBoxLogin.Text          = "";
            textBoxPassword.Text       = "";
            textBoxPasswordRepeat.Text = "";
        }
        private void selectComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ArrayListToString(flagList).Contains("" + selectComboBox.SelectedIndex))
            {
                String query = "UPDATE Historia SET Blokada = 1 WHERE ID = " + id;
                ourDB.executeSettingData(new SqlCommand(query, ourDB.connection));

                TimerRestart();
                timerLabel.Visible = true;
            }
            else
            {
                _timer.Stop();
                timerLabel.Visible = false;

                String query = "UPDATE Historia SET Blokada = 0 WHERE ID = " + id;
                ourDB.executeSettingData(new SqlCommand(query, ourDB.connection));
            }

            actualiseFlagList(currentPrivilages, tableNumber, tableNumber = selectComboBox.SelectedIndex);
        }