Beispiel #1
0
        private void gastosToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            HandleVisibleIngresarMov(true);
            HandleVisiblePeriodo(false);
            HandleVisibleIngresarArticulo(false);
            HandleVisibleTable(false);
            this.buttonOKPeriodo.Visible = true;
            this.labelMaestro.Text       = "Ingresar Gasto";


            Properties.MovPorUsuariosEntities consultaM = BusinessEntity.GetEntity();
            consultaM.ARTICULOS.Load();

            Dictionary <int, string> arrayArticulos = consultaM.ARTICULOS
                                                      .ToDictionary((Properties.ARTICULOS art) => art.ID, (Properties.ARTICULOS art) => art.Concepto);

            this.comboBoxArticle.DataSource    = new BindingSource(arrayArticulos, null);
            this.comboBoxArticle.DisplayMember = "Value";
            this.comboBoxArticle.ValueMember   = "Key";
        }
Beispiel #2
0
        public int GetID()
        {
            Properties.MovPorUsuariosEntities porUsuariosEntities = GetEntity();
            int number = randomNumbers.Next(0, int.MaxValue);

            porUsuariosEntities.ARTICULOS.Load();
            for (bool retry = true; retry == true;)
            {
                System.Int32 countItem = porUsuariosEntities.ARTICULOS
                                         .Where((Properties.ARTICULOS artP) => artP.ID == number)
                                         .Count();
                if (countItem == 0)
                {
                    retry = false;
                }
                else
                {
                    number = randomNumbers.Next(0, int.MaxValue);
                    retry  = true;
                }
            }
            return(number);
        }
