private void metroButton1_Click(object sender, EventArgs e) { //First project double trema = Convert.ToDouble(txt_TREMA1.Text); int nper = Convert.ToInt16(txt_Per1.Text); double[] flow1 = new double[nper]; int cont = 0; foreach (DataGridViewRow row in metroGrid1.Rows) { if (cont < nper) { flow1[cont] = Convert.ToDouble(row.Cells["Ingresos"].Value) - Convert.ToDouble(row.Cells["Egresos"].Value); cont++; } } flow1[nper - 1] += Convert.ToDouble(txt_ValRec1.Text); double inicial = Convert.ToDouble(txt_CostoIn1.Text); Proyecto producto1 = new Proyecto(nper, trema, flow1, inicial); producto1.calcularVNA(); producto1.calcularVAE(); lbl_VNA1.Text = Convert.ToString(producto1.vna); lbl_VAE1.Text = Convert.ToString(producto1.vae); //Second Project trema = Convert.ToDouble(txt_TREMA2.Text); nper = Convert.ToInt16(txt_Per2.Text); double[] flow2 = new double[nper]; cont = 0; foreach (DataGridViewRow row in metroGrid2.Rows) { if (cont < nper) { flow2[cont] = Convert.ToDouble(row.Cells["Ingresos"].Value) - Convert.ToDouble(row.Cells["Egresos"].Value); cont++; } } flow2[nper - 1] += Convert.ToDouble(txt_ValRec2.Text); inicial = Convert.ToDouble(txt_CostoIn2.Text); Proyecto producto2 = new Proyecto(nper, trema, flow2, inicial); producto2.calcularVNA(); producto2.calcularVAE(); lbl_VNA2.Text = Convert.ToString(producto2.vna); lbl_VAE2.Text = Convert.ToString(producto2.vae); int uno, dos; uno = Convert.ToInt32(txt_Per1.Text); dos = Convert.ToInt32(txt_Per2.Text); if (uno == dos) { if (producto1.vna > producto2.vna) { resultado.Text = "Producto 1"; } else { resultado.Text = "Producto 2"; } } else { if (producto1.vae > producto2.vae) { resultado.Text = "Producto 1"; } else { resultado.Text = "Producto 2"; } } }
private void btn_Comparar_Click(object sender, EventArgs e) { double trema = Convert.ToDouble(Prod1Trema.Text); int nper = Convert.ToInt16(Prod1Per.Text); double[] flow1 = new double[nper]; double mantenimiento = Convert.ToDouble(Prod1Mant.Text); for (int i = 0; i < nper; i++) { flow1[i] = -mantenimiento; } flow1[nper - 1] += Convert.ToDouble(Prod1ValRec.Text); double inicial = Convert.ToDouble(Prod1CostInicial.Text); Proyecto producto1 = new Proyecto(nper, trema, flow1, inicial); producto1.calcularVNA(); producto1.calcularVAE(); lbl_VNA1.Text = Convert.ToString(producto1.vna); lbl_VAE1.Text = Convert.ToString(producto1.vae); //Second Project trema = Convert.ToDouble(Prod2Trema.Text); nper = Convert.ToInt16(Prod2Per.Text); double[] flow2 = new double[nper]; mantenimiento = Convert.ToDouble(Prod2Mant.Text); for (int i = 0; i < nper; i++) { flow2[i] = -mantenimiento; } flow2[nper - 1] += Convert.ToDouble(Prod2ValRec.Text); inicial = Convert.ToDouble(Prod2CostInicial.Text); Proyecto producto2 = new Proyecto(nper, trema, flow2, inicial); producto2.calcularVNA(); producto2.calcularVAE(); lbl_VNA2.Text = Convert.ToString(producto2.vna); lbl_VAE2.Text = Convert.ToString(producto2.vae); int uno, dos; uno = Convert.ToInt32(Prod1Per.Text); dos = Convert.ToInt32(Prod2Per.Text); if (uno == dos) { if (producto1.vna > producto2.vna) { resultado.Text = "Producto 1"; } else { resultado.Text = "Producto 2"; } } else { if (producto1.vae > producto2.vae) { resultado.Text = "Producto 1"; } else { resultado.Text = "Producto 2"; } } }