Exemple #1
0
 public static Proyecto GetProyecto(this Locales_Proyecto localProyecto)
 {
     using (var db = new DB_BIM())
     {
         return(db.GetSingleElement <Proyecto>(x => x.Id == localProyecto.Proyecto));
     }
 }
Exemple #2
0
        /*public static T Convert<T>(this object obj)
         * {
         *  Type _objectType = obj.GetType();
         *  Type _targetType = typeof(T);
         *  var _instance = Activator.CreateInstance(_targetType, false);
         *  var s = from source in _objectType.GetMembers().ToList()
         *          where source.MemberType == MemberTypes.Property
         *          select source;
         *  var d = from source in _targetType.GetMembers().ToList()
         *          where source.MemberType == MemberTypes.Property
         *          select source;
         *  //var d = _targetType.GetMembers().Where(mt => mt.MemberType == MemberTypes.Property);
         *  List<MemberInfo> _members = d.Where(memberInfo => d.Select(c => c.Name)
         *     .ToList().Contains(memberInfo.Name)).ToList();
         *  PropertyInfo _propertyInfo;
         *  object _propertyValue;
         *  foreach (var item in _members)
         *  {
         *      if (item != null)
         *      {
         *          _propertyInfo = typeof(T).GetProperty(item.Name);
         *          _propertyValue = obj.GetType().GetProperty(item.Name).GetValue(obj, null);
         *
         *          _propertyInfo.SetValue(_instance, _propertyValue, null);
         *      }
         *  }
         *  return (T)_instance;
         * }*/

        public static Local GetLocal(this Locales_Proyecto localProyecto)
        {
            using (var db = new DB_BIM())
            {
                return(db.GetSingleElement <Local>(x => x.Id == localProyecto.Local));
            }
        }
Exemple #3
0
 public static void AddLocalesProyecto(Locales_Proyecto localProyecto)
 {
     using (var db = new DB_BIM())
     {
         db.AddElemento <Locales_Proyecto>(localProyecto.GetType(), localProyecto);
         db.Locales_Proyecto.Add(localProyecto);
         db.SaveChanges();
     }
 }
Exemple #4
0
        private void btn_Acept_Click(object sender, EventArgs e)
        {
            var _desgloses = new DB_BIM().GetAllElements <Desglose>();

            foreach (var item in _localesByProject)
            {
                var      _desglose         = _desgloses.FirstOrDefault(x => x.Id == item.Local1.Desglose);
                var      _desgloseProyecto = _proyecto.Desglose;
                Desglose _a = null;
                if (_desglose != null && _proyecto.Desglose.FirstOrDefault(x => x.Value == _desglose.Value) == null)
                {
                    var _nuevoDesglose = new Desglose()
                    {
                        Proyecto = _proyecto.Id,
                        Value    = _desglose.Value
                    };
                    _a = new DB_BIM().AddElemento <Desglose>(typeof(Desglose), _nuevoDesglose);
                }
                else
                {
                    _a = _proyecto.Desglose.FirstOrDefault(x => x.Value == _desglose.Value);
                }

                var _itemLocal = new DB_BIM().GetSingleElement <Local>(x => x.Id == item.Local);

                var _local = new Local()
                {
                    Key_Name          = _itemLocal.Key_Name,
                    Ambiente          = _itemLocal.Ambiente,
                    Climatizacion     = _itemLocal.Climatizacion,
                    Coef_Area         = _itemLocal.Coef_Area,
                    Comunicaciones_TV = _itemLocal.Comunicaciones_TV,
                    Desglose          = _a.Id,
                    Habitacion        = _itemLocal.Habitacion,
                    Local_Tipo        = _itemLocal.Local_Tipo,
                    Mod            = _itemLocal.Mod,
                    Porciento_BD   = _itemLocal.Porciento_BD,
                    RoomId         = _itemLocal.RoomId,
                    SubsistemaArea = _itemLocal.SubsistemaArea,
                    SubsistemaTipo = _itemLocal.SubsistemaTipo
                };

                new DB_BIM().AddElemento <Local>(typeof(Local), _local);


                Locales_Proyecto _localProyecto = new Locales_Proyecto()
                {
                    Local    = _local.Id,
                    Proyecto = _proyecto.Id,
                    Cantidad = item.Cantidad
                };
                new DB_BIM().AddElemento <Locales_Proyecto>(typeof(Locales_Proyecto), _localProyecto);
            }

            MessageBox.Show("Todos los locales fueron importados!");
            this.Close();
        }
Exemple #5
0
        public static Locales_Proyecto UpdateLocalesProyecto(Locales_Proyecto localProyecto)
        {
            using (var db = new DB_BIM())
            {
                var _record = db.GetSingleElement <Locales_Proyecto>(x => x.Id == localProyecto.Id);
                _record.Local1.RoomId   = localProyecto.Local1.RoomId;
                db.Entry(_record).State = EntityState.Modified;
                db.SaveChanges();

                return(_record);
            }
        }
        private static void AddSingleRoom(ref GridView selectedGrid, int i, T_Local KeyRoom)
        {
            if (i != -2147483647)
            {
                try
                {
                    using (var db = new DB_BIM())
                    {
                        selectedGrid.FocusedRowHandle = i;

                        Local            local         = new Local();
                        Locales_Proyecto localProyecto = new Locales_Proyecto();

                        var subsistemaTipo = "";
                        var subsistemaArea = "";

                        ExcelImportForm.GetSubsistemas(selectedGrid.GetRowCellValue(i, "Cod2").ToString(), ref subsistemaTipo, ref subsistemaArea, selectedGrid.GetRowCellValue(i, "Cod1").ToString());

                        local.SubsistemaTipo =
                            new DB_PLANTILLA().GetSingleRecord <T_Subsistema_Tipo>(x => x.Value == subsistemaTipo).Id;

                        local.SubsistemaArea =
                            new DB_PLANTILLA().GetSingleRecord <T_Subsistema_Area>(x => x.Value == subsistemaArea).Id;

                        var localTipoValue = selectedGrid.GetRowCellValue(i, "LocalTipo").ToString();



                        var cod1       = selectedGrid.GetRowCellValue(i, "Cod1").ToString().Replace(',', '.');
                        var grupoLocal = _grupoLocales.FirstOrDefault(x => x.Cod1.Contains(cod1)).Id;

                        var localTipo = db.GetSingleElement <LocalTipo>(x => x.Value == localTipoValue) ?? new LocalTipo()
                        {
                            Grupo_Locales = grupoLocal,
                            Value         = localTipoValue
                        };


                        var porcientoBD = double.Parse(selectedGrid.GetRowCellValue(i, "PorcientoBD").ToString());
                        local.Porciento_BD = new DB_PLANTILLA().GetSingleElement <T_Porciento_BD>(x => x.Value == porcientoBD).Id;

                        var      areaUtil = selectedGrid.GetRowCellValue(i, "AreaLocal").ToString() == "" ? 0.00 : double.Parse(selectedGrid.GetRowCellValue(i, "AreaLocal").ToString());
                        CoefArea coef     = new CoefArea()
                        {
                            Area_Local = areaUtil
                        };


                        var desgloseValue = selectedGrid.GetRowCellValue(i, "Desglose").ToString();
                        var desglose      = db.GetSingleElement <Desglose>(x => x.Value == desgloseValue && x.Proyecto == _proyecto.Id);

                        if (desglose != null)
                        {
                            local.Desglose = desglose.Id;
                        }
                        else
                        {
                            Desglose _newDesglose = new Desglose()
                            {
                                Value    = desgloseValue,
                                Proyecto = _proyecto.Id
                            };
                            desglose        = _newDesglose;
                            local.Desglose1 = _newDesglose;
                        }

                        //var roomKeyValue = selectedGrid.GetRowCellValue(i, "RoomID").ToString();
                        //var localID = new DB_PLANTILLA().GetSingleElement<T_Local>(x => x.Key_Name == roomKeyValue);
                        var localID = KeyRoom;
                        local.RoomId         = localID.RoomId;
                        local.CoefArea       = coef;
                        local.CoefArea.Value = new DB_PLANTILLA().GetSingleElement <T_CoefArea>(x => x.Id == localID.Coef_Area).Value;
                        local.LocalTipo      = localTipo;

                        local.Key_Name = selectedGrid.GetRowCellValue(i, "Local").ToString();

                        local.Ambiente1          = localID.T_Ambiente.ToProject();
                        local.Comunicaciones_Tv1 = localID.T_Comunicaciones_Tv.ToProject();
                        local.Climatizacion1     = localID.T_Climatizacion.ToProject();

                        localProyecto.Local1   = local;
                        localProyecto.Proyecto = _proyecto.Id;
                        localProyecto.Cantidad = selectedGrid.GetRowCellValue(i, "Hab") == null || selectedGrid.GetRowCellValue(i, "Hab").ToString() == "" ? 0 : int.Parse(selectedGrid.GetRowCellValue(i, "Hab").ToString());

                        var localesProyecto =
                            db.GetSingleElement <Locales_Proyecto>(x =>
                                                                   x.Proyecto1.Cod == _proyecto.Cod &&
                                                                   x.Local1.Desglose == desglose.Id &&
                                                                   x.Local1.Local_Tipo == localTipo.Id &&
                                                                   x.Local1.Key_Name == local.Key_Name);

                        if (localesProyecto == null)
                        {
                            //new DB_BIM().AddElemento<Locales_Proyecto>(typeof(Locales_Proyecto), localProyecto);
                            //LocalController.AddLocalcesProyecto(localProyecto);
                            //LocalController.AddLocalesProyecto(localProyecto);
                            db.Locales_Proyecto.Add(localProyecto);
                            db.SaveChanges();
                        }
                        else
                        {
                            localProyecto.Id = localesProyecto.Id;
                            LocalController.UpdateLocalesProyecto(localProyecto);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    //Excepciones.Excepciones.EnviarCorreo(ex);
                    //throw;
                }
            }
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var _selectedGrid = gridControlPrograma.Visible ? gridPrograma : gridDetalle;

            var _subsistemasTipo = new DB_PLANTILLA().GetAllRecords <T_Subsistema_Tipo>();
            var _subsistemasArea = new DB_PLANTILLA().GetAllRecords <T_Subsistema_Area>();
            var _grupoLocales    = new DB_PLANTILLA().GetAllRecords <T_Grupo_Locales>();
            var _porcientos      = new DB_PLANTILLA().GetAllRecords <T_Porciento_BD>();
            var _coefAreas       = new DB_PLANTILLA().GetAllRecords <T_CoefArea>();
            var _locales         = new DB_PLANTILLA().GetAllRecords <T_Local>();

            for (int i = 0; i < _selectedGrid.DataRowCount; i++)
            {
                try
                {
                    _selectedGrid.FocusedRowHandle = i;
                    Local            _local         = new Local();
                    Locales_Proyecto _localProyecto = new Locales_Proyecto();

                    var _subsistemaTipo = "";
                    var _subsistemaArea = "";

                    GetSubsistemas(_selectedGrid.GetRowCellValue(i, "Cod2").ToString(), ref _subsistemaTipo, ref _subsistemaArea, _selectedGrid.GetRowCellValue(i, "Cod1").ToString());
                    //var _subTipoValue = _selectedGrid.GetRowCellValue(i, "Subsistema Tipo").ToString();
                    _local.SubsistemaTipo = _subsistemasTipo.FirstOrDefault(x => x.Value == _subsistemaTipo).Id;

                    //var _subAreaValue = _selectedGrid.GetRowCellValue(i, "Subsistema Area").ToString();
                    _local.SubsistemaArea = _subsistemasArea.FirstOrDefault(x => x.Value == _subsistemaArea).Id;

                    var _localTipoValue = _selectedGrid.GetRowCellValue(i, "LocalTipo").ToString();
                    var _cod1Value      = _selectedGrid.GetRowCellValue(i, "Cod1").ToString().Replace(',', '.');
                    var _grupoLocal     = _grupoLocales.FirstOrDefault(x => x.Cod1.Contains(_cod1Value)).Id;

                    LocalTipo _localTipo = new LocalTipo()
                    {
                        Grupo_Locales = _grupoLocal,
                        Value         = _localTipoValue
                    };

                    var _porcientoBD = double.Parse(_selectedGrid.GetRowCellValue(i, "PorcientoBD").ToString());
                    //_porcientoBD = _porcientoBD / 100;

                    _local.Porciento_BD = _porcientos.FirstOrDefault(x => x.Value == _porcientoBD).Id;


                    var      _areaUtil = _selectedGrid.GetRowCellValue(i, "AreaLocal").ToString() == "" ? 0.00 : double.Parse(_selectedGrid.GetRowCellValue(i, "AreaLocal").ToString());
                    CoefArea _coef     = new CoefArea()
                    {
                        Area_Local = _areaUtil
                    };

                    var _desgloseValue = _selectedGrid.GetRowCellValue(i, "Desglose").ToString();
                    var _desglose      = new DB_BIM().GetSingleElement <Desglose>(x => x.Value == _desgloseValue && x.Proyecto == _proyecto.Id);

                    if (_desglose != null)
                    {
                        _local.Desglose = _desglose.Id;
                    }
                    else
                    {
                        Desglose _newDesglose = new Desglose()
                        {
                            Value    = _desgloseValue,
                            Proyecto = _proyecto.Id
                        };

                        _local.Desglose1 = _newDesglose;
                    }

                    var _localID = _locales.FirstOrDefault(x => x.Key_Name == _selectedGrid.GetRowCellValue(i, "RoomID").ToString());

                    var keyName = _selectedGrid.GetRowCellValue(i, "Local").ToString();

                    var localesProyecto = new DB_BIM().GetElements <Locales_Proyecto>(x => x.Proyecto == _proyecto.Id);
                    var realLocal       =
                        localesProyecto.FirstOrDefault(
                            x =>
                            x.Local1.Desglose == _local.Desglose && x.Local1.LocalTipo == _localTipo &&
                            x.Local1.Key_Name == keyName);


                    if (realLocal != null)
                    {
                        LocalController.UpdateLocalesProyecto(realLocal);
                    }
                    else
                    {
                        _local.RoomId         = _localID.RoomId;
                        _local.CoefArea       = _coef;
                        _local.CoefArea.Value = _coefAreas.FirstOrDefault(x => x.Id == _localID.Coef_Area).Value;
                        _local.LocalTipo      = _localTipo;
                        _local.Key_Name       = keyName;

                        _local.Ambiente1          = _localID.T_Ambiente.ToProject();
                        _local.Comunicaciones_Tv1 = _localID.T_Comunicaciones_Tv.ToProject();
                        _local.Climatizacion1     = _localID.T_Climatizacion.ToProject();

                        _localProyecto.Local1   = _local;
                        _localProyecto.Proyecto = _proyecto.Id;
                        _localProyecto.Cantidad = _selectedGrid.GetRowCellValue(i, "Hab") == null ? 0 : int.Parse(_selectedGrid.GetRowCellValue(i, "Hab").ToString());

                        new DB_BIM().AddElemento <Locales_Proyecto>(typeof(Locales_Proyecto), _localProyecto);
                    }
                }
                catch (Exception ex)
                {
                    Excepciones.Excepciones.EnviarCorreo(ex);
                    //throw;
                }
            }

            MessageBox.Show("Completado!");
        }
Exemple #8
0
        private void bnt_add_Click(object sender, EventArgs e)
        {
            if (cmb_LocalTipo.Text != "" && txt_nombreLocal.Text != "")
            {
                try
                {
                    using (var db = new DB_BIM())
                    {
                        var _localKeyName = cmb_LocalTipo.Text;
                        var _local        = new DB_PLANTILLA().GetSingleRecord <T_Local>(x => x.Key_Name == _localKeyName).ToProject();

                        _local.Key_Name = txt_nombreLocal.Text;
                        var _climatizacionID = _local.Climatizacion;
                        var _climatizacion   = new DB_PLANTILLA().GetSingleRecord <T_Climatizacion>(x => x.Id == _climatizacionID).ToProject();
                        _local.Climatizacion1 = _climatizacion;

                        var _ambienteID = _local.Ambiente;
                        var _ambiente   = new DB_PLANTILLA().GetSingleRecord <T_Ambiente>(x => x.Id == _ambienteID).ToProject();
                        _local.Ambiente1 = _ambiente;

                        var _comunicacionesID = _local.Comunicaciones_TV;
                        var _comunicaciones   = new DB_PLANTILLA().GetSingleRecord <T_Comunicaciones_Tv>(x => x.Id == _comunicacionesID).ToProject();
                        _local.Comunicaciones_Tv1 = _comunicaciones;


                        //Esto viene de la BD, aun asi se sobrescribe con el valor del excel, considerar como codigo sobrante.
                        var _coef = new DB_PLANTILLA().GetSingleRecord <T_CoefArea>(x => x.Id == _local.Coef_Area).ToProject();
                        _local.CoefArea = _coef;

                        var _localTipo = new DB_PLANTILLA().GetSingleRecord <T_LocalTipo>(x => x.Id == _local.Local_Tipo).ToProject();
                        _local.LocalTipo = _localTipo;

                        var _desgloseName = cmb_Desglose.Text;
                        var _desglose     = db.GetSingleElement <Desglose>(x => x.Value == _desgloseName && x.Proyecto == _proyecto.Id);
                        _local.Desglose = _desglose.Id;

                        var coef = AddNewRoom(_local.RoomId);

                        if (coef != null)
                        {
                            _local.CoefArea.Area_Programa = coef.Area_Programa;
                        }

                        Locales_Proyecto _localProyecto = new Locales_Proyecto()
                        {
                            Proyecto = _proyecto.Id,
                            Local1   = _local,
                            Cantidad = int.Parse(numeric_cantidad.Value.ToString())
                        };

                        _localProyecto = db.AddElemento <Locales_Proyecto>(typeof(Locales_Proyecto), _localProyecto);
                        AddGridViewRow(_localProyecto);
                    }
                }
                catch (Exception ex)
                {
                    //Excepciones.Excepciones.EnviarCorreo(ex);
                    throw;
                }
            }
            else
            {
                MessageBox.Show("Existen campos sin completar");
            }
        }
Exemple #9
0
        void AddGridViewRow(Locales_Proyecto localProyecto)
        {
            var _local           = localProyecto.GetLocal();
            var _proyecto        = localProyecto.GetProyecto();
            var _subsistemasTipo = new DB_PLANTILLA().GetAllRecords <T_Subsistema_Tipo>();
            var _subsistemasArea = new DB_PLANTILLA().GetAllRecords <T_Subsistema_Area>();
            var _localesTipo     = new DB_BIM().GetAllElements <LocalTipo>();
            var _grupoLocales    = new DB_PLANTILLA().GetAllRecords <T_Grupo_Locales>();
            var _cod1            = _grupoLocales.FirstOrDefault(x => x.Id == _localesTipo.FirstOrDefault(y => y.Id == _local.Local_Tipo).Grupo_Locales).Cod1;
            var _porcientos      = new DB_PLANTILLA().GetAllRecords <T_Porciento_BD>();
            var _coeficientes    = new DB_BIM().GetAllElements <CoefArea>();
            var _desgloses       = new DB_BIM().GetElements <Desglose>(x => x.Proyecto == _proyecto.Id);

            gridView1.AddNewRow();
            var _rowHandle = gridView1.GetRowHandle(gridView1.DataRowCount);

            if (gridView1.IsNewItemRow(_rowHandle))
            {
                var _coef = _coeficientes.FirstOrDefault(x => x.Id == _local.Coef_Area);

                if (_coef.Value == null)
                {
                    _coef.Value = "0";
                }



                //var _coefValue = float.Parse(_coef.Value);

                var _coefCalc = AddNewRoom(_local.RoomId);

                var _coefValue = 0f;

                _coefValue = float.Parse(_coefCalc.Area_Programa?.ToString() ?? _coef.Value);

                //var _coefValue = float.Parse(_coef.Value);

                //var _coefValue = _local.CoefArea == null ? float.Parse(_coef.Value) : float.Parse(_local.CoefArea.Value);

                //var _coefValue = _coef.Value == null ? 0.0 : float.Parse(_coef.Value);
                var _coefNumHab   = _local.GetCoefNumHab(_proyecto.Cant_Habitaciones.GetValueOrDefault());
                var _porciento    = _porcientos.FirstOrDefault(x => x.Id == _local.Porciento_BD).Value;
                var _areaPrograma = (_coefValue * _coefNumHab);
                var _areaCalculo  = (_areaPrograma * _porciento).GetValueOrDefault().ToString("#.##");

                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Obj. Obra"], _desgloses.FirstOrDefault(x => x.Id == _local.Desglose).Value);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["RoomID"], _local.RoomId);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["ID"], _local.Id);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Local"], _local.Key_Name);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["SubsistemaTipo"], _subsistemasTipo.FirstOrDefault(x => x.Id == _local.SubsistemaTipo).Value);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["SubsistemaArea"], _subsistemasArea.FirstOrDefault(x => x.Id == _local.SubsistemaArea).Value);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["LocalTipo"], _localesTipo.FirstOrDefault(x => x.Id == _local.Local_Tipo).Value);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Cod1"], _cod1);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Cod2"], _local.CalcularCod2());
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Cod3"], _local.CalcularCod3());
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Hab"], localProyecto.Local1.Habitacion.GetValueOrDefault() ? "1" : "0");
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Cantidad"], localProyecto.Cantidad);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Coef/Area"], _coef.Area_Programa);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Coef/Num.Habitaciones"], _coefNumHab);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Área Útil [m²]"], _coef.Area_Local);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Promedio de % Base Diseño"], _porciento);
                gridView1.SetRowCellValue(_rowHandle, gridView1.Columns["Áreas De Cálculo [m²]"], _areaCalculo);
            }

            gridView1.Focus();
        }