protected void btnAsignar_Click(object sender, EventArgs e)
    {
        Entidades.EntidadesConosud dcAux = new Entidades.EntidadesConosud();

        foreach (GridDataItem item in gvSubContratistas.Items)
        {
            if ((item.FindControl("chkSeleccion") as CheckBox).Checked)
            {
                long idContrado = long.Parse(Request.QueryString["IdContrato"].ToString());
                long idEmpresa  = long.Parse(gvSubContratistas.Items[item.DataSetIndex].GetDataKeyValue("IdEmpresa").ToString());

                Entidades.Contrato contrato = (from CE in dcAux.Contrato
                                               where  CE.IdContrato == idContrado
                                               select CE).First <Entidades.Contrato>();

                Entidades.Empresa empresa = (from E in dcAux.Empresa
                                             where  E.IdEmpresa == idEmpresa
                                             select E).First <Entidades.Empresa>();


                ContratoEmpresas contemp = new ContratoEmpresas();
                contemp.EsContratista = false;
                contemp.Empresa       = empresa;
                contemp.Contrato      = contrato;
                dcAux.AddObject("EntidadesConosud.ContratoEmpresas", contemp);


                DateTime FFin = DateTime.Now;
                if (!contrato.Prorroga.HasValue)
                {
                    FFin = contrato.FechaVencimiento.Value;
                }
                else
                {
                    FFin = contrato.Prorroga.Value;
                }

                Helpers.GenerarHojadeRuta(dcAux, txtFechaAlta.SelectedDate.Value, FFin, contemp);
                //Helpers.GenerarHojadeRuta(dcAux, contrato.FechaInicio.Value, FFin, contemp);
            }
        }

        dcAux.SaveChanges();
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "ocultar", "CloseWindows();", true);
    }
Exemplo n.º 2
0
    private void GenerarContratos(ContratosImp ContImp, EntidadesConosud dc)
    {
        int HayEmpresa = (from E in dc.Empresa
                          where E.CUIT.Replace("-", "").Contains(ContImp.CUIT_FK.Replace("-", ""))
                          select E).Count();


        if (HayEmpresa > 0)
        {
            /// Creo el contrato
            Entidades.Contrato newContrato = new Entidades.Contrato();
            newContrato.Codigo           = ContImp.Codigo;
            newContrato.FechaInicio      = DateTime.Parse(ContImp.FechaInicio);
            newContrato.FechaVencimiento = DateTime.Parse(ContImp.FechaVencimiento);
            newContrato.Prorroga         = ContImp.Prorroga;
            newContrato.Servicio         = ContImp.Servicio.ToLower();

            newContrato.TipoContrato = (from T in dc.Clasificacion
                                        where T.Tipo == "Tipo Contrato" && T.Descripcion.Contains(ContImp.TipoContrato)
                                        select T).FirstOrDefault <Entidades.Clasificacion>();

            newContrato.Contratadopor = (from T in dc.Clasificacion
                                         where T.Tipo == "Contratado  por" && T.Descripcion.Contains(ContImp.ContratadoPor)
                                         select T).FirstOrDefault <Entidades.Clasificacion>();


            /// Creo el Contrato Empresa
            Entidades.ContratoEmpresas _ContEmp = new Entidades.ContratoEmpresas();

            _ContEmp.EsContratista = true;
            _ContEmp.Contrato      = newContrato;
            _ContEmp.Empresa       = (from E in dc.Empresa
                                      where E.CUIT.Replace("-", "").Contains(ContImp.CUIT_FK.Replace("-", ""))
                                      select E).First <Entidades.Empresa>();


            /// Creo las Hojas de Ruta
            DateTime FFin = DateTime.Now;
            if (newContrato.Prorroga.HasValue)
            {
                FFin = newContrato.Prorroga.Value;
            }
            else
            {
                FFin = newContrato.FechaVencimiento.Value;
            }
            DateTime FechaInicio = new DateTime(newContrato.FechaInicio.Value.Year, newContrato.FechaInicio.Value.Month, 1);

            Helpers.GenerarHojadeRuta(dc, FechaInicio, FFin, _ContEmp);


            /// Creo los contrato empresa para las subcontratista
            List <ContratoEmpresasImp> contratosSubContratistas = (from C in dc.ContratoEmpresasImp
                                                                   where C.Contratista.Replace("-", "") == _ContEmp.Empresa.CUIT.Replace("-", "") &&
                                                                   C.NroContrato == _ContEmp.Contrato.Codigo
                                                                   select C).ToList <ContratoEmpresasImp>();

            foreach (ContratoEmpresasImp item in contratosSubContratistas)
            {
                Entidades.Empresa SubContratista = (from E in dc.Empresa
                                                    where E.CUIT.Replace("-", "").Contains(item.SubContratista.Replace("-", ""))
                                                    select E).FirstOrDefault <Entidades.Empresa>();
                if (SubContratista != null)
                {
                    /// creo el contrato empresa para el subcontratista
                    Entidades.ContratoEmpresas _ContEmpSub = new Entidades.ContratoEmpresas();
                    _ContEmpSub.EsContratista = false;
                    _ContEmpSub.Empresa       = SubContratista;
                    newContrato.ContratoEmpresas.Add(_ContEmpSub);

                    /// Creo las Hojas de Ruta
                    FFin = DateTime.Now;
                    if (newContrato.Prorroga.HasValue)
                    {
                        FFin = newContrato.Prorroga.Value;
                    }
                    else
                    {
                        FFin = newContrato.FechaVencimiento.Value;
                    }
                    FechaInicio = new DateTime(newContrato.FechaInicio.Value.Year, newContrato.FechaInicio.Value.Month, 1);
                    Helpers.GenerarHojadeRuta(dc, FechaInicio, FFin, _ContEmpSub);
                }
            }


            dc.AddToContrato(newContrato);
        }
    }
