private void submitButton_Click(object sender, EventArgs e) { if ("".Equals(tbName.Text.Trim()) || "".Equals(tbLastname.Text.Trim()) || "".Equals(tbUsername.Text.Trim()) || "".Equals(tbPassword.Text.Trim()) || "".Equals(tbDepartment.Text.Trim()) || (radioFirst.Checked == false && radioSecond.Checked == false) ) { errorLabel.Text = "Popunite sva polja!"; errorLabel.Visible = true; return; } if (tbPassword.Text.Length < 8) { errorLabel.Text = "Lozinka mora imati najmanje 8 karaktera!"; errorLabel.Visible = true; return; } DatabaseModel db = new DatabaseModel(); //check username duplicates var query = from insp in db.inspectors where insp.username == tbUsername.Text select insp; if (query.Count() != 0) { errorLabel.Text = "Postoji nalog sa tim korisničkim imenom!"; errorLabel.Visible = true; return; } string salt = CreateString(4); inspector i = new inspector() { first_name = tbName.Text, last_name = tbLastname.Text, username = tbUsername.Text, department = tbDepartment.Text, isActive = (sbyte)1, is_coordinator = (sbyte)0, unavailable = (sbyte)0, shift = radioFirst.Checked ? 1 : 2, salt = salt, password_hash = Form1.generateHash(tbPassword.Text, salt) }; db.inspectors.Add(i); db.SaveChanges(); this.Close(); }
private void obrišiToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { MessageBox.Show("Niste odabrali nijedan nalog."); return; } DialogResult result = MessageBox.Show("Da li ste sigurni da želite obrisati odabrane naloge?", "Brisanje naloga", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { int selIndex = dataGridView1.SelectedRows[0].Index; for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) { int id = 0; try { id = (int)dataGridView1.SelectedRows[i].Cells[0].Value; } catch (NullReferenceException) { //the row is already deleted continue; } inspector ins = db.inspectors.Find(id); //check if user is deleting himself if (ins.id == startForm.id) { MessageBox.Show("Ne možete obrisati trenutno aktivan nalog."); return; } if (ins != null) { ins.isActive = 0; } } db.SaveChanges(); InspectorView_Load(sender, e); if (selIndex != 0 && selIndex < dataGridView1.Rows.Count) { dataGridView1.Rows[selIndex - 1].Selected = true; } } }