Esempio n. 1
0
 private void BtnAgregarArticulo_Click(object sender, EventArgs e)
 {
     if (int.TryParse(txtCantidad.Text, out int cantidad))
     {
         if (cantidad > ExistenciaArticulo)
         {
             MessageBox.Show($"No contamos con la cantidad indicada de artículos en existencia.\n la cantidad actual del artículo es: {ExistenciaArticulo}");
             txtCantidad.Text = ExistenciaArticulo.ToString();
         }
         else
         {
             var detalleNota = DetallesNotas.FirstOrDefault(x => x.IdArticulo.ToString() == txtIdArticulo.Text);
             if (detalleNota != null)
             {
                 detalleNota.Cantidad = cantidad;
             }
             else
             {
                 DgvDetalleNota data = DetallesNotas.AddNew();
                 data.Cantidad    = cantidad;
                 data.IdArticulo  = Convert.ToInt32(txtIdArticulo.Text);
                 data.Articulo    = txtDescripcionArticulo.Text;
                 data.PrecioVenta = Convert.ToDecimal(txtPrecioUnitario.Text);
                 data.Total       = data.Cantidad * data.PrecioVenta;
                 DetallesNotas.EndNew(DetallesNotas.IndexOf(data));
             }
             LimpiarArticulo();
         }
     }
     else
     {
         MessageBox.Show("Ingrese una cantidad válida.");
     }
 }
Esempio n. 2
0
 private void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (dgv.Rows[e.RowIndex].Cells[2].Value != null)
     {
         int total = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells[3].Value) * Convert.ToInt32(dgv.Rows[e.RowIndex].Cells[4].Value);
         BindingLista[e.RowIndex].Total = total;
         calculatotal();
         BindingLista.EndNew(e.RowIndex);
         dgv.Refresh();
     }
     else
     {
         BindingLista.RemoveAt(e.RowIndex);
     }
 }
Esempio n. 3
0
        public void TestAddNew_EndDifferentIndexThenCancel()
        {
            BindingList <object> l = new BindingList <object>();

            bool   adding_event_raised = false;
            object o = new object();

            bool            list_changed       = false;
            ListChangedType change_type        = ListChangedType.Reset;
            int             list_changed_index = -1;

            l.AddingNew += delegate(object sender, AddingNewEventArgs e)
            {
                adding_event_raised = true;
                Assert.Null(e.NewObject);
            };

            l.ListChanged += delegate(object sender, ListChangedEventArgs e)
            {
                list_changed       = true;
                change_type        = e.ListChangedType;
                list_changed_index = e.NewIndex;
            };

            object rv = l.AddNew();

            Assert.True(adding_event_raised, "2");
            Assert.NotNull(rv);

            Assert.Equal(1, l.Count);
            Assert.Equal(0, l.IndexOf(rv));
            Assert.True(list_changed, "6");
            Assert.Equal(ListChangedType.ItemAdded, change_type);
            Assert.Equal(0, list_changed_index);

            list_changed = false;

            l.EndNew(2);

            Assert.Equal(1, l.Count);
            Assert.False(list_changed, "10");

            l.CancelNew(0);

            Assert.True(list_changed, "11");
            Assert.Equal(ListChangedType.ItemDeleted, change_type);
            Assert.Equal(0, list_changed_index);
        }
        public void TestAddNew_CancelDifferentIndexThenEnd()
        {
            BindingList <object> l = new BindingList <object>();

            bool   adding_event_raised = false;
            object o = new object();

            bool            list_changed       = false;
            ListChangedType change_type        = ListChangedType.Reset;
            int             list_changed_index = -1;

            l.AddingNew += delegate(object sender, AddingNewEventArgs e)
            {
                adding_event_raised = true;
                Assert.IsNull(e.NewObject, "1");
            };

            l.ListChanged += delegate(object sender, ListChangedEventArgs e)
            {
                list_changed       = true;
                change_type        = e.ListChangedType;
                list_changed_index = e.NewIndex;
            };

            object rv = l.AddNew();

            Assert.IsTrue(adding_event_raised, "2");
            Assert.IsNotNull(rv, "3");

            Assert.AreEqual(1, l.Count, "4");
            Assert.AreEqual(0, l.IndexOf(rv), "5");
            Assert.IsTrue(list_changed, "6");
            Assert.AreEqual(ListChangedType.ItemAdded, change_type, "7");
            Assert.AreEqual(0, list_changed_index, "8");

            list_changed = false;

            l.CancelNew(2);

            Assert.AreEqual(1, l.Count, "9");
            Assert.IsFalse(list_changed, "10");

            l.EndNew(0);

            Assert.AreEqual(1, l.Count, "11");
            Assert.IsFalse(list_changed, "12");
        }
