Wednesday, April 20, 2011

Accessing the methods of a MasterPage from inside the Web Form

write this code inside child page of masterpage to access a control.

Label lblmsg;
lblmsg = (Label)Master.FindControl("lblTitle");
lblmsg.Text = "I love my india";

//---------------------------------- 


((EmpMasterPage)this.Master).SetMessage("I love my India");

here EmpMasterPage is a name of MasterPage and SetMessage is a method of that MasterPage.

Bind check box in datalist and show the selected checked

 <asp:DataList ID="da"   runat="server" ShowHeader="False" ShowFooter="False"
                        CellPadding="0" RepeatColumns="1" RepeatDirection="Vertical" style="overflow:scroll !important;">
                       <ItemStyle Width="200" HorizontalAlign="Left"></ItemStyle>
                        <ItemTemplate>
                            <input type="checkbox" class="radio_botton" value='<%# DataBinder.Eval(Container.DataItem, "uid")%>'
                                name='chk' <%# search != null && search.chk.IndexOf("," + DataBinder.Eval(Container.DataItem, "uid").ToString() + ",") > -1 ? "checked" : ""%>><%# DataBinder.Eval(Container.DataItem, "Amen_Name")%>
                        </ItemTemplate>
                    </asp:DataList>

Wednesday, April 13, 2011

SQL SERVER – Add New Column With Default Value

SQL Server is a very interesting system, but the people who work in SQL Server are even more remarkable. The amount of communication, the thought process, the brainstorming that they do are always phenomenal. Today I will share a quick conversation I have observed in one of the organizations that I recently visited.
While we were heading to the conference room, we passed by some developers and I noticed the following script on the screen of one of the developers.
CREATE TABLE TestTable
(FirstCol INT NOT NULL)
GO
------------------------------
-- Option 1
------------------------------
-- Adding New Column
ALTER TABLE TestTable
ADD SecondCol INT
GO
-- Updating it with Default
UPDATE TestTable
SET SecondCol = 0
GO
-- Alter
ALTER TABLE TestTable
ALTER COLUMN SecondCol INT NOT NULL
GO
Curious, I asked why he wrote such a long script. He replied with another question, asking whether there is any existing short method that he can use to add a column which is not null and can be populated with some specific values.
Of course! The method exists and here is the quick script. When he learned it he said, “Well, I searched at your blog but it was not there.”
------------------------------
-- Option 2
------------------------------
-- Adding Value with Default Value
ALTER TABLE TestTable
ADD ThirdCol INT NOT NULL DEFAULT(0)
GO
Well, now it’s in my blog.

SQL Server Reporting Services (SSRS): Part 1- Basics of creating a report


Introduction


SQL Server Reporting services are very good features provided in SQL to build a report of user choice and deploy it to make use of it anywhere as per the requirement. In this article we are going to see on how to create a simple report then build and execute the report. Reports can be exported to multiple formats including delimited text, XML format, PDF format and Microsoft Excel as well.
Let's jump into the process and see the step by step process of how to create and execute an SSRS report.

Steps:

Go to SQL Server Business Intelligence Development Studio and create a new project as shown below:
Now a wizard will / may open based on the existing option selected; if it opens then just skip that window by clicking Next. It will open a new window which shows the basic configuration as shown in the screen below:
Next window will show an option to build a query based on which the result set will be displayed as a report. We can write our own query to fetch the output as shown in the screen below.
Clicking on Next; a window will open with the option to select how the result should display as shown in the screen below:
Clicking on Next will open the window below; if you can see the option here to group the data and show as per our requirement.
Clicking on the Next button will open a window which gives options to design the report based on the templates available as shown in the screen below:
Now when clicking on the button an interesting thing appears, which is nothing but where to deploy the report. We can give as per our requirement
Clicking on Next will open a window as shown in the screen below. Here we can give our customized report name:
Clicking on Finish will open a window as shown in the screen below, which shows the structure of the report as shown below:

Now press F5 to build and execute the process. It will show the result as shown in the figure below:

Conclusion

So in this article we have seen how to create, build and execute a basic report using SQL reporting services.

Test Emails in ASP.NET without a Mail Server

This summary is not available. Please click here to view the post.

Monday, April 4, 2011

implement advance search


  
                
ALTER PROCEDURE [dbo].[advance_search]              
               
        @zip_code   varchar(10) = null,                         
        @bedrooms   float = null,                         
        @bathrooms   float = null,                         
        @price_min   money = null,                         
        @price_max   money = null,                         
        @built    int = null,                         
        @sq_ft    int = null,                         
        @aptType_id   int = null,                         
        @minLong   real = null,                         
        @maxLong   real = null,                         
        @minLat    real = null,                         
        @maxLat    real = null,                         
        @amenities   varchar(100) = null,                         
        @amenityCnt   int = null,                         
  @longitudes   varchar(8000) = null,                         
  @latitudes   varchar(8000) = null,                         
  @filter    varchar(1000) = null,                         
        @pageNum   int = 1,                         
        @pageSize   smallint = 50,                         
        @wd     bit = 1                         
 , @High_Altitude  varchar(50)= 'false