Exemplo n.º 3
0
    protected void LinkButtonEliminar_OnClick(object sender, EventArgs e)
    {
        try
        {
            int    i          = RadGrid1.SelectedItems[0].DataSetIndex - (this.RadGrid1.CurrentPageIndex * this.RadGrid1.PageSize);
            string IdContrato = RadGrid1.Items[i].GetDataKeyValue("IdContrato").ToString();
            long   id         = Convert.ToInt64(IdContrato);


            //if ((from h in Contexto.HojasDeRuta
            //     where h.CabeceraHojasDeRuta.ContratoEmpresas.Contrato.IdContrato == id
            //     && h.HojaFechaAprobacion != null
            //     select h).Count() > 0)
            //{
            //    string scriptstring = "radalert('<h4>No se puede eliminar el contrato porque tiene cargada infomacion en su hoja de ruta!</h4>', 330, 100, 'Contratos');";
            //    ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", scriptstring, true);
            //    return;
            //}

            Entidades.Contrato _contrato = (from c in Contexto.Contrato
                                            .Include("ContratoEmpresas.CabeceraHojasDeRuta.HojasDeRuta")
                                            where c.IdContrato == id
                                            select c).First();



            int j = _contrato.ContratoEmpresas.Count();
            while (j > 0)
            {
                Entidades.ContratoEmpresas _ContratoEmpresas = _contrato.ContratoEmpresas.Take(1).First();
                if (!_ContratoEmpresas.ComentariosGral.IsLoaded)
                {
                    _ContratoEmpresas.ComentariosGral.Load();
                }
                List <ComentariosGral> coment = _ContratoEmpresas.ComentariosGral.ToList();

                foreach (ComentariosGral itemComent in coment)
                {
                    Contexto.DeleteObject(itemComent);
                }

                if (!_ContratoEmpresas.Contrato.DatosDeSueldos.IsLoaded)
                {
                    _ContratoEmpresas.Contrato.DatosDeSueldos.Load();
                }
                List <DatosDeSueldos> infoSueldos = _ContratoEmpresas.Contrato.DatosDeSueldos.ToList();

                foreach (DatosDeSueldos itemsueldo in infoSueldos)
                {
                    Contexto.DeleteObject(itemsueldo);
                }



                int j2 = _ContratoEmpresas.CabeceraHojasDeRuta.Count();
                while (j2 > 0)
                {
                    Entidades.CabeceraHojasDeRuta _CabeceraHojasDeRuta = _ContratoEmpresas.CabeceraHojasDeRuta.Take(1).First();

                    int j3 = _CabeceraHojasDeRuta.HojasDeRuta.Count();
                    while (j3 > 0)
                    {
                        Entidades.HojasDeRuta _HojasDeRuta = _CabeceraHojasDeRuta.HojasDeRuta.Take(1).First();
                        Contexto.DeleteObject(_HojasDeRuta);
                        j3--;
                    }
                    Contexto.DeleteObject(_CabeceraHojasDeRuta);
                    j2--;
                }
                Contexto.DeleteObject(_ContratoEmpresas);
                j--;
            }

            Contexto.DeleteObject(_contrato);
            Contexto.SaveChanges();

            this.CargarSessionContratos();
            this.RadGrid1.Rebind();
        }
        catch (Exception err)
        {
            string scriptstring = "radalert('<h4>" + err.InnerException.Message.Substring(0, 150) + "</h4>', 630, 100, 'Contratos');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", scriptstring, true);
        }
    }
Exemplo n.º 4
0
    public static void ActualizarVencimientoCredencialesVehiEquipos(EntidadesConosud Ds, DateTime FFin, Entidades.Contrato ContratoActual)
    {
        var ve = (from v in Ds.VahiculosyEquipos
                  where v.objContrato.IdContrato == ContratoActual.IdContrato
                  select v).ToList();


        foreach (var item in ve)
        {
            SortedList fechas = new SortedList();
            fechas.Add(item.FechaUltimoPagoSeguro != null ? item.FechaUltimoPagoSeguro.Value : DateTime.MaxValue, "fechaSeguro");
            fechas.Add(FFin, "FecahContrato");
            fechas.Add(item.FechaHabilitacion != null ? item.FechaHabilitacion.Value : DateTime.MaxValue.AddDays(-1), "fechaCENT");

            DateTime menor = (DateTime)fechas.GetKeyList()[0];

            item.VencimientoCredencial = (menor - DateTime.Now).Days > 90 ? DateTime.Now.AddDays(90) : menor;
        }
    }
Exemplo n.º 5
0
    private void InsertContrato(GridEditFormInsertItem editedItem)
    {
        #region Genero el CONTRATO con los datos ingresado por el usuario
        long            idCategoria_Ingresada = 0;
        GridEditManager editMan                        = editedItem.EditManager;
        string          codigo_Ingresado               = ((TextBox)editedItem.FindControl("TextBoxCodigo")).Text;
        string          servicio_Ingresado             = ((TextBox)editedItem.FindControl("TextBoxServicio")).Text;
        long            idContratista_Ingresado        = long.Parse(((RadComboBox)editedItem.FindControl("RadComboBoxContratista")).SelectedValue);
        long            idTipoContrato_Ingresado       = long.Parse(((RadComboBox)editedItem.FindControl("cboTipoContrato")).SelectedValue);
        long            idContratadoPor_Ingresado      = long.Parse(((RadComboBox)editedItem.FindControl("cboContratadoPor")).SelectedValue);
        DateTime        fechaInicioContrato_Ingresado  = DateTime.Parse((editedItem.FindControl("TextBoxFechaInicio") as TextBox).Text);
        DateTime        fechaFinContrato_Ingresado     = DateTime.Parse((editedItem.FindControl("TextBoxFechaVencimiento") as TextBox).Text);
        DateTime?       fechaPorrogaContrato_Ingresado = null;

        if (((RadComboBox)editedItem.FindControl("cboCategoria")).SelectedValue != "")
        {
            idCategoria_Ingresada = long.Parse(((RadComboBox)editedItem.FindControl("cboCategoria")).SelectedValue);
        }


        if ((editedItem.FindControl("TextBoxProrroga") as TextBox).Text != "")
        {
            fechaPorrogaContrato_Ingresado = DateTime.Parse((editedItem.FindControl("TextBoxProrroga") as TextBox).Text);
        }


        if ((from c in Contexto.Contrato
             where c.Codigo == codigo_Ingresado.Trim()
             select c).Count() > 0)
        {
            string scriptstring = "radalert('<h4>No se puede crear el contrato ya que el nro del mismo ya existe!</h4>', 330, 100, 'Contratos');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", scriptstring, true);
            return;
        }



        Entidades.Contrato _Contrato = new Entidades.Contrato();
        _Contrato.Codigo           = codigo_Ingresado;
        _Contrato.Servicio         = servicio_Ingresado;
        _Contrato.FechaInicio      = fechaInicioContrato_Ingresado;
        _Contrato.FechaVencimiento = fechaFinContrato_Ingresado;
        _Contrato.Contratadopor    = Contexto.Clasificacion.Where(w => w.IdClasificacion == idContratadoPor_Ingresado).FirstOrDefault();
        _Contrato.TipoContrato     = Contexto.Clasificacion.Where(w => w.IdClasificacion == idTipoContrato_Ingresado).FirstOrDefault();

        if (idCategoria_Ingresada > 0)
        {
            _Contrato.objCategoria = Contexto.Clasificacion.Where(w => w.IdClasificacion == idCategoria_Ingresada).FirstOrDefault();
        }


        #endregion

        #region Genero el CONTRATO-EMPRESA con los datos ingresado por el usuario

        Entidades.ContratoEmpresas _ContEmp = new Entidades.ContratoEmpresas();
        IEnumerable <KeyValuePair <string, object> > entityKeyValues =
            new KeyValuePair <string, object>[] {
            new KeyValuePair <string, object>("IdEmpresa", idContratista_Ingresado)
        };
        EntityKey         key  = new EntityKey("EntidadesConosud.Empresa", entityKeyValues);
        Entidades.Empresa _emp = (Entidades.Empresa)Contexto.GetObjectByKey(key);

        _ContEmp.EsContratista = true;
        _ContEmp.Contrato      = _Contrato;
        _ContEmp.Empresa       = _emp;

        Contexto.AddObject("EntidadesConosud.ContratoEmpresas", _ContEmp);

        #endregion

        #region Genero el ENCABEZADO Y LAS HOJAS con los datos ingresado por el usuario

        DateTime FFin = DateTime.Now;
        if (_Contrato.Prorroga.HasValue)
        {
            FFin = _Contrato.Prorroga.Value;
        }
        else
        {
            FFin = _Contrato.FechaVencimiento.Value;
        }

        DateTime FechaInicio = new DateTime(_Contrato.FechaInicio.Value.Year, _Contrato.FechaInicio.Value.Month, 1);

        Helpers.GenerarHojadeRuta(Contexto, FechaInicio, FFin, _ContEmp);

        #endregion

        Contexto.SaveChanges();
        CargarSessionContratos();
    }