Esempio n. 5
0
        public void AddNew_EndDifferenceIndexThanCancel_Success()
        {
            var bindingList = new BindingList <object>();

            bool            calledAddingNew   = false;
            bool            calledListChanged = false;
            ListChangedType listChangedType   = ListChangedType.Reset;
            int             listChangedIndex  = -1;

            bindingList.AddingNew += (object sender, AddingNewEventArgs e) =>
            {
                calledAddingNew = true;
                Assert.Null(e.NewObject);
            };
            bindingList.ListChanged += (object sender, ListChangedEventArgs e) =>
            {
                calledListChanged = true;
                listChangedType   = e.ListChangedType;
                listChangedIndex  = e.NewIndex;
            };

            // Make sure AddNew changed the list.
            object newValue = bindingList.AddNew();

            Assert.True(calledAddingNew);
            Assert.NotNull(newValue);

            Assert.Equal(1, bindingList.Count);
            Assert.Equal(0, bindingList.IndexOf(newValue));
            Assert.True(calledListChanged);
            Assert.Equal(ListChangedType.ItemAdded, listChangedType);
            Assert.Equal(0, listChangedIndex);

            // EndNew with an invalid index does not change the list.
            calledListChanged = false;
            bindingList.EndNew(2);
            Assert.Equal(1, bindingList.Count);
            Assert.False(calledListChanged);

            // CancelNew with a valid index changes the list.
            bindingList.CancelNew(0);
            Assert.True(calledListChanged);
            Assert.Equal(ListChangedType.ItemDeleted, listChangedType);
            Assert.Equal(0, listChangedIndex);
        }
Esempio n. 6
0
        public void AddNew_CancelDifferentIndexThenEnd_Success()
        {
            var list = new BindingList <object>();

            bool            calledAddingNew   = false;
            bool            calledListChanged = false;
            ListChangedType listChangedType   = ListChangedType.Reset;
            int             listChangedIndex  = -1;

            list.AddingNew += delegate(object sender, AddingNewEventArgs e)
            {
                calledAddingNew = true;
                Assert.Null(e.NewObject);
            };
            list.ListChanged += delegate(object sender, ListChangedEventArgs e)
            {
                calledListChanged = true;
                listChangedType   = e.ListChangedType;
                listChangedIndex  = e.NewIndex;
            };

            // Make sure AddNew changed the list.
            object newValue = list.AddNew();

            Assert.True(calledAddingNew);
            Assert.NotNull(newValue);

            Assert.Equal(1, list.Count);
            Assert.Equal(0, list.IndexOf(newValue));
            Assert.True(calledListChanged);
            Assert.Equal(ListChangedType.ItemAdded, listChangedType);
            Assert.Equal(0, listChangedIndex);

            // Calling CancelNew on an invalid index does not change the list.
            calledListChanged = false;
            list.CancelNew(2);
            Assert.Equal(1, list.Count);
            Assert.False(calledListChanged);

            // Calling EndNew does not change the list.
            list.EndNew(0);
            Assert.Equal(1, list.Count);
            Assert.False(calledListChanged);
        }
Esempio n. 7
0
        public void AddNew_EndNew_Success()
        {
            var bindingList = new BindingList <object>();

            bool            calledAddNew      = false;
            bool            calledListChanged = false;
            ListChangedType listChangedType   = ListChangedType.Reset;
            int             listChangedIndex  = -1;

            bindingList.AddingNew += (object sender, AddingNewEventArgs e) =>
            {
                calledAddNew = true;
                Assert.Null(e.NewObject);
            };
            bindingList.ListChanged += (object sender, ListChangedEventArgs e) =>
            {
                calledListChanged = true;
                listChangedType   = e.ListChangedType;
                listChangedIndex  = e.NewIndex;
            };

            // Make sure the item was added.
            object newValue = bindingList.AddNew();

            Assert.True(calledAddNew);
            Assert.NotNull(newValue);

            Assert.Equal(1, bindingList.Count);
            Assert.Equal(0, bindingList.IndexOf(newValue));
            Assert.True(calledListChanged);
            Assert.Equal(ListChangedType.ItemAdded, listChangedType);
            Assert.Equal(0, listChangedIndex);

            // EndNew does not change the list.
            calledListChanged = false;
            bindingList.EndNew(0);
            Assert.Equal(1, bindingList.Count);
            Assert.False(calledListChanged);
        }