Tuesday, July 16, 2013

Steps to create Horizontal or pivoted table through rdlc report/asp.net/C# and if suppose selection is dynamic


 //I had a task where i need to display Zone,Areaname,DealerCode,DealerName,EmployeeCode,EmployeeName,Role and tricking part whatever course user selects it should only show that course and its course schedule time.
//For course selection i used Checkbox list

//Codebehind i put a condition for Checkbox selection

 if (chkLstSkill.SelectedValue == "")
                {
}
else
{
ReportViewerDealerStatus.Visible = true;                                                     //Reports Div is Enabled True
                    ReportViewerDealerStatus.Reset();
                    ReportViewerDealerStatus.ProcessingMode = ProcessingMode.Local;



                    ReportDataSource objRDS;
                    LocalReport objLRPT = new LocalReport();
                    objLRPT = ReportViewerDealerStatus.LocalReport;

                    //objLRPT.Refresh();

                    objLRPT.ReportPath = Server.MapPath("../RDLC/TrainingReadinessReport.rdlc");

                    //Set Reports Parametres                                                                                                           
                    ReportParameter[] p ={              
                               new ReportParameter("Title","Some Report")};
                    objLRPT.SetParameters(p);
                    objRDS = new ReportDataSource();

                    objRDS.Name = "DataSet1";
                    BusinessRptTrainingReadiness.Delete(new EntityRptTrainingReadiness
                    {
                        sessionid = Session.SessionID
                    });

                    // We perform a for loop to check if each checkbox is selected then we get the value
                    foreach (ListItem objItem in chkLstSkill.Items)
                    {
                        if (objItem.Selected)
                        {
                            values += objItem.Value;
                            TrainingID = values;
                        
                          //  BusinessRptTrainingReadiness obj
                    BusinessRptTrainingReadiness.Save(new EntityRptTrainingReadiness
                     {
                         TrainingID = TrainingID,
                        sessionid=Session.SessionID
                     });

                  
                    values = "";
                    TrainingID = "";
                  
                        }
                       // objLRPT.DataSources.Add(objRDS);
                        //divReport.Visible = true;
                        //ReportViewerDealerStatus.Visible = true;
                    }
                    sessionid = Session.SessionID;
                                     objRDS.Value = new BusinessRptTrainingReadiness().RptTrainingReadiness(ChannnelID, DealerID, AreaID, ZoneID, TrainingID, sessionid, Role); //Gets procedure from business logic

                    objLRPT.DataSources.Clear();
                    objLRPT.DataSources.Add(objRDS);
                    divReport.Visible = true;
                    ReportViewerDealerStatus.Visible = true;

}

//For this  first created a dummy table
Consisting of TrainingID and sessionid

on checkbox selection it first deleted all the content from the table for the sessionid and inserted user selection. and inside the procedure i call the trainingID from the table using 'in' clause example(MPT.TrainingId IN (select TrainingId from DumyTrainingReadiness where sessionid =@sessionid))







CREATE Procedure Sp_test      
@ChannelID nvarchar(100),       
@DealerID nvarchar(100),         
       
@AreaID nvarchar(100),         
       
@ZoneID nvarchar(100),        
       
@RoleID nvarchar(100),       
@TrainingID nvarchar(100),       
@sessionid nvarchar(100)       
       
as       
       
SELECT Distinct MZ.ZONE,MA.AREANAME as AO,D.Code as DealerCode,D.Name as DealerName,MP1.EmployeeCode,         
(MP1.FirstName + ' ' + MP1.LastName) as Name,MS.SkillName as empRole,MT.Code,MPT.TrainingCompletionDate              
FROM MAS_AREA MA            
INNER JOIN MAS_ZONE MZ ON MA.ZONEID=MZ.ID          
          
INNER JOIN DEALER D ON MA.ID=D.AREACODEID           
INNER JOIN DEALERLOCATION  DL ON D.ID=DL.DEALERID  and DL.IsActive=1         
INNER JOIN DEALERCHANNELMAPPING DM ON D.ID=DM.DEALERID and D.IsActive=1         
inner join ManPowerTraining MPT on DL.ID=MPT.ManPowerId and MPT.IsActive=1         
INNER JOIN LOCATIONMANPOWERASSOCIATON LMA ON LMA.MANPOWERID = MPT.MANPOWERID and  LMA.ENDDATE IS NULL           
inner join  ManPower MP1 on MP1.ID=MPT.ManPowerId and MP1.IsActive=1         
inner join  ManPowerExperience MPE1 on MP1.ID=MPE1.ManPowerId and MPE1.IsActive=1         
inner join  Mas_Skills MS on MS.ID=LMA.SkillID and MS.IsActive=1         
inner join Mas_Training MT on MT.ID=MPT.TrainingId and MT.IsActive=1        
where       
 MPT.TrainingId IN (select TrainingId from DumyTrainingReadiness where sessionid =@sessionid)  -- 23 --COTEK BAISC MODULE - PERSONAL         
 --AND MT.ISACTIVE = 1         
 and       
 (@RoleID=0 OR @RoleID=NULL OR MPE1.SKILLID =@RoleID)-- 8 --COTEK  (role)       
AND DM.CHANNELID=@ChannelID --20         
 AND (@AREAID=0 OR @AREAID=NULL OR MA.ID=@AREAID)         
 AND (@DEALERID=0 OR @DEALERID= NULL OR D.ID=@DEALERID)         
AND (@ZONEID=0 OR @ZONEID=NULL OR MZ.ID=@ZONEID)        
   --Area       
  --Dealer       
 --AND MZ.ID=@ZONEID  --Zone       
        
order BY MZ.ZONE,MA.AREANAME

//

in the rdlc design
use matrix table instead of normal table
Afterbinding it to dataset,in the properties of the matrix table select group by to some id ,in my case i used EmployeeCode.

No comments:

Post a Comment