public int CrearOModificar(int IDPyT, object IDPresupuestoVersion, int IDTarifa) { bool estaSiendoUsadaEnOtraVersion = false; foreach (BaseNegocio b in Padre.Coleccion("ColPresupuestoVersion")) { if (IDPresupuestoVersion is DBNull || b.IDActual[0] != (int)IDPresupuestoVersion) { foreach (BaseNegocio dt in b.Coleccion("ColPresupuestoVersionDetalle")) { if ((int)dt["IDPyT"] == IDPyT) { estaSiendoUsadaEnOtraVersion = true; break; } } } } if (estaSiendoUsadaEnOtraVersion) { PresupuestoYTarifa pyt = null; Tarifa t = new Tarifa(); BaseNegocio b = CrearEnBlanco(); t.IDActual[0] = IDTarifa; t.Leer(); b.ValoresPorDefecto(t); AnexarObjetoActivo(); pyt = (PresupuestoYTarifa)this.ObjetoActivo; // Necesario. pyt.Guardar(); return(pyt.IDActual[0]); } else { return(IDPyT); } }
//public PresupuestoYTarifa BuscarPorCodigo(int CodigoTarifa) //{ // PresupuestoYTarifa pyt = null; // foreach (BaseNegocio p in this) // { // if ((int) p["Codigo"] == CodigoTarifa) // { // pyt = (PresupuestoYTarifa)p; // break; // } // } // return pyt; //} public PresupuestoYTarifa BuscarCrear(int IDTarifa) { PresupuestoYTarifa pyt = null; if (padre != null && padre is BasePresupuesto) { string sql = "SELECT TOP 1 PresupuestoYTarifa.IDPyT" + " FROM PresupuestoYTarifa INNER JOIN" + " PresupuestoVersionDetalle ON PresupuestoYTarifa.IDPyT = PresupuestoVersionDetalle.IDPyT INNER JOIN" + " PresupuestoVersion ON PresupuestoVersionDetalle.IDPresupuestoVersion = PresupuestoVersion.IDPresupuestoVersion" + " WHERE PresupuestoYTarifa.IDPresupuesto = " + padre.IDActual[0].ToString() + " AND PresupuestoYTarifa.IDTarifa = " + IDTarifa.ToString(); int IDPyT; if (((Presupuesto)padre).AceptadoAhora) { sql += " AND (PresupuestoVersionDetalle.Aceptada = 1)" + " AND (PresupuestoVersion.Aceptado = 1)"; } sql += " ORDER BY PresupuestoYTarifa.FechaAplicacion DESC"; IDPyT = Datos.Instancia().DameExpresionInt(sql); if (IDPyT > 0) { foreach (BaseNegocio b in this) { if (Lib.NoIntNulo(b["IDPyT"]) == IDPyT) { pyt = (PresupuestoYTarifa)b; break; } } } } if (pyt == null) { foreach (BaseNegocio b in this) { if (Lib.NoIntNulo(b["IDTarifa"]) == IDTarifa) { pyt = (PresupuestoYTarifa)b; break; } } } if (pyt == null) { Tarifa t = new Tarifa(); BaseNegocio b = CrearEnBlanco(); t.IDActual[0] = IDTarifa; t.Leer(); b.ValoresPorDefecto(t); AnexarObjetoActivo(); pyt = (PresupuestoYTarifa)this.ObjetoActivo; // Necesario. pyt.Guardar(); } return(pyt); }