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(); // Graba persona OperationResult objOperationResult1 = new OperationResult(); personId = _objPacientBL.AddPerson(ref objOperationResult1, objPerson, null, null, ((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["v_personId"] != null) { personId = Request.QueryString["v_personId"].ToString(); } personDto _objPerson = Session["objEntity"] as personDto; #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 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; // Actualiza persona OperationResult objOperationResult1 = new OperationResult(); _objPacientBL.UpdatePerson(ref objOperationResult1, isChangeDocNumber, _objPerson, null, isChangeUserName, null, ((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()); }
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()); }