Ejemplo n.º 1
0
        public void PlantRemove()
        {
            if (this.ParentForm?.Name != "MainForm")
            {
                return;
            }

            herbariumEntities      entity      = new herbariumEntities();
            List <plant>           plants      = new List <plant>();
            List <DataGridViewRow> toBeDeleted = new List <DataGridViewRow>();

            if (dtgDataView.SelectedRows.Count > 0 && MessageBox.Show(dtgDataView.SelectedRows.Count + " adet bitki kaydını silmek istediğinize emin misiniz?", "Emin misiniz?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                foreach (DataGridViewRow dr in dtgDataView.SelectedRows)
                {
                    plant silinecek = entity.plant.Find(Convert.ToInt32(dr.Cells[0].Value));
                    plants.Add(silinecek);
                    DataRow row = (dr.DataBoundItem as DataRowView).Row;
                    Log.Debug("Silinen bitki kaydı" + silinecek.herbno, "Silinen bitki:\n" + Log.PlantRowToJson(row));
                    toBeDeleted.Add(dr);
                }
                entity.plant.RemoveRange(plants);
                entity.SaveChanges();
                ShowMessage.Success("Silme işlemi başarılı");

                foreach (DataGridViewRow row in toBeDeleted)
                {
                    dtgDataView.Rows.Remove(row);
                }
            }
        }
Ejemplo n.º 2
0
        public void PlantRemove()
        {
            if (UserBLL.YekisiYok("Bitki Sil"))
            {
                return;
            }
            if (this.ParentForm?.Name != "MainForm")
            {
                return;
            }

            herbariumEntities      entity      = new herbariumEntities();
            List <plant>           plants      = new List <plant>();
            List <DataGridViewRow> toBeDeleted = new List <DataGridViewRow>();

            if (dtgDataView.SelectedRows.Count > 0 && MessageBox.Show(dtgDataView.SelectedRows.Count + " adet bitki kaydını silmek istediğinize emin misiniz?", "Emin misiniz?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                foreach (DataGridViewRow dr in dtgDataView.SelectedRows)
                {
                    plant silinecek = entity.plant.Find(Convert.ToInt32(dr.Cells[0].Value));
                    silinecek.grid.Clear();
                    plants.Add(silinecek);
                    DataRow row = (dr.DataBoundItem as DataRowView).Row;
                    Log.Debug("[Silinen Bitki]: " + silinecek.herbno, $"{silinecek.herbno} kodlu {DateTime.Now.ToString()} tarihinde  {UserBLL.ActiveUser.name} tarafından {row["Tür"]} silindi.\nSilinen bitkinin detayları:\n" + Log.PlantRowToJson(row));
                    toBeDeleted.Add(dr);
                }
                entity.plant.RemoveRange(plants);
                entity.SaveChanges();
                ShowMessage.Success("Silme işlemi başarılı");

                foreach (DataGridViewRow row in toBeDeleted)
                {
                    dtgDataView.Rows.Remove(row);
                }
            }
        }