CommissionAmount, @Search_Para               
 , @Commission_Amount varchar(50)= null               
 , @Search_Para varchar(50) = null           
                         
AS                      
                 
begin                  
SET NOCOUNT ON;                
               
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ               
                 
Begin Transaction                 
                    
DECLARE @firstRecord int, @lastRecord int                         
SET @firstRecord = (@pageNum - 1) * @pageSize + 1                         
SET @lastRecord = (@pageNum * @pageSize)                         
declare @exec varchar(8000)                     
                     
set @exec = 'SELECT DISTINCT complexes_active.UID,CommissionAmount,complexes_active.Property_Name,               
complexes_active.Street_Address_1,complexes_active.City,complexes_active.metro_area,Longitude,Latitude,               
Survey_Date,(SELECT COUNT(*) FROM apartment_graphics with (updlock)                
WHERE apartment_id=complexes_active.uid AND type = ''.JPG'') AS gr, promoted,property_status,
State, Zip_Code, Telephone_Number'                         
                 
If @amenities is not null                          
    set @exec = @exec + ',(select count(*) from ACAmenities with (updlock) where ac_uid=complexes_active.UID and Amenity_id in (' + @amenities + ')) as foundAmens'                          
                 
set @exec = @exec + ' into #tPaging FROM complexes_active with (updlock) INNER JOIN apartment_units  ON apartment_units.AC_UID=complexes_active.UID'                         
           
If (@Search_Para is not null)            
 set @exec = @exec + ' Inner Join submarkets On submarkets.smrkt_Id =  complexes_active.submarketid '           
            
