private void printableListView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            modificarButton.Enabled = true;
            eliminarButton.Enabled  = true;

            ListViewItem selectedItem = e.Item;

            selectedItem.Checked = true;

            if (_selectedindex != -1 && _selectedindex != e.ItemIndex)
            {
                printableListView1.Items[_selectedindex].Checked = false;
            }

            _selectedindex = e.ItemIndex;

            //Cargo los valores del elemento seleccionado en los componentes
            var user =
                (usuarios)_entities.GetObjectByKey(new EntityKey("mayaEntities.usuarios", "id", _idUser[selectedItem.Index]));

            tboxNombre.Text    = user.nombre;
            tboxApellidos.Text = user.apellidos;
            tboxUsuarios.Text  = user.usuario;
            tboxPass.Text      = user.pass;
            tboxPass2.Text     = user.pass;

            //busco los roles del usuario
            int index_rol = _idrol.FindIndex(r => r == user.id_rol);

            comboBox1.SelectedIndex = index_rol;
        }
Exemple #2
0
        private void aceptarButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (nuevo)
                {
                    if (string.IsNullOrEmpty(tbxPuntoVenta.Text))
                    {
                        MessageBox.Show("El punto de venta no puede ser vacío", "Error en la entrada de datos",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    _entities.AddTopunto_venta(new punto_venta
                    {
                        valor = tbxPuntoVenta.Text
                    });
                    _entities.AddTobitacora(new bitacora
                    {
                        id_usuario  = this._user.id,
                        descripcion = "El usuario " + this._user.nombre + " ha creado el punto de venta " + tbxPuntoVenta.Text,
                        fecha       = DateTime.Now
                    });
                    _entities.SaveChanges();
                    this.Reload();
                }
                else
                {
                    punto_venta pv =
                        (punto_venta)
                        _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                               _idPuntoVenta[_selectedIndex]));
                    if (pv.valor.Equals(tbxPuntoVenta.Text))
                    {
                        return;
                    }
                    pv.valor = tbxPuntoVenta.Text;

                    _entities.AddTobitacora(new bitacora
                    {
                        id_usuario  = _user.id,
                        descripcion = "El usuario " + _user.nombre + " ha modificado el punto de venta " + pv.valor,
                        fecha       = DateTime.Now
                    });
                    _entities.SaveChanges();
                    this.Reload();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public ListadoProductosInventario(usuarios user, int id_punto_venta)
 {
     InitializeComponent();
     _entities = new mayaEntities();
     _user     = user;
     _pv       =
         (punto_venta)_entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id", id_punto_venta));
 }
Exemple #4
0
        private void Reload()
        {
            try
            {
                this.printableListView1.Items.Clear();



                if (fecha_inicio.Value.Date > fecha_fin.Value.Date)
                {
                    MessageBox.Show("La fecha de inicio debe ser menor que la fecha final",
                                    "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //Variable para los valores totales por dias del punto de venta
                decimal valor        = 0;
                int     tejedora     = 0;
                int     tipoProducto = 0;

                //Caso en que se levanta la ventana por defecto o si selecciona el almacen
                if (comboBox1.SelectedIndex == 0 || comboBox1.SelectedIndex == 1)
                {
                    if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex == 0)
                    {
                        valor += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == null), p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString("dd/MM/yyyy"),
                            "Almacén",
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture), 2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex == 0)
                    {
                        tejedora = _idTejedora[cbTejedora.SelectedIndex];
                        valor   += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == null && pro.id_tejedora == tejedora), p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString("dd/MM/yyyy"),
                            "Almacén",
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture), 2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex != 0)
                    {
                        tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                        valor       += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == null && pro.id_tipo_producto == tipoProducto), p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString("dd/MM/yyyy"),
                            "Almacén",
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture), 2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex != 0)
                    {
                        tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                        tejedora     = _idTejedora[cbTejedora.SelectedIndex];
                        valor       += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == null && pro.id_tipo_producto == tipoProducto && pro.id_tejedora == tejedora), p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString("dd/MM/yyyy"),
                            "Almacén",
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture), 2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date != fecha_fin.Value.Date && cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex == 0)
                    {
                        int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                        for (int i = 0; i <= cant_dias; i++)
                        {
                            valor = 0;
                            foreach (var p in _entities.productos)
                            {
                                if (p.fecha_entrada.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                {
                                    if (p.fecha_salida == null)
                                    {
                                        if (p.fecha_devolucion == null)
                                        {
                                            valor += p.valor;
                                        }
                                        else
                                        {
                                            if (p.fecha_devolucion.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                            }
                            DateTime aux = fecha_inicio.Value.AddDays(i);
                            this.printableListView1.Items.Add(new ListViewItem(new[]
                            {
                                aux.Date.ToString("dd/MM/yyyy"),
                                "Almacén",
                                Math.Round(
                                    Convert.ToDecimal(valor,
                                                      CultureInfo.
                                                      InvariantCulture), 2)
                                .ToString()
                            }));
                        }
                    }
                    else if (fecha_inicio.Value.Date != fecha_fin.Value.Date && cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex == 0)
                    {
                        int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                        tejedora = _idTejedora[cbTejedora.SelectedIndex];
                        for (int i = 0; i <= cant_dias; i++)
                        {
                            valor = 0;
                            foreach (var p in _entities.productos.Where(pro => pro.id_tejedora == tejedora))
                            {
                                if (p.fecha_entrada.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                {
                                    if (p.fecha_salida == null)
                                    {
                                        if (p.fecha_devolucion == null)
                                        {
                                            valor += p.valor;
                                        }
                                        else
                                        {
                                            if (p.fecha_devolucion.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                            }
                            DateTime aux = fecha_inicio.Value.AddDays(i);
                            this.printableListView1.Items.Add(new ListViewItem(new[]
                            {
                                aux.Date.ToString("dd/MM/yyyy"),
                                "Almacén",
                                Math.Round(
                                    Convert.ToDecimal(valor,
                                                      CultureInfo.
                                                      InvariantCulture), 2)
                                .ToString()
                            }));
                        }
                    }
                    else if (fecha_inicio.Value.Date != fecha_fin.Value.Date && cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex != 0)
                    {
                        int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                        tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                        for (int i = 0; i <= cant_dias; i++)
                        {
                            valor = 0;
                            foreach (var p in _entities.productos.Where(pro => pro.id_tipo_producto == tipoProducto))
                            {
                                if (p.fecha_entrada.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                {
                                    if (p.fecha_salida == null)
                                    {
                                        if (p.fecha_devolucion == null)
                                        {
                                            valor += p.valor;
                                        }
                                        else
                                        {
                                            if (p.fecha_devolucion.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                            }
                            DateTime aux = fecha_inicio.Value.AddDays(i);
                            this.printableListView1.Items.Add(new ListViewItem(new[]
                            {
                                aux.Date.ToString("dd/MM/yyyy"),
                                "Almacén",
                                Math.Round(
                                    Convert.ToDecimal(valor,
                                                      CultureInfo.
                                                      InvariantCulture), 2)
                                .ToString()
                            }));
                        }
                    }
                    else if (fecha_inicio.Value.Date != fecha_fin.Value.Date && cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex != 0)
                    {
                        int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                        tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                        tejedora     = _idTejedora[cbTejedora.SelectedIndex];
                        for (int i = 0; i <= cant_dias; i++)
                        {
                            valor = 0;
                            foreach (var p in _entities.productos.Where(pro => pro.id_tipo_producto == tipoProducto && pro.id_tejedora == tejedora))
                            {
                                if (p.fecha_entrada.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                {
                                    if (p.fecha_salida == null)
                                    {
                                        if (p.fecha_devolucion == null)
                                        {
                                            valor += p.valor;
                                        }
                                        else
                                        {
                                            if (p.fecha_devolucion.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                            }
                            DateTime aux = fecha_inicio.Value.AddDays(i);
                            this.printableListView1.Items.Add(new ListViewItem(new[]
                            {
                                aux.Date.ToString("dd/MM/yyyy"),
                                "Almacén",
                                Math.Round(
                                    Convert.ToDecimal(valor,
                                                      CultureInfo.
                                                      InvariantCulture), 2)
                                .ToString()
                            }));
                        }
                    }
                }
                //Caso en que sean puntos de ventas
                else
                {
                    if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex == 0)
                    {
                        var indice =
                            (punto_venta)
                            _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                   _idPuntoVenta[comboBox1.SelectedIndex]));
                        valor += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == indice.id),
                                                p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString(
                                "dd/MM/yyyy"),
                            indice.valor,
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture),
                                2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex == 0)
                    {
                        var indice =
                            (punto_venta)
                            _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                   _idPuntoVenta[comboBox1.SelectedIndex]));
                        tejedora = _idTejedora[cbTejedora.SelectedIndex];
                        valor   += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == indice.id && pro.id_tejedora == tejedora),
                                                  p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString(
                                "dd/MM/yyyy"),
                            indice.valor,
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture),
                                2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex != 0)
                    {
                        var indice =
                            (punto_venta)
                            _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                   _idPuntoVenta[comboBox1.SelectedIndex]));
                        tejedora     = _idTejedora[cbTejedora.SelectedIndex];
                        tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                        valor       += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == indice.id && pro.id_tejedora == tejedora && pro.id_tipo_producto == tipoProducto),
                                                      p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString(
                                "dd/MM/yyyy"),
                            indice.valor,
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture),
                                2)
                            .ToString()
                        }));
                    }
                    else if (fecha_inicio.Value.Date == fecha_fin.Value.Date && cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex != 0)
                    {
                        var indice =
                            (punto_venta)
                            _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                   _idPuntoVenta[comboBox1.SelectedIndex]));
                        tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                        valor       += Enumerable.Sum(_entities.productos.Where(pro => pro.id_punto_venta == indice.id && pro.id_tipo_producto == tipoProducto),
                                                      p => p.valor);
                        this.printableListView1.Items.Add(new ListViewItem(new[]
                        {
                            fecha_inicio.Value.Date.ToString(
                                "dd/MM/yyyy"),
                            indice.valor,
                            Math.Round(
                                Convert.ToDecimal(valor,
                                                  CultureInfo.
                                                  InvariantCulture),
                                2)
                            .ToString()
                        }));
                    }
                    else
                    {
                        if (cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex == 0)
                        {
                            var indice =
                                (punto_venta)
                                _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                       _idPuntoVenta[comboBox1.SelectedIndex]));
                            int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                            for (int i = 0; i <= cant_dias; i++)
                            {
                                valor = 0;
                                foreach (var p in _entities.productos.Where(pro => pro.id_punto_venta == indice.id))
                                {
                                    if (p.fecha_salida != null)
                                    {
                                        if (p.fecha_salida.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                        {
                                            if (p.fecha_venta == null)
                                            {
                                                valor += p.valor;
                                            }
                                            else if (p.fecha_venta.Value.DayOfYear > fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                                DateTime aux = fecha_inicio.Value.AddDays(i);
                                this.printableListView1.Items.Add(new ListViewItem(new[]
                                {
                                    aux.Date.ToString("dd/MM/yyyy"),
                                    indice.valor,
                                    Math.Round(
                                        Convert.ToDecimal(valor,
                                                          CultureInfo
                                                          .
                                                          InvariantCulture),
                                        2)
                                    .ToString()
                                }));
                            }
                        }
                        else if (cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex != 0)
                        {
                            var indice =
                                (punto_venta)
                                _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                       _idPuntoVenta[comboBox1.SelectedIndex]));
                            tejedora     = _idTejedora[cbTejedora.SelectedIndex];
                            tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                            int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                            for (int i = 0; i <= cant_dias; i++)
                            {
                                valor = 0;
                                foreach (var p in _entities.productos.Where(pro => pro.id_punto_venta == indice.id && pro.id_tejedora == tejedora && pro.id_tipo_producto == tipoProducto))
                                {
                                    if (p.fecha_salida != null)
                                    {
                                        if (p.fecha_salida.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                        {
                                            if (p.fecha_venta == null)
                                            {
                                                valor += p.valor;
                                            }
                                            else if (p.fecha_venta.Value.DayOfYear > fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                                DateTime aux = fecha_inicio.Value.AddDays(i);
                                this.printableListView1.Items.Add(new ListViewItem(new[]
                                {
                                    aux.Date.ToString("dd/MM/yyyy"),
                                    indice.valor,
                                    Math.Round(
                                        Convert.ToDecimal(valor,
                                                          CultureInfo
                                                          .
                                                          InvariantCulture),
                                        2)
                                    .ToString()
                                }));
                            }
                        }
                        else if (cbTejedora.SelectedIndex != 0 && cboxTipoProducto.SelectedIndex == 0)
                        {
                            var indice =
                                (punto_venta)
                                _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                       _idPuntoVenta[comboBox1.SelectedIndex]));
                            tejedora = _idTejedora[cbTejedora.SelectedIndex];
                            int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                            for (int i = 0; i <= cant_dias; i++)
                            {
                                valor = 0;
                                foreach (var p in _entities.productos.Where(pro => pro.id_punto_venta == indice.id && pro.id_tejedora == tejedora))
                                {
                                    if (p.fecha_salida != null)
                                    {
                                        if (p.fecha_salida.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                        {
                                            if (p.fecha_venta == null)
                                            {
                                                valor += p.valor;
                                            }
                                            else if (p.fecha_venta.Value.DayOfYear > fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                                DateTime aux = fecha_inicio.Value.AddDays(i);
                                this.printableListView1.Items.Add(new ListViewItem(new[]
                                {
                                    aux.Date.ToString("dd/MM/yyyy"),
                                    indice.valor,
                                    Math.Round(
                                        Convert.ToDecimal(valor,
                                                          CultureInfo
                                                          .
                                                          InvariantCulture),
                                        2)
                                    .ToString()
                                }));
                            }
                        }
                        else if (cbTejedora.SelectedIndex == 0 && cboxTipoProducto.SelectedIndex != 0)
                        {
                            var indice =
                                (punto_venta)
                                _entities.GetObjectByKey(new EntityKey("mayaEntities.punto_venta", "id",
                                                                       _idPuntoVenta[comboBox1.SelectedIndex]));
                            tipoProducto = _idTipoProducto[cboxTipoProducto.SelectedIndex];
                            int cant_dias = fecha_fin.Value.Date.DayOfYear - fecha_inicio.Value.Date.DayOfYear;
                            for (int i = 0; i <= cant_dias; i++)
                            {
                                valor = 0;
                                foreach (var p in _entities.productos.Where(pro => pro.id_punto_venta == indice.id && pro.id_tipo_producto == tipoProducto))
                                {
                                    if (p.fecha_salida != null)
                                    {
                                        if (p.fecha_salida.Value.DayOfYear <= fecha_inicio.Value.DayOfYear + i)
                                        {
                                            if (p.fecha_venta == null)
                                            {
                                                valor += p.valor;
                                            }
                                            else if (p.fecha_venta.Value.DayOfYear > fecha_inicio.Value.DayOfYear + i)
                                            {
                                                valor += p.valor;
                                            }
                                        }
                                    }
                                }
                                DateTime aux = fecha_inicio.Value.AddDays(i);
                                this.printableListView1.Items.Add(new ListViewItem(new[]
                                {
                                    aux.Date.ToString("dd/MM/yyyy"),
                                    indice.valor,
                                    Math.Round(
                                        Convert.ToDecimal(valor,
                                                          CultureInfo
                                                          .
                                                          InvariantCulture),
                                        2)
                                    .ToString()
                                }));
                            }
                        }
                    }
                }
                ResetCombox();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }
Exemple #5
0
 private void aceptar_Click(object sender, EventArgs e)
 {
     try
     {
         if (_aumentar == 0)
         {
             if (ValidarDatos().Equals(""))
             {
                 _entities.AddTomateria_prima(new materia_prima
                 {
                     cantidad    = nCantidad.Value,
                     descripcion = tbDescripcion.Text
                 });
                 _entities.AddTobitacora(new bitacora
                 {
                     id_usuario  = _user.id,
                     descripcion = "EL usuario " + _user.nombre + " ha agregado " + nCantidad.Value.ToString() + " " + tbDescripcion.Text,
                     fecha       = DateTime.Now
                 });
                 _entities.SaveChanges();
                 this.Reload();
             }
         }
         else if (_aumentar == 1)
         {
             var x  = _idMateriaP[_selectedindex];
             var mp =
                 (materia_prima)_entities.GetObjectByKey(new EntityKey("mayaEntities.materia_prima", "id", x));
             if (nCantidad.Value == 0)
             {
                 MessageBox.Show("Al seleccionar aumentar debe introducir una cantidad a aumentar",
                                 "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             mp.cantidad += nCantidad.Value;
             _entities.AddTobitacora(new bitacora
             {
                 id_usuario  = _user.id,
                 descripcion = "El usuario " + _user.nombre + " ha agregado " + nCantidad.Value.ToString() + " elementos a " + mp.descripcion,
                 fecha       = DateTime.Now
             });
             _entities.SaveChanges();
             this.Reload();
         }
         else
         {
             var x  = _idMateriaP[_selectedindex];
             var mp =
                 (materia_prima)_entities.GetObjectByKey(new EntityKey("mayaEntities.materia_prima", "id", x));
             mp.descripcion = tbDescripcion.Text;
             mp.cantidad    = nCantidad.Value;
             _entities.AddTobitacora(new bitacora
             {
                 id_usuario  = _user.id,
                 descripcion = "El usuario " + _user.nombre + " ha modificado el elementos " + mp.descripcion,
                 fecha       = DateTime.Now
             });
             _entities.SaveChanges();
             this.Reload();
         }
     }
     catch
     {
         MessageBox.Show("error en la entrada de datos, chequear los valores", "Error", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
Exemple #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int pos_select = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells["Tejedora"].Value == null && dataGridView1.Rows[i].Cells["Cantidad_a_Asignar"].Value != null)
                    {
                        MessageBox.Show("Debe seleccionar una tejedora a la cual asignarle las materias primas",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                    if (dataGridView1.Rows[i].Cells["Tejedora"].Value != null && dataGridView1.Rows[i].Cells["Cantidad_a_Asignar"].Value == null)
                    {
                        MessageBox.Show(
                            "Debe introducir la cantidad de materias primas que desea asignar a la tejedora",
                            "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                    if (dataGridView1.Rows[i].Cells["Tejedora"].Value == null && dataGridView1.Rows[i].Cells["Cantidad_a_Asignar"].Value == null)
                    {
                        continue;
                    }
                    List <char> aux = new List <char>();
                    string      id  = "";
                    aux = dataGridView1.Rows[i].Cells["Tejedora"].Value.ToString().ToList();

                    foreach (var elemento in aux)
                    {
                        if (elemento.Equals(' '))
                        {
                            break;
                        }
                        id += elemento;
                    }
                    materia_prima mp =
                        (materia_prima)_entities.GetObjectByKey(new EntityKey("mayaEntities.materia_prima", "id", _idMateriasP[i]));
                    tejedora t =
                        (tejedora)_entities.GetObjectByKey(new EntityKey("mayaEntities.tejedora", "id", int.Parse(id)));
                    decimal variable = decimal.Parse(dataGridView1.Rows[i].Cells["Cantidad_a_Asignar"].Value.ToString());
                    if (mp.cantidad - variable < 0)
                    {
                        MessageBox.Show(
                            "No se pudo rebajar la cantidad especificada de la materia prima\n" + "(" + mp.descripcion + ") existe menos cantidad de lo que se desea rebajar",
                            "No se puede realizar la operación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        continue;
                    }
                    else
                    {
                        mp.cantidad -= variable;
                        _entities.AddTomp_tejedora(new mp_tejedora
                        {
                            id_mp       = mp.id,
                            id_tejedora = int.Parse(id),
                            fehca       = DateTime.Now,
                            cantidad    = variable,
                            id_usuario  = _user.id
                        });
                        _entities.AddTobitacora(new bitacora
                        {
                            id_usuario  = _user.id,
                            descripcion = "El usuario " + _user.nombre + " ha asignado " + variable.ToString() + " unidades de " + mp.descripcion + "\na la tejedora " + t.id.ToString() + " -- " + t.nombre,
                            fecha       = DateTime.Now
                        });
                        _entities.SaveChanges();
                    }
                }
                this.Reload();
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void aceptarButton_Click(object sender, EventArgs e)
        {
            if (nuevo == 1)
            {
                try
                {
                    if (_entities.tipo_producto.Any(tp => tp.id == numericIdentificador.Value))
                    {
                        MessageBox.Show("Ya existe un tipo de producto con ese identificador",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (_entities.tipo_producto.Any(tp => tp.valor.Equals(tbxTipoProducto.Text)))
                    {
                        MessageBox.Show("Ya existe un tipo de producto " + tbxTipoProducto.Text,
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (numericIdentificador.Value == 0)
                    {
                        MessageBox.Show("Debe insertar un identificador distinto de 0",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (tbxTipoProducto.Text.Trim().Equals(""))
                    {
                        MessageBox.Show("Debe insertar el tipo de producto",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    _entities.AddTotipo_producto(new tipo_producto
                    {
                        id    = (int)numericIdentificador.Value,
                        valor = tbxTipoProducto.Text
                    });
                    _entities.AddTobitacora(new bitacora
                    {
                        id_usuario  = _user.id,
                        descripcion = "El usuario " + this._user.nombre + " ha creado un nuevo tipo de producto (" + tbxTipoProducto.Text + ")",
                        fecha       = DateTime.Now
                    });
                    _entities.SaveChanges();
                    this.Reload();
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                try
                {
                    if (_entities.tipo_producto.Any(tp => tp.id == numericIdentificador.Value))
                    {
                        MessageBox.Show("Ya existe un tipo de producto con ese identificador",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    //if (_entities.tipo_producto.Any(tp => tp.valor.Equals(tbxTipoProducto.Text)))
                    //{
                    //    MessageBox.Show("Ya existe un tipo de producto " + tbxTipoProducto.Text,
                    //                    "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    return;
                    //}
                    if (numericIdentificador.Value == 0)
                    {
                        MessageBox.Show("Debe insertar un identificador distinto de 0",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (tbxTipoProducto.Text.Trim().Equals(""))
                    {
                        MessageBox.Show("Debe insertar el tipo de producto",
                                        "Error en la entrada de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    tipo_producto tip =
                        (tipo_producto)
                        _entities.GetObjectByKey(new EntityKey("mayaEntities.tipo_producto", "id",
                                                               _idTipo_producto[_selectedIndex]));
                    tip.id    = (int)numericIdentificador.Value;
                    tip.valor = tbxTipoProducto.Text;

                    _entities.AddTobitacora(new bitacora
                    {
                        id_usuario  = this._user.id,
                        descripcion =
                            "Se ha modificado el tipo de prodcuto " + tbxTipoProducto.Text,
                        fecha = DateTime.Now
                    });
                    _entities.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        private void aceptarButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (nuevo)
                {
                    var messageValidation = ValidarEntrada((int)tbxRegistro.Value);
                    if (!string.IsNullOrEmpty(messageValidation))
                    {
                        MessageBox.Show(messageValidation, "Error en la entrada de datos", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                    _entities.AddTotejedora(new tejedora
                    {
                        id        = (int)tbxRegistro.Value,
                        nombre    = tbxNombre.Text,
                        apellidos = tbxApellidos.Text
                    });
                    _entities.AddTobitacora(new bitacora
                    {
                        id_usuario  = this._user.id,
                        descripcion = "El usuario " + this._user.nombre + " ha agregado la tejedora " + tbxNombre.Text,
                        fecha       = DateTime.Now
                    });
                    _entities.SaveChanges();
                    this.Reload();
                }
                else
                {
                    var messageValidation = ValidarEntrada((int)tbxRegistro.Value);
                    if (!string.IsNullOrEmpty(messageValidation))
                    {
                        MessageBox.Show(messageValidation, "Error en la entrada de datos", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                    tejedora aux =
                        (tejedora)_entities.GetObjectByKey(new EntityKey("mayaEntities.tejedora", "id", _idTejedora[_selectedIndex]));
                    aux.id        = (int)tbxRegistro.Value;
                    aux.nombre    = tbxNombre.Text;
                    aux.apellidos = tbxApellidos.Text;

                    _entities.AddTobitacora(new bitacora
                    {
                        id_usuario  = this._user.id,
                        descripcion =
                            "El usuario " + this._user.nombre +
                            " ha modificado la tejedora " + tbxNombre.Text,
                        fecha = DateTime.Now
                    });

                    _entities.SaveChanges();
                    this.Reload();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }