Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
During my rdlc development client demand that base on total beats ,then there is employee available then put it ,or else put empty row ,i am using following code,but problem is that same employee is repeated, i thought that if we remove employee from the list when it is used,then it could be done.
C#
int SecBeat2 = _service.GetBeatBySector_Id(sectorId).Count();
           for (int i = 1; i <= SecBeat2; i++ )
           {
               var bsec4 = _service.GetAllBeatStatus().Where(x => x.Date == dt && x.Sector_Id == sectorId && x.Shift == 1).FirstOrDefault();

               if (bsec4 != null)
               {

                   Employee emp = _service.GetEmployee(bsec4.Employee_Id);
                   Beat beat = beats.FirstOrDefault(x => x.Id == bsec4.Beat_Id && x.Sector_Id == sectorId);
                   dataset.Beat.Rows.Add(
                     emp.Name,
                      emp.Id,
                      emp.CellNo
                       //bs1.HasWireless
              );


               }
               else
               {

                       dataset.Beat.Rows.Add("", "", "");


               }
           }
Posted

1 solution

Didn't we already seen this?

Try this:

C#
int SecBeat2 = _service.GetBeatBySector_Id(sectorId).Count();
            for (int i = 1; i <= SecBeat2; i++ )
            {
                var bsec4 = _service.GetAllBeatStatus().Where(x => x.Date == dt && x.Sector_Id == sectorId && x.Shift == 1).FirstOrDefault();
               
                if (bsec4 != null)
                {
                    
                    Employee emp = _service.GetEmployee(bsec4.Employee_Id);
                    Beat beat = beats.FirstOrDefault(x => x.Id == bsec4.Beat_Id && x.Sector_Id == sectorId);
            if (emp != null)
                    dataset.Beat.Rows.Add(
                      emp.Name,
                       emp.Id,
                       emp.CellNo
                        //bs1.HasWireless
            else
                dataset.Beat.Rows.Add("", "", "");
               );
                  
 
                }
            }


If your emp query returns default (probably null, adjust if it is not so) you will add empty row. If it finds the employee it will add it normally (assuming you have all needed objects ready (dataset) )

Good luck
 
Share this answer
 
Comments
Sajid227 15-Mar-15 4:07am    
i tried your code but problem is that it repeat same employee.i want that if there are 5 beats, and 4 emp are available ,then it fillup them,for last beat there will be a blank row against it.
Sinisa Hajnal 16-Mar-15 3:00am    
Then don't use firstOrDefault for beats, use some loop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900