set @exec = @exec + ' WHERE 1=1 '                         
               
                 
If @ManagementID is not null                          
 set @exec = @exec + ' AND Management_UID=''' + cast(@ManagementID as varchar(6)) + ''''                          
else             
 If @city is not null                          
  set @exec = @exec + ' AND City=''' + @city + ''''                   
 If @Metro_Area is not null                          
  set @exec = @exec + ' AND Metro_Area=''' + @Metro_Area + ''''                                
 If @city_region is not null                          
  set @exec = @exec + ' AND City_Region in (' + @city_region + ')'                          
 If @zip_code is not null            
  set @exec = @exec + ' AND zip_code LIKE ''' + @zip_code + '%'''                          
 If @Property_Name is not null                       
 Begin                      
  set @exec = @exec + ' AND ' + dbo.f_PropertyNames(@Property_Name)                          
  --set @exec= @exec +' or '+ dbo.f_FKANames(@Property_Name)                     
 End                   
 If @Street_Address is not null                          
  set @exec = @exec + ' AND Street_Address_1 like ''%' + @Street_Address + '%'''                          
 If @built is not null                  
  set @exec = @exec + ' AND Year_Built>=''' + CAST(@built as varchar(4)) + ''''                          
 If @minLong is not null and @maxLong is not null and @minLat is not null and @maxLat is not null                         
  set @exec = @exec + ' AND Longitude between ' + CAST(@minLong as varchar(12)) + ' and ' + CAST(@maxLong as varchar(12)) + ' and Latitude between ' + CAST(@minLat as varchar(12)) + ' and ' + CAST(@maxLat as varchar(12))                          

                         
 If @price_max is not null or @price_min is not null  or @bedrooms is not null or @bathrooms is not null or @sq_ft is not null or @aptType_id is not null or @wd = 1                         
  set @exec = @exec + ' AND PFP_DELETED = 0'                         
                     
 If @aptType_id is not null                          
  set @exec = @exec + ' AND PFP_CC_ID_UNITTYPE=' + CAST(@aptType_id as varchar(10))                          
 If @price_min is not null                          
  set @exec = @exec + ' AND PFP_MarketRentMin>' + CAST(@price_min as varchar(10))                          
 If @price_max is not null                          
  set @exec = @exec + ' AND PFP_MarketRentMin<' + CAST(@price_max as varchar(10))                          
 If @bedrooms is not null                          
  set @exec = @exec + ' AND PFP_NumBed=' + CAST(@bedrooms as varchar(3))                          
 If @bathrooms is not null                          
  set @exec = @exec + ' AND PFP_NumBath=' + CAST(@bathrooms as varchar(3))                          
 If @sq_ft is not null                         
  set @exec = @exec + ' and PFP_SqFt>=' + cast(@sq_ft as varchar(5))                          
               
if (@Commission_Amount is not null)               
   set @exec = @exec + ' and CommissionAmount >= '+ @Commission_Amount -- added by Tarveen to make filter for Commission_Amount               
               
 If (lower(@High_Altitude) =  'true')  -- added by Tarveen to make filter for High_Rise                 
  set @exec = @exec + ' and High_Altitude = 1'                  
               
If (@Search_Para is not null)  -- added by Tarveen to make filter for Galleria and Midtown             
 set @exec = @exec + ' and submarkets.smrkt_name = '''+ @Search_Para + ''''                  
            
 If @amenities is not null                          
  set @exec = @exec + ' AND 1<=(select count(*) from ACAmenities with(updlock)                 
     where ac_uid=complexes_active.UID and Amenity_id in (' + @amenities + '))'                          
 If @filter is not null                         
  set @exec = @exec + @filter                         
 If @amenities is not null                          
  set @exec = @exec + ' order by foundAmens desc, gr desc, CommissionAmount desc, Property_Name'                          
 else                         
  set @exec = @exec + ' order by gr desc, CommissionAmount desc, Property_Name'                          
                         
 If @amenityCnt is not null and @amenityCnt>0                  
 begin                         
  SET @exec = @exec + '; SELECT COUNT(*) FROM #tPaging with(updlock) where foundAmens=' +  CAST(@amenityCnt as varchar(3))                          
  SET @exec = @exec + '; SELECT * FROM #tPaging with(updlock) where foundAmens=' +  CAST(@amenityCnt as varchar(3))                          
 end                         
 else                  
 begin                         
  SET @exec = @exec + '; SELECT COUNT(*) FROM #tPaging with(updlock)'                         
  SET @exec = @exec + '; SELECT * FROM #tPaging with(updlock)'                         
 end                         
                 
print @exec                         
 exec (@exec)                 
                  
 commit transaction                 
                 
 if(@@error > 0)                  
 rollback                  
end                 
                 

Friday, April 1, 2011

Sql get distnict value in sql

    
             
CREATE  PROCEDURE  check             
 @uid int                      
AS                     
begin           
         
declare @price int         
set @price=0         
         
DECLARE @temptable table                       
(                       
              
 PFP_MarketRentMin money ,          
 PFP_MarketRentMax money ,          
                  
 PFP_NumUnitsMin int ,                  
 PFP_NumUnitsMax int ,                   
                    
 PFP_StackWDOnly bit ,                   
 UnitType_Name varchar(50),                   
 Extra1_Name varchar(50),                   
 Extra2_Name varchar(50),                   
    
 )                       
                   
 INSERT INTO    @temptable                    
 SELECT  *,          
                      
          
     ut.CC_Value as UnitType_Name,                         
   e1.CC_Value as Extra1_Name,                         
     e2.CC_Value as Extra2_Name,                         
     e3.CC_Value as Extra3_Name,               
ISNULL(e4.specials_desc,'Call') AS 'special',  
CASE    
     

         
         

         

       
-charindex(convert(varchar,PFP_Deposit),'.',0)-2)))))) from apartment_units  WHERE             
AC_UID = @uid and PFP_NumBed=2 and PFP_Deleted = 0)   
        
WHEN  pfp_numbed = 3 THEN          
(select(CONVERT(varchar(12), min(convert(int,substring(convert(varchar,PFP_Deposit),0,len(convert(varchar,PFP_Deposit))-     
charindex(convert(varchar,PFP_Deposit),'.',0)-2)))))       
 +'-'+ (CONVERT(varchar(12),max(convert(int,ISNULL(substring(convert(varchar,PFP_Deposit),0,len(convert(varchar,PFP_Deposit))       
-charindex(convert(varchar,PFP_Deposit),'.',0)-2)       
,substring(convert(varchar,PFP_Deposit),0,len(convert(varchar,PFP_Deposit))       
-charindex(convert(varchar,PFP_Deposit),'.',0)-2)))))) from apartment_units  WHERE             
AC_UID = @uid and PFP_NumBed=3 and PFP_Deleted = 0)  
         

         
    
END AS bath   
 
          
FROM                            
 apartment_units                        
                      
 inner join CommonCodes ut on PFP_CC_ID_UNITTYPE = ut.CC_ID                         
 left outer join CommonCodes e1 on PFP_Extra1 = e1.CC_ID                         
 left outer join CommonCodes e2 on PFP_Extra2 = e2.CC_ID                         
 left outer join CommonCodes e3 on PFP_Extra3 = e3.CC_ID                
 left join apartment_complexes  e4 on ac_uid = e4.uid                          
WHERE               
     AC_UID = @uid and PFP_Deleted = 0                     
    ORDER BY  PFP_NumBed,PFP_NumBath,PFP_SqFt                     
     END         
     DECLARE @unique_floor table                       
     (                       
      PFP_NumBed tinyint           
     )                  
   insert into @unique_floor                       
   SELECT distinct PFP_NumBed FROM @temptable                    
   declare @min int                       
   declare @max int          
   declare @temp1 table                       
  (                       
  UID int,                   
 AC_UID int ,                   
 PFP_CC_ID_UNITTYPE int ,                   

 price varchar(50) , 
 bath varchar(10)  
  )                    
  set @min=(Select min(PFP_NumBed) from @unique_floor)          
  set @max=(Select max(PFP_NumBed) from @unique_floor)          
           
  While (@min<=@max)                       
  BEGIN                       
    PRINT @min            
  insert into @temp1                  
  SELECT TOP 1 * FROM @temptable where PFP_NumBed =@min   
  
   
  order by uid desc          
  SET @min=(SELECT min(112) from @unique_floor where PFP_NumBed>@min)          
  END                       
  SELECT *,         
CASE  
     
WHEN  cgecj = 6 THEN '6 12(s)'          
END AS 12
  FROM @temp1