Пример #1
0
        private bool checkLogin(string login)
        {
            string    query = $"SELECT login FROM users where login='******'";
            DataTable DT    = DBFunc.sendRequest(query);

            return(DT.Rows.Count == 0);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string login = textBoxLogin.Text;
            string pass  = textBoxPass.Text;
            string fName = textBoxFName.Text;
            string sName = textBoxSName.Text;
            string email = textBoxEMail.Text;

            if (IsValidEmail(email) == false)
            {
                MessageBox.Show("You entered invalid email!");
                return;
            }
            string errorMsg = "";

            if (ValidatePassword(pass, out errorMsg) == false)
            {
                MessageBox.Show(errorMsg);
                return;
            }
            if (checkLogin(login) == false)
            {
                MessageBox.Show("This login is already taken!");
                return;
            }
            // adding user
            string query = $"INSERT INTO users values(0, '{login}', '{HashFunc.CalculateMD5Hash(pass)}', '{fName}', '{sName}', '{email}')";

            DBFunc.sendRequest(query);
            (this).Close();
        }
Пример #3
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.SelectedRows.Count == 0)
                {
                    return;
                }

                DataGridViewRow row = dataGridView1.SelectedRows[0];

                Adress adr = new Adress(textBoxSurname.Text, textBoxStreetNsme.Text, textBoxBuildingNum.Text, textBoxfloorNum.Text, textBoxRoomNumber.Text);

                /*row.Cells[1].Value = textBoxSurname.Text;
                 * row.Cells[2].Value = textBoxStreetNsme.Text;
                 * row.Cells[3].Value = textBoxBuildingNum.Text;
                 * row.Cells[4].Value = textBoxfloorNum.Text;
                 * row.Cells[5].Value = textBoxRoomNumber.Text;
                 */
                string id = row.Cells[0].Value.ToString();
                if (id == "")
                {
                    return;
                }
                DBFunc.sendRequest($"UPDATE data set surname='{textBoxSurname.Text}', street_name='{textBoxStreetNsme.Text}', building_num='{textBoxBuildingNum.Text}', floor_num='{textBoxfloorNum.Text}', room_num='{textBoxRoomNumber.Text}' where id='{id}'");
                loadItems();
            }
            catch (Exception ex)
            { MessageBox.Show("Invalid data"); }
            clearData();
        }
Пример #4
0
        private void loadItemsForUser(string login)
        {
            var items = DBFunc.sendRequest($"SELECT id, surname, street_name, building_num, floor_num, room_num FROM data WHERE user_login='******'");

            dataGridViewItems.DataSource         = items;
            dataGridViewItems.Columns[0].Visible = false;
        }
Пример #5
0
        private bool userIsAdmin(string login)
        {
            string    query = $"SELECT login FROM admins where login='******'";
            DataTable DT    = DBFunc.sendRequest(query);

            return(DT.Rows.Count != 0);
        }
Пример #6
0
        private bool userExists(string login, string pass)
        {
            string    query = $"SELECT login FROM users where login='******' and pass='******'";
            DataTable DT    = DBFunc.sendRequest(query);

            return(DT.Rows.Count != 0);
        }
Пример #7
0
 private void banUser(string login)
 {
     try
     {
         DBFunc.sendRequest($"Insert into ban VALUES('{login}')");
         loadUsersList();
     }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
 }
Пример #8
0
 private void unBanUser(string login)
 {
     try
     {
         DBFunc.sendRequest($"DELETE FROM ban WHERE login='******'");
         loadUsersList();
     }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
 }
Пример #9
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         Adress adr = new Adress(textBoxSurname.Text, textBoxStreetNsme.Text, textBoxBuildingNum.Text, textBoxfloorNum.Text, textBoxRoomNumber.Text);
         DBFunc.sendRequest($"INSERT INTO data values(0, '{textBoxSurname.Text}','{textBoxStreetNsme.Text}', '{textBoxBuildingNum.Text}','{textBoxfloorNum.Text}','{textBoxRoomNumber.Text}','{login}')");
         loadItems();
     }
     catch (Exception ex)
     { MessageBox.Show("Invalid data" + ex.Message); }
     clearData();
 }
Пример #10
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     try
     {
         string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
         if (id == "")
         {
             return;
         }
         dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
         DBFunc.sendRequest($"DELETE FROM data WHERE id='{id}'");
     }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
     clearData();
 }
Пример #11
0
        private void loadUsersList()
        {
            var users = DBFunc.sendRequest($"SELECT login, fname as 'First Name', lname as 'Last name', email FROM users");

            dataGridViewUsers.DataSource = users;
            DataTable        ban          = DBFunc.sendRequest($"SELECT login FROM ban");
            HashSet <string> bannedLogins = new HashSet <string>();

            foreach (DataRow row in ban.Rows)
            {
                bannedLogins.Add(row.ItemArray[0].ToString());
            }
            foreach (DataGridViewRow row in dataGridViewUsers.Rows)
            {
                if (bannedLogins.Contains(row.Cells[0].Value.ToString()))
                {
                    row.DefaultCellStyle.BackColor = Color.LightYellow;
                }
            }
        }