Esempio n. 1
0
    protected void gvEmpresas_ItemCommand(object source, GridCommandEventArgs e)
    {
        (progressToolTip.FindControl("lbltituloCarga") as Label).Text = "Actualizando datos de la empresa..";
        e.Canceled            = true;
        gvEmpresas.DataSource = Session["Empresas"];
        gvEmpresas.DataBind();

        long id = long.Parse(gvEmpresas.Items[e.Item.DataSetIndex].GetDataKeyValue("IdEmpresa").ToString());

        Entidades.Empresa emp = (from E in (Session["Empresas"] as List <Entidades.Empresa>)
                                 where E.IdEmpresa == id
                                 select E).Single <Entidades.Empresa>();



        txtCUIT.Text        = emp.CUIT;
        txtDireccion.Text   = emp.Direccion;
        txtEmail.Text       = emp.CorreoElectronico;
        txtPEmergencia.Text = emp.PrestacionEmergencia;
        txtRazonSocial.Text = emp.RazonSocial;
        txtRTecnico.Text    = emp.RepresentanteTecnico;
        txtTelefono.Text    = emp.Telefono;

        if (emp.FechaAlta.HasValue)
        {
            DpFechaAlta.SelectedDate = emp.FechaAlta.Value;
        }

        HiddenId.Value       = emp.IdEmpresa.ToString();
        toolTipEdicion.Title = "Edición Empresa: " + emp.RazonSocial;
        upToolTip.Update();
    }
 public void init()
 {
     cfg = new Configuration();
     cfg.Configure();
     cfg.AddAssembly(typeof(Empresa).Assembly);
     //new SchemaExport(cfg).Execute(true, true, false); // Crearía las tablas.
     fab_sesion = cfg.BuildSessionFactory();
     sesion = fab_sesion.OpenSession();
     e = new Empresa(1, "aucas libreria", "italia 3973");
 }
        public void init()
        {
            cfg = new Configuration();
            cfg.Configure();
            cfg.AddAssembly(typeof(Empresa).Assembly);
            e = new Empresa(3, "ABC123", "EmpTest");

            //new SchemaExport(cfg).Execute(true, true, false); // Crearía las tablas.
            fab_sesion = cfg.BuildSessionFactory();
            sesion = fab_sesion.OpenSession();
        }
         public void setup()
         {
             dPro = DAOProyecto.Instance();
             dSpr = DAOSprintNHibernate.Instance();
             oEmp = new Empresa(1, "AAA", "X"); //Hardcodeo empresa 1.
             oPro = new Proyecto(2, "Proyecto X", oEmp);

             ISession sesion = NHHelper.openSession(typeof(Historia));
             var hists = sesion.CreateQuery("from Historia").List<Historia>();
             List<Historia> lstHist = (List<Historia>)hists;
             oSprint = new Sprint(0, oPro, Convert.ToDateTime("1990-01-01"),Convert.ToDateTime("1990-02-01"), "Sprint X", lstHist);
         }
        public void init()
        {
            cfg = new Configuration();
            cfg.Configure();
            cfg.AddAssembly(typeof(Empresa).Assembly);
            //new SchemaExport(cfg).Execute(true, true, false); // Crearía las tablas.
            fab_sesion = cfg.BuildSessionFactory();
            sesion = fab_sesion.OpenSession();

            //miEmp = sesion.CreateQuery("from Empresa WHERE Id=5 Select Empresa").List<Empresa>().First(); //LINQ
            //no está bueno esto, sería ideal buscar un id existente
            miEmp = sesion.Get<Empresa>(1);
        }
    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);
    }
Esempio n. 7
0
    protected void btnAceptar_Click(object sender, EventArgs e)
    {
        EntidadesConosud dc = new EntidadesConosud();

        Entidades.Empresa emp = null;

        if (int.Parse(HiddenId.Value) > 0)
        {
            long id = long.Parse(HiddenId.Value);
            emp = (from E in dc.Empresa
                   where E.IdEmpresa == id
                   select E).First <Entidades.Empresa>();
        }
        else
        {
            emp = new Entidades.Empresa();
        }

        emp.CUIT                 = txtCUIT.Text;
        emp.Direccion            = txtDireccion.Text;
        emp.CorreoElectronico    = txtEmail.Text;
        emp.PrestacionEmergencia = txtPEmergencia.Text;
        emp.RazonSocial          = txtRazonSocial.Text;
        emp.RepresentanteTecnico = txtRTecnico.Text;
        emp.Telefono             = txtTelefono.Text;
        if (DpFechaAlta.SelectedDate.HasValue)
        {
            emp.FechaAlta = DpFechaAlta.SelectedDate;
        }

        if (int.Parse(HiddenId.Value) == 0)
        {
            dc.AddToEmpresa(emp);
        }

        dc.SaveChanges();
        HiddenId.Value = "0";
        CargarGrilla(txtEmpresa.Text);
        ScriptManager.RegisterClientScriptBlock(upToolTip, typeof(UpdatePanel), "show", "HideTooTil();", true);
        upToolTip.Update();
        upGrilla.Update();
    }
