private void Vender_Click(object sender, EventArgs e) { this.GuardarPresupuesto(sender, e); List <int> idLineas = controladorFachada.CheckStockPresupuesto(IdPresupuesto); string EstadoPresupuesto = controladorFachada.BuscarPresupuesto(IdPresupuesto).Estado; if (IdCliente == 0) { MessageBox.Show("Debe seleccionar un cliente"); } else if (dataGridView1.Rows.Count < 1) { MessageBox.Show("Debe seleccionar al menos un producto"); } else if (idLineas.Count == 0 && EstadoPresupuesto != "Vendido" && EstadoPresupuesto != "Cancelado") //Hay stock de todos los productos a vender { new VVenderPresupuesto(IdCliente, IdPresupuesto).ShowDialog(); } else if (idLineas.Count > 0 && EstadoPresupuesto != "Vendido" && EstadoPresupuesto != "Cancelado") { foreach (int idLinea in idLineas) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value.ToString() == idLinea.ToString()) { ProductoDTO producto = controladorFachada.BuscarProducto(Convert.ToInt32(row.Cells[0].Value)); this.dataGridView1.Rows[row.Index].Cells[2].ErrorText = ("Hay en stock " + producto.CantidadEnStock); Console.WriteLine(dataGridView1.Rows[row.Index].Cells[2].Value); row.Cells[2].Style.BackColor = Color.Salmon; } } } } this.VAdministrarPresupuesto_Load(sender, e); }
private void Listo_Click(object sender, EventArgs e) { int idLote = 0; List <ProductoDTO> ListaProductoDTO = new List <ProductoDTO>(); int i = 0; Boolean controlVence = true; //True si esta ok Boolean controlDatos = false; //True si esta ok Dictionary <LoteDTO, int> lotesAGuardar = new Dictionary <LoteDTO, int>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (Convert.ToInt32(row.Cells[2].Value) == 0 | Convert.ToDouble(row.Cells[3].Value) == 0) //Chequeo que cantidad y precio de compra sean >0 { controlDatos = false; } else //Cantidad y Precio de compra ok { ProductoDTO unProducto = controladorFachada.BuscarProducto((Convert.ToInt32(row.Cells[0].Value))); unProducto.CantidadEnStock += Convert.ToInt32(row.Cells[2].Value); unProducto.IdCategoria = unProducto.CategoriaProductoDTO.Id; unProducto.PrecioDeCompra = Convert.ToDouble(row.Cells[3].Value); if (row.Cells[4].Value != "------") { if (string.IsNullOrEmpty((row.Cells[4].Value).ToString())) //Si no colocó fechaVencimiento { controlVence = false; } else { LoteDTO unLote = new LoteDTO(); unLote.CantidadProductos = Convert.ToInt32(row.Cells[2].Value); unLote.FechaCompra = DateTime.Now; // ARREGLAME unLote.FechaVencimiento = Convert.ToDateTime(row.Cells[4].Value); controlVence = true; //fechaVencimiento OK if (unLote.FechaCompra < unLote.FechaVencimiento) { unLote.Vencido = false; } else { unLote.Vencido = true; } unLote.IdProducto = unProducto.Id; lotesAGuardar.Add(unLote, i); //idLote = controladorFachada.GuardarLote(unLote); //dataGridView1.Rows[i].Cells[5].Value = idLote; } } i++; ListaProductoDTO.Add(unProducto); controlDatos = true; } controladorFachada.IngresoMercarderias(ListaProductoDTO); } Listo.Visible = false; Cancelar.Visible = false; Agregar.Visible = false; Boolean vencen = false; foreach (DataGridViewRow row in dataGridView1.Rows) { if (!vencen) { if (row.Cells[4].Value != "------") { vencen = true; } } } if (!controlDatos | !controlVence) //Si falta algun dato { if (!controlDatos) { MessageBox.Show("Debe completar la cantidad a ingresar y el Precio de Compra"); } if (!controlVence) { MessageBox.Show("Debe ingresar una fecha de vencimiento"); } Listo.Visible = true; Cancelar.Visible = true; Agregar.Visible = true; } else if (vencen) //Esta todo Ok y vencen { Console.WriteLine(dataGridView1.Rows.Count); // int j = 0; foreach (KeyValuePair <LoteDTO, int> lote in lotesAGuardar) { idLote = controladorFachada.GuardarLote(lote.Key); dataGridView1.Rows[lote.Value].Cells[5].Value = idLote; //Console.WriteLine(lotesAGuardar.Count()); } Confirmar.Visible = true; ConfirmarText.Visible = true; } else { this.Hide(); VControlProducto vControlProducto = new VControlProducto(); vControlProducto.ShowDialog(); this.Close(); } }