private void btnGuardar_Click(object sender, EventArgs e) { Models.Ajuste ajutes = new Models.Ajuste( 0, dtFecha.Text + " 00:00:00", Convert.ToDouble(txtTotal.Text), "", "A" ); using (ajutes) { ajutes.createAjuste(); List <Models.Ajuste> general = ajutes.getlastAjustes(dtFecha.Text + " 00:00:00", Convert.ToDouble(txtTotal.Text)); Models.det_ajustes detalle = new Models.det_ajustes(); detalle.Id = 0; detalle.Id_ajuste = general[0].Id; Models.Kardex kardex = new Models.Kardex(); Models.Product producto = new Models.Product(); Models.Afecta_inv afecta = new Models.Afecta_inv(); double nuevo = 0; folio = general[0].Id.ToString(); foreach (DataGridViewRow row in dtProductos.Rows) { detalle.Id_producto = Convert.ToInt16(row.Cells["id_producto"].Value.ToString()); detalle.P_u = Convert.ToDouble(row.Cells["costo"].Value.ToString()); detalle.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalle.Total = Convert.ToDouble(row.Cells["total"].Value.ToString()); using (detalle) { detalle.craeteDet_ajuste(); using (producto) { Models.Log historia = new Models.Log(); using (historia) { historia.Id_usuario = Convert.ToInt32(Inicial.id_usario); historia.Descripcion = "se ajusto el inventario del producto " + row.Cells["descripcion"].Value.ToString(); historia.createLog(); } List <Models.Product> prod = producto.getProductById(Convert.ToInt16(row.Cells["id_producto"].Value.ToString())); nuevo = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); while (prod[0].Parent != "0") { nuevo = nuevo * Convert.ToDouble(prod[0].C_unidad); prod = producto.getProductById(Convert.ToInt16(prod[0].Parent)); } kardex.Fecha = Convert.ToDateTime(dtFecha.Text).ToString(); kardex.Id_producto = prod[0].Id; kardex.Tipo = "A"; kardex.Cantidad = nuevo; kardex.Antes = prod[0].Existencia; kardex.Id = 0; kardex.Id_documento = Convert.ToInt16(folio); using (kardex) { kardex.CreateKardex(); List <Models.Kardex> numeracion = kardex.getidKardex(prod[0].Id, Convert.ToInt16(folio), "A"); using (afecta) { afecta.Ajusta(numeracion[0].Id); } } } } } } this.Close(); }