Exemplo n.º 1
0
        public IList <Insumos> listar(string cadena)
        {
            SqlConnection   conexion = new SqlConnection();
            SqlCommand      comando  = new SqlCommand();
            SqlDataReader   lector;
            IList <Insumos> lista = new List <Insumos>();

            try
            {
                conexion.ConnectionString = "data source=.; initial catalog=TPC_Sidauy; integrated security=sspi";
                comando.CommandType       = System.Data.CommandType.Text;
                comando.Connection        = conexion;
                comando.CommandText       = "select descripcion,pu,disponibles from " + cadena + " order by descripcion asc";
                conexion.Open();
                lector = comando.ExecuteReader();
                while (lector.Read())
                {
                    Insumos aux = new Insumos();
                    aux.Descripcion = lector.GetString(0);
                    aux.Pu          = lector.GetDecimal(1);
                    aux.Disponibles = lector.GetInt32(2);
                    lista.Add(aux);
                }
                return(lista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
                conexion = null;
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CodIns,Concen,Labora,NomIns,PrecioU,Pres,Unid,CategoriaId")] Insumos insumos)
        {
            if (id != insumos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(insumos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InsumosExists(insumos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoriaId"] = new SelectList(_context.CategoriasInsumos, "Id", "NomCate", insumos.CategoriaId);
            return(View(insumos));
        }
Exemplo n.º 3
0
        public List <Insumos> leer(string cadena)
        {
            SqlConnection  conexion = new SqlConnection("data source=.; initial catalog=TPC_Sidauy; integrated security=sspi");
            SqlCommand     command  = new SqlCommand("select id,descripcion,pu,disponibles from " + cadena + " order by descripcion asc", conexion);
            SqlDataReader  lector;
            List <Insumos> lista = new List <Insumos>();

            conexion.Open();
            lector = command.ExecuteReader();
            try
            {
                while (lector.Read())
                {
                    Insumos aux = new Insumos();
                    aux.Id          = lector.GetInt32(0);
                    aux.Descripcion = lector.GetString(1);
                    aux.Pu          = lector.GetDecimal(2);
                    aux.Disponibles = lector.GetInt32(3);
                    lista.Add(aux);
                }
                return(lista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
                conexion = null;
            }
        } //lee insumos dependiendo de la tabla
Exemplo n.º 4
0
        public IList <Insumos> listarFactura(string cadena, int numeroPedido)
        {
            AccesoDatos conexion = new AccesoDatos();

            try
            {
                IList <Insumos> lista = new List <Insumos>();
                conexion.limpiarParametros();
                conexion.setearConsulta("select id,descripcion,pu,fecha from " + cadena + "xmesa where numeropedido=" + numeroPedido.ToString());
                conexion.leerConsulta();
                while (conexion.Lector.Read())
                {
                    Insumos insumos = new Insumos();
                    insumos.Id          = conexion.Lector.GetInt32(0);
                    insumos.Descripcion = conexion.Lector.GetString(1);
                    insumos.Pu          = conexion.Lector.GetDecimal(2);
                    insumos.fecha       = conexion.Lector.GetDateTime(3);
                    lista.Add(insumos);
                }
                return(lista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.cerrarConexion();
            }
        }
        public void GuardarInsumo()
        {
            try
            {
                Insumos insumo = new Insumos();

                insumo.Descripcion = txtDescripcionInsumo.Text;
                insumo.Estado      = 1;

                int resultado = controladorInsumo.AgregarInsumo(insumo);

                if (resultado > 0)
                {
                    this.m.ShowToastr(this.Page, "Proceso concluido con éxito", "Exito");
                    ObtenerInsumos();
                }
                else
                {
                    this.m.ShowToastr(this.Page, "Proceso no se pudo concluir", "warning");
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void EditarInsumo()
        {
            try
            {
                Insumos insumo = new Insumos();
                insumo.id_insumo   = this.idInsumo;
                insumo.Descripcion = txtDescripcionInsumo.Text;
                insumo.Estado      = 1;

                int resultado = controladorInsumo.EditarInsumo(insumo);

                if (resultado > 0)
                {
                    this.m.ShowToastr(this.Page, "Insumo editado con Exito!", "Exito");
                    Response.Redirect("InsumosF.aspx");
                }
                else
                {
                    this.m.ShowToastr(this.Page, "No se pudo editar el insumo", "warning");
                }
            }
            catch (Exception ex)
            {
            }
        }
        public bool insumo_upd(Insumos obIns)
        {
            SqlConnection cn   = new SqlConnection(new Conexion().cadenaConexion());
            bool          resp = false;
            SqlCommand    cmd  = new SqlCommand()
            {
                CommandText = "insumos_udp", CommandType = System.Data.CommandType.StoredProcedure, Connection = cn
            };

            try
            {
                cmd.Parameters.Add("@idinsu", SqlDbType.Int).Value               = obIns.IdInsumo;
                cmd.Parameters.Add("@fecha_reg", SqlDbType.Date).Value           = obIns.Fecha_reg;
                cmd.Parameters.Add("@insumo", SqlDbType.VarChar, 100).Value      = obIns.Insumo;
                cmd.Parameters.Add("@tipo_cant", SqlDbType.VarChar, 30).Value    = obIns.Tipo_cant;
                cmd.Parameters.Add("@cantidad", SqlDbType.Int).Value             = obIns.Cantidad;
                cmd.Parameters.Add("@descripcion", SqlDbType.VarChar, 200).Value = obIns.Descripcion;
                cmd.Parameters.Add("@id_empresa", SqlDbType.Int).Value           = obIns.Idempresa;
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                resp = true;
            }
            catch (Exception)
            {
                resp = false;
                throw;
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
            return(resp);
        }
Exemplo n.º 8
0
        public List <Insumos> buscar(string cadena, string busqueda)
        {
            SqlConnection  conexion = new SqlConnection("data source=DESKTOP-O7A5ID6\\SQLEXPRESS; initial catalog=TPC_Sidauy; integrated security=sspi");
            SqlCommand     command  = new SqlCommand("select id,descripcion,pu,disponibles from " + cadena + " where descripcion like '" + busqueda + "%'", conexion);
            SqlDataReader  lector;
            List <Insumos> lista = new List <Insumos>();

            conexion.Open();
            lector = command.ExecuteReader();
            try
            {
                while (lector.Read())
                {
                    Insumos aux = new Insumos();
                    aux.Id          = lector.GetInt32(0);
                    aux.Descripcion = lector.GetString(1);
                    aux.Pu          = lector.GetDecimal(2);
                    aux.Disponibles = lector.GetInt32(3);
                    lista.Add(aux);
                }
                return(lista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
                conexion = null;
            }
        }
Exemplo n.º 9
0
        } //lee insumos dependiendo de la tabla

        public List <Insumos> leerCargado(string cadena, int numeropedido) // lee insumos ya cargados en el pedido
        {
            AccesoDatos conexion = new AccesoDatos();

            try
            {
                conexion.limpiarParametros();
                conexion.setearConsulta("select id,descripcion,pu fecha from " + cadena + "xmesa where numeropedido=" + numeropedido);
                conexion.leerConsulta();
                List <Insumos> lista = new List <Insumos>();
                while (conexion.Lector.Read())
                {
                    Insumos insumo = new Insumos();
                    insumo.Id          = conexion.Lector.GetInt32(0);
                    insumo.Descripcion = conexion.Lector.GetString(1);
                    insumo.Pu          = conexion.Lector.GetDecimal(2);
                    //insumo.Disponibles = conexion.Lector.GetInt32(3);
                    lista.Add(insumo);
                }
                return(lista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.cerrarConexion();
            }
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            Insumos obIns = new Insumos();

            if (rbUnidad.Checked)
            {
                obIns.Tipo_cant = "Unidades";
            }
            else if (rbKilo.Checked)
            {
                obIns.Tipo_cant = "Kilos";
            }
            else
            {
                obIns.Tipo_cant = "Litros";
            }

            obIns.CodInsumo   = "001INS";
            obIns.Fecha_reg   = dtIngreso.Value;
            obIns.Insumo      = cmbInsumo.Text;
            obIns.Cantidad    = Convert.ToInt32(spCantidad.Value);
            obIns.Descripcion = txtDescrip.Text;
            obIns.Idempresa   = Convert.ToInt32(cmbProveedor.SelectedValue);

            new ne_insumos().insumos_ins(obIns);
            MessageBox.Show("Registrado con éxito");
        }
        public async Task <ActionResult <Insumos> > PostInsumos(Insumos insumos)
        {
            _context.Insumos.Add(insumos);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetInsumos", new { id = insumos.Id }, insumos));
        }
        public async Task <IActionResult> PutInsumos(int id, Insumos insumos)
        {
            if (id != insumos.Id)
            {
                return(BadRequest());
            }

            _context.Entry(insumos).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InsumosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Edit(int id, [Bind("IdInsumo,NombreInsumo,IdColor,IdProveedor")] Insumos insumos)
        {
            if (id != insumos.IdInsumo)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(insumos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InsumosExists(insumos.IdInsumo))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdColor"]     = new SelectList(_context.Colores, "IdColor", "Color", insumos.IdColor);
            ViewData["IdProveedor"] = new SelectList(_context.Proveedor, "IdProveedor", "Distribuidora", insumos.IdProveedor);
            return(View(insumos));
        }
Exemplo n.º 14
0
        public ActionResult DeleteConfirmed(int id)
        {
            Insumos insumos = db.insumos.Find(id);

            db.insumos.Remove(insumos);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // PUT: api/Insumos
        public void Put([FromBody] Insumos Datos)
        {
            if (Datos == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            ClassBD.ActualizarInsumos(Datos);
        }
        public ColeccionClases insumos_by_id(int idInsu)
        {
            SqlConnection   cn    = new SqlConnection(new Conexion().cadenaConexion());
            ColeccionClases obCol = new ColeccionClases();
            SqlCommand      cmd   = new SqlCommand()
            {
                CommandText = "insumo_by_id", CommandType = System.Data.CommandType.StoredProcedure, Connection = cn
            };

            cmd.Parameters.Add("@idinsu", SqlDbType.Int).Value = idInsu;
            cmd.Connection.Open();
            try
            {
                using (IDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        Insumos obInsu = new Insumos();
                        if (!dr[0].Equals(DBNull.Value))
                        {
                            obInsu.Fecha_reg = dr.GetDateTime(0);
                        }
                        if (!dr[1].Equals(DBNull.Value))
                        {
                            obInsu.Insumo = dr.GetString(1);
                        }
                        if (!dr[2].Equals(DBNull.Value))
                        {
                            obInsu.Tipo_cant = dr.GetString(2);
                        }
                        if (!dr[3].Equals(DBNull.Value))
                        {
                            obInsu.Cantidad = dr.GetInt32(3);
                        }
                        if (!dr[4].Equals(DBNull.Value))
                        {
                            obInsu.Descripcion = dr.GetString(4);
                        }
                        if (!dr[5].Equals(DBNull.Value))
                        {
                            obInsu.Empresa = dr.GetString(5);
                        }
                        obCol.Add(obInsu);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
            return(obCol);
        }
        // POST: api/Insumos
        public ID Post([FromBody] Insumos Datos)
        {
            if (Datos == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return(new ID(ClassBD.AgregarInsumos(Datos)));
        }
Exemplo n.º 18
0
        public void CargarInsumosPH(Insumos insumo)
        {
            try
            {
                //fila
                TableRow tr = new TableRow();
                tr.ID = insumo.id_insumo.ToString();

                //Celdas
                TableCell celNumero = new TableCell();
                celNumero.Text            = insumo.id_insumo.ToString();
                celNumero.VerticalAlign   = VerticalAlign.Middle;
                celNumero.HorizontalAlign = HorizontalAlign.Right;
                tr.Cells.Add(celNumero);

                TableCell celNombre = new TableCell();
                celNombre.Text            = insumo.Descripcion;
                celNombre.VerticalAlign   = VerticalAlign.Middle;
                celNombre.HorizontalAlign = HorizontalAlign.Left;
                tr.Cells.Add(celNombre);

                //agrego fila a tabla
                TableCell  celAccion   = new TableCell();
                LinkButton btnDetalles = new LinkButton();
                btnDetalles.CssClass = "btn btn-primary";
                //btnDetalles.Attributes.Add("data-toggle", "tooltip");
                //btnDetalles.Attributes.Add("title data-original-title", "Editar");
                btnDetalles.ID     = "btnSelec_" + insumo.id_insumo + "_";
                btnDetalles.Text   = "<span><i class='fa fa-pencil'></i></span>";
                btnDetalles.Click += new EventHandler(this.editarInsumo);
                celAccion.Controls.Add(btnDetalles);

                Literal l2 = new Literal();
                l2.Text = "&nbsp";
                celAccion.Controls.Add(l2);
                tr.Cells.Add(celAccion);


                LinkButton btnEliminar = new LinkButton();
                btnEliminar.ID       = "btnEliminar_" + insumo.id_insumo;
                btnEliminar.CssClass = "btn btn-danger";
                btnEliminar.Attributes.Add("data-toggle", "modal");
                btnEliminar.Attributes.Add("href", "#modalConfirmacion");
                btnEliminar.Text          = "<span><i class='fa fa-trash - o'></i></span>";
                btnEliminar.OnClientClick = "abrirdialog(" + insumo.id_insumo + ");";

                celAccion.Controls.Add(btnEliminar);
                celAccion.Width = Unit.Percentage(25);
                tr.Cells.Add(celAccion);

                phInsumos.Controls.Add(tr);
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "Handle,Produto,Descricao,Quantidade,DataCompra")] Insumos insumos)
 {
     if (ModelState.IsValid)
     {
         db.Entry(insumos).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(insumos));
 }
Exemplo n.º 20
0
        public ActionResult Create([Bind(Include = "Handle,Produto,Descricao,Quantidade,DataCompra")] Insumos insumos)
        {
            if (ModelState.IsValid)
            {
                db.insumos.Add(insumos);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(insumos));
        }
Exemplo n.º 21
0
 public async Task Create(Insumos model)
 {
     try
     {
         _db.dbSetInsumos.Add(model);
         await _db.SaveChangesAsync();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
 }
Exemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("Id,CodIns,Concen,Labora,NomIns,PrecioU,Pres,Unid,CategoriaId")] Insumos insumos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(insumos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoriaId"] = new SelectList(_context.CategoriasInsumos, "Id", "NomCate", insumos.CategoriaId);
            return(View(insumos));
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("IdInsumo,NombreInsumo,IdColor,IdProveedor")] Insumos insumos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(insumos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdColor"]     = new SelectList(_context.Colores, "IdColor", "Color", insumos.IdColor);
            ViewData["IdProveedor"] = new SelectList(_context.Proveedor, "IdProveedor", "Distribuidora", insumos.IdProveedor);
            return(View(insumos));
        }
Exemplo n.º 24
0
        // GET: Insumos/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Insumos insumos = db.insumos.Find(id);

            if (insumos == null)
            {
                return(HttpNotFound());
            }
            return(View(insumos));
        }
        public ColeccionClases insumos_sel()
        {
            SqlConnection   cn    = new SqlConnection(new Conexion().cadenaConexion());
            ColeccionClases obCol = new ColeccionClases();
            SqlCommand      cmd   = new SqlCommand()
            {
                CommandText = "insumos_sel", CommandType = System.Data.CommandType.StoredProcedure, Connection = cn
            };

            cmd.Connection.Open();
            try
            {
                using (IDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        Insumos obIns = new Insumos();
                        if (!dr[0].Equals(DBNull.Value))
                        {
                            obIns.IdInsumo = dr.GetInt32(0);
                        }
                        if (!dr[0].Equals(DBNull.Value))
                        {
                            obIns.Fecha_reg = dr.GetDateTime(1);
                        }
                        if (!dr[1].Equals(DBNull.Value))
                        {
                            obIns.Insumo = dr.GetString(2);
                        }
                        if (!dr[2].Equals(DBNull.Value))
                        {
                            obIns.Cantidad = dr.GetInt32(3);
                        }
                        obCol.Add(obIns);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmd.Connection.Close();
                cmd.Dispose();
            }
            return(obCol);
        }
Exemplo n.º 26
0
        public async Task Update(Insumos model)
        {
            try
            {
                var _model = await _db.dbSetInsumos.FirstOrDefaultAsync(e => e.InsumosId == model.InsumosId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Exemplo n.º 27
0
        public void insertarDetalle(List <_Insumos> listado, int idSalida)
        {
            _conexion.Open();

            MySqlTransaction transaction = _conexion.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            MySqlCommand     comando     = _conexion.CreateCommand();
            MySqlCommand     comando2    = _conexion.CreateCommand();

            try
            {
                foreach (_Insumos Insumos in listado)
                {
                    comando.CommandText = "INSERT INTO DetalleSalida (Cantidad, Alimentos_idAlimentos,Activo, Salida_idSalida) VALUES (@Cantidad, @idAlimentos, @activo, @idSalida)";
                    comando.Parameters.AddWithValue("@Cantidad", Insumos.Existencia);
                    comando.Parameters.AddWithValue("@idAlimentos", Insumos.idAlimentos);
                    comando.Parameters.AddWithValue("@activo", true);
                    comando.Parameters.AddWithValue("@idSalida", idSalida);
                    comando.ExecuteNonQuery();
                    comando.Parameters.Clear();

                    comando2.CommandText = "update alimentos SET Existencia = @nExistencia WHERE idAlimentos = @idA";
                    comando2.Parameters.AddWithValue("@nExistencia", Insumos.nuevaExistencia(Insumos.idAlimentos, Insumos.Existencia));
                    comando2.Parameters.AddWithValue("@idA", Insumos.idAlimentos);
                    comando2.ExecuteNonQuery();
                    comando2.Parameters.Clear();
                }
                transaction.Commit();
            }
            catch (Exception e)
            {
                transaction.Rollback();
                comando.Dispose();
                comando2.Dispose();
                transaction.Dispose();
                _conexion.Close();
            }
            finally
            {
                comando.Dispose();
                comando2.Dispose();
                transaction.Dispose();
                _conexion.Close();
            }
        }
Exemplo n.º 28
0
        public void devolverInsumo(string tipoInsumo, int numeromesa, int numeropedido)
        {
            AccesoDatos conexion = new AccesoDatos();

            try
            {
                conexion.limpiarParametros();
                conexion.setearConsulta("select id,descripcion from " + tipoInsumo + "xmesa where numeropedido=" + numeropedido.ToString());
                conexion.leerConsulta();
                List <Insumos> listaDevolver = new List <Insumos>();
                while (conexion.Lector.Read())
                {
                    Insumos insumos = new Insumos();
                    insumos.Id          = conexion.Lector.GetInt32(0);
                    insumos.Descripcion = conexion.Lector.GetString(1);
                    listaDevolver.Add(insumos);
                }
                conexion.cerrarConexion();
                if (listaDevolver.Count > 0)
                {
                    foreach (var item in listaDevolver)
                    {
                        Insumos insumos = item;
                        conexion.limpiarParametros();
                        conexion.agregarParametro("@id", insumos.Id.ToString());
                        conexion.agregarParametro("@descripcion", insumos.Descripcion);
                        conexion.agregarParametro("@numeromesa", numeromesa.ToString());
                        conexion.agregarParametro("@numeropedido", numeropedido.ToString());
                        conexion.setearConsultaSP("sp_devolver_insumo_" + tipoInsumo);
                        conexion.ejecutarAccion();
                        conexion.cerrarConexion();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.cerrarConexion();
            }
        }
Exemplo n.º 29
0
        private void button1_Click(object sender, EventArgs e)
        {
            Insumos obIns = new Insumos();

            obIns.IdInsumo    = Convert.ToInt32(txtId.Text);
            obIns.Fecha_reg   = Convert.ToDateTime(txtFecha.Text);
            obIns.Insumo      = cmbTipo.Text;
            obIns.Tipo_cant   = txtTipo.Text;
            obIns.Cantidad    = Convert.ToInt32(txtCantidad.Text);
            obIns.Descripcion = txtDescrip.Text;
            obIns.Idempresa   = Convert.ToInt32(cmbProveedor.SelectedValue);

            if (new ne_insumos().insumo_upd(obIns))
            {
                MessageBox.Show("Modificado con éxito");
                Insumos_Registrados i = new Insumos_Registrados();
                i.gvInsumos.DataSource = new ne_insumos().insumos_sel();
                this.Close();
            }
        }
Exemplo n.º 30
0
        } //Borrar

        public void agregaInsumo(Insumos insumo, string cadena)
        {
            AccesoDatos conexion = new AccesoDatos();

            try
            {
                conexion.limpiarParametros();
                conexion.agregarParametro("@id", insumo.Id.ToString());
                conexion.agregarParametro("@descripcion", insumo.Descripcion);
                conexion.setearConsultaSP("sp_agregar_insumo_" + cadena);
                conexion.ejecutarAccion();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.cerrarConexion();
            }
        }
Exemplo n.º 31
0
        private void btnNuevo_Click(object sender, EventArgs e)
        {
            Double Suma = 0;
            Double IVA = 0;
            foreach (DataGridViewRow row in grdCompras.Rows)
            {
                if(row.Cells[6].Value != null)
                Suma += Convert.ToDouble(row.Cells[6].Value.ToString());
            }

            IVA = Suma * .16;
            List<Compras> compraInsert = (BusController(new ComprasBU()) as ComprasBU).InsertWithLastID(new Compras{
                    comp_fecha = DateTime.Now,
                    comp_iva = IVA,
                    comp_subtotal = Suma,
                    comp_total = IVA + Suma,
                    comp_tipocompra =1
                }).ToList<Compras>();

            List<DetalleCompra> listadetallecompra = new List<DetalleCompra>();
            foreach (DataGridViewRow row in grdCompras.Rows)
            {
                if (row.Cells[6].Value != null)
                {
                    listadetallecompra.Add(new DetalleCompra
                    {
                        detco_precio = Convert.ToDouble(row.Cells[4].Value.ToString()),
                        detco_cantidad = Convert.ToDouble(row.Cells[5].Value.ToString()),
                        detco_tipocambio = 1,
                        detco_insumoid = Convert.ToInt32(row.Cells[3].Value.ToString()),
                        Compras_comp_compraid = compraInsert[0].comp_compraid
                    });
                    Insumos stockInsumos = new Insumos();
                    stockInsumos = (BusController(new InsumosBU()) as InsumosBU).Find(new Insumos { insu_insumosid = Convert.ToInt32(row.Cells[3].Value.ToString()) }).ToList<Insumos>()[0];
                    stockInsumos.insu_stock += Convert.ToDouble(row.Cells[5].Value.ToString());
                    (BusController(new InsumosBU()) as InsumosBU).Update(stockInsumos);

                }
            }

            foreach(DetalleCompra detco in listadetallecompra)
            {
                (BusController(new DetalleCompraBU()) as DetalleCompraBU).Insert(detco);
            }
            MensajeExito("Guardado","Se ha guardado con exito su compra de insumos");
            this.Close();
        }