예제 #1
0
        private void LoadDataExternalUser()
        {
            // Setear lenght dimamicos de numero de documento
            SetLenght(ddlDocType.SelectedValue.ToString());

            OperationResult objCommonOperationResultedit = new OperationResult();

            objPerson = _objPacientBL.GetPerson(ref objCommonOperationResultedit, _personId);

            Text = this.Text + " (" + objPerson.v_FirstName + " " + objPerson.v_FirstLastName + " " + objPerson.v_SecondLastName + ")";

            // Informacion de la persona
            txtName.Text             = objPerson.v_FirstName;
            txtFirstLastName.Text    = objPerson.v_FirstLastName;
            txtSecondLastName.Text   = objPerson.v_SecondLastName;
            txtDocNumber.Text        = objPerson.v_DocNumber;
            ddlDocType.SelectedValue = objPerson.i_DocTypeId.ToString();
            txtDocNumber.Text        = objPerson.v_DocNumber;
            txtMail.Text             = objPerson.v_Mail;


            for (int i = 0; i < chkEmpresas.Items.Count - 1; i++)
            {
                chkEmpresas.SetItemChecked(i, false);
            }

            // Informacion del usuario
            OperationResult objOperationResult = new OperationResult();

            _objSystemUserTemp = _objSecurityBL.GetSystemUser(ref objOperationResult, _systemUserId.Value);

            //cboEmpresa.SelectedItem = item;// _objSystemUserTemp.v_SystemUserByOrganizationId == null ? "-1" : _objSystemUserTemp.v_SystemUserByOrganizationId;
            if (!string.IsNullOrEmpty(_objSystemUserTemp.v_SystemUserByOrganizationId))
            {
                var organizationIds = _objSystemUserTemp.v_SystemUserByOrganizationId.Split(',').ToList();

                foreach (var item in organizationIds)
                {
                    for (int i = 0; i < chkEmpresas.Items.Count; i++)
                    {
                        KeyValueDTO obj = (KeyValueDTO)chkEmpresas.Items[i];

                        if (obj.Id.Trim() == item.Trim())
                        {
                            chkEmpresas.SetItemChecked(i, true);
                            break;
                        }
                    }
                }
            }



            txtUserName.Text  = _objSystemUserTemp.v_UserName;
            txtPassword1.Text = _objSystemUserTemp.v_Password;
            txtPassword2.Text = _objSystemUserTemp.v_Password;

            if (_objSystemUserTemp.d_ExpireDate != null)
            {
                rbFEchaExpiracion.Checked = true;
                dtpExpiredDate.Value      = _objSystemUserTemp.d_ExpireDate.Value;
            }
            else
            {
                rbNuncaCaduca.Checked  = true;
                dtpExpiredDate.Enabled = false;
            }

            LoadchkListByProtocolIdAndSystemUserId();
        }
