Пример #1
0
    protected void addPersona_Click(object sender, EventArgs e)
    {
        var _per_ID = Request.QueryString["per_id"];
        int per_id;
        if (_per_ID != null)
        {

            bool isNumeric = int.TryParse(_per_ID, out per_id);
            if (!isNumeric)
            {
                HelperUtil.showNotifi("persona no encontrada");
                return;
            }

        }
        else
        {
            HelperUtil.showNotifi("persona no encontrada");
            return;
        }
        //datos funcionario
        //SCPM_PERSONALES p =( from cc in new DataClassesDataContext().SCPM_PERSONALES where cc.PER_ID == per_id select cc).First();
        SCPM_PERSONALES p = psvm.getPersonasByID(per_id).First();
        p.SCPM_CONYUGES.Load();
        p.SCPM_RAZASReference.Load();
        p.SCPM_DISCAPACIDADES.Load();
        p.SCPM_EMERGENCIAS.Load();
        p.SCPM_ESTADOS_CIVILESReference.Load();
        p.SCPM_SECTORESReference.Load();

        //psvm.detach(p);
        p.PER_APE_PAT = inApellido1.Text;
        p.PER_APE_MAT = inApellido2.Text;
        p.PER_NOM1 = inNombre1.Text;
        p.PER_NOM2 = inNombre2.Text;

        p.SCPM_PAIS = psvm.getPaisByID(Convert.ToInt32(comboPais.SelectedValue));
        p.SCPM_TIPO_IDENTIFICACIONES = psvm.getIdentificacionByID(Convert.ToInt32(comboDocumento.SelectedValue));

        p.PER_NUM_DOC = inDocumento.Text;
        p.PER_GEN = sexo.Checked;

        //raza

        //         ((IEntityWithRelationships)p).RelationshipManager.

        p.SCPM_RAZASReference.Load();
        p.SCPM_RAZAS.SCPM_PERSONALES.Load();
        //p.SCPM_RAZAS = null;
        p.SCPM_RAZAS = psvm.getRazaByID(Convert.ToInt32(comboRaza.SelectedValue));//set new raza
        //psvm.saveDB();
        //psvm.refresh(p);

        //end raza

        p.PER_LIB_MIL_NUM = inMilitar.Text;
        //end raza

        var _fec = inFechaNac.Text.Split('-');
        p.PER_FEC_NAC = new DateTime(Convert.ToInt32(_fec[0]), Convert.ToInt32(_fec[1]), Convert.ToInt32(_fec[2]));
        p.PER_TIP_SAN = comboSangre.SelectedValue.ToString().Replace(" ", "");
        p.SCPM_ESTADOS_CIVILES = psvm.getEstadoCivilByID(Convert.ToInt32(comboEstadoCivil.SelectedValue));
        p.PER_CEL = inCelular.Text;
        p.PER_TEL = inTelefono.Text;

        p.PER_COR_PER = inEmail.Text;
        p.PER_TAR = tarjeta.Checked;
        //file avatar

        if (!hasAvatar.Value.Equals("0"))
        {
            var tempPath = "~/Uploads/Temp/";
            var uploadPath = "~/Uploads/";

            string filename = hasAvatar.Value;
            File.Move(Server.MapPath(tempPath + filename), Server.MapPath(uploadPath + filename));
            if (p.PER_PHOTO != null)
            {
                try
                {
                    File.Delete(Server.MapPath(p.PER_PHOTO));
                }
                catch (Exception ex)
                {
                    HelperUtil.showNotifi("foto anterior no eliminada.");
                }
            }
            p.PER_PHOTO = "~/Uploads/" + hasAvatar.Value;
        }
        else
        {
            //if (p.PER_PHOTO == null) p.PER_PHOTO = "~/Uploads/avatar.png";
        }

        //end file avatar

        //domicilio
        p.SCPM_SECTORES = psvm.getSectorByID(Convert.ToInt32(comboSector.SelectedValue));
        p.PER_DIR = inDireccion.Text;

        ///---CONYUGUE---///
        SCPM_CONYUGES con = null;
        bool newConyugue = false;
        if (p.SCPM_CONYUGES.Count > 0)
        {
            con = p.SCPM_CONYUGES.FirstOrDefault();
        }
        if (stepConyugue.Visible)
        {
            if (con == null)
            {
                con = new SCPM_CONYUGES();
                newConyugue = true;
            }

            con.CON_APE_PAT = con_apellido1.Text;
            con.CON_APE_MAT = con_apellido2.Text;
            con.CON_NOM1 = con_nombre1.Text;
            con.CON_NOM2 = con_nombre2.Text;
            con.SCPM_PAIS = psvm.getPaisByID(Convert.ToInt32(con_pais.SelectedValue));
            con.SCPM_TIPO_IDENTIFICACIONES = psvm.getIdentificacionByID(Convert.ToInt32(con_comboDocumento.SelectedValue));
            con.CON_NUM_DOC = con_documento.Text;
            var _fec1 = con_fechaNacimiento.Text.Split('-');
            con.CON_FEC_NAC = new DateTime(Convert.ToInt32(_fec1[0]), Convert.ToInt32(_fec1[1]), Convert.ToInt32(_fec1[2]));
            con.CON_TEL = con_telefono.Text;
            con.CON_CEL = con_celular.Text;
            con.CON_COR_PER = con_Email.Text;
            con.SCPM_PROFESIONES = psvm.getProfesionByID(Convert.ToInt32(con_comboProfesion.SelectedValue));
            con.CON_TRA = con_trabaja.Checked;
            if (con_trabaja.Checked)
            {
                con.CON_NOM_EMP = con_empresa.Text;
                con.CON_NUM_TRA = con_telfTrabajo.Text;
                con.CON_DIR_TRAB = con_lugarTrab.Text;
            }
            else
            {
                con.CON_NOM_EMP = "";
                con.CON_NUM_TRA = "";
                con.CON_DIR_TRAB = "";
            }

            if (newConyugue) p.SCPM_CONYUGES.Add(con);
        }
        else
        {
            if (con != null)
            {
                p.SCPM_CONYUGES.Remove(con);
                psvm.deleteConyugue(con);
            }
        }
        ///---discapacidad---///
        if (hasDisapacidad.Checked)
        {
            var parentezcoRef = psvm.getParentezcoByID(Convert.ToInt32(dis_comboParentesco.SelectedValue));

            p.SCPM_DISCAPACIDADES.Load();
            var current_dis = p.SCPM_DISCAPACIDADES;
            foreach (var item in current_dis)
            {
                item.SCPM_TIPO_DISCAPACIDADESReference.Load();
            }
            foreach (RepeaterItem item in Repeater1.Items)
            {
                int rango = Convert.ToInt32((item.FindControl("slider_input") as TextBox).Text.Split('-')[0]);
                int dis_tip_id = Convert.ToInt32((item.FindControl("dis_tip_id") as HiddenField).Value);

                SCPM_DISCAPACIDADES dis = (from c in current_dis where c.SCPM_TIPO_DISCAPACIDADES.TIP_DIS_ID == dis_tip_id select c).FirstOrDefault(); //busco si esa discapacidad ya fue guardada anteriormente
                bool newDis = dis == null; //si no fue guardada debo crear una nueva
                if (rango > 0)              //si la discapacidad debe ser guardada
                {
                    if (dis == null) dis = new SCPM_DISCAPACIDADES();

                    dis.DIS_CLA = dis_isPropia.Checked;
                    dis.DIS_POR = rango;
                    dis.DIS_CONADIS = (dis_hasConadis.Checked ? dis_conadis.Text : "");
                    dis.SCPM_TIPO_DISCAPACIDADES = psvm.getDiscapacidadByID(dis_tip_id);
                    dis.SCPM_PARENTESCOS = parentezcoRef;

                    if (newDis) p.SCPM_DISCAPACIDADES.Add(dis); //la discapacidad no fue guardada anteriormente, entonces la añado
                }
                else
                {
                    if (dis != null)        //si la discapacidad fue guardada antroirmente pero nuevo valor es cero, la elimino
                    {
                        p.SCPM_DISCAPACIDADES.Remove(dis);
                        psvm.deleteteDiscapaciad(dis);
                    }
                }
            }
        }
        ///---emergencia---///

        SCPM_EMERGENCIAS emg = p.SCPM_EMERGENCIAS.FirstOrDefault();

        emg.CON_FAM_EME_NOM = emg_nombre.Text;
        emg.CON_FAM_EME_TEF = emg_telefono.Text;
        emg.CON_FAM_EME_CEL = emg_celular.Text;
        emg.SCPM_PARENTESCOS = psvm.getParentezcoByID(Convert.ToInt32(emg_comboParentesco.SelectedValue));
        //p.SCPM_EMERGENCIAS.Add(emg);

        ///---estado funcionario---///
        p.PER_EST = onFuncionario.Checked;

        if (psvm.saveDB())
        {
            // Page.Redirect(Page.Request.RawUrl, false);
            HelperUtil.showNotifi("persona actualizada");

        }
        else
        {
            HelperUtil.showNotifi("persona no actualizada");
        }
    }
Пример #2
0
 public void deleteteDiscapaciad(SCPM_DISCAPACIDADES dis)
 {
     db.DeleteObject(dis);
 }