Dynamic Search for records
===================VFPage========================
<apex:page controller="nnrauthosearch1" sidebar="false" applyBodyTag="true" ApplyHtmlTag="true" showHeader="false">
<script language="javascript">
window.onload = new function()
{
// bring popup window to front
window.focus();
var ele=document.getElementById('{!$Component.form.block.section.query}');
if (ele)
{
ele.focus();
}
}
function fillIn(name, id)
{
var winMain=window.opener;
if (null==winMain)
{
winMain=window.parent.opener;
}
var ele=winMain.document.getElementById('{!$CurrentPage.parameters.namefield}');
ele.value=name;
ele=winMain.document.getElementById('{!$CurrentPage.parameters.idfield}');
ele.value=id;
winMain.closeLookupPopup();
}
</script>
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Patient!" mode="edit"><!-- starting pblock1-->
<table width="100%" border="0"><!-- starting table1-->
<tr> <!-- starting row1-->
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria"><!-- starting pblock2-->
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;"><br/>
<apex:outputLabel >Main Name:</apex:outputLabel>
<apex:inputText value="{!firstname}" >
<apex:actionSupport event="onkeyup" action="{!runSearch}" reRender="results,pb"/>
</apex:inputText>
</td>
</tr>
<tr>
<td style="font-weight:bold;"><br/>
<apex:outputLabel >Sur Name:</apex:outputLabel>
<apex:inputText value="{!lastname}" >
<apex:actionSupport event="onkeyup" action="{!runSearch}" reRender="results,pb"/>
</apex:inputText>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Mobile Number<br/>
<apex:inputText value="{!mobilenumber}" >
<apex:actionSupport event="onkeyup" action="{!runSearch}" reRender="results,pb"/>
</apex:inputText>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Patient Id<br/>
<apex:inputText value="{!patientid}" >
<apex:actionSupport event="onkeyup" action="{!runSearch}" reRender="results,pb"/>
</apex:inputText>
</td>
</tr>
<tr><td> <h1 style="color:RED"> OR</h1></td></tr>
<tr><td> <apex:outputPanel style="color:#1475FF">From Date:</apex:outputPanel>
<apex:inputText value="{!fromdateselected}" id="fromdateid" onfocus="DatePicker.pickDate(false, this, false);" >
</apex:inputText> </td></tr>
<tr><td> <apex:outputPanel style="color:#1475FF">To Date:</apex:outputPanel>
<apex:inputText id="todateid" value="{!todateselected}" onfocus="DatePicker.pickDate(false, this, false);" >
</apex:inputText> </td></tr>
<tr>
<td>
<apex:commandButton value="search" action="{!searchaction}" style="background:pink" reRender="results"/>
</td>
</tr>
</table>
<apex:pageBlockSection columns="1" id="pb">
<apex:PageBlockSectionItem >
<apex:selectRadio value="{!daycheckl}" ><apex:selectOptions value="{!value}"></apex:selectOptions>
<apex:actionSupport event="onclick" action="{!DayRecords}" reRender="results"/>
</apex:selectRadio>
</apex:PageBlockSectionItem>
</apex:pageblockSection>
</apex:pageBlock><!-- end pblock2-->
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column headerValue="PatientId">
<apex:outputLink value="#" onclick="fillIn('{!c.Patient_Id__c}', '{!c.id}')">{!c.Patient_Id__c}
<apex:param name="sortField" value="firstName" assignTo="{!sortField}"/>
</apex:outputLink>
</apex:column>
<apex:column value="{!c.First_Name__c}" />
<apex:column value="{!c.LastName__c}" />
<apex:column value="{!c.Mobile__c}" />
<apex:column headerValue="Registration No" value="{!c.Name}" />
<apex:column value="{!c.Status__c}"/>
<apex:column value="{!c.createddate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table><!-- end table1-->
</apex:pageblock> <!-- end of pblock1-->
</apex:form>
</apex:page>
========================Controller==============================
public with sharing class nnrauthosearch1 {
public string daycheckl { get; set; }
public boolean monthcheck{ get; set; }
public boolean yearcheck{ get; set; }
public boolean weekcheck{ get; set; }
public string firstName{set;get;}
public string lastname{set;get;}
public string mobilenumber{set;get;}
public string patientid{set;get;}
public string OPDRegistrationNo{set;get;}
private String soql {get;set;}
public list<OPD_Registration__c> contacts{set;get;}
public Date todateselected { get; set; }
public Date fromdateselected { get; set; }
public static string str='open';
// Constructor
public nnrauthosearch1 (){
daycheckl='Day';
//soql = 'select id,First_Name__c,Mobile__c,Patient_Id__c,Name,LastName__c,city__c,state__c,status__c,CreatedDate From OPD_Registration__c where CreatedDate =today ';
//contacts=[select id,First_Name__c,Mobile__c,Patient_Id__c,Name,LastName__c,city__c,state__c,status__c,CreatedDate From OPD_Registration__c where CreatedDate =today ];
runQuery1();
}
public String sortDir {
get { if (sortDir == null) { sortDir = 'desc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField {
get { if (sortField == null) {sortField = 'createddate desc limit 2'; } return sortField; }
set;
}
public List<SelectOption> getValue(){
List<SelectOption> opt=new List<SelectOption>();
opt.add(new SelectOption('Day','Day'));
opt.add(new selectOption('Week','Week'));
opt.add(new SelectOption('Month','Month'));
opt.add(new SelectOption('Year','Year'));
return opt;
}
// Date wise search
public PageReference searchaction() {
if(todateselected != NULL && fromdateselected != NULL){
system.debug('PPPPPPPPPPPPPPPPPPPPP'+todateselected+'dddddddddddddddddddddddddddddddddddddddddd'+fromdateselected );
contacts =[select id,First_Name__c,Mobile__c,Patient_Id__c,Name,LastName__c,City__c,status__c,CreatedDate From OPD_Registration__c where createddate >=: fromdateselected and createddate <=: todateselected and patient_id__c!=null ];
}
return null;
}
public void runQuery() {
try {
contacts = Database.query(soql+ ' order by ' + sortField );
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
public void runQuery1(){
system.debug('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh@@@@@@@@@@@@@');
//contacts =[select id,First_Name__c,Mobile__c,LastName__c ,Patient_Id__c,Name,Country__c,Registration_Date__c,city__c,state__c,CreatedDate,status__c,opd_Reg_Date__c From OPD_Registration__c where CreatedDate =TODAY ];
contacts=[select id,First_Name__c,Mobile__c,Patient_Id__c,Name,LastName__c,city__c,state__c,status__c,CreatedDate From OPD_Registration__c where CreatedDate =today ];
system.debug('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh'+contacts);
daycheckl='Day';
//runQuery();
}
// Radio button search
public void DayRecords() {
if(daycheckl=='day'){
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&');
contacts =[select id,First_Name__c,Mobile__c,LastName__c ,Patient_Id__c,Name,Country__c,Registration_Date__c,city__c,state__c,CreatedDate,status__c,opd_Reg_Date__c From OPD_Registration__c where CreatedDate =TODAY ];}
else if(daycheckl=='week'){
contacts =[select id,First_Name__c,Mobile__c,LastName__c ,Patient_Id__c,Name,Country__c,Registration_Date__c,city__c,state__c,CreatedDate,opd_Reg_Date__c,status__c From OPD_Registration__c where CreatedDate = THIS_WEEK];}
else if(daycheckl=='month'){
contacts =[select id,First_Name__c,LastName__c ,Mobile__c,Patient_Id__c,Name,Country__c,Registration_Date__c,city__c,state__c,CreatedDate,opd_Reg_Date__c,status__c From OPD_Registration__c where CreatedDate = THIS_MONTH ];}
else if(daycheckl=='year'){
contacts =[select id,First_Name__c,LastName__c ,Mobile__c,Patient_Id__c,Name,Country__c,Registration_Date__c,city__c,state__c,CreatedDate,opd_Reg_Date__c,status__c From OPD_Registration__c where CreatedDate = THIS_YEAR ];}
else{
contacts =[select id,First_Name__c,Mobile__c,LastName__c ,Patient_Id__c,Name,Country__c,Registration_Date__c,city__c,state__c,CreatedDate,opd_Reg_Date__c,status__c From OPD_Registration__c ];}
}
// inputtext box search
public PageReference runSearch() {
soql ='select id,First_Name__c,Mobile__c,Patient_Id__c,Name,LastName__c,city__c,state__c,status__c,CreatedDate From OPD_Registration__c where name!=null and (createddate >=: fromdateselected and createddate <=: todateselected) ';
if (!firstName.equals('')){
soql += ' and First_Name__c LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';
system.debug('first name @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+firstname);
}
if (!lastname.equals('')){
soql += ' and lastname__c LIKE \''+String.escapeSingleQuotes(lastname)+'%\'';
system.debug('lastname @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+lastname);
}
if (!mobilenumber.equals('')){
soql += ' and mobile__c LIKE \''+String.escapeSingleQuotes(mobilenumber)+'%\'';
system.debug('mobile number@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+mobilenumber);
}
if (!patientid.equals('')){
soql += ' and patient_id__c LIKE \''+String.escapeSingleQuotes(patientid)+'%\'';
system.debug('patientid @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+patientid);
}
if( patientid.equals('') && mobilenumber.equals('') && lastname.equals('') && firstname.equals('')){
runQuery1();
daycheckl='Day';
}
runQuery();
return null;
}
}
No comments:
Post a Comment