Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 101.7k

how to combine two table in rdlc

Dec 20 2014 12:53 PM
                 protected void Roaster_Click(object sender, EventArgs e)
        {
            int sectorId = SafeConvert.ToInt32(ddlsectorRoaster.SelectedValue);
            var beats = _service.GetBeatBySector_Id(sectorId);
            var points = _service.GetDutyPointBySector_Id(sectorId);
            DateTime date = SafeConvert.ToDateTime(txtDate.Text);
           // var EmpDuty = _service.GetEmployeeDutyByToSector_Id(sectorId);
             // var employee = _service.GetAllEmployee();
            //var hasWirles =_service.GetEmployeeDutyByToSector_Id(sectorId).Where(x=>x.HasWireless = true);
            var employees = _service.GetEmployeeStatusBySector_Id(sectorId).Where(x => x.EndDate >= date && x.IsDutiable).ToList();

            for (int category = 1; category <= 3; category++)
            {
                var categorizedBeats = beats.Where(x => x.Category_Id == category);
                foreach (var beat in categorizedBeats)
                {
                    if (beat.EmployeeShift_Id == 4)
                    {
                        var emp1 = employees.FirstOrDefault();
                        var emp2 = employees.FirstOrDefault();

                        if (emp1 != null)
                        {
                            BeatStatus beatStatus1 = new BeatStatus();
                            beatStatus1.Date = date;
                            beatStatus1.Employee_Id = emp1.Employee_Id;
                            beatStatus1.HasWireless = true;
                            beatStatus1.Shift = 1;
                            beatStatus1.Beat_Id = beat.Id;
                            employees.Remove(emp1);
                        }

                        if (emp2 != null)
                        {
                            BeatStatus beatStatus2 = new BeatStatus();
                            beatStatus2.Date = date;
                            beatStatus2.Employee_Id = emp2.Employee_Id;
                            beatStatus2.HasWireless = true;
                            beatStatus2.Shift = 2;
                            beatStatus2.Beat_Id = beat.Id;
                            employees.Remove(emp2);
                        }
                    }
                    else
                    {
                        var emp1 = employees.FirstOrDefault();
                        if (emp1 != null)
                        {
                            BeatStatus beatStatus = new BeatStatus();
                            beatStatus.Date = date;
                            beatStatus.Employee_Id = emp1.Employee_Id;
                            beatStatus.HasWireless = true;
                            beatStatus.Shift = beat.EmployeeShift_Id;
                            beatStatus.Beat_Id = beat.Id;
                            employees.Remove(emp1);
                        }
                    }
                }

                var categorizedPoints = points.Where(x => x.Category_Id == category);
                foreach (var point in categorizedPoints)
                {
                    if (point.EmployeeShift_Id == 4)
                    {

                        for (int i = 1; i <= point.NoOfMinEmployes; i++)
                        {
                            var emp1 = (i == 1 && point.NoOfMinWirlessEmp == 1) ? employees.FirstOrDefault(x => x.HasWirles) : employees.FirstOrDefault();
                            //var emp1 = employees.FirstOrDefault();
                            if (emp1 != null)
                            {
                                DutyPointStatus pointStatus1 = new DutyPointStatus();
                                pointStatus1.Date = date;
                                pointStatus1.Employee_Id = emp1.Employee_Id;
                                pointStatus1.HasWireless = true;
                                pointStatus1.Shift = 1;
                                pointStatus1.DutyPoint_Id = point.Id;
                                employees.Remove(emp1);
                            }

                            var emp2 = employees.FirstOrDefault();
                            if (emp2 != null)
                            {
                                DutyPointStatus pointStatus2 = new DutyPointStatus();
                                pointStatus2.Date = date;
                                pointStatus2.Employee_Id = emp2.Employee_Id;
                                pointStatus2.HasWireless = true;
                                pointStatus2.Shift = 2;
                                pointStatus2.DutyPoint_Id = point.Id;
                                employees.Remove(emp2);
                            }
                        }
                    }
                    else
                    {
                        var emp1 = employees.FirstOrDefault();
                        if (emp1 != null)
                        {
                            DutyPointStatus pointStatus = new DutyPointStatus();
                            pointStatus.Date = date;
                            pointStatus.Employee_Id = emp1.Employee_Id;
                            pointStatus.HasWireless = true;
                            pointStatus.Shift = point.EmployeeShift_Id;
                            pointStatus.DutyPoint_Id = point.Id;
                            employees.Remove(emp1);
                        }
                    }
                 
                    CTPRoasterDataSet dataset = new CTPRoasterDataSet();
                    Employee Emp = new Employee();
                    EmployeeDuty EmpDuty = new EmployeeDuty();
                        foreach (Beat beat in beats)
                        {

                            dataset.Beat.Rows.Add
                            (
                             beat.Name,beat.ShiftName,EmpDuty.Employee_Id,Emp.CellNo,Emp.Name
                            );
                        }
                        foreach (DutyPoint dutypoint in points)
                        {
                            dataset.Point.Rows.Add(point.Beat_Id, point.Description, Emp.CellNo, Emp.Name, EmpDuty.Employee_Id,point.EmployeeShift_Id);
                        }
                        ReportDataSource datasource = new ReportDataSource("BeatDataSet", (DataTable)dataset.Beat);
                        ReportDataSource datasource1 = new ReportDataSource("PointDataSet", (DataTable)dataset.Point);

                        ReportViewer2.LocalReport.DataSources.Clear();
                        ReportViewer2.LocalReport.DataSources.Add(datasource);
                        ReportViewer2.LocalReport.DataSources.Add(datasource1);
                        ReportViewer2.LocalReport.Refresh();
                    }
                }
            }
        }
    }

Here beat.Name,beat.ShiftName are from beat table that are showing in report,but next EmpDuty.Employee_Id,Emp.CellNo,Emp.Name are from two other table that are not showing in the report??how can i get value from these table as well for the report?/