Пример #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (_canChange)
     {
         if (MessageBox.Show("Czy chcesz usunąć wpis?", "Usuwanie", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
             {
                 var entry = db.Entry(_payments);
                 if (entry.State == System.Data.Entity.EntityState.Detached)
                 {
                     db.Payments.Attach(_payments);
                 }
                 db.Payments.Remove(_payments);
                 db.SaveChanges();
                 ReloadGrid();
                 Clear();
             }
         }
     }
     else
     {
         MessageBox.Show("Kliknij 2x na wiersz, który chcesz usunąć - następnie usuń");
     }
 }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //sprawdzic czy jest uzupelnione
            if (txtValue.Text != "" & txtPlace.Text != "" & txtType.Text != "" & dateTimePickPayments.Value.ToString() != "" && txtNamePayment.Text != "")
            {
                _payments.ValuePayment = decimal.Parse(txtValue.Text);
                _payments.PlaceName    = txtPlace.Text.Trim();
                _payments.TypeName     = txtType.Text.Trim();
                _payments.DatePayment  = dateTimePickPayments.Value;
                _payments.ShopName     = txtNamePayment.Text.Trim();

                using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
                {
                    if (_payments.IdPayment == 0) //insert
                    {
                        db.Payments.Add(_payments);
                    }
                    else //update
                    {
                        db.Entry(_payments).State = System.Data.Entity.EntityState.Modified; //ustawienie flagi na update
                    }
                    db.SaveChanges();
                }
                ReloadGrid();
                Clear();
            }
            else
            {
                MessageBox.Show("Uzupełnij dane - następnie dodaj");
            }
        }