Exemplo n.º 6
0
    private void UpdateContrato(GridEditableItem editedItem)
    {
        Contexto.CommandTimeout = 30000;
        long idContrato = Convert.ToInt64(ViewState["idsel"]);


        Entidades.Contrato _ContratoAnt = (from c in Contexto.Contrato
                                           where c.IdContrato == idContrato
                                           select c).FirstOrDefault();

        if (_ContratoAnt != null)
        {
            try
            {
                #region Recupero los  Datos Ingresado por el usuario
                long idCategoria_Ingresada = 0;

                GridEditManager editMan            = editedItem.EditManager;
                string          codigo_Ingresado   = ((TextBox)editedItem.FindControl("TextBoxCodigo")).Text;
                string          servicio_Ingresado = ((TextBox)editedItem.FindControl("TextBoxServicio")).Text;

                long idContratista_Ingresado  = long.Parse(((RadComboBox)editedItem.FindControl("RadComboBoxContratista")).SelectedValue);
                long idTipoContrato_Ingresado = long.Parse(((RadComboBox)editedItem.FindControl("cboTipoContrato")).SelectedValue);

                if (((RadComboBox)editedItem.FindControl("cboCategoria")).SelectedValue != "")
                {
                    idCategoria_Ingresada = long.Parse(((RadComboBox)editedItem.FindControl("cboCategoria")).SelectedValue);
                }

                long     idContratadoPor_Ingresado      = long.Parse(((RadComboBox)editedItem.FindControl("cboContratadoPor")).SelectedValue);
                DateTime fechaInicioContrato_Ingresado  = DateTime.Parse((editedItem.FindControl("TextBoxFechaInicio") as TextBox).Text);
                DateTime fechaFinContrato_Ingresado     = DateTime.Parse((editedItem.FindControl("TextBoxFechaVencimiento") as TextBox).Text);
                DateTime?fechaPorrogaContrato_Ingresado = null;

                if ((editedItem.FindControl("TextBoxProrroga") as TextBox).Text != "")
                {
                    fechaPorrogaContrato_Ingresado = DateTime.Parse((editedItem.FindControl("TextBoxProrroga") as TextBox).Text);
                }

                #endregion


                /// Actualizar el campo emprsa contratista del contrato
                IEnumerable <KeyValuePair <string, object> > entityKeyValues = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("IdEmpresa", idContratista_Ingresado) };

                EntityKey         key  = new EntityKey("EntidadesConosud.Empresa", entityKeyValues);
                Entidades.Empresa _emp = (Entidades.Empresa)Contexto.GetObjectByKey(key);

                if (!_ContratoAnt.ContratoEmpresas.IsLoaded)
                {
                    _ContratoAnt.ContratoEmpresas.Load();
                }
                _ContratoAnt.ContratoEmpresas.Where(w => w.EsContratista.Value).First().Empresa = _emp;


                DateTime?FechaInicioAnt   = _ContratoAnt.FechaInicio;
                DateTime?FechaFinAnt      = DateTime.MinValue;
                DateTime?FechaInicioNuevo = fechaInicioContrato_Ingresado;
                DateTime?FechaFinNuevo    = DateTime.MinValue;

                FechaFinAnt   = Helpers.DeterminarFinPeriodo(_ContratoAnt.FechaVencimiento, _ContratoAnt.Prorroga, ref FechaFinAnt);
                FechaFinNuevo = Helpers.DeterminarFinPeriodo(fechaFinContrato_Ingresado, fechaPorrogaContrato_Ingresado, ref FechaFinNuevo);


                foreach (Entidades.ContratoEmpresas ContEmp in _ContratoAnt.ContratoEmpresas)
                {
                    if (FechaInicioNuevo > FechaInicioAnt)
                    {
                        if ((from h in Contexto.HojasDeRuta
                             where h.CabeceraHojasDeRuta.ContratoEmpresas.Contrato.IdContrato == idContrato &&
                             h.HojaFechaAprobacion != null &&
                             FechaInicioNuevo > h.CabeceraHojasDeRuta.Periodo
                             select h).Count() == 0)
                        {
                            List <object> objEliminar = new List <object>();
                            if (ContEmp.CabeceraHojasDeRuta.Count == 0)
                            {
                                ContEmp.CabeceraHojasDeRuta.Load();
                            }

                            ///Borro Diferencias
                            foreach (Entidades.CabeceraHojasDeRuta rowCabHR in ContEmp.CabeceraHojasDeRuta)
                            {
                                if (FechaInicioNuevo > rowCabHR.Periodo)
                                {
                                    objEliminar.Add(rowCabHR);

                                    if (!rowCabHR.ContEmpLegajos.IsLoaded)
                                    {
                                        rowCabHR.ContEmpLegajos.Load();
                                    }
                                    foreach (Entidades.ContEmpLegajos itemC in rowCabHR.ContEmpLegajos)
                                    {
                                        objEliminar.Add(itemC);
                                    }
                                }
                            }

                            foreach (object item in objEliminar)
                            {
                                Contexto.DeleteObject(item);
                            }
                        }
                    }
                    else
                    {
                        if (FechaInicioNuevo < FechaInicioAnt)
                        {
                            ///Agrega Diferencias
                            Helpers.GenerarHojadeRuta(Contexto, FechaInicioNuevo.Value, FechaInicioAnt.Value, ContEmp);
                        }
                    }


                    // Agrego los periodos que superan la fecha de fin.
                    if (FechaFinNuevo > FechaFinAnt)
                    {
                        ///Agrega Diferencias
                        Helpers.GenerarHojadeRuta(Contexto, FechaFinAnt.Value, FechaFinNuevo.Value, ContEmp);

                        ////Helpers.ActualizarVencimientoCredencialesVehiEquipos(Contexto, FechaFinNuevo.Value, _ContratoAnt);

                        var ve = (from v in Contexto.VahiculosyEquipos
                                  where v.objContrato.IdContrato == _ContratoAnt.IdContrato
                                  select v).ToList();


                        foreach (var item in ve)
                        {
                            SortedList fechas = new SortedList();
                            if (item.FechaUltimoPagoSeguro != null)
                            {
                                fechas.Add(item.FechaUltimoPagoSeguro, "fechaSeguro");
                            }
                            fechas.Add(FechaFinNuevo.Value, "FecahContrato");
                            if (item.FechaVencimientoHabilitacion != null)
                            {
                                fechas.Add(item.FechaVencimientoHabilitacion.Value.AddSeconds(3), "fechaCENT");
                            }
                            ;

                            DateTime menor = (DateTime)fechas.GetKeyList()[0];

                            item.VencimientoCredencial = (menor - DateTime.Now).Days > 90 ? DateTime.Now.AddDays(90) : menor;
                        }
                    }
                    else
                    {
                        List <object> objEliminar = new List <object>();

                        if ((from h in Contexto.HojasDeRuta
                             where h.CabeceraHojasDeRuta.ContratoEmpresas.Contrato.IdContrato == idContrato &&
                             h.HojaFechaAprobacion == null &&
                             h.CabeceraHojasDeRuta.Periodo > FechaFinNuevo
                             select h).Count() > 0)
                        {
                            ///Borro Diferencias
                            if (ContEmp.CabeceraHojasDeRuta.Count == 0)
                            {
                                ContEmp.CabeceraHojasDeRuta.Load();
                            }
                            foreach (Entidades.CabeceraHojasDeRuta rowCabHR in ContEmp.CabeceraHojasDeRuta)
                            {
                                if (rowCabHR.Periodo > FechaFinNuevo)
                                {
                                    // Elimino la cabecera
                                    objEliminar.Add(rowCabHR);

                                    // Elimino los legajos asociados
                                    if (!rowCabHR.ContEmpLegajos.IsLoaded)
                                    {
                                        rowCabHR.ContEmpLegajos.Load();
                                    }
                                    foreach (Entidades.ContEmpLegajos itemC in rowCabHR.ContEmpLegajos)
                                    {
                                        objEliminar.Add(itemC);
                                    }

                                    // Elimino los seguimientos asociados
                                    if (!rowCabHR.colSeguimientoAuditoria.IsLoaded)
                                    {
                                        rowCabHR.colSeguimientoAuditoria.Load();
                                    }
                                    foreach (Entidades.SeguimientoAuditoria itemS in rowCabHR.colSeguimientoAuditoria)
                                    {
                                        objEliminar.Add(itemS);
                                    }
                                }
                            }
                        }

                        foreach (object item in objEliminar)
                        {
                            Contexto.DeleteObject(item);
                        }


                        var ve = (from v in Contexto.VahiculosyEquipos
                                  where v.objContrato.IdContrato == idContrato
                                  select v).ToList();


                        foreach (var item in ve)
                        {
                            SortedList fechas = new SortedList();
                            if (item.FechaUltimoPagoSeguro != null)
                            {
                                fechas.Add(item.FechaUltimoPagoSeguro, "fechaSeguro");
                            }
                            fechas.Add(FechaFinNuevo.Value, "FecahContrato");
                            if (item.FechaVencimientoHabilitacion != null)
                            {
                                fechas.Add(item.FechaVencimientoHabilitacion.Value.AddSeconds(3), "fechaCENT");
                            }
                            ;

                            DateTime menor = (DateTime)fechas.GetKeyList()[0];

                            item.VencimientoCredencial = (menor - DateTime.Now).Days > 90 ? DateTime.Now.AddDays(90) : menor;
                        }
                    }
                }


                _ContratoAnt.Codigo           = codigo_Ingresado;
                _ContratoAnt.Servicio         = servicio_Ingresado;
                _ContratoAnt.FechaInicio      = fechaInicioContrato_Ingresado;
                _ContratoAnt.FechaVencimiento = fechaFinContrato_Ingresado;
                _ContratoAnt.Prorroga         = fechaPorrogaContrato_Ingresado;
                _ContratoAnt.Contratadopor    = Contexto.Clasificacion.Where(w => w.IdClasificacion == idContratadoPor_Ingresado).FirstOrDefault();
                _ContratoAnt.TipoContrato     = Contexto.Clasificacion.Where(w => w.IdClasificacion == idTipoContrato_Ingresado).FirstOrDefault();

                if (idCategoria_Ingresada > 0)
                {
                    _ContratoAnt.objCategoria = Contexto.Clasificacion.Where(w => w.IdClasificacion == idCategoria_Ingresada).FirstOrDefault();
                }


                Contexto.SaveChanges();
                CargarSessionContratos();
            }
            catch (Exception e)
            {
                DivError.InnerText = e.Message + ":" + e.InnerException.Message;
                ScriptManager.RegisterStartupScript(updpnlGrilla, typeof(UpdatePanel), "Error Grabacion", "alert(" + e.Message + ":" + e.InnerException.Message + ")", true);
                updpnlGrilla.Update();
            }
        }
    }