Esempio n. 8
0
    protected void btnEmpresas_Click(object sender, EventArgs e)
    {
        EntidadesConosud dc = new EntidadesConosud();

        List <Entidades.EmpresasImp> empresass = (from E in dc.EmpresasImp
                                                  select E).ToList <Entidades.EmpresasImp>();


        foreach (Entidades.EmpresasImp emp in empresass)
        {
            string cuitEmpresa = emp.CUIT.Value.ToString().Replace("-", "");
            int    HayEmpresa  = (from E in dc.Empresa
                                  where E.CUIT.Replace("-", "").Contains(cuitEmpresa)
                                  select E).Count();


            if (HayEmpresa == 0)
            {
                Entidades.Empresa newemp = new Entidades.Empresa();
                newemp.CUIT        = emp.CUIT.ToString();
                newemp.RazonSocial = emp.RazonSocial;
                //newemp.Telefono = emp.Telefono;
                //newemp.FechaAlta = emp.FechaAlta;
                //newemp.Direccion = emp.Direccion;
                //newemp.RepresentanteTecnico = emp.RepresentanteTecnico;
                //newemp.Emergencia = emp.Emergencias;
                //newemp.PrestacionEmergencia = emp.PrestacionEmergencia;
                //newemp.CorreoElectronico = emp.CorreoElectronico;
                //newemp.objART = (from Art in dc.Clasificacion
                //                 where Art.Tipo == "ART"
                //                 && Art.Descripcion == emp.ART
                //                 select Art).FirstOrDefault();


                dc.AddToEmpresa(newemp);
            }
        }

        dc.SaveChanges();
    }
Esempio n. 9
0
 public Proyecto(int id, string nombre,Empresa oEmp)
 {
     this.Id = id;
     this.Nombre = nombre;
     this.oEmpresa = oEmp;
 }
Esempio n. 10
0
    public void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        EntidadesConosud dc = Contexto;

        if (e.Argument == "Update")
        {
            long id = long.Parse(RadGrid1.SelectedValue.ToString());

            Entidades.Empresa EmpUpdate = (from L in dc.Empresa
                                           where L.IdEmpresa == id
                                           select L).FirstOrDefault <Entidades.Empresa>();

            int cant = (from l in dc.Empresa
                        where l.CUIT.Trim() == txtCUIT.Text.Trim() &&
                        l.IdEmpresa != id
                        select l).Count();

            txtCUIT.Attributes.Remove("NroExistente");

            if (cant > 0)
            {
                txtCUIT.Attributes.Add("NroExistente", true.ToString());
                upNroCUIT.Update();
                return;
            }
            else
            {
                txtCUIT.Attributes.Add("NroExistente", false.ToString());
                upNroCUIT.Update();
            }


            if (EmpUpdate != null)
            {
                /// Controles Tipo TextBox
                EmpUpdate.RazonSocial          = txtRazonSocial.Text.Trim();
                EmpUpdate.RepresentanteTecnico = txtTecnico.Text.Trim();
                EmpUpdate.PrestacionEmergencia = txtPrestacionEmergencias.Text.Trim();
                EmpUpdate.Direccion            = txtDireccion.Text.Trim();
                EmpUpdate.Telefono             = txtTelefono.Text.Trim();
                EmpUpdate.Emergencia           = txtEmergencias.Text.Trim();
                EmpUpdate.CorreoElectronico    = txtEmail.Text.Trim();

                /// Controles Tipo Telerik
                EmpUpdate.CUIT = txtCUIT.Text;

                /// Controles Tipo Fecha
                EmpUpdate.FechaAlta = txtFechaAlta.SelectedDate;

                dc.SaveChanges();
            }

            FiltrarEmpresas(txtApellidoLegajo.Text.Trim());
            return;
        }
        if (e.Argument == "delete")
        {
            long id = long.Parse(RadGrid1.SelectedValue.ToString());


            Entidades.Empresa EmpDelete = (from L in Contexto.Empresa
                                           where L.IdEmpresa == id
                                           select L).FirstOrDefault <Entidades.Empresa>();


            /// Saco a todos los lejos asociados a la empresa.
            List <Legajos> legajosAsociados = EmpDelete.Legajos.ToList();
            foreach (Legajos leg in legajosAsociados)
            {
                leg.objEmpresaLegajo = null;
            }


            /// Saco a todos vehiculos asociados
            List <VahiculosyEquipos> VehiculosAsociados = EmpDelete.VahiculosyEquipos.ToList();
            foreach (VahiculosyEquipos vec in VehiculosAsociados)
            {
                vec.objEmpresa = null;
            }


            /// Saco el usario a asociado a la empresa
            List <SegUsuario> SegUsuairoEmp = (from L in Contexto.SegUsuario
                                               where L.IdEmpresa == id
                                               select L).ToList <SegUsuario>();

            foreach (SegUsuario item in SegUsuairoEmp)
            {
                item.Empresa = null;
            }


            int j = EmpDelete.ContratoEmpresas.Count();
            while (j > 0)
            {
                Entidades.ContratoEmpresas _ContratoEmpresas = EmpDelete.ContratoEmpresas.Take(1).First();
                //if (!_ContratoEmpresas.ComentariosGral.IsLoaded) { _ContratoEmpresas.ComentariosGral.Load(); }
                List <ComentariosGral> comentsGrales = _ContratoEmpresas.ComentariosGral.ToList();
                foreach (ComentariosGral itemComent in comentsGrales)
                {
                    Contexto.DeleteObject(itemComent);
                }


                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--;
                    }


                    int j4 = _CabeceraHojasDeRuta.ContEmpLegajos.Count();
                    while (j4 > 0)
                    {
                        ContEmpLegajos _Leghoja = _CabeceraHojasDeRuta.ContEmpLegajos.Take(1).First();
                        Contexto.DeleteObject(_Leghoja);
                        j4--;
                    }


                    Contexto.DeleteObject(_CabeceraHojasDeRuta);
                    j2--;
                }
                Contexto.DeleteObject(_ContratoEmpresas);
                j--;
            }

            Contexto.DeleteObject(EmpDelete);

            try
            {
                Contexto.SaveChanges();
                FiltrarEmpresas(txtApellidoLegajo.Text.Trim());
            }
            catch
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "eliminacionEmpresa", "radalert('La emprsa no puede ser eliminada ya que posee mucha información asociada, por favor tome contacto con el administrador del sistema.',300,150)", true);
                FiltrarEmpresas(txtApellidoLegajo.Text.Trim());
            }
        }
        if (e.Argument == "Insert")
        {
            Entidades.Empresa EmpInsert = new Entidades.Empresa();

            int cant = (from l in dc.Empresa
                        where l.CUIT == txtCUIT.Text.Trim()
                        select l).Count();


            if (cant > 0)
            {
                txtCUIT.Attributes.Add("NroExistente", true.ToString());
                upNroCUIT.Update();
                return;
            }
            else
            {
                txtCUIT.Attributes.Add("NroExistente", false.ToString());
                upNroCUIT.Update();
            }


            /// Controles Tipo TextBox
            EmpInsert.RazonSocial          = txtRazonSocial.Text.Trim();
            EmpInsert.RepresentanteTecnico = txtTecnico.Text.Trim();
            EmpInsert.PrestacionEmergencia = txtPrestacionEmergencias.Text.Trim();
            EmpInsert.Direccion            = txtDireccion.Text.Trim();
            EmpInsert.Telefono             = txtTelefono.Text.Trim();
            EmpInsert.Emergencia           = txtEmergencias.Text.Trim();
            EmpInsert.CorreoElectronico    = txtEmail.Text.Trim();

            /// Controles Tipo Telerik
            EmpInsert.CUIT = txtCUIT.Text;

            /// Controles Tipo Fecha
            EmpInsert.FechaAlta = txtFechaAlta.SelectedDate;


            dc.AddToEmpresa(EmpInsert);
            dc.SaveChanges();
        }

        FiltrarEmpresas(txtApellidoLegajo.Text.Trim());
    }
Esempio n. 11
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);
        }
    }
Esempio n. 12
0
    public void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        EntidadesConosud dc = new EntidadesConosud();

        if (e.Argument == "Update")
        {
            long id = long.Parse(RadGrid1.SelectedValue.ToString());

            Entidades.Empresa EmpUpdate = (from L in dc.Empresa
                                           where L.IdEmpresa == id
                                           select L).FirstOrDefault <Entidades.Empresa>();

            int cant = (from l in dc.Empresa
                        where l.CUIT.Trim() == txtCUIT.Text.Trim() &&
                        l.IdEmpresa != id
                        select l).Count();

            if (cant > 0)
            {
                txtCUIT.Attributes.Add("NroExistente", true.ToString());
                upNroCUIT.Update();
                return;
            }
            else
            {
                txtCUIT.Attributes.Add("NroExistente", false.ToString());
                upNroCUIT.Update();
            }



            if (EmpUpdate != null)
            {
                /// Controles Tipo TextBox
                EmpUpdate.RazonSocial          = txtRazonSocial.Text.Trim();
                EmpUpdate.RepresentanteTecnico = txtTecnico.Text.Trim();
                EmpUpdate.PrestacionEmergencia = txtPrestacionEmergencias.Text.Trim();
                EmpUpdate.Direccion            = txtDireccion.Text.Trim();
                EmpUpdate.Telefono             = txtTelefono.Text.Trim();
                EmpUpdate.Emergencia           = txtEmergencias.Text.Trim();
                EmpUpdate.CorreoElectronico    = txtEmail.Text.Trim();

                /// Controles Tipo Telerik
                EmpUpdate.CUIT = txtCUIT.Text;

                /// Controles Tipo Fecha
                EmpUpdate.FechaAlta = txtFechaAlta.SelectedDate;

                /// Controles Tipo Combos
                long idCombo = 0;
                if (cboART.SelectedItem != null)
                {
                    idCombo          = long.Parse(cboART.SelectedValue);
                    EmpUpdate.objART = dc.Clasificacion.Where(w => w.IdClasificacion == idCombo).FirstOrDefault();
                }
                else
                {
                    EmpUpdate.objART = null;
                }

                dc.SaveChanges();
            }
        }
        else if (e.Argument == "Eliminar")
        {
            long id = long.Parse(RadGrid1.SelectedValue.ToString());

            Entidades.Empresa EmpEliminar = (from L in dc.Empresa
                                             where L.IdEmpresa == id
                                             select L).FirstOrDefault <Entidades.Empresa>();

            if (EmpEliminar.ContratoEmpresas.Count == 0)
            {
                dc.DeleteObject(EmpEliminar);
            }
            else
            {
                ScriptManager.RegisterStartupScript(updpnlGrilla, updpnlGrilla.GetType(), "eliemp", "alert('La empresa seleccionada no puede ser eliminada ya que posee uno o más contratos asociados')", true);
            }

            dc.SaveChanges();
        }
        else
        {
            Entidades.Empresa EmpInsert = new Entidades.Empresa();

            int cant = (from l in dc.Empresa
                        where l.CUIT == txtCUIT.Text.Trim()
                        select l).Count();


            if (cant > 0)
            {
                txtCUIT.Attributes.Add("NroExistente", true.ToString());
                upNroCUIT.Update();
                return;
            }
            else
            {
                txtCUIT.Attributes.Add("NroExistente", false.ToString());
                upNroCUIT.Update();
            }


            /// Controles Tipo TextBox
            EmpInsert.RazonSocial          = txtRazonSocial.Text.Trim();
            EmpInsert.RepresentanteTecnico = txtTecnico.Text.Trim();
            EmpInsert.PrestacionEmergencia = txtPrestacionEmergencias.Text.Trim();
            EmpInsert.Direccion            = txtDireccion.Text.Trim();
            EmpInsert.Telefono             = txtTelefono.Text.Trim();
            EmpInsert.Emergencia           = txtEmergencias.Text.Trim();
            EmpInsert.CorreoElectronico    = txtEmail.Text.Trim();

            /// Controles Tipo Telerik
            EmpInsert.CUIT = txtCUIT.Text;

            /// Controles Tipo Fecha
            EmpInsert.FechaAlta = txtFechaAlta.SelectedDate;

            /// Controles Tipo Combos
            long idCombo = 0;
            if (cboART.SelectedItem != null)
            {
                idCombo          = long.Parse(cboART.SelectedValue);
                EmpInsert.objART = dc.Clasificacion.Where(w => w.IdClasificacion == idCombo).FirstOrDefault();
            }

            dc.AddToEmpresa(EmpInsert);
            dc.SaveChanges();
        }

        RadGrid1.Rebind();
        updpnlGrilla.Update();
    }
Esempio n. 13
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();
    }
Esempio n. 14
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();
            }
        }
    }
Esempio n. 15
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();
    }
Esempio n. 16
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();
            }
        }
    }
Esempio n. 17
0
 public Producto(string nombre, string descripcion, decimal precioCosto, double margen, Empresa proveedor, Categoria categoria, Categoria subCategoria)
 {
     Nombre       = nombre;
     Descripcion  = descripcion;
     PrecioCosto  = PrecioCosto;
     Margen       = Margen;
     Proveedor    = proveedor;
     Categoria    = categoria;
     SubCategoria = subCategoria;
 }
Esempio n. 18
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);
        }
    }