private void devolucion() { Models.Devolutions devolucion = new Models.Devolutions(); Models.Log historial = new Models.Log(); using (devolucion) { devolucion.Fecha = dtFecha.Text + " 00:00:00"; devolucion.Autorizo = id_usuario; devolucion.Total = Convert.ToDouble(txtTotal.Text); devolucion.create(); List <Models.Devolutions> devo = devolucion.get_lastdevocion(dtFecha.Text + " 00:00:00", id_usuario, Convert.ToDouble(txtTotal.Text)); Models.det_devolution detalles = new Models.det_devolution(); using (detalles) { detalles.Id_devolucion = devo[0].Id; Folio_guardado = devo[0].Id; Models.Product productos = new Models.Product(); foreach (DataGridViewRow row in dtProductos.Rows) { detalles.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalles.Id_producto = Convert.ToInt16(row.Cells["id_producto"].Value.ToString()); detalles.Pu = Convert.ToDouble(row.Cells["pu"].Value.ToString()); detalles.Almacen = row.Cells["almacen"].Value.ToString(); detalles.create_det(); using (historial) { historial.Id_usuario = Convert.ToInt32(Inicial.id_usario); historial.Descripcion = "el usuairo " + id_usuario + " autorizo la devolucion de " + row.Cells["cantidad"].Value.ToString() + " " + row.Cells["descripcion"].Value.ToString(); historial.createLog(); } using (productos) { productos.Id = Convert.ToInt16(row.Cells["id_producto"].Value.ToString()); List <Models.Product> produ = productos.getProductById(Convert.ToInt16(row.Cells["id_producto"].Value.ToString())); if (row.Cells["almacen"].Value.ToString() == "Devolucion") { productos.Devoluciones = produ[0].Devoluciones + Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); productos.update_devoluciones(); } else { productos.Existencia = produ[0].Existencia + Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); productos.update_inventary(); } } } } } imprimir(); limpiar(); MessageBox.Show("Se guardo con exito la devolucion"); }
private void button1_Click(object sender, EventArgs e) { Models.Dev_prov devo = new Models.Dev_prov(); Models.det_dev_prov detalles = new Models.det_dev_prov(); Models.Product productos = new Models.Product(); Models.det_devolution det_devolu = new Models.det_devolution(); Models.Log historial = new Models.Log(); using (devo) { devo.Id_proveedor = Convert.ToInt32(txtId_proveedor.Text); devo.Total = Convert.ToDouble(txtTotal.Text); devo.Estado = false; devo.Motivo = txtMotivo.Text; devo.create_dev(); string mensaje = "se envio una devolucion a " + txtProveedor.Text + "<br/>"; List <Models.Dev_prov> ultimo = devo.get_lastdevolucion(Convert.ToInt32(txtId_proveedor.Text), Convert.ToDouble(txtTotal.Text), txtMotivo.Text); Folio_guardado = ultimo[0].Id; using (detalles) { foreach (DataGridViewRow row in dtProductos.Rows) { detalles.Id_devolucion = ultimo[0].Id; detalles.Id_producto = Convert.ToInt32(row.Cells["id"].Value.ToString()); detalles.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalles.Pu = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); detalles.Estado = false; detalles.create_det(); using (historial) { historial.Id_usuario = Convert.ToInt32(Inicial.id_usario); historial.Descripcion = "se envio " + row.Cells["cantidad"].Value.ToString() + " del producto " + row.Cells["desripcion"].Value.ToString() + " como devolucion al proveedor " + txtProveedor.Text; historial.createLog(); } mensaje += row.Cells["cantidad"].Value.ToString() + " -- " + row.Cells["desripcion"].Value.ToString() + "<br/>"; if (row.Cells["folios"].Value is null) { using (productos) { List <Models.Product> producto = productos.getProductById(Convert.ToInt32(row.Cells["id"].Value.ToString())); productos.Existencia = producto[0].Existencia - Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); productos.Id = Convert.ToInt32(row.Cells["id"].Value.ToString()); productos.update_inventary(); } } else { using (productos) { productos.Id = Convert.ToInt32(row.Cells["id"].Value.ToString()); List <Models.Product> produ = productos.getProductById(Convert.ToInt32(row.Cells["id"].Value.ToString())); productos.Devoluciones = produ[0].Devoluciones - Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); productos.update_devoluciones(); } char delimitar = ','; string[] folios = row.Cells["folios"].Value.ToString().Split(delimitar); int cuantos = folios.Count(); for (int i = 0; i < cuantos; i++) { using (det_devolu) { det_devolu.Id_producto = Convert.ToInt32(row.Cells["id"].Value.ToString()); det_devolu.Id_devolucion = Convert.ToInt32(folios[i]); det_devolu.enviar(); } } } } } mensaje += "con un total de $" + txtTotal.Text; intercambios intercambios = new intercambios(); intercambios.enviar_correo("", mensaje, "Envio de devolucion"); } imprimir(); }