Exemplo n.º 7
0
    private void BindResults()
    {
        try
        {
            EntidadesConosud dc         = new EntidadesConosud();
            ArchivosSueldos  newArchivo = new ArchivosSueldos();
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                #region Lectura y Carga Archivo Excel
                string          rutaArchivo = Server.MapPath("ArchivosSueldos") + "/" + RadUpload1.UploadedFiles[0].GetName();
                OleDbConnection connection  = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + rutaArchivo + ";Extended Properties=Excel 8.0");
                OleDbCommand    command     = new OleDbCommand("SELECT * FROM [Info$]", connection);
                OleDbDataReader dr;
                try
                {
                    connection.Open();
                    dr = command.ExecuteReader(CommandBehavior.CloseConnection);
                }
                catch
                {
                    connection = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + rutaArchivo + ";Extended Properties=Excel 8.0");
                    command    = new OleDbCommand("SELECT * FROM [FEBRERO$]", connection);
                    connection.Open();
                    dr = command.ExecuteReader(CommandBehavior.CloseConnection);
                }

                DataTable excelData = new DataTable("ExcelData");
                excelData.Load(dr);

                var AlllegajosExcel = (from excel in excelData.AsEnumerable()
                                       select new
                {
                    dni = excel.Field <object>("DNI"),
                    fechaIngeso = excel.Field <DateTime?>("FECHA DE INGRESO"),
                    Categoria = excel.Field <string>("CATEGORIA SEGÚN CCT"),
                    Funcion = excel.Field <string>("FUNCION"),
                    NombreCompleto = excel.Field <string>("APELLIDO Y NOMBRE"),
                    FechaNacimiento = excel.Field <DateTime?>("FECHA DE NACIMIENTO"),
                    CUIL = excel.Field <double?>("CUIL"),
                    EncuadreGremial = excel.Field <string>("ENCUADRE GREMIAL"),

                    Basico = excel.Field <decimal?>("BASICO/VALOR HORA SEGÚN CCT"),
                    BasicoLiquidado = excel.Field <decimal?>("BASICO LIQUIDADO"),
                    HorasExtras = excel.Field <decimal?>("HORAS EXTRAS"),
                    AdicionalesRemunerativos = excel.Field <decimal?>("ADICIONALES REMUNERATIVOS (SIN HORAS EXTRAS)"),
                    Vacaciones = excel.Field <decimal?>("VACACIONES"),
                    SAC = excel.Field <decimal?>("SAC"),
                    TotalBruto = excel.Field <decimal?>("TOTAL BRUTO"),
                    AsigFliares = excel.Field <decimal?>("ASIGN FLIARES"),
                    AdicionalesNoRemunerativos = excel.Field <decimal?>("ADICIONALES NO REMUNERATIVOS"),
                    Descuentos = excel.Field <decimal?>("DESCUENTOS"),
                    TotalNeto = excel.Field <decimal?>("TOTAL NETO"),
                    CUITEmpresa = excel.Field <double?>("CUIT_(EMPRESA)"),
                    Periodo = excel.Field <DateTime?>("MES DE LIQUIDACIÓN"),
                    NroContrato = excel.Field <object>("CONTRATO N°"),
                    RazonSocial = excel.Field <string>("RAZON SOCIAL")
                }).ToList();
                #endregion

                #region Valido informacion
                ///Valido que el periodo no exista en la base
                ///
                var claveArchivo = (from L in AlllegajosExcel
                                    where L.Periodo != null
                                    select new { L.Periodo, L.NroContrato, L.CUITEmpresa, L.RazonSocial });

                if (claveArchivo.Count() > 0)
                {
                    int    mes     = claveArchivo.First().Periodo.Value.Month;
                    int    ano     = claveArchivo.First().Periodo.Value.Year;
                    string cuitemp = claveArchivo.First().CUITEmpresa.ToString();
                    string nrocon  = claveArchivo.First().NroContrato.ToString();

                    Entidades.Empresa emp = (from E in dc.Empresa
                                             where E.CUIT == cuitemp
                                             select E).FirstOrDefault();
                    if (emp == null)
                    {
                        string scriptstring = "alert('La empresa " + claveArchivo.First().RazonSocial + " no existe en la base de datos.');";
                        ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript2", scriptstring, true);
                        return;
                    }


                    if ((from D in dc.DatosDeSueldos
                         where D.objContrato.Codigo == nrocon && D.objEmpresa.CUIT == cuitemp &&
                         D.Periodo.Value.Year == ano && D.Periodo.Value.Month == mes
                         select D).Count() > 0)
                    {
                        string scriptstring = "alert('El periodo "
                                              + mes + "/" + ano + " del contrato " + nrocon + " correspondiente a " + claveArchivo.First().RazonSocial
                                              + " ya existe, debe eliminar el archivo del listado para completar la acción.');";

                        ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript1", scriptstring, true);
                        return;
                    }
                }
                else
                {
                    string scriptstring = "alert('El archivo no contiene informacion.');";
                    ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript2", scriptstring, true);
                    return;
                }

                #endregion

                #region Actualizacion de info

                List <string> legajosDni = (from L in AlllegajosExcel
                                            where L.dni != null
                                            select L.dni.ToString()).ToList();

                List <Entidades.Legajos> LegajosEncontrados = dc.Legajos.Where(
                    Helpers.ContainsExpression <Entidades.Legajos, string>(l => l.NroDoc, legajosDni)).ToList <Entidades.Legajos>();

                /// Actualizo la información de los legajos encontrados
                foreach (Entidades.Legajos leg in LegajosEncontrados)
                {
                    var LegExcel = (from L in AlllegajosExcel
                                    where L.dni.ToString() == leg.NroDoc
                                    select L).First();

                    //leg.FuncionCCT = LegExcel.Funcion;
                    leg.FechaIngreos = LegExcel.fechaIngeso;
                    //leg.CategoriaCCT = LegExcel.Categoria;
                }

                /// Con la información de los legajos nuevos
                /// doy de alta a los nuevos legajos
                List <string> legajosDniBase = (from L in dc.Legajos
                                                select L.NroDoc).ToList();


                List <string> LegajosDniNevos = (from L in legajosDni
                                                 where !legajosDniBase.Contains(L)
                                                 select L).ToList();

                foreach (string dni in LegajosDniNevos)
                {
                    var LegExcel = (from L in AlllegajosExcel
                                    where L.dni == dni
                                    select L).First();

                    if (dni != null && dni != "" && dni.Length == 8)
                    {
                        Entidades.Legajos leg = new Entidades.Legajos();
                        //leg.FuncionCCT = LegExcel.Funcion;
                        leg.FechaIngreos = LegExcel.fechaIngeso;
                        //leg.CategoriaCCT = LegExcel.Categoria;
                        leg.NroDoc = dni;

                        if (LegExcel.NombreCompleto.IndexOf(",") > 0)
                        {
                            leg.Apellido = LegExcel.NombreCompleto.Substring(0, LegExcel.NombreCompleto.IndexOf(",")).Trim();
                            leg.Nombre   = LegExcel.NombreCompleto.Substring(LegExcel.NombreCompleto.IndexOf(",") + 1).Replace(".", "").Trim();
                        }
                        else
                        {
                            leg.Apellido = LegExcel.NombreCompleto.Substring(0, LegExcel.NombreCompleto.IndexOf(" ")).Trim();
                            leg.Nombre   = LegExcel.NombreCompleto.Substring(LegExcel.NombreCompleto.IndexOf(" ") + 1).Replace(".", "").Trim();
                        }

                        leg.FechaNacimiento = LegExcel.FechaNacimiento;

                        if (LegExcel.CUIL != null)
                        {
                            leg.CUIL = string.Format("{0:##-########-#}", long.Parse(LegExcel.CUIL.ToString()));
                        }

                        leg.objConvenio = (from Cla in dc.Clasificacion
                                           where Cla.Tipo == "Convenio" && Cla.Descripcion.Contains(LegExcel.EncuadreGremial)
                                           select Cla).FirstOrDefault();

                        dc.AddToLegajos(leg);
                    }
                }
                #endregion

                #region Carga registro de Archivo
                long idUsuario = long.Parse(this.Session["idusu"].ToString());
                newArchivo.Nombre     = RadUpload1.UploadedFiles[0].GetName();
                newArchivo.SegUsuario = (from U in dc.SegUsuario
                                         where U.IdSegUsuario == idUsuario
                                         select U).First();

                newArchivo.FechaCreacion = DateTime.Now;
                dc.AddToArchivosSueldos(newArchivo);
                #endregion

                #region Generacion Información Sueldo Mensual
                List <Entidades.DatosDeSueldos> dtosSuel = new List <DatosDeSueldos>();
                foreach (var item in AlllegajosExcel)
                {
                    string StringDNI = Convert.ToInt32(item.dni).ToString();

                    Entidades.Legajos leg = (from L in dc.Legajos
                                             where L.NroDoc == StringDNI
                                             select L).FirstOrDefault();

                    string cuitemp = string.Empty;
                    if (item.CUITEmpresa.HasValue)
                    {
                        cuitemp = item.CUITEmpresa.Value.ToString();
                    }
                    Entidades.Empresa emp = (from E in dc.Empresa
                                             where E.CUIT == cuitemp
                                             select E).FirstOrDefault();

                    string nrocont = string.Empty;
                    if (item.NroContrato != null)
                    {
                        nrocont = item.NroContrato.ToString();
                    }
                    Entidades.Contrato cont = (from E in dc.Contrato
                                               where E.Codigo == nrocont
                                               select E).FirstOrDefault();

                    if (leg != null && emp != null && cont != null)
                    {
                        Entidades.DatosDeSueldos DatoSueldo = new DatosDeSueldos();
                        DatoSueldo.objLegajo = leg;
                        DatoSueldo.AdicionalesNORemunerativos = item.AdicionalesNoRemunerativos;
                        DatoSueldo.AdicionalesRemunerativos   = item.AdicionalesRemunerativos;
                        DatoSueldo.AsignacionFamiliar         = item.AsigFliares;
                        DatoSueldo.Basico_ValorHora           = item.Basico;
                        DatoSueldo.BasicoLiquidado            = item.BasicoLiquidado;
                        DatoSueldo.Descuentos  = item.Descuentos;
                        DatoSueldo.HorasExtras = item.HorasExtras;
                        DatoSueldo.SAC         = item.SAC;
                        DatoSueldo.TotalBruto  = item.TotalBruto;
                        DatoSueldo.TotalNeto   = item.TotalNeto;
                        DatoSueldo.Vacaciones  = item.Vacaciones;
                        DatoSueldo.Periodo     = item.Periodo;
                        DatoSueldo.objEmpresa  = emp;
                        DatoSueldo.objContrato = cont;
                        dtosSuel.Add(DatoSueldo);
                    }
                }
                #endregion


                if (dtosSuel.Count > 0)
                {
                    foreach (Entidades.DatosDeSueldos ds in dtosSuel)
                    {
                        newArchivo.colDatosDeSueldos.Add(ds);
                    }

                    dc.SaveChanges();
                    gvArchivos.Rebind();
                }
                else
                {
                    string scriptstring = "alert('No existe informacion de Sueldos en el archivo o no estan cargado ninguno de los contratos o legagos en el sistema');";
                    ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript2", scriptstring, true);
                    return;
                }
            }
        }
        catch (Exception ex)
        {
            string script = string.Format("alert('Error al procesar archivo!  {0}');", ex.Message.Replace("'", " "));
            ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);
        }
    }
Exemplo n.º 8
0
    private void InsertContrato(GridEditFormInsertItem editedItem)
    {
        #region Genero el CONTRATO con los datos ingresado por el usuario

        GridEditManager editMan                   = editedItem.EditManager;
        string          codigo_Ingresado          = (editMan.GetColumnEditor("Codigo") as GridTextBoxColumnEditor).Text;
        string          servicio_Ingresado        = (editMan.GetColumnEditor("Servicio") as GridTextBoxColumnEditor).Text;
        long            idContratista_Ingresado   = long.Parse(((RadComboBox)editedItem.FindControl("cboContratista")).SelectedValue);
        long            idTipoContrato_Ingresado  = long.Parse(((RadComboBox)editedItem.FindControl("cboTipoContrato")).SelectedValue);
        long            idContratadoPor_Ingresado = long.Parse(((RadComboBox)editedItem.FindControl("cboContratadoPor")).SelectedValue);
        long            idCategoria_Ingresado     = long.Parse(((RadComboBox)editedItem.FindControl("cboCategoria")).SelectedValue);
        long            idArea_Ingresado          = long.Parse(((RadComboBox)editedItem.FindControl("cboArea")).SelectedValue);


        string GestorNombre_Ingresado = ((TextBox)editedItem.FindControl("txtNombreGestor")).Text;
        string GestorEmail_Ingresado  = ((TextBox)editedItem.FindControl("txtEmailGestor")).Text;
        string FiscalNombre_Ingresado = ((TextBox)editedItem.FindControl("txtNombreFiscales")).Text;
        string FiscalEmail_Ingresado  = ((TextBox)editedItem.FindControl("txtEmailFiscales")).Text;


        DateTime fechaInicioContrato_Ingresado  = DateTime.Parse((editedItem.FindControl("TextBoxFechaInicio") as TextBox).Text);
        DateTime fechaFinContrato_Ingresado     = DateTime.Parse((editedItem.FindControl("TextBoxFechaVencimiento") as TextBox).Text);
        DateTime?fechaPorrogaContrato_Ingresado = null;

        if ((editedItem.FindControl("TextBoxProrroga") as TextBox).Text != "")
        {
            fechaPorrogaContrato_Ingresado = DateTime.Parse((editedItem.FindControl("TextBoxProrroga") as TextBox).Text);
        }

        Entidades.Contrato _Contrato = new Entidades.Contrato();
        _Contrato.Codigo           = codigo_Ingresado.Trim();
        _Contrato.Servicio         = servicio_Ingresado;
        _Contrato.FechaInicio      = fechaInicioContrato_Ingresado;
        _Contrato.FechaVencimiento = fechaFinContrato_Ingresado;
        _Contrato.Contratadopor    = idContratadoPor_Ingresado;
        _Contrato.TipoContrato     = idTipoContrato_Ingresado;
        _Contrato.Categoria        = idCategoria_Ingresado;
        _Contrato.Area             = idArea_Ingresado;
        _Contrato.GestorNombre     = GestorNombre_Ingresado;
        _Contrato.GestorEmail      = GestorEmail_Ingresado;
        _Contrato.FiscalNombre     = FiscalNombre_Ingresado;
        _Contrato.FiscalEmail      = FiscalEmail_Ingresado;

        #endregion

        #region Genero el CONTRATO-EMPRESA con los datos ingresado por el usuario

        Entidades.ContratoEmpresas _ContEmp = new Entidades.ContratoEmpresas();
        IEnumerable <KeyValuePair <string, object> > entityKeyValues =
            new KeyValuePair <string, object>[] {
            new KeyValuePair <string, object>("IdEmpresa", idContratista_Ingresado)
        };
        EntityKey         key  = new EntityKey("EntidadesConosud.Empresa", entityKeyValues);
        Entidades.Empresa _emp = (Entidades.Empresa)Contexto.GetObjectByKey(key);

        _ContEmp.EsContratista = true;
        _ContEmp.Contrato      = _Contrato;
        _ContEmp.Empresa       = _emp;

        Contexto.AddObject("EntidadesConosud.ContratoEmpresas", _ContEmp);

        #endregion

        #region Genero el ENCABEZADO Y LAS HOJAS con los datos ingresado por el usuario

        DateTime FFin = DateTime.Now;
        if (_Contrato.Prorroga.HasValue)
        {
            FFin = _Contrato.Prorroga.Value;
        }
        else
        {
            FFin = _Contrato.FechaVencimiento.Value;
        }

        DateTime FechaInicio = new DateTime(_Contrato.FechaInicio.Value.Year, _Contrato.FechaInicio.Value.Month, 1);

        Helpers.GenerarHojadeRuta(Contexto, FechaInicio, FFin, _ContEmp);

        #endregion

        Contexto.SaveChanges();
        CargarSessionContratos();
        RadGrid1.Rebind();
    }
