private void Eliminar()
 {
     try
     {
         if (MessageBox.Show("¿Esta seguro de eliminar el registro?", "Eliminar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             Cursor = Cursors.WaitCursor;
             var _context          = new ApplicationDbContext();
             var _AlmacenViewModel = (AlmacenViewModel)almacenViewModelBindingSource.Current;
             var _Almacen          = _context.Almacens
                                     .Where(o => o.AlmacenId == _AlmacenViewModel.AlmacenId)
                                     .FirstOrDefault();
             _context.Almacens.Remove(_Almacen);
             _context.SaveChanges();
             _AlmacenViewModels.Remove(_AlmacenViewModel);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Ocurrió un error al eliminar, mensaje de error: {0}", ex.Message)
                         , "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Cursor = Cursors.Default;
     }
 }
 private void Eliminar()
 {
     try
     {
         if (MessageBox.Show("¿Esta seguro de eliminar el registro?", "Eliminar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             Cursor = Cursors.WaitCursor;
             var context   = new ApplicationDbContext();
             var viewModel = (TipoMercaderiaViewModel)tipoMercaderiaViewModelBindingSource.Current;
             var model     = context.TipoMercaderias
                             .Where(o => o.TipoMercaderiaId == viewModel.TipoMercaderiaId)
                             .FirstOrDefault();
             context.TipoMercaderias.Remove(model);
             context.SaveChanges();
             ViewModelList.Remove(viewModel);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Ocurrió un error al eliminar, mensaje de error: {0}", ex.Message)
                         , "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Cursor = Cursors.Default;
     }
 }
Exemple #3
0
        private void BtnEliminarEmpleado_Click(object sender, EventArgs e)
        {
            try
            {
                var empleado = (Empleado)empleadoBindingSource.Current;

                if (empleado != null)
                {
                    empleados.Remove(empleado);
                }
                else
                {
                    throw new Exception("Debe de seleccionar un registro a eliminar");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Ocurrió un error: {0}", ex.Message), "Eliminar Empleado", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        public void ObservableListSource_GetList_returns_BindingList_attached_to_the_ObservableCollection()
        {
            var ols = new ObservableListSource <FakeEntity>
            {
                new FakeEntity(),
                new FakeEntity()
            };
            var bindingList = ((IListSource)ols).GetList();

            Assert.Equal(2, bindingList.Count);

            ols.Add(new FakeEntity());
            Assert.Equal(3, bindingList.Count);

            ols.Remove(ols[0]);
            Assert.Equal(2, bindingList.Count);

            bindingList.Add(new FakeEntity());
            Assert.Equal(3, ols.Count);

            bindingList.RemoveAt(0);
            Assert.Equal(2, ols.Count);
        }
Exemple #5
0
        private void CarregarDados(bool recarregarListaDeAtivos = false)
        {
            if (ContaAtual == null)
            {
                return;
            }

            if (recarregarListaDeAtivos)
            {
                _acoes.Remove(a => a.ContaId > 0);
                _acoes.AddRange(ContaAtual.AcoesNaoZerado);
                bsCotacoes.DataSource = _acoes;
            }
            else
            {
                bsCotacoes.Sort = "Codigo";
                dgvCotacoes.Refresh();
            }
            dgvTotal.Refresh();

            AtualizarGrafico();

            toolStripStatusLabelAtualizadoEm.Text = $@"Atualizado em: {DateTime.Now}";
            toolStripStatusLabelErros.Text        = $@"Erros: {Erros}";

            // Alerta de venda
            if (_acoes.Any(a => a.AlertaVenda >= 1.00m && a.AlertaVenda < 1.004m))
            {
                var x = _acoes.Where(a => a.AlertaVenda > 1.00m && a.AlertaVenda < 1.004m)
                        .Select(a => $"{a.Codigo} - Compra: {a.ValorMedioCompra:c2} - Atual: {a.LastTrade:c2}");
                var popup = new PopupNotifier
                {
                    Size           = new Size(450, 75 * x.Count()),
                    Delay          = 10000,
                    Image          = Resources.alert_icon,
                    HeaderColor    = Color.Red,
                    TitleColor     = Color.Red,
                    TitleFont      = new Font("Segoe UI Semibold", 18),
                    TitlePadding   = new Padding(10),
                    TitleText      = "Alerta de Venda de Ações",
                    ContentFont    = new Font("Segoe UI", 14),
                    ContentText    = x.Aggregate((current, next) => current + "\n" + next),
                    ContentPadding = new Padding(10)
                };
                popup.Popup();
            }

            // Resize if number of Ativos changes
            var oldHeight = (int)tableLayoutPanel1.RowStyles[0].Height;
            var newHeight = dgvCotacoes.ColumnHeadersHeight +
                            (dgvCotacoes.RowTemplate.Height + 2) *
                            Math.Min(10, bsCotacoes.Count);

            if (oldHeight == newHeight)
            {
                return;
            }

            tableLayoutPanel1.RowStyles[0].Height = newHeight;
            Height = Height - oldHeight + newHeight;
        }