Beispiel #3
0
        private void buttonOKPeriodo_Click(object sender, EventArgs e)
        {
            Article      myArticle;
            BusinessItem myBussItem;
            int          IDBase;
            decimal      precioUnitario;
            int          cantidadLeida;
            DataTable    dt;
            DateTime     fechasup;
            DateTime     fechainf;

            Properties.MovPorUsuariosEntities myMov = BusinessEntity.GetEntity();
            Properties.ARTICULOS   artip            = new Properties.ARTICULOS();
            Properties.MOVIMIENTOS movp             = new Properties.MOVIMIENTOS();

            if (this.labelMaestro.Text == "Ingresar Articulo")
            {
                IngresarArticulo(out myArticle);
                IDBase                   = myArticle.GetID();
                artip.ID                 = IDBase;
                artip.Concepto           = myArticle.Concepto;
                artip.Descripcion        = myArticle.Description;
                artip.Tipo_de_Movimiento = myArticle.MovementString;
                myMov.ARTICULOS.Local.Add(artip);
                myMov.SaveChanges();

                this.IconType   = MessageBoxIcon.Information;
                this.ButtonType = MessageBoxButtons.OK;

                MessageBox.Show($"El articulo fue registrado exitosamente", "New Article", this.ButtonType, this.IconType);
            }
            else if (this.labelMaestro.Text == "Ingresar Gasto")
            {
                KeyValuePair <int, string> selectedComboBox = (KeyValuePair <int, string>) this.comboBoxArticle.SelectedItem;
                precioUnitario = decimal.Parse(this.textBoxPrecioUnitario.Text);
                cantidadLeida  = System.Int32.Parse(this.InputCantidad.Text);
                myBussItem     = new BusinessItem(precioUnitario, cantidadLeida, selectedComboBox.Key, DateTime.Today, this.IDUser);

                movp.Precio_Unitario = (double)myBussItem.PricePerUnit;
                movp.N_de_movimiento = myBussItem.GetNumberOfMovement();
                movp.Cantidad        = myBussItem.Quantity;
                movp.ID_Articulo     = myBussItem.IDArt;
                movp.ID_Usuario      = myBussItem.IDUser;
                movp.Fecha           = myBussItem.DateOfMovement;

                this.IconType   = MessageBoxIcon.Information;
                this.ButtonType = MessageBoxButtons.OK;
                myMov.MOVIMIENTOS.Local.Add(movp);
                myMov.SaveChanges();
                MessageBox.Show($"El movimiento fue registrado exitosamente", "New Movement", this.ButtonType, this.IconType);
            }
            else if (this.labelMaestro.Text == "Datos Gastos")
            {
                fechasup = DateTime.Parse(this.inputFechaSup.Text);
                fechainf = DateTime.Parse(this.inputFechaInf.Text);

                myMov.MOVIMIENTOS.Load();
                myMov.ARTICULOS.Load();
                DateTime.Parse("03/01/2020");
                var queryByDate = myMov.MOVIMIENTOS
                                  .Where((Properties.MOVIMIENTOS itemMov) => itemMov.Fecha.Value >= fechainf && itemMov.Fecha.Value <= fechasup && itemMov.ID_Usuario.Value == this.IDUser)
                                  .Join(myMov.ARTICULOS.Select((ARTICULOS item) => item),
                                        (MOVIMIENTOS itemM) => itemM.ID_Articulo,
                                        (ARTICULOS itemA) => itemA.ID,
                                        (MOVIMIENTOS itemM, ARTICULOS itemA) => new { cantidad = itemM.Cantidad.Value, precioUnit = itemM.Precio_Unitario.Value, concept = itemA.Concepto, fech = itemM.Fecha.Value })
                                  .OrderByDescending(item => item.fech);

                dt = LINQToData(queryByDate);
                this.dataGridView1.DataSource        = dt;
                this.bindingSource1.DataSource       = dt;
                this.bindingNavigator1.BindingSource = this.bindingSource1;
            }
            else if (this.labelMaestro.Text == "Balance por Periodo")
            {
                fechasup = DateTime.Parse(this.inputFechaSup.Text);
                fechainf = DateTime.Parse(this.inputFechaInf.Text);
                myMov.MOVIMIENTOS.Load();
                myMov.ARTICULOS.Load();
                double gastos = 0;
                try
                {
                    gastos = myMov.MOVIMIENTOS
                             .Where((Properties.MOVIMIENTOS item) => item.ID_Usuario == this.IDUser && item.Fecha.Value >= fechainf && item.Fecha.Value <= fechasup &&
                                    myMov.ARTICULOS.Where((Properties.ARTICULOS itemArt) => itemArt.ID == item.ID_Articulo && (itemArt.Tipo_de_Movimiento.Contains("Gas") ||
                                                                                                                               itemArt.Tipo_de_Movimiento.Contains("Inv")))
                                    .Any())
                             .Select((Properties.MOVIMIENTOS item) => item.Precio_Unitario.Value * item.Cantidad.Value)
                             .Sum();
                }
                catch (InvalidOperationException)
                {
                    gastos = 0; // El caso en que no hay ningun item para Sum() Falla con este tipo de excepcion
                }


                double ganancias = 0;

                try
                {
                    ganancias = myMov.MOVIMIENTOS
                                .Where((Properties.MOVIMIENTOS item) => item.ID_Usuario == this.IDUser && item.Fecha.Value >= fechainf && item.Fecha.Value <= fechasup &&
                                       myMov.ARTICULOS.Where((Properties.ARTICULOS itemArt) => itemArt.ID == item.ID_Articulo && (itemArt.Tipo_de_Movimiento.Contains("Ven") ||
                                                                                                                                  itemArt.Tipo_de_Movimiento.Contains("Sal")))
                                       .Any())
                                .Select((Properties.MOVIMIENTOS item) => item.Precio_Unitario.Value * item.Cantidad.Value)
                                .Sum();
                }
                catch (InvalidOperationException)
                {
                    ganancias = 0; // El caso en que no hay ningun item para Sum() falla con este tipo de excepcion
                }

                this.IconType   = MessageBoxIcon.Information;
                this.ButtonType = MessageBoxButtons.OK;

                MessageBox.Show($"Los gastos totales son {gastos}\nLas ganancias totales son {ganancias}", "Resumen", this.ButtonType, this.IconType);
            }
        }