public override bool Insertar() { DbVentana cone = new DbVentana(); DataTable dt = new DataTable(); int Retornar = 0; object Identity; try { Identity = cone.ObtenerValor(String.Format("Insert Into Proyectos(Fecha,Total,ClienteId) values(Convert(datetime,'{0}',5),{1},{2}) SELECT @@Identity", this.Fecha, this.Total, this.ClienteId)); int.TryParse(Identity.ToString(), out Retornar); if (Retornar > 0) { object Identity2; int Retornar2 = 0; foreach (ProyectosDetalle item in this.Detalle) { //areglar ete insert (poner id del producto) Identity2 = cone.ObtenerValor(String.Format("Insert Into ProyectosDetalle(ProyectoId,ProductoId,Pie,Ancho,Altura,Precio) Values({0},'{1}',{2},{3},{4},{5}) SELECT @@Identity", Retornar, item.ProductoId, item.Pie, item.Ancho, item.Altura, item.Precio)); int.TryParse(Identity2.ToString(), out Retornar2); //con el id anterior del producto hacer un select a a la tabla productodetalle y llenar ListaMateriales dt = cone.ObtenerDatos(String.Format("Select * from ProductosDetalle where ProductoId ={0}", item.ProductoId)); foreach (DataRow row in dt.Rows) { this.ListaMateriales.Add(new ProductosDetalle(Convert.ToInt32(row[2]), Convert.ToInt32(row[3]))); } //recorrer lista materiales para insertar cada material y el calculo de su valor o cantidad en la tabla pryecto conduce foreach (ProductosDetalle item2 in this.ListaMateriales) { if (item2.Asociacion == 0) { item2.Cantidad = item.Ancho / 12; } else if (item2.Asociacion == 1) { item2.Cantidad = item.Altura / 12; } cone.Ejecutar(String.Format("Insert Into ProyectoPresupuesto(ProyectoId,MaterialId,Cantidad) Values({0},{1},{2}) ", Retornar, item2.MaterialId, item2.Cantidad)); } } } return(Retornar > 0); }catch (Exception ex) { throw ex; } }
public override bool Insertar() { int Retornar = 0; DbVentana cone = new DbVentana(); object Identity = null; try { Identity = cone.ObtenerValor(String.Format("Insert into Productos(Descripcion,Pie,MinimoPie) Values('{0}',{1},{2}) SELECT @@Identity", this.Descripcion, this.Pie, this.MinimoPie)); int.TryParse(Identity.ToString(), out Retornar); if (Retornar > 0) { foreach (ProductosDetalle item in this.Detalle) { cone.Ejecutar(String.Format("Insert into ProductosDetalle(ProductoId,MaterialId,Asociacion) Values({0},{1},{2})", Retornar, item.MaterialId, item.Asociacion)); } } }catch (Exception ex) { throw ex; } return(Retornar > 0); }