Exemplo n.º 9
0
    private void UpdateContrato(GridEditableItem editedItem)
    {
        long idContrato = Convert.ToInt64(ViewState["idsel"]);


        Entidades.Contrato _ContratoAnt = (from c in Contexto.Contrato
                                           where c.IdContrato == idContrato
                                           select c).FirstOrDefault();

        if (_ContratoAnt != null)
        {
            try
            {
                #region Recupero los  Datos Ingresado por el usuario

                GridEditManager editMan                   = editedItem.EditManager;
                string          codigo_Ingresado          = (editMan.GetColumnEditor("Codigo") as GridTextBoxColumnEditor).Text;
                string          servicio_Ingresado        = (editMan.GetColumnEditor("Servicio") as GridTextBoxColumnEditor).Text;
                long            idContratista_Ingresado   = long.Parse(((RadComboBox)editedItem.FindControl("cboContratista")).SelectedValue);
                long            idTipoContrato_Ingresado  = long.Parse(((RadComboBox)editedItem.FindControl("cboTipoContrato")).SelectedValue);
                long            idContratadoPor_Ingresado = long.Parse(((RadComboBox)editedItem.FindControl("cboContratadoPor")).SelectedValue);
                long            idCategoria_Ingresado     = long.Parse(((RadComboBox)editedItem.FindControl("cboCategoria")).SelectedValue);
                long            idArea_Ingresado          = long.Parse(((RadComboBox)editedItem.FindControl("cboArea")).SelectedValue);

                string GestorNombre_Ingresado = ((TextBox)editedItem.FindControl("txtNombreGestor")).Text;
                string GestorEmail_Ingresado  = ((TextBox)editedItem.FindControl("txtEmailGestor")).Text;
                string FiscalNombre_Ingresado = ((TextBox)editedItem.FindControl("txtNombreFiscales")).Text;
                string FiscalEmail_Ingresado  = ((TextBox)editedItem.FindControl("txtEmailFiscales")).Text;


                DateTime fechaInicioContrato_Ingresado  = DateTime.Parse((editedItem.FindControl("TextBoxFechaInicio") as TextBox).Text);
                DateTime fechaFinContrato_Ingresado     = DateTime.Parse((editedItem.FindControl("TextBoxFechaVencimiento") as TextBox).Text);
                DateTime?fechaPorrogaContrato_Ingresado = null;

                if ((editedItem.FindControl("TextBoxProrroga") as TextBox).Text != "")
                {
                    fechaPorrogaContrato_Ingresado = DateTime.Parse((editedItem.FindControl("TextBoxProrroga") as TextBox).Text);
                }

                #endregion

                #region Actualización de las hojas de ruta segun las nuevas fechas
                IEnumerable <KeyValuePair <string, object> > entityKeyValues = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("IdEmpresa", idContratista_Ingresado) };

                EntityKey         key  = new EntityKey("EntidadesConosud.Empresa", entityKeyValues);
                Entidades.Empresa _emp = (Entidades.Empresa)Contexto.GetObjectByKey(key);

                if (!_ContratoAnt.ContratoEmpresas.IsLoaded)
                {
                    _ContratoAnt.ContratoEmpresas.Load();
                }
                _ContratoAnt.ContratoEmpresas.Where(w => w.EsContratista.Value).First().Empresa = _emp;


                DateTime?FechaInicioAnt   = _ContratoAnt.FechaInicio;
                DateTime?FechaFinAnt      = DateTime.MinValue;
                DateTime?FechaInicioNuevo = fechaInicioContrato_Ingresado;
                DateTime?FechaFinNuevo    = DateTime.MinValue;

                FechaFinAnt   = Helpers.DeterminarFinPeriodo(_ContratoAnt.FechaVencimiento, _ContratoAnt.Prorroga, ref FechaFinAnt);
                FechaFinNuevo = Helpers.DeterminarFinPeriodo(fechaFinContrato_Ingresado, fechaPorrogaContrato_Ingresado, ref FechaFinNuevo);


                foreach (Entidades.ContratoEmpresas ContEmp in _ContratoAnt.ContratoEmpresas)
                {
                    if (FechaInicioNuevo > FechaInicioAnt)
                    {
                        if ((from h in Contexto.HojasDeRuta
                             where h.CabeceraHojasDeRuta.ContratoEmpresas.Contrato.IdContrato == idContrato &&
                             h.HojaFechaAprobacion != null &&
                             FechaInicioNuevo > h.CabeceraHojasDeRuta.Periodo
                             select h).Count() == 0)
                        {
                            List <object> objEliminar = new List <object>();
                            if (ContEmp.CabeceraHojasDeRuta.Count == 0)
                            {
                                ContEmp.CabeceraHojasDeRuta.Load();
                            }

                            ///Borro Diferencias
                            foreach (Entidades.CabeceraHojasDeRuta rowCabHR in ContEmp.CabeceraHojasDeRuta)
                            {
                                if (FechaInicioNuevo > rowCabHR.Periodo)
                                {
                                    objEliminar.Add(rowCabHR);

                                    if (!rowCabHR.ContEmpLegajos.IsLoaded)
                                    {
                                        rowCabHR.ContEmpLegajos.Load();
                                    }
                                    foreach (Entidades.ContEmpLegajos itemC in rowCabHR.ContEmpLegajos)
                                    {
                                        objEliminar.Add(itemC);
                                    }
                                }
                            }

                            foreach (object item in objEliminar)
                            {
                                Contexto.DeleteObject(item);
                            }
                        }
                    }
                    else
                    {
                        if (FechaInicioNuevo < FechaInicioAnt)
                        {
                            ///Agrega Diferencias
                            Helpers.GenerarHojadeRuta(Contexto, FechaInicioNuevo.Value, FechaInicioAnt.Value, ContEmp);
                        }
                    }


                    // Agrego los periodos que superan la fecha de fin.
                    if (FechaFinNuevo > FechaFinAnt)
                    {
                        ///Agrega Diferencias
                        Helpers.GenerarHojadeRuta(Contexto, FechaFinAnt.Value, FechaFinNuevo.Value, ContEmp, true);
                    }
                    else
                    {
                        List <object> objEliminar = new List <object>();

                        if ((from h in Contexto.HojasDeRuta
                             where h.CabeceraHojasDeRuta.ContratoEmpresas.Contrato.IdContrato == idContrato &&
                             h.HojaFechaAprobacion == null &&
                             h.CabeceraHojasDeRuta.Periodo > FechaFinNuevo
                             select h).Count() > 0)
                        {
                            ///Borro Diferencias
                            if (ContEmp.CabeceraHojasDeRuta.Count == 0)
                            {
                                ContEmp.CabeceraHojasDeRuta.Load();
                            }
                            foreach (Entidades.CabeceraHojasDeRuta rowCabHR in ContEmp.CabeceraHojasDeRuta)
                            {
                                if (rowCabHR.Periodo > FechaFinNuevo)
                                {
                                    objEliminar.Add(rowCabHR);
                                    if (!rowCabHR.ContEmpLegajos.IsLoaded)
                                    {
                                        rowCabHR.ContEmpLegajos.Load();
                                    }
                                    foreach (Entidades.ContEmpLegajos itemC in rowCabHR.ContEmpLegajos)
                                    {
                                        objEliminar.Add(itemC);
                                    }
                                }
                            }
                        }

                        foreach (object item in objEliminar)
                        {
                            Contexto.DeleteObject(item);
                        }
                    }
                }

                #endregion


                #region  CAMBIO DE FECHAS DE FINALIZACION CONTRATO.
                /// Si las fechas de finalización son distintas, entonces debo actualizar
                /// el vencimiento de la credenciales de los legajos asociados al contrato
                if (FechaFinNuevo != FechaFinAnt)
                {
                    /// 91: Categoria del contrato Auditable al ingreso
                    /// Solo se tiene que actualizar los datos de la credencial si la cateria
                    /// del contrato es distinta a esta.
                    if (_ContratoAnt.objCategoria.IdClasificacion != 91)
                    {
                        foreach (ContratoEmpresas ContEmp in _ContratoAnt.ContratoEmpresas)
                        {
                            foreach (ContEmpLegajos ContLeg in ContEmp.ContEmpLegajos)
                            {
                                if (ContLeg.Legajos != null)
                                {
                                    ContLeg.Legajos.CredVencimiento = FechaFinNuevo;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region CAMBIO DE CATEGORIA DEL CONTRATO.
                /// Caso 1: Al momento de cambiar la clasificacion de un contrato el cual pasa de Auditable a Auditable al ingreso
                /// se debe sacar todas las fechas de venc. cred. de los legajos asociaciodos al contrato.
                ///
                /// Caso 2: Caso contrario, es decir de Aud al Ingreso a Auditable
                /// se les tiene que poner la fecha de finalizacion del contrato
                /// como fecha de ven. cred.

                long CategoriaAnt = _ContratoAnt.objCategoria.IdClasificacion;
                if (CategoriaAnt != idCategoria_Ingresado)
                {
                    /// 91: Auditable al ingreso
                    if (idCategoria_Ingresado == 91)
                    {
                        foreach (ContratoEmpresas ContEmp in _ContratoAnt.ContratoEmpresas)
                        {
                            foreach (ContEmpLegajos ContLeg in ContEmp.ContEmpLegajos)
                            {
                                ContLeg.Legajos.CredVencimiento = null;
                            }
                        }
                    }
                    else
                    {
                        foreach (ContratoEmpresas ContEmp in _ContratoAnt.ContratoEmpresas)
                        {
                            foreach (ContEmpLegajos ContLeg in ContEmp.ContEmpLegajos)
                            {
                                if (ContLeg.Legajos != null)
                                {
                                    ContLeg.Legajos.CredVencimiento = FechaFinNuevo;
                                }
                            }
                        }
                    }
                }

                #endregion

                #region ACTUALIZACION DE LOS DATOS DEL CONTRATO
                _ContratoAnt.Codigo           = codigo_Ingresado.Trim();
                _ContratoAnt.Servicio         = servicio_Ingresado;
                _ContratoAnt.FechaInicio      = fechaInicioContrato_Ingresado;
                _ContratoAnt.FechaVencimiento = fechaFinContrato_Ingresado;
                _ContratoAnt.Prorroga         = fechaPorrogaContrato_Ingresado;
                _ContratoAnt.Contratadopor    = idContratadoPor_Ingresado;
                _ContratoAnt.TipoContrato     = idTipoContrato_Ingresado;
                _ContratoAnt.Categoria        = idCategoria_Ingresado;
                _ContratoAnt.Area             = idArea_Ingresado;
                _ContratoAnt.GestorNombre     = GestorNombre_Ingresado;
                _ContratoAnt.GestorEmail      = GestorEmail_Ingresado;
                _ContratoAnt.FiscalNombre     = FiscalNombre_Ingresado;
                _ContratoAnt.FiscalEmail      = FiscalEmail_Ingresado;
                #endregion

                Contexto.SaveChanges();
                CargarSessionContratos();
                RadGrid1.Rebind();
            }
            catch (Exception e)
            {
                ScriptManager.RegisterStartupScript(updpnlGrilla, typeof(UpdatePanel), "Error Grabacion", "alert(" + e.Message + ")", true);
                lblError.Text = e.StackTrace;
                UpdatePanel1.Update();
            }
        }
    }