예제 #2
0
        private void btnSaveExternalUser_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            string          Result             = "";
            string          personId;
            bool            sendNotification = false;
            int             systemUserId     = -1;
            string          SihayError       = "";

            if (uvPacient.Validate(true, false).IsValid)
            {
                #region Validation

                if (txtName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtFirstLastName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Apellido Paterno.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtSecondLastName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Apellido Materno.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtDocNumber.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Número Documento.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtMail.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un Email .", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (txtMail.Text.Trim() != "")
                {
                    if (!Sigesoft.Common.Utils.email_bien_escrito(txtMail.Text.Trim()))
                    {
                        MessageBox.Show("Por favor ingrese un Email con formato correcto.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                int caracteres = txtDocNumber.TextLength;
                if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.DNI)
                {
                    if (caracteres != 8)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.PASAPORTE)
                {
                    if (caracteres != 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.LICENCIACONDUCIR)
                {
                    if (caracteres != 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.CARNETEXTRANJ)
                {
                    if (caracteres < 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                if (txtPassword2.Text.Trim() != txtPassword1.Text.Trim())
                {
                    MessageBox.Show("Los Password no coinciden Por favor verifique.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                #endregion

                if (_mode == "New")
                {
                    // Validar la longitud de los numeros de documentos
                    if (!IsValidDocumentNumberLenght())
                    {
                        return;
                    }

                    // Populate the entity
                    objPerson                  = new personDto();
                    objPerson.v_FirstName      = txtName.Text.Trim();
                    objPerson.v_FirstLastName  = txtFirstLastName.Text.Trim();
                    objPerson.v_SecondLastName = txtSecondLastName.Text.Trim();
                    objPerson.i_DocTypeId      = Convert.ToInt32(ddlDocType.SelectedValue);
                    objPerson.v_DocNumber      = txtDocNumber.Text.Trim();
                    objPerson.v_Mail           = txtMail.Text.Trim();


                    // Datos de usuario
                    systemuserDto pobjSystemUser = new systemuserDto();
                    pobjSystemUser.v_UserName         = txtUserName.Text.Trim();
                    pobjSystemUser.v_Password         = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                    pobjSystemUser.i_SystemUserTypeId = (int)SystemUserTypeId.External;
                    //if (rbFEchaExpiracion.Checked)
                    //    pobjSystemUser.d_ExpireDate = dtpExpiredDate.Value.Date;
                    var ListIds = new List <string>();

                    for (int i = 0; i < chkEmpresas.CheckedItems.Count; i++)
                    {
                        KeyValueDTO obj = (KeyValueDTO)chkEmpresas.CheckedItems[i];
                        ListIds.Add(obj.Id);
                    }

                    var concateOrganizationId = string.Join(",", ListIds.ToList().Select(p => p));

                    pobjSystemUser.v_SystemUserByOrganizationId = concateOrganizationId;


                    // Graba persona
                    systemUserId = _protocolBL.AddPersonUsuarioExterno(ref objOperationResult,
                                                                       objPerson,
                                                                       null,
                                                                       pobjSystemUser,
                                                                       Globals.ClientSession.GetAsList());

                    Utils.LoadDropDownList(cboExternalUser, "Value1", "Id", BLL.Utils.GetAllExternalSystemUser(ref objOperationResult, ""), DropDownListAction.Select);

                    cboExternalUser.SelectedValue = systemUserId.ToString();
                    if (SihayError == "-1")
                    {
                        if (objOperationResult.ErrorMessage != null)
                        {
                            //MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            //return;
                            MessageBox.Show(objOperationResult.ErrorMessage, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }

                    //this.Enabled = false;
                    //frmWaiting.Show(this);
                    //bgwSendEmail.RunWorkerAsync();
                }
                else if (_mode == "Edit")
                {
                    bool isChangeUserName  = false;
                    bool isChangeDocNumber = false;

                    // Validar la longitud de los numeros de documentos
                    if (!IsValidDocumentNumberLenght())
                    {
                        return;
                    }

                    #region Validate SystemUSer
                    // Almacenar temporalmente el nombre de usuario actual
                    if (txtUserName.Text != _objSystemUserTemp.v_UserName)
                    {
                        isChangeUserName = true;
                        sendNotification = true;
                    }
                    #endregion

                    #region Validate Document Number
                    // Almacenar temporalmente el número de documento del usuario actual
                    if (txtDocNumber.Text != objPerson.v_DocNumber)
                    {
                        isChangeDocNumber = true;
                    }
                    #endregion

                    // Almacenar temporalmente el password del usuario actual
                    var passTemp = _objSystemUserTemp.v_Password;

                    // Si el password actual es diferente al ingresado en la cajita de texto, quiere decir que se ha cambiado el password por lo tanto
                    // se bede encriptar el nuevo password
                    if (txtPassword2.Text != passTemp)
                    {
                        _objSystemUserTemp.v_Password = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                        sendNotification = true;
                    }
                    else
                    {
                        _objSystemUserTemp.v_Password = txtPassword2.Text.Trim();
                    }

                    #region Datos de persona

                    // Datos de persona
                    objPerson.v_PersonId       = _personId;
                    objPerson.v_FirstName      = txtName.Text.Trim();
                    objPerson.v_FirstLastName  = txtFirstLastName.Text.Trim();
                    objPerson.v_SecondLastName = txtSecondLastName.Text.Trim();
                    objPerson.i_DocTypeId      = Convert.ToInt32(ddlDocType.SelectedValue);
                    objPerson.v_DocNumber      = txtDocNumber.Text.Trim();
                    objPerson.v_Mail           = txtMail.Text.Trim();

                    #endregion

                    #region Datos de Usuario

                    // Datos de Usuario
                    _objSystemUserTemp.i_SystemUserId = _objSystemUserTemp.i_SystemUserId;
                    _objSystemUserTemp.v_PersonId     = _personId;
                    _objSystemUserTemp.v_UserName     = txtUserName.Text;
                    _objSystemUserTemp.d_InsertDate   = _objSystemUserTemp.d_InsertDate;
                    _objSystemUserTemp.i_InsertUserId = _objSystemUserTemp.i_SystemUserId;
                    _objSystemUserTemp.i_IsDeleted    = _objSystemUserTemp.i_IsDeleted;

                    var ListIds = new List <string>();

                    for (int i = 0; i < chkEmpresas.CheckedItems.Count; i++)
                    {
                        KeyValueDTO obj = (KeyValueDTO)chkEmpresas.CheckedItems[i];
                        ListIds.Add(obj.Id);
                    }

                    var concateOrganizationId = string.Join(",", ListIds.ToList().Select(p => p));

                    _objSystemUserTemp.v_SystemUserByOrganizationId = concateOrganizationId;
                    if (rbFEchaExpiracion.Checked)
                    {
                        _objSystemUserTemp.d_ExpireDate = dtpExpiredDate.Value.Date;
                    }
                    else if (rbNuncaCaduca.Checked)
                    {
                        _objSystemUserTemp.d_ExpireDate = null;
                    }

                    #endregion


                    // Actualiza persona
                    _protocolBL.UpdateSystemUserExternal(ref objOperationResult,
                                                         isChangeDocNumber,
                                                         objPerson,
                                                         null,
                                                         isChangeUserName,
                                                         _objSystemUserTemp,
                                                         null,
                                                         null,
                                                         null,
                                                         null,
                                                         Globals.ClientSession.GetAsList());

                    //if (sendNotification)
                    //{
                    //    this.Enabled = false;
                    //    frmWaiting.Show(this);
                    //    bgwSendEmail.RunWorkerAsync();
                    //}
                }

                if (objOperationResult.ErrorMessage != null)
                {
                    MessageBox.Show(objOperationResult.ErrorMessage, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    if (objOperationResult.Success != 1)
                    {
                        MessageBox.Show("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Se grabó correctamente", "INFORMACIÓN", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #3
0
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult1 = new OperationResult();
            string          Mode         = Request.QueryString["Mode"].ToString();
            int             systemUserId = -1;
            string          SihayError   = "";
            string          personId     = "";

            if (Mode == "New")
            {
                // Datos de persona
                personDto objPerson = new personDto();
                objPerson.v_FirstName       = txtFirstName.Text.Trim().ToUpper();
                objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim().ToUpper();
                objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim().ToUpper();
                objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                objPerson.v_DocNumber       = txtDocNumber.Text.Trim();
                objPerson.d_Birthdate       = dpBirthdate.SelectedDate;
                objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim().ToUpper();
                objPerson.v_TelephoneNumber = txtTelephoneNumber.Text.Trim();
                objPerson.v_Mail            = txtMail.Text.Trim();

                // Datos de usuario
                systemuserDto pobjSystemUser = new systemuserDto();
                pobjSystemUser.v_UserName         = txtUserName.Text.Trim();
                pobjSystemUser.v_Password         = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                pobjSystemUser.i_SystemUserTypeId = (int)SystemUserTypeId.External;

                systemUserId = _objPacientBL.AddPersonUsuarioExterno(ref objOperationResult1,
                                                                     objPerson,
                                                                     null,
                                                                     pobjSystemUser,
                                                                     ((ClientSession)Session["objClientSession"]).GetAsList());


                if (_tmpListProtocolSystemUser == null)
                {
                    _tmpListProtocolSystemUser = new List <protocolsystemuserDto>();
                }


                //Obtener Todos los protocolos de la Empresa

                var ListaEmpresas = (List <KeyValueDTO>)Session["ListaEmpresas"];
                foreach (var itemEmpresa in ListaEmpresas)
                {
                    string[] x = itemEmpresa.Id.ToString().Split('|');


                    var ListaProtocolos = _protocolBL.DevolverProtocolosPorEmpresa(x[0].ToString(), x[1].ToString());
                    foreach (var item in ListaProtocolos)
                    {
                        _tmpListProtocolSystemUser = new List <protocolsystemuserDto>();
                        protocolsystemuserDto protocolSystemUser;
                        if (chkAdminServicios.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1084;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkAgenda.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 2000;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);

                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 2001;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkEstadistica.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 3000;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkCertificado.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1087;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkExamenes.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 165;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkFichaOcupacional.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1086;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkSegTrabajador.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1085;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        // Graba UsuarioExterno
                        SihayError = _protocolBL.AddSystemUserExternal(ref objOperationResult1, _tmpListProtocolSystemUser, ((ClientSession)Session["objClientSession"]).GetAsList(), systemUserId);
                    }
                }



                bgwSendEmail_DoWork();

                if (SihayError == "-1")
                {
                    Alert.ShowInTop(objOperationResult1.ErrorMessage);
                    return;
                }
                else
                {
                    if (objOperationResult1.Success != 1)
                    {
                        Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult1.ExceptionMessage);
                        return;
                    }
                }
            }
            else if (Mode == "Edit")
            {
                if (Request.QueryString["personId"] != null)
                {
                    personId = Request.QueryString["personId"].ToString();
                }
                if (Request.QueryString["systemUserId"] != null)
                {
                    systemUserId = int.Parse(Request.QueryString["systemUserId"].ToString());
                }

                systemuserDto systemUser         = new systemuserDto();
                personDto     _objPerson         = Session["objEntity"] as personDto;
                systemuserDto _objSystemUserTemp = Session["objSystemUser"] as systemuserDto;

                bool isChangeUserName  = false;
                bool isChangeDocNumber = false;

                #region Validate SystemUSer
                // Almacenar temporalmente el nombre de usuario actual
                var _userNameTemp = _objSystemUserTemp.v_UserName;
                if (txtUserName.Text != _userNameTemp)
                {
                    isChangeUserName = true;
                }
                #endregion

                // Datos de persona
                _objPerson.v_FirstName       = txtFirstName.Text.Trim().ToUpper();
                _objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim().ToUpper();
                _objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim().ToUpper();
                _objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                _objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                _objPerson.v_DocNumber       = txtDocNumber.Text;
                _objPerson.d_Birthdate       = dpBirthdate.SelectedDate;
                _objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim().ToUpper();
                _objPerson.v_TelephoneNumber = txtTelephoneNumber.Text;
                _objPerson.v_Mail            = txtMail.Text;
                _objPerson.i_UpdateNodeId    = ((ClientSession)Session["objClientSession"]).i_CurrentExecutionNodeId;

                // Almacenar temporalmente el password del usuario actual
                var _passTemp = _objSystemUserTemp.v_Password;

                // Si el password actual es diferente al ingresado en la cajita de texto, quiere decir que se ha cambiado el password por lo tanto
                // se bede encriptar el nuevo password
                if (txtPassword2.Text != _passTemp)
                {
                    systemUser.v_Password = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                }
                else
                {
                    systemUser.v_Password = txtPassword2.Text.Trim();
                }

                // Datos de Usuario
                systemUser.i_SystemUserId     = _objSystemUserTemp.i_SystemUserId;
                systemUser.v_PersonId         = personId;
                systemUser.v_UserName         = txtUserName.Text;
                systemUser.d_InsertDate       = _objSystemUserTemp.d_InsertDate;
                systemUser.i_InsertUserId     = _objSystemUserTemp.i_SystemUserId;
                systemUser.i_IsDeleted        = _objSystemUserTemp.i_IsDeleted;
                systemUser.i_SystemUserTypeId = (int)SystemUserTypeId.External;
                // Actualiza persona

                _objPacientBL.UpdatePerson(ref objOperationResult1,
                                           isChangeDocNumber,
                                           _objPerson,
                                           null,
                                           isChangeUserName,
                                           systemUser,
                                           ((ClientSession)Session["objClientSession"]).GetAsList());


                //Eliminar Los permisos de este usuario
                _protocolBL.EliminarFisicamentePermisosPorUsuario(ref objOperationResult1, systemUserId);

                //Obtener Permisos nuevos
                //Obtener Todos los protocolos de la Empresa

                //string[] x = ddlEmpresaCliente.SelectedValue.ToString().Split('|');
                var ListaEmpresas = (List <KeyValueDTO>)Session["ListaEmpresas"];
                foreach (var itemEmpresa in ListaEmpresas)
                {
                    string[] x = itemEmpresa.Id.ToString().Split('|');

                    var ListaProtocolos = _protocolBL.DevolverProtocolosPorEmpresa(x[0].ToString(), x[1].ToString());

                    //var ListaProtocolos=  _protocolBL.DevolverProtocolosPorEmpresa(ddlEmpresaCliente.SelectedValue.ToString());
                    foreach (var item in ListaProtocolos)
                    {
                        _tmpListProtocolSystemUser = new List <protocolsystemuserDto>();
                        protocolsystemuserDto protocolSystemUser;
                        if (chkAdminServicios.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1084;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkAgenda.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 2000;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);

                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 2001;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkCertificado.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1087;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkEstadistica.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 3000;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkExamenes.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 165;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkFichaOcupacional.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1086;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        if (chkSegTrabajador.Checked)
                        {
                            protocolSystemUser = new protocolsystemuserDto();
                            protocolSystemUser.i_ApplicationHierarchyId = 1085;
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        // Graba UsuarioExterno
                        SihayError = _protocolBL.AddSystemUserExternal(ref objOperationResult1, _tmpListProtocolSystemUser, ((ClientSession)Session["objClientSession"]).GetAsList(), systemUserId);
                    }
                }



                if (objOperationResult1.ErrorMessage != null)
                {
                    Alert.ShowInTop(objOperationResult1.ErrorMessage);
                    return;
                }
                else
                {
                    if (objOperationResult1.Success != 1)
                    {
                        Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult1.ExceptionMessage);
                        return;
                    }
                }
            }

            // Cerrar página actual y hacer postback en el padre para actualizar
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
예제 #4
0
        private void LoadData()
        {
            string Mode         = Request.QueryString["Mode"].ToString();
            int    systemUserId = -1;
            string personId     = string.Empty;

            LoadComboBox();

            if (Mode == "New")
            {
                // Additional logic here.

                txtFirstName.Focus(true);
            }
            else if (Mode == "Edit")
            {
                if (Request.QueryString["systemUserId"] != null)
                {
                    systemUserId = int.Parse(Request.QueryString["systemUserId"].ToString());
                }
                if (Request.QueryString["personId"] != null)
                {
                    personId = Request.QueryString["personId"].ToString();
                }

                OperationResult objCommonOperationResultedit = new OperationResult();
                personDto       personDTO = _objPacientBL.GetPerson(ref objCommonOperationResultedit, personId);

                Session["objEntity"] = personDTO;

                // Informacion de la persona
                txtFirstName.Text        = personDTO.v_FirstName;
                txtFirstLastName.Text    = personDTO.v_FirstLastName;
                txtSecondLastName.Text   = personDTO.v_SecondLastName;
                txtDocNumber.Text        = personDTO.v_DocNumber;
                dpBirthdate.SelectedDate = personDTO.d_Birthdate;
                txtBirthPlace.Text       = personDTO.v_BirthPlace;


                ddlDocType.SelectedValue = personDTO.i_DocTypeId.ToString();
                ddlSexType.SelectedValue = personDTO.i_SexTypeId.ToString();
                txtTelephoneNumber.Text  = personDTO.v_TelephoneNumber;

                txtMail.Text = personDTO.v_Mail;

                // Informacion del usuario
                OperationResult objOperationResult = new OperationResult();
                systemuserDto   objSystemUser      = _objSecurityBL.GetSystemUser(ref objOperationResult, systemUserId);

                Session["objSystemUser"] = objSystemUser;

                txtUserName.Text  = objSystemUser.v_UserName;
                txtPassword1.Text = objSystemUser.v_Password;
                txtPassword2.Text = objSystemUser.v_Password;


                //Obtener la empresa por medio del systemuserId
                var EmpresaId_ProtocoloId = _protocolBL.ObtenerEmpresaPorSystemUserId(systemUserId);
                //ddlEmpresaCliente.SelectedValue = EmpresaId_ProtocoloId.EmpresaId;

                var ListaEmpresas = oOrganizationBL.GetEmpresasPorUsuarioExterno(objSystemUser.i_SystemUserId);
                Session["ListaEmpresas"] = ListaEmpresas;
                grdData.DataSource       = ListaEmpresas;
                grdData.DataBind();

                //Obtener Los permisos por el ProtocolId
                var Permisos = _protocolBL.ObtenerPermisosPorProtocoloId(EmpresaId_ProtocoloId.ProtocoloId, systemUserId);
                foreach (var item in Permisos)
                {
                    if (item.i_ApplicationHierarchyId == 1084)
                    {
                        chkAdminServicios.Checked = true;
                    }
                    if (item.i_ApplicationHierarchyId == 2000)
                    {
                        chkAgenda.Checked = true;
                    }
                    if (item.i_ApplicationHierarchyId == 3000)
                    {
                        chkEstadistica.Checked = true;
                    }
                    else if (item.i_ApplicationHierarchyId == 1087)
                    {
                        chkCertificado.Checked = true;
                    }
                    if (item.i_ApplicationHierarchyId == 165)
                    {
                        chkExamenes.Checked = true;
                    }
                    else if (item.i_ApplicationHierarchyId == 1086)
                    {
                        chkFichaOcupacional.Checked = true;
                    }
                    else if (item.i_ApplicationHierarchyId == 1085)
                    {
                        chkSegTrabajador.Checked = true;
                    }
                }
            }
        }
예제 #5
0
        private void LoadData()
        {
            LoadComboBox();
            LoadAllchkList();

            if (_mode == "New")
            {
                // Additional logic here.
                this.Text = "Nuevo Usuario Externo";
                txtName.Select();
            }
            else if (_mode == "Edit")
            {
                // Setear lenght dimamicos de numero de documento
                SetLenght(ddlDocType.SelectedValue.ToString());

                OperationResult objCommonOperationResultedit = new OperationResult();
                objPerson = _objPacientBL.GetPerson(ref objCommonOperationResultedit, _personId);

                this.Text = this.Text + " (" + objPerson.v_FirstName + " " + objPerson.v_FirstLastName + " " + objPerson.v_SecondLastName + ")";

                // Informacion de la persona
                txtName.Text                   = objPerson.v_FirstName;
                txtFirstLastName.Text          = objPerson.v_FirstLastName;
                txtSecondLastName.Text         = objPerson.v_SecondLastName;
                txtDocNumber.Text              = objPerson.v_DocNumber;
                dtpBirthdate.Value             = objPerson.d_Birthdate.Value;
                txtBirthPlace.Text             = objPerson.v_BirthPlace;
                ddlMaritalStatus.SelectedValue = objPerson.i_MaritalStatusId.ToString();
                ddlLevelOfId.SelectedValue     = objPerson.i_LevelOfId.ToString();
                ddlDocType.SelectedValue       = objPerson.i_DocTypeId.ToString();
                txtDocNumber.Text              = objPerson.v_DocNumber;
                ddlSexType.SelectedValue       = objPerson.i_SexTypeId.ToString();
                txtTelephoneNumber.Text        = objPerson.v_TelephoneNumber;
                txtAdressLocation.Text         = objPerson.v_AdressLocation;
                txtMail.Text                   = objPerson.v_Mail;

                // Informacion de Profesional
                OperationResult objCommonOperationResult1 = new OperationResult();
                var             objProfessional           = _objPacientBL.GetProfessional(ref objCommonOperationResult1, _personId);

                if (objProfessional != null)
                {
                    ComboTreeNode nodoABuscar = ddlProfession.AllNodes.First(x => x.Tag.ToString() == objProfessional.i_ProfessionId.ToString());
                    ddlProfession.SelectedNode      = nodoABuscar;
                    txtProfessionalCode.Text        = objProfessional.v_ProfessionalCode;
                    txtProfessionalInformation.Text = objProfessional.v_ProfessionalInformation;
                }

                // Informacion del usuario
                OperationResult objOperationResult = new OperationResult();
                _objSystemUserTemp = _objSecurityBL.GetSystemUser(ref objOperationResult, _systemUserId.Value);

                txtUserName.Text  = _objSystemUserTemp.v_UserName;
                txtPassword1.Text = _objSystemUserTemp.v_Password;
                txtPassword2.Text = _objSystemUserTemp.v_Password;

                if (_objSystemUserTemp.d_ExpireDate != null)
                {
                    rbFEchaExpiracion.Checked = true;
                    dtpExpiredDate.Value      = _objSystemUserTemp.d_ExpireDate.Value;
                }
                else
                {
                    rbNuncaCaduca.Checked  = true;
                    dtpExpiredDate.Enabled = false;
                }

                LoadchkListByProtocolIdAndSystemUserId();
            }
        }
예제 #6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            string          Result             = "";
            string          personId;
            bool            sendNotification = false;
            int             systemUserId     = -1;
            string          SihayError       = "";

            if (uvPacient.Validate(true, false).IsValid)
            {
                #region Validation

                if (txtName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtFirstLastName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Apellido Paterno.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtSecondLastName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Apellido Materno.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtDocNumber.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Número Documento.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtMail.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un Email .", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (txtMail.Text.Trim() != "")
                {
                    if (!Sigesoft.Common.Utils.email_bien_escrito(txtMail.Text.Trim()))
                    {
                        MessageBox.Show("Por favor ingrese un Email con formato correcto.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                if (dtpBirthdate.Checked == false)
                {
                    MessageBox.Show("Por favor ingrese una fecha de nacimiento.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int caracteres = txtDocNumber.TextLength;
                if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.DNI)
                {
                    if (caracteres != 8)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.PASAPORTE)
                {
                    if (caracteres != 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.LICENCIACONDUCIR)
                {
                    if (caracteres != 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.CARNETEXTRANJ)
                {
                    if (caracteres < 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                if (txtPassword2.Text.Trim() != txtPassword1.Text.Trim())
                {
                    MessageBox.Show("Los Password no coinciden Por favor verifique.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                #endregion

                if (_tmpListProtocolSystemUser == null)
                {
                    _tmpListProtocolSystemUser = new List <protocolsystemuserDto>();
                }

                if (_mode == "New")
                {
                    // Validar la longitud de los numeros de documentos
                    if (!IsValidDocumentNumberLenght())
                    {
                        return;
                    }

                    // Populate the entity
                    objPerson                   = new personDto();
                    objPerson.v_FirstName       = txtName.Text.Trim();
                    objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim();
                    objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim();
                    objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                    objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                    objPerson.i_MaritalStatusId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                    objPerson.i_LevelOfId       = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                    objPerson.v_DocNumber       = txtDocNumber.Text.Trim();
                    objPerson.d_Birthdate       = dtpBirthdate.Value;
                    objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim();
                    objPerson.v_TelephoneNumber = txtTelephoneNumber.Text.Trim();
                    objPerson.v_AdressLocation  = txtAdressLocation.Text.Trim();
                    objPerson.v_Mail            = txtMail.Text.Trim();


                    // Datos de usuario
                    systemuserDto pobjSystemUser = new systemuserDto();
                    pobjSystemUser.v_UserName         = txtUserName.Text.Trim();
                    pobjSystemUser.v_Password         = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                    pobjSystemUser.i_SystemUserTypeId = (int)SystemUserTypeId.External;
                    //if (rbFEchaExpiracion.Checked)
                    //    pobjSystemUser.d_ExpireDate = dtpExpiredDate.Value.Date;


                    // Graba persona
                    systemUserId = _protocolBL.AddPersonUsuarioExterno(ref objOperationResult,
                                                                       objPerson,
                                                                       null,
                                                                       pobjSystemUser,
                                                                       Globals.ClientSession.GetAsList());

                    //Obtener Todos los protocolos de la Empresa
                    var idEmpresa       = cboEmpresa.SelectedValue.ToString().Split('|');
                    var ListaProtocolos = _protocolBL.DevolverProtocolosPorEmpresa(idEmpresa[0].ToString());


                    #region Eval CheckedList for create new ->  chklPermisosOpciones / chklNotificaciones

                    foreach (var item in ListaProtocolos)
                    {
                        _tmpListProtocolSystemUser = new List <protocolsystemuserDto>();
                        for (int i = 0; i < chklPermisosOpciones.CheckedItems.Count; i++)
                        {
                            protocolsystemuserDto protocolSystemUser = new protocolsystemuserDto();
                            KeyValueDTO           obj = (KeyValueDTO)chklPermisosOpciones.CheckedItems[i];
                            protocolSystemUser.v_ProtocolId             = item.v_ProtocolId;
                            protocolSystemUser.i_ApplicationHierarchyId = int.Parse(obj.Id);
                            _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        }

                        // Graba UsuarioExterno
                        SihayError = _protocolBL.AddSystemUserExternal_(ref objOperationResult, _tmpListProtocolSystemUser, Globals.ClientSession.GetAsList(), systemUserId);

                        //for (int i = 0; i < chklNotificaciones.CheckedItems.Count; i++)
                        //{
                        //    protocolsystemuserDto protocolSystemUser = new protocolsystemuserDto();
                        //    KeyValueDTO obj = (KeyValueDTO)chklNotificaciones.CheckedItems[i];
                        //    protocolSystemUser.v_ProtocolId = item.v_ProtocolId;
                        //    protocolSystemUser.i_ApplicationHierarchyId = int.Parse(obj.Id);
                        //    _tmpListProtocolSystemUser.Add(protocolSystemUser);
                        //}
                    }



                    #endregion


                    if (SihayError == "-1")
                    {
                        if (objOperationResult.ErrorMessage != null)
                        {
                            //MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            //return;
                            MessageBox.Show(objOperationResult.ErrorMessage, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }

                    this.Enabled = false;
                    frmWaiting.Show(this);
                    bgwSendEmail.RunWorkerAsync();
                }
                else if (_mode == "Edit")
                {
                    bool isChangeUserName  = false;
                    bool isChangeDocNumber = false;

                    // Validar la longitud de los numeros de documentos
                    if (!IsValidDocumentNumberLenght())
                    {
                        return;
                    }

                    #region Validate SystemUSer
                    // Almacenar temporalmente el nombre de usuario actual
                    if (txtUserName.Text != _objSystemUserTemp.v_UserName)
                    {
                        isChangeUserName = true;
                        sendNotification = true;
                    }
                    #endregion

                    #region Validate Document Number
                    // Almacenar temporalmente el número de documento del usuario actual
                    if (txtDocNumber.Text != objPerson.v_DocNumber)
                    {
                        isChangeDocNumber = true;
                    }
                    #endregion

                    // Almacenar temporalmente el password del usuario actual
                    var passTemp = _objSystemUserTemp.v_Password;

                    // Si el password actual es diferente al ingresado en la cajita de texto, quiere decir que se ha cambiado el password por lo tanto
                    // se bede encriptar el nuevo password
                    if (txtPassword2.Text != passTemp)
                    {
                        _objSystemUserTemp.v_Password = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                        sendNotification = true;
                    }
                    else
                    {
                        _objSystemUserTemp.v_Password = txtPassword2.Text.Trim();
                    }

                    #region Datos de persona

                    // Datos de persona
                    objPerson.v_PersonId        = _personId;
                    objPerson.v_FirstName       = txtName.Text.Trim();
                    objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim();
                    objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim();
                    objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                    objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                    objPerson.i_MaritalStatusId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                    objPerson.i_LevelOfId       = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                    objPerson.v_DocNumber       = txtDocNumber.Text.Trim();
                    objPerson.d_Birthdate       = dtpBirthdate.Value;
                    objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim();
                    objPerson.v_TelephoneNumber = txtTelephoneNumber.Text.Trim();
                    objPerson.v_AdressLocation  = txtAdressLocation.Text.Trim();
                    objPerson.v_Mail            = txtMail.Text.Trim();

                    #endregion

                    #region Datos de Profesional

                    // Datos de Profesional
                    if (ddlProfession.SelectedNode.Tag.ToString() != "-1" ||
                        !string.IsNullOrEmpty(txtProfessionalCode.Text) ||
                        !string.IsNullOrEmpty(txtProfessionalInformation.Text))
                    {
                        _professionalDto = new professionalDto();
                        _professionalDto.i_ProfessionId = Convert.ToInt32(ddlProfession.SelectedNode.Tag);
                        if (!string.IsNullOrEmpty(txtProfessionalCode.Text))
                        {
                            _professionalDto.v_ProfessionalCode = txtProfessionalCode.Text.Trim();
                        }
                        if (!string.IsNullOrEmpty(txtProfessionalInformation.Text))
                        {
                            _professionalDto.v_ProfessionalInformation = txtProfessionalInformation.Text.Trim();
                        }
                    }

                    #endregion

                    #region Datos de Usuario

                    // Datos de Usuario
                    _objSystemUserTemp.i_SystemUserId = _objSystemUserTemp.i_SystemUserId;
                    _objSystemUserTemp.v_PersonId     = _personId;
                    _objSystemUserTemp.v_UserName     = txtUserName.Text;
                    _objSystemUserTemp.d_InsertDate   = _objSystemUserTemp.d_InsertDate;
                    _objSystemUserTemp.i_InsertUserId = _objSystemUserTemp.i_SystemUserId;
                    _objSystemUserTemp.i_IsDeleted    = _objSystemUserTemp.i_IsDeleted;
                    if (rbFEchaExpiracion.Checked)
                    {
                        _objSystemUserTemp.d_ExpireDate = dtpExpiredDate.Value.Date;
                    }
                    else if (rbNuncaCaduca.Checked)
                    {
                        _objSystemUserTemp.d_ExpireDate = null;
                    }

                    #endregion

                    //
                    LoadCheckedListForUpdate();

                    // Actualiza persona
                    _protocolBL.UpdateSystemUserExternal(ref objOperationResult,
                                                         isChangeDocNumber,
                                                         objPerson,
                                                         _professionalDto,
                                                         isChangeUserName,
                                                         _objSystemUserTemp,
                                                         _listProtocolSystemUserPermisoUpdate,
                                                         _listProtocolSystemUserPermisoDelete,
                                                         _listProtocolSystemUserNotifcacionUpdate,
                                                         _listProtocolSystemUserNotifcacionDelete,
                                                         Globals.ClientSession.GetAsList());

                    if (sendNotification)
                    {
                        this.Enabled = false;
                        frmWaiting.Show(this);
                        bgwSendEmail.RunWorkerAsync();
                    }
                }

                if (objOperationResult.ErrorMessage != null)
                {
                    //MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //return;
                    MessageBox.Show(objOperationResult.ErrorMessage, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    if (objOperationResult.Success != 1)
                    {
                        MessageBox.Show("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                        return;
                    }
                }

                if (!sendNotification && _mode != "New")
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            string          Result             = "";
            string          personId;
            bool            sendNotification = false;

            Sigesoft.Api.Api API = new Sigesoft.Api.Api();
            if (uvPacient.Validate(true, false).IsValid)
            {
                #region Validation

                if (txtName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtFirstLastName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Apellido Paterno.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtSecondLastName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Apellido Materno.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtDocNumber.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Número Documento.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (txtMail.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un Email .", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (txtMail.Text.Trim() != "")
                {
                    if (!Sigesoft.Common.Utils.email_bien_escrito(txtMail.Text.Trim()))
                    {
                        MessageBox.Show("Por favor ingrese un Email con formato correcto.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                if (dtpBirthdate.Checked == false)
                {
                    MessageBox.Show("Por favor ingrese una fecha de nacimiento.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                int caracteres = txtDocNumber.TextLength;
                if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.DNI)
                {
                    if (caracteres != 8)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.PASAPORTE)
                {
                    if (caracteres != 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.LICENCIACONDUCIR)
                {
                    if (caracteres != 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (int.Parse(ddlDocType.SelectedValue.ToString()) == (int)Common.Document.CARNETEXTRANJ)
                {
                    if (caracteres < 9)
                    {
                        MessageBox.Show("La cantida de caracteres de Número Documento es invalido.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                if (txtPassword2.Text.Trim() != txtPassword1.Text.Trim())
                {
                    MessageBox.Show("Los Password no coinciden Por favor verifique.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                #endregion

                if (_tmpListProtocolSystemUser == null)
                {
                    _tmpListProtocolSystemUser = new List <protocolsystemuserDto>();
                }

                if (_mode == "New")
                {
                    // Validar la longitud de los numeros de documentos
                    if (!IsValidDocumentNumberLenght())
                    {
                        return;
                    }

                    // Populate the entity
                    objPerson                   = new personDto();
                    objPerson.v_FirstName       = txtName.Text.Trim();
                    objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim();
                    objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim();
                    objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                    objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                    objPerson.i_MaritalStatusId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                    objPerson.i_LevelOfId       = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                    objPerson.v_DocNumber       = txtDocNumber.Text.Trim();
                    objPerson.d_Birthdate       = dtpBirthdate.Value;
                    objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim();
                    objPerson.v_TelephoneNumber = txtTelephoneNumber.Text.Trim();
                    objPerson.v_AdressLocation  = txtAdressLocation.Text.Trim();
                    objPerson.v_Mail            = txtMail.Text.Trim();

                    // Datos de Profesional
                    if (ddlProfession.SelectedNode.Tag.ToString() != "-1" ||
                        !string.IsNullOrEmpty(txtProfessionalCode.Text) ||
                        !string.IsNullOrEmpty(txtProfessionalInformation.Text))
                    {
                        _professionalDto = new professionalDto();
                        _professionalDto.i_ProfessionId = Convert.ToInt32(ddlProfession.SelectedNode.Tag);
                        if (!string.IsNullOrEmpty(txtProfessionalCode.Text))
                        {
                            _professionalDto.v_ProfessionalCode = txtProfessionalCode.Text.Trim();
                        }
                        if (!string.IsNullOrEmpty(txtProfessionalInformation.Text))
                        {
                            _professionalDto.v_ProfessionalInformation = txtProfessionalInformation.Text.Trim();
                        }
                    }

                    // Datos de usuario
                    systemuserDto pobjSystemUser = new systemuserDto();
                    pobjSystemUser.v_UserName = txtUserName.Text.Trim();
                    pobjSystemUser.v_Password = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                    if (rbFEchaExpiracion.Checked)
                    {
                        pobjSystemUser.d_ExpireDate = dtpExpiredDate.Value.Date;
                    }



                    #region Eval CheckedList for create new ->  chklPermisosOpciones / chklNotificaciones

                    for (int i = 0; i < chklPermisosOpciones.CheckedItems.Count; i++)
                    {
                        protocolsystemuserDto protocolSystemUser = new protocolsystemuserDto();
                        KeyValueDTO           obj = (KeyValueDTO)chklPermisosOpciones.CheckedItems[i];
                        protocolSystemUser.v_ProtocolId             = _protocolId;
                        protocolSystemUser.i_ApplicationHierarchyId = int.Parse(obj.Id);
                        _tmpListProtocolSystemUser.Add(protocolSystemUser);
                    }

                    for (int i = 0; i < chklNotificaciones.CheckedItems.Count; i++)
                    {
                        protocolsystemuserDto protocolSystemUser = new protocolsystemuserDto();
                        KeyValueDTO           obj = (KeyValueDTO)chklNotificaciones.CheckedItems[i];
                        protocolSystemUser.v_ProtocolId             = _protocolId;
                        protocolSystemUser.i_ApplicationHierarchyId = int.Parse(obj.Id);
                        _tmpListProtocolSystemUser.Add(protocolSystemUser);
                    }

                    #endregion

                    // Graba persona
                    personId = _protocolBL.AddSystemUserExternal(ref objOperationResult,
                                                                 objPerson,
                                                                 _professionalDto,
                                                                 pobjSystemUser,
                                                                 _tmpListProtocolSystemUser,
                                                                 Globals.ClientSession.GetAsList());

                    if (_tmpListProtocolSystemUser.Find(p => p.i_ApplicationHierarchyId == 3003).i_ApplicationHierarchyId != null)
                    {
                        //    #region API TRACKING


                        //    var oUsuarioExternoSeguimientoNew = new UsuarioExternoSeguimiento();

                        //    oUsuarioExternoSeguimientoNew.v_PersonId = _personId;
                        //    oUsuarioExternoSeguimientoNew.Nombres = txtName.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.ApellidoPaterno = txtFirstLastName.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.ApellidoMaterno = txtSecondLastName.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.TipoDocumentoId = Convert.ToInt32(ddlDocType.SelectedValue);
                        //    oUsuarioExternoSeguimientoNew.GeneroId = Convert.ToInt32(ddlSexType.SelectedValue);
                        //    oUsuarioExternoSeguimientoNew.EstadoCivilId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                        //    oUsuarioExternoSeguimientoNew.GradoInstruccionId = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                        //    oUsuarioExternoSeguimientoNew.NroDocumento = txtDocNumber.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.FechaNacimiento = dtpBirthdate.Value;
                        //    oUsuarioExternoSeguimientoNew.LugarNacimiento = txtBirthPlace.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.Telefono = txtTelephoneNumber.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.Direccion = txtAdressLocation.Text.Trim();
                        //    oUsuarioExternoSeguimientoNew.Correo = txtMail.Text.Trim();

                        //    var jsonPersonNew = new JavaScriptSerializer().Serialize(oUsuarioExternoSeguimientoNew);

                        //    var oUsuarioTrackingNew = new UsuarioTracking();
                        //    oUsuarioTrackingNew.NombreUsuario = txtUserName.Text;
                        //    oUsuarioTrackingNew.Contrasenia = txtPassword1.Text;
                        //    oUsuarioTrackingNew.RolId = 2;
                        //    oUsuarioTrackingNew.EmpresaId = 1;
                        //    oUsuarioTrackingNew.FechaCaduca = dtpExpiredDate.Value;
                        //    var jsonUsuarioNew = new JavaScriptSerializer().Serialize(oUsuarioTrackingNew);

                        //    Dictionary<string, string> arg1New = new Dictionary<string, string>()
                        //{
                        //    { "String1", jsonPersonNew },
                        //    { "String2", jsonUsuarioNew },
                        //      { "Int1", "2" }
                        //};
                        //    var resultNew = API.Post<bool>("Persona/InsertNewPersona", arg1New);

                        //    //if (!result)
                        //    //{
                        //    //    MessageBox.Show("Error al grabar usuario en Seguimiento", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        //    //}

                        //    #endregion
                    }

                    if (personId == "-1")
                    {
                        if (objOperationResult.ErrorMessage != null)
                        {
                            //MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            //return;
                            MessageBox.Show(objOperationResult.ErrorMessage, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }

                    this.Enabled = false;
                    frmWaiting.Show(this);
                    bgwSendEmail.RunWorkerAsync();
                }
                else if (_mode == "Edit")
                {
                    bool isChangeUserName  = false;
                    bool isChangeDocNumber = false;

                    // Validar la longitud de los numeros de documentos
                    if (!IsValidDocumentNumberLenght())
                    {
                        return;
                    }

                    #region Validate SystemUSer
                    // Almacenar temporalmente el nombre de usuario actual
                    if (txtUserName.Text != _objSystemUserTemp.v_UserName)
                    {
                        isChangeUserName = true;
                        sendNotification = true;
                    }
                    #endregion

                    #region Validate Document Number
                    // Almacenar temporalmente el número de documento del usuario actual
                    if (txtDocNumber.Text != objPerson.v_DocNumber)
                    {
                        isChangeDocNumber = true;
                    }
                    #endregion

                    // Almacenar temporalmente el password del usuario actual
                    var passTemp = _objSystemUserTemp.v_Password;

                    // Si el password actual es diferente al ingresado en la cajita de texto, quiere decir que se ha cambiado el password por lo tanto
                    // se bede encriptar el nuevo password
                    if (txtPassword2.Text != passTemp)
                    {
                        _objSystemUserTemp.v_Password = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                        sendNotification = true;
                    }
                    else
                    {
                        _objSystemUserTemp.v_Password = txtPassword2.Text.Trim();
                    }

                    #region Datos de persona

                    // Datos de persona
                    objPerson.v_PersonId        = _personId;
                    objPerson.v_FirstName       = txtName.Text.Trim();
                    objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim();
                    objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim();
                    objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                    objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                    objPerson.i_MaritalStatusId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                    objPerson.i_LevelOfId       = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                    objPerson.v_DocNumber       = txtDocNumber.Text.Trim();
                    objPerson.d_Birthdate       = dtpBirthdate.Value;
                    objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim();
                    objPerson.v_TelephoneNumber = txtTelephoneNumber.Text.Trim();
                    objPerson.v_AdressLocation  = txtAdressLocation.Text.Trim();
                    objPerson.v_Mail            = txtMail.Text.Trim();

                    #endregion

                    #region Datos de Profesional

                    // Datos de Profesional
                    if (ddlProfession.SelectedNode.Tag.ToString() != "-1" ||
                        !string.IsNullOrEmpty(txtProfessionalCode.Text) ||
                        !string.IsNullOrEmpty(txtProfessionalInformation.Text))
                    {
                        _professionalDto = new professionalDto();
                        _professionalDto.i_ProfessionId = Convert.ToInt32(ddlProfession.SelectedNode.Tag);
                        if (!string.IsNullOrEmpty(txtProfessionalCode.Text))
                        {
                            _professionalDto.v_ProfessionalCode = txtProfessionalCode.Text.Trim();
                        }
                        if (!string.IsNullOrEmpty(txtProfessionalInformation.Text))
                        {
                            _professionalDto.v_ProfessionalInformation = txtProfessionalInformation.Text.Trim();
                        }
                    }

                    #endregion

                    #region Datos de Usuario

                    // Datos de Usuario
                    _objSystemUserTemp.i_SystemUserId = _objSystemUserTemp.i_SystemUserId;
                    _objSystemUserTemp.v_PersonId     = _personId;
                    _objSystemUserTemp.v_UserName     = txtUserName.Text;
                    _objSystemUserTemp.d_InsertDate   = _objSystemUserTemp.d_InsertDate;
                    _objSystemUserTemp.i_InsertUserId = _objSystemUserTemp.i_SystemUserId;
                    _objSystemUserTemp.i_IsDeleted    = _objSystemUserTemp.i_IsDeleted;
                    if (rbFEchaExpiracion.Checked)
                    {
                        _objSystemUserTemp.d_ExpireDate = dtpExpiredDate.Value.Date;
                    }
                    else if (rbNuncaCaduca.Checked)
                    {
                        _objSystemUserTemp.d_ExpireDate = null;
                    }

                    #endregion

                    //
                    LoadCheckedListForUpdate();

                    // Actualiza persona
                    _protocolBL.UpdateSystemUserExternal(ref objOperationResult,
                                                         isChangeDocNumber,
                                                         objPerson,
                                                         _professionalDto,
                                                         isChangeUserName,
                                                         _objSystemUserTemp,
                                                         _listProtocolSystemUserPermisoUpdate,
                                                         _listProtocolSystemUserPermisoDelete,
                                                         _listProtocolSystemUserNotifcacionUpdate,
                                                         _listProtocolSystemUserNotifcacionDelete,
                                                         Globals.ClientSession.GetAsList());

                    if (sendNotification)
                    {
                        this.Enabled = false;
                        frmWaiting.Show(this);
                        bgwSendEmail.RunWorkerAsync();
                    }
                }

                var listaPermisosActualizados = new List <protocolsystemuserDto>();
                for (int i = 0; i < chklPermisosOpciones.CheckedItems.Count; i++)
                {
                    protocolsystemuserDto protocolSystemUser = new protocolsystemuserDto();
                    KeyValueDTO           obj = (KeyValueDTO)chklPermisosOpciones.CheckedItems[i];
                    protocolSystemUser.v_ProtocolId             = _protocolId;
                    protocolSystemUser.i_ApplicationHierarchyId = int.Parse(obj.Id);
                    listaPermisosActualizados.Add(protocolSystemUser);
                }

                //if (listaPermisosActualizados.Find(p => p.i_ApplicationHierarchyId == 3003).i_ApplicationHierarchyId != null)
                //{
                //    #region API TRACKING

                //    var oUsuarioExternoSeguimiento = new UsuarioExternoSeguimiento();

                //    oUsuarioExternoSeguimiento.v_PersonId = _personId;
                //    oUsuarioExternoSeguimiento.Nombres = txtName.Text.Trim();
                //    oUsuarioExternoSeguimiento.ApellidoPaterno = txtFirstLastName.Text.Trim();
                //    oUsuarioExternoSeguimiento.ApellidoMaterno = txtSecondLastName.Text.Trim();
                //    oUsuarioExternoSeguimiento.TipoDocumentoId = Convert.ToInt32(ddlDocType.SelectedValue);
                //    oUsuarioExternoSeguimiento.GeneroId = Convert.ToInt32(ddlSexType.SelectedValue);
                //    oUsuarioExternoSeguimiento.EstadoCivilId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                //    oUsuarioExternoSeguimiento.GradoInstruccionId = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                //    oUsuarioExternoSeguimiento.NroDocumento = txtDocNumber.Text.Trim();
                //    oUsuarioExternoSeguimiento.FechaNacimiento = dtpBirthdate.Value;
                //    oUsuarioExternoSeguimiento.LugarNacimiento = txtBirthPlace.Text.Trim();
                //    oUsuarioExternoSeguimiento.Telefono = txtTelephoneNumber.Text.Trim();
                //    oUsuarioExternoSeguimiento.Direccion = txtAdressLocation.Text.Trim();
                //    oUsuarioExternoSeguimiento.Correo = txtMail.Text.Trim();

                //    var jsonPerson = new JavaScriptSerializer().Serialize(oUsuarioExternoSeguimiento);

                //    var oUsuarioTracking = new UsuarioTracking();
                //    oUsuarioTracking.NombreUsuario = txtUserName.Text;
                //    oUsuarioTracking.Contrasenia = txtPassword1.Text;
                //    oUsuarioTracking.RolId = 2;
                //    oUsuarioTracking.EmpresaId = 1;
                //    oUsuarioTracking.FechaCaduca = dtpExpiredDate.Value;
                //    var jsonUsuario = new JavaScriptSerializer().Serialize(oUsuarioTracking);

                //    Dictionary<string, string> arg1 = new Dictionary<string, string>()
                //    {
                //        { "String1", jsonPerson },
                //        { "String2", jsonUsuario },
                //          { "Int1", "2" }
                //    };
                //    var result = API.Post<bool>("Persona/InsertNewPersona", arg1);

                //    //if (!result)
                //    //{
                //    //    MessageBox.Show("Error al grabar usuario en Seguimiento", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    //}

                //    #endregion
                //}



                if (objOperationResult.ErrorMessage != null)
                {
                    //MessageBox.Show("Por favor ingrese un nombre apropiado para Nombres.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //return;
                    MessageBox.Show(objOperationResult.ErrorMessage, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    if (objOperationResult.Success != 1)
                    {
                        MessageBox.Show("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                        return;
                    }
                }

                if (!sendNotification && _mode != "New")
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #8
0
        private void LoadData()
        {
            string Mode         = Request.QueryString["Mode"].ToString();
            int    systemUserId = -1;
            string personId     = string.Empty;

            LoadComboBox();

            if (Mode == "New")
            {
                // Additional logic here.

                txtFirstName.Focus(true);
            }
            else if (Mode == "Edit")
            {
                if (Request.QueryString["systemUserId"] != null)
                {
                    systemUserId = int.Parse(Request.QueryString["systemUserId"].ToString());
                }
                if (Request.QueryString["personId"] != null)
                {
                    personId = Request.QueryString["personId"].ToString();
                }

                OperationResult objCommonOperationResultedit = new OperationResult();
                personDto       personDTO = _objPacientBL.GetPerson(ref objCommonOperationResultedit, personId);

                Session["objEntity"] = personDTO;

                // Informacion de la persona
                txtFirstName.Text              = personDTO.v_FirstName;
                txtFirstLastName.Text          = personDTO.v_FirstLastName;
                txtSecondLastName.Text         = personDTO.v_SecondLastName;
                txtDocNumber.Text              = personDTO.v_DocNumber;
                dpBirthdate.SelectedDate       = personDTO.d_Birthdate;
                txtBirthPlace.Text             = personDTO.v_BirthPlace;
                ddlMaritalStatus.SelectedValue = personDTO.i_MaritalStatusId.ToString();
                ddlLevelOfId.SelectedValue     = personDTO.i_LevelOfId.ToString();
                ddlDocType.SelectedValue       = personDTO.i_DocTypeId.ToString();
                ddlSexType.SelectedValue       = personDTO.i_SexTypeId.ToString();
                txtTelephoneNumber.Text        = personDTO.v_TelephoneNumber;
                txtAdressLocation.Text         = personDTO.v_AdressLocation;
                txtMail.Text = personDTO.v_Mail;

                // Setear lenght dimamicos de numero de documento
                SetLenght(ddlDocType.SelectedValue);

                // Informacion de Profesional
                OperationResult objCommonOperationResult1 = new OperationResult();
                var             objProfessional           = _objPacientBL.GetProfessional(ref objCommonOperationResult1, personId);

                if (objProfessional != null)
                {
                    ddlProfession.SelectedValue     = objProfessional.i_ProfessionId.ToString();
                    txtProfessionalCode.Text        = objProfessional.v_ProfessionalCode;
                    txtProfessionalInformation.Text = objProfessional.v_ProfessionalInformation;
                    ImgPhoto.ImageUrl = null;
                    if (objProfessional.b_SignatureImage != null)
                    {
                        string pathImage = byteArrayToImage(objProfessional.b_SignatureImage);
                        string str       = @"~\Utils\GetImageText.ashx?" + getParameterRequest("imgDeliverValid", "180", "", "Arial Black", "Black", "9", "30", "20", "");
                        ImgPhoto.ImageUrl = str;
                    }
                }
                else
                {
                    objProfessional = new professionalDto();
                }

                Session["objProfessional"] = objProfessional;


                // Informacion del usuario
                OperationResult objOperationResult = new OperationResult();
                systemuserDto   objSystemUser      = _objSecurityBL.GetSystemUser(ref objOperationResult, systemUserId);

                Session["objSystemUser"] = objSystemUser;

                txtUserName.Text          = objSystemUser.v_UserName;
                txtPassword1.Text         = objSystemUser.v_Password;
                txtPassword2.Text         = objSystemUser.v_Password;
                ddlRolVenta.SelectedValue = objSystemUser.i_RolVentaId.ToString();
            }
        }
예제 #9
0
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            string Mode         = Request.QueryString["Mode"].ToString();
            string personId     = string.Empty;
            int    systemUserId = -1;

            int intCurrentExecutionNodeId = ((ClientSession)Session["objClientSession"]).i_CurrentExecutionNodeId;
            int intCurrentOrganizationId  = ((ClientSession)Session["objClientSession"]).i_CurrentOrganizationId;

            byte[] byteArrayPhoto = null;



            if (Mode == "New")
            {
                #region Validations
                // Validar la longitud de los numeros de documentos
                if (!IsValidDocumentNumberLenght())
                {
                    return;
                }
                #endregion

                // Datos de persona
                personDto objPerson = new personDto();
                objPerson.v_FirstName       = txtFirstName.Text.Trim().ToUpper();
                objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim().ToUpper();
                objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim().ToUpper();
                objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                objPerson.i_MaritalStatusId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                objPerson.i_LevelOfId       = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                objPerson.v_DocNumber       = txtDocNumber.Text.Trim();
                objPerson.d_Birthdate       = dpBirthdate.SelectedDate;
                objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim().ToUpper();
                objPerson.v_TelephoneNumber = txtTelephoneNumber.Text.Trim();
                objPerson.v_AdressLocation  = txtAdressLocation.Text.Trim().ToUpper();
                objPerson.v_Mail            = txtMail.Text.Trim();

                professionalDto objProfessional = null;

                // Datos de Profesional
                objProfessional = new professionalDto();
                objProfessional.i_ProfessionId = Convert.ToInt32(ddlProfession.SelectedValue);
                if (txtProfessionalCode.Text.Trim() != string.Empty)
                {
                    objProfessional.v_ProfessionalCode = txtProfessionalCode.Text.Trim();
                }
                if (txtProfessionalInformation.Text.Trim() != string.Empty)
                {
                    objProfessional.v_ProfessionalInformation = txtProfessionalInformation.Text.Trim();
                }

                if (filePhoto.HasFile) // Si hay una imagen cargada lista para ser serializada sino se graba x defecto null
                {
                    byteArrayPhoto = FileUploadToByteArray();
                    objProfessional.b_SignatureImage = byteArrayPhoto;
                }

                // Datos de usuario
                systemuserDto pobjSystemUser = new systemuserDto();
                pobjSystemUser.v_PersonId         = personId;
                pobjSystemUser.v_UserName         = txtUserName.Text.Trim();
                pobjSystemUser.v_Password         = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                pobjSystemUser.i_RolVentaId       = int.Parse(ddlRolVenta.SelectedValue.ToString());
                pobjSystemUser.i_SystemUserTypeId = (int)SystemUserTypeId.Internal;
                // Graba persona
                OperationResult objOperationResult1 = new OperationResult();
                personId = _objPacientBL.AddPerson(ref objOperationResult1,
                                                   objPerson,
                                                   objProfessional,
                                                   pobjSystemUser,
                                                   ((ClientSession)Session["objClientSession"]).GetAsList());

                if (personId == "-1")
                {
                    Alert.ShowInTop(objOperationResult1.ErrorMessage);
                    return;
                }
                else
                {
                    if (objOperationResult1.Success != 1)
                    {
                        Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult1.ExceptionMessage);
                        return;
                    }
                }
            }
            else if (Mode == "Edit")
            {
                if (Request.QueryString["personId"] != null)
                {
                    personId = Request.QueryString["personId"].ToString();
                }
                if (Request.QueryString["systemUserId"] != null)
                {
                    systemUserId = int.Parse(Request.QueryString["systemUserId"].ToString());
                }

                systemuserDto systemUser         = new systemuserDto();
                personDto     _objPerson         = Session["objEntity"] as personDto;
                systemuserDto _objSystemUserTemp = Session["objSystemUser"] as systemuserDto;

                #region Validate Document Number Lenght
                // Validar la longitud de los numeros de documentos
                if (!IsValidDocumentNumberLenght())
                {
                    return;
                }
                #endregion

                bool isChangeUserName  = false;
                bool isChangeDocNumber = false;

                #region Validate SystemUSer
                // Almacenar temporalmente el nombre de usuario actual
                var _userNameTemp = _objSystemUserTemp.v_UserName;
                if (txtUserName.Text != _userNameTemp)
                {
                    isChangeUserName = true;
                }
                #endregion

                #region Validate Document Number
                // Almacenar temporalmente el número de documento del usuario actual
                var _docNumberTemp = _objPerson.v_DocNumber;
                if (txtDocNumber.Text != _docNumberTemp)
                {
                    isChangeDocNumber = true;
                }
                #endregion

                // Datos de persona
                _objPerson.v_FirstName       = txtFirstName.Text.Trim().ToUpper();
                _objPerson.v_FirstLastName   = txtFirstLastName.Text.Trim().ToUpper();
                _objPerson.v_SecondLastName  = txtSecondLastName.Text.Trim().ToUpper();
                _objPerson.i_DocTypeId       = Convert.ToInt32(ddlDocType.SelectedValue);
                _objPerson.i_SexTypeId       = Convert.ToInt32(ddlSexType.SelectedValue);
                _objPerson.i_MaritalStatusId = Convert.ToInt32(ddlMaritalStatus.SelectedValue);
                _objPerson.i_LevelOfId       = Convert.ToInt32(ddlLevelOfId.SelectedValue);
                _objPerson.v_DocNumber       = txtDocNumber.Text;
                _objPerson.d_Birthdate       = dpBirthdate.SelectedDate;
                _objPerson.v_BirthPlace      = txtBirthPlace.Text.Trim().ToUpper();
                _objPerson.v_TelephoneNumber = txtTelephoneNumber.Text;
                _objPerson.v_AdressLocation  = txtAdressLocation.Text.Trim().ToUpper();
                _objPerson.v_Mail            = txtMail.Text;
                _objPerson.i_UpdateNodeId    = ((ClientSession)Session["objClientSession"]).i_CurrentExecutionNodeId;

                // Datos de Profesional
                professionalDto _objProfessional = Session["objProfessional"] as professionalDto;

                var b = filePhoto.HasFile;

                if (_objProfessional != null)
                {
                    _objProfessional.v_PersonId                = personId;
                    _objProfessional.i_ProfessionId            = Convert.ToInt32(ddlProfession.SelectedValue);
                    _objProfessional.v_ProfessionalCode        = txtProfessionalCode.Text;
                    _objProfessional.v_ProfessionalInformation = txtProfessionalInformation.Text;
                    _objProfessional.i_UpdateNodeId            = ((ClientSession)Session["objClientSession"]).i_CurrentExecutionNodeId;

                    if (filePhoto.HasFile) // chekar si el control Upload tiene una imagen cargada para serializar
                    {
                        var byteArrayPhoto1 = FileUploadToByteArray();
                        _objProfessional.b_SignatureImage = byteArrayPhoto1;
                    }
                    else
                    {
                        bool isDeleted = Convert.ToBoolean(ViewState["isDeleted"]);

                        if (isDeleted)
                        {
                            _objProfessional.b_SignatureImage = null;
                        }
                    }
                }


                // Almacenar temporalmente el password del usuario actual
                var _passTemp = _objSystemUserTemp.v_Password;

                // Si el password actual es diferente al ingresado en la cajita de texto, quiere decir que se ha cambiado el password por lo tanto
                // se bede encriptar el nuevo password
                if (txtPassword2.Text != _passTemp)
                {
                    systemUser.v_Password = SecurityBL.Encrypt(txtPassword2.Text.Trim());
                }
                else
                {
                    systemUser.v_Password = txtPassword2.Text.Trim();
                }

                // Datos de Usuario
                systemUser.i_SystemUserId     = _objSystemUserTemp.i_SystemUserId;
                systemUser.v_PersonId         = personId;
                systemUser.v_UserName         = txtUserName.Text;
                systemUser.d_InsertDate       = _objSystemUserTemp.d_InsertDate;
                systemUser.i_InsertUserId     = _objSystemUserTemp.i_SystemUserId;
                systemUser.i_IsDeleted        = _objSystemUserTemp.i_IsDeleted;
                systemUser.i_SystemUserTypeId = (int)SystemUserTypeId.Internal;
                systemUser.i_RolVentaId       = int.Parse(ddlRolVenta.SelectedValue.ToString());
                // Actualiza persona
                OperationResult objOperationResult1 = new OperationResult();
                _objPacientBL.UpdatePerson(ref objOperationResult1,
                                           isChangeDocNumber,
                                           _objPerson,
                                           _objProfessional,
                                           isChangeUserName,
                                           systemUser,
                                           ((ClientSession)Session["objClientSession"]).GetAsList());
                ImgPhoto.Dispose();

                if (objOperationResult1.ErrorMessage != null)
                {
                    Alert.ShowInTop(objOperationResult1.ErrorMessage);
                    return;
                }
                else
                {
                    if (objOperationResult1.Success != 1)
                    {
                        Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult1.ExceptionMessage);
                        return;
                    }
                }
            }

            // Cerrar página actual y hacer postback en el padre para actualizar
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }