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!");
        }
Beispiel #2
0
        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;
                }
            }
        }
Beispiel #3
0
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName == "Coef/Area")
            {
                var _localID     = int.Parse(gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["ID"]).ToString());
                var _local       = new DB_BIM().GetSingleElement <Local>(x => x.Id == _localID);
                var _porcientoBD = new DB_PLANTILLA().GetSingleRecord <T_Porciento_BD>(x => x.Id == _local.Porciento_BD).Value;
                var _coef        = float.Parse(gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["Coef/Area"]).ToString());

                var _coefNumHab = (_coef < 2 && !_local.Key_Name.Contains("Closet")) ? _proyecto.Cant_Habitaciones : 1;

                gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Coef/Num.Habitaciones"], _coefNumHab);

                gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Área Útil [m²]"], (_coef * _coefNumHab).ToString());

                var _area      = gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["Área Útil [m²]"]).ToString() == "" ? "1" : gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["Área Útil [m²]"]).ToString();
                var _areaUtil  = float.Parse(_area);
                var _porciento = float.Parse(_porcientoBD.ToString());

                var _AreaPrograma = (_areaUtil * _porciento).ToString("#.##");

                gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Promedio de % Base Diseño"], _porciento);

                var _coefEntity = new DB_BIM().GetSingleElement <CoefArea>(x => x.Id == _local.Coef_Area);
                _coefEntity.Value         = _coef.ToString();
                _coefEntity.Area_Local    = _areaUtil;
                _coefEntity.Area_Programa = _AreaPrograma == "" ? double.Parse("0") : double.Parse(_AreaPrograma);

                ProyectoController.UpdateCoefArea(_coefEntity);

                gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Áreas De Cálculo [m²]"], _AreaPrograma);
                gridView1.UpdateCurrentRow();
                gridView1.RefreshRow(e.RowHandle);
            }

            if (e.Column.FieldName == "Promedio de % Base Diseño" && gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["Áreas De Cálculo [m²]"]) != null)
            {
                var _localID        = int.Parse(gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["ID"]).ToString());
                var _local          = new DB_BIM().GetSingleElement <Local>(x => x.Id == _localID);
                var _porcientoValue = float.Parse(gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["Promedio de % Base Diseño"]).ToString());
                var _areaUtil       = float.Parse(gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["Área Útil [m²]"]).ToString());
                var _areaPrograma   = (_areaUtil * _porcientoValue);
                gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Áreas De Cálculo [m²]"], _areaPrograma);
                gridView1.UpdateCurrentRow();
                gridView1.RefreshRow(e.RowHandle);

                var _coefEntity = new DB_BIM().GetSingleElement <CoefArea>(x => x.Id == _local.Coef_Area);
                _coefEntity.Area_Programa = double.Parse(_areaPrograma.ToString());

                var _porcientoEntity = new DB_PLANTILLA().GetSingleRecord <T_Porciento_BD>(x => x.Value == _porcientoValue);
                _local.Porciento_BD = _porcientoEntity.Id;

                ProyectoController.UpdateCoefArea(_coefEntity);
                LocalController.UpdatePorcientoBD(_local);
            }

            if (e.Column.FieldName == "Hab")
            {
                var _localID       = int.Parse(gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["ID"]).ToString());
                var _localProyecto = new DB_BIM().GetSingleElement <Locales_Proyecto>(x => x.Local == _localID && x.Proyecto == _proyecto.Id);
                _localProyecto.Cantidad = int.Parse(gridView1.GetRowCellValue(e.RowHandle, "Hab").ToString());
                LocalController.UpdateLocalesProyecto(_localProyecto);
            }
        }