public void Delete(PropertyInterface myProperty, int SelektovaniRed, Bunifu.Framework.UI.BunifuCustomDataGrid dgv)
        {
            try
            {
                DataGridViewRow row        = dgv.SelectedRows[0];
                var             properties = myProperty.GetType().GetProperties();

                foreach (PropertyInfo item in properties)
                {
                    if (item.GetCustomAttribute <PrimaryKeyAttribute>() != null)
                    {
                        string value = row.Cells[item.GetCustomAttribute <SqlNameAttribute>().Name]
                                       .Value.ToString();

                        item.SetValue(myProperty, Convert.ChangeType(value, item.PropertyType));
                    }
                }

                SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text,
                                          myProperty.GetDeleteQuery(), myProperty.GetDeleteParameters().ToArray());
                CRUD.IstorijaCRUD.Istorija(UserEmail, StateEnum.Delete, myProperty);
                //PopulateGrid(myProperty);
            }
            catch (System.Data.SqlClient.SqlException)
            {
                MessageBox.Show("\n\nNemoguce je obrisati ovaj red zbog povezanosti sa drugim tabelama!!!\n\n", "Greska pri brisanju!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
 private void tileObrisi_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvPrikaz.SelectedRows[0] != null)
         {
             if (MessageBox.Show("Da li ste sigurni da zelite da obrisete ovaj podatak?", "Poruka", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 populatePropertyInterface();
                 try
                 {
                     SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text, myProperty.GetDeleteQuery(), myProperty.GetDeleteParameters().ToArray());
                     MessageBox.Show("Podatak je obrisan!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     refreshTable();
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Brisanje nije moguće, podatak se koristi u drugoj tabeli!", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Selektujte u tabeli podatak za brisanje!", "Poruka", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Beispiel #3
0
        private void tsbtnObrisi_Click(object sender, EventArgs e)
        {
            try
            {
                var properties = property.GetType().GetProperties();

                PropertyInfo myProperty = properties.Where(x => x.IsDefined(typeof(PrimaryKeyAttribute))).FirstOrDefault();
                myProperty.SetValue(property, Convert.ChangeType(dgvPrikaz.SelectedRows[0].Cells[0].Value, myProperty.PropertyType));
                if (DialogResult.Yes == (MessageBox.Show("Da li zelite da izbrisete izabrani red?", "Informacija o brisanju", MessageBoxButtons.YesNo
                                                         , MessageBoxIcon.Warning)))
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.GetConnectionString(), CommandType.Text, property.GetDeleteQuery(), property.GetDeleteParameters().ToArray());
                    UcitajDGV(property);
                }
                state = StateEnum.Preview;
                txtPretraga.Enabled = true;
            }
            catch
            {
                if (property.GetType() == typeof(FilmPropertyClass))
                {
                    MessageBox.Show("Film je koristen u jednom od repertoara i ne moze biti obrisan!", "Poruka", MessageBoxButtons.OK);
                    return;
                }
            }
        }