// Usuwanie produktu private void btnRemove_Click(object sender, EventArgs e) { admin = new Administracja(); DialogResult result = MessageBox.Show("Czy napewno usunąć produkt z bazy produktów?", "Usuwanie produktu", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (txtRFID.Text != string.Empty) { if (!admin.SprawdzRFID(txtRFID.Text)) { if (admin.UsunProdukt(txtRFID.Text)) { MessageBox.Show("Pomyślnie usunięto produkt", "Usuwanie produktu", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFields(); LoadData(); } } } else { MessageBox.Show("Nie udało się usunąć produkt!", "Błąd usuwania", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnEdit_Click(object sender, EventArgs e) { admin = new Administracja(); if (!edit) { edit = true; btnRemove.Enabled = true; btnAdd.Enabled = false; btnEdit.Text = "Zapisz"; MessageBox.Show("W przypadku edycji tagu RFID usuń produkt, a następnie dodaj go ponownie!", "Edycja transpondera", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { edit = false; btnRemove.Enabled = false; btnAdd.Enabled = true; btnEdit.Text = "Aktualizuj"; string VAT; if (rb5.Checked) { VAT = "A"; } else if (rb8.Checked) { VAT = "B"; } else { VAT = "C"; } if (txtNazwa.Text != string.Empty && txtRFID.Text != string.Empty && txtCena.Text != string.Empty && txtJednostka.Text != string.Empty) { if (!admin.SprawdzRFID(txtRFID.Text)) { if (admin.AktualizujProdukt(txtNazwa.Text, txtRFID.Text, txtCena.Text, txtJednostka.Text, VAT)) { MessageBox.Show("Pomyślnie zaaktualizowano produkt!", "Aktualizacja produktu", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { MessageBox.Show("Wszystkie pola muszą być wypełnione!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); edit = false; btnRemove.Enabled = false; btnAdd.Enabled = true; btnEdit.Text = "Aktualizuj produkt"; } ClearFields(); LoadData(); } }
// Dodanie nowego produktu private void btnAdd_Click(object sender, EventArgs e) { string VAT; if (rb5.Checked) { VAT = "A"; } else if (rb8.Checked) { VAT = "B"; } else { VAT = "C"; } admin = new Administracja(); if (txtNazwa.Text != string.Empty && txtRFID.Text != string.Empty && txtCena.Text != string.Empty && txtJednostka.Text != string.Empty) { if (!admin.SprawdzRFID(txtRFID.Text)) { if (admin.DodajProdukt(txtNazwa.Text, txtRFID.Text, txtCena.Text, txtJednostka.Text, VAT)) { MessageBox.Show("Pomyślnie dodano produkt do bazy", "Dodano produkt", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFields(); LoadData(); } else { MessageBox.Show("Podany tag RFID jest już w bazie danych!", "Wykryto duplikat RFID", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtRFID.Clear(); } } } else { MessageBox.Show("Wszystkie pola muszą być wypełnione!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }