private void btnStart_Click(object sender, EventArgs e)
        {
            if (btnStart.Text == "Start")
            {

                pnlops.Controls.Clear();
                Employee emp = new Employee();
                //1-Tabaco Lab
                //2-Central Office
                //3-Legazpi
                //4-Ligao
                //5-Polangui
                emp.branch = "2";// LOAD CENTRAL EMPLOYEES
                //DataTable empdt = emp.SELECT_ALL();
                DataTable empdt = emp.SELECT_BY_BRANCH();

                if (empdt != null)
                {
                    label1.Text = "Payroll Generator : FROM :" + cutoff.from_date.ToShortDateString() + " - " + cutoff.to_date.ToShortDateString() + " Total Employee [" + empdt.Rows.Count.ToString() + "]";

                    foreach (DataRow dr in empdt.Rows)
                    {

                        String empid = dr["empid"].ToString();

                        emp_payroll_new ep = new emp_payroll_new();
                        ep.cutoff = cutoff;
                        ep.cutoffdetailsdt = cutoffdetailsdt;
                        ep.empid = empid; ;
                        ep.Dock = DockStyle.Top;
                        ep.Width = pnlops.Width - 40;

                        pnlops.Controls.Add(ep);

                    }
                }
                else
                {
                    MessageBox.Show("EMPLOYEE BY BRANCH NOT WORKING...");
                }

                btnStart.Text = "Print";
            }
            else {

                frmCutoffAttendanceReport frm = new frmCutoffAttendanceReport();

                frm.cutoff_date_from = cutoff.from_date;
                frm.cutoff_date_to = cutoff.to_date;
                frm.cutoffdetailsdt = cutoffdetailsdt;

                frm.ShowDialog();

                btnStart.Text = "Start";
            }
        }
        private void frmCutoffAttendanceReport_Load(object sender, EventArgs e)
        {
            this.rptViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
            this.rptViewer.LocalReport.DataSources.Clear();

            string path = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();
            var directory = System.IO.Path.GetDirectoryName(path);
            directory += "\\reports\\atttendance_cutoff.rdlc";

            //C:\projects\MMG-PIAPS\MMG-PIAPS\bin\Debug\reports\cutoff_attendance.rdlc
            //C:\projects\MMG-PIAPS\MMG-PIAPS\bin\Debug\reports\atttendance_cutoff.rdlc
            this.rptViewer.LocalReport.ReportPath = directory;

            //MessageBox.Show(directory);

            Employee emp = new Employee();
            emp.branch = "2";

            DataTable dt = emp.SELECT_BY_BRANCH();

            DataSet1 ds = new DataSet1();
            cutoffdt = ds.Tables["cutoffattendance"];

            //CREATE AN IMAGE COLUMN
            //SET THE IMAGE VALUE
            //THEN ADD TO DATASET FOR REPORT REFERENCE
            DataColumn colByteArray = new DataColumn("emp_img");
            colByteArray.DataType = System.Type.GetType("System.Byte[]");
            dt.Columns.Add(colByteArray);

            foreach (DataRow item in dt.Rows) {

                Employee e1 = new Employee();
                e1.empid = item["empid"].ToString();
                item["emp_img"] = e1.GET_IMAGE_BY_ID();

                //=====================================

                //FOR SUBREPORT DATASOURCE
                //POPULATE THE DATASET, FOR SUBREPORT USAGE
                //WITH THE EMPLOYEE'S ATTENDANCE FROM BIOMETRICS
                //THEN CHECKS THE ATTENDANCE WHETHER GOOD (IN,OUT,IN,OUT)
                //OR INAPPROPRIATE (IN ONLY, OR (IN, OUT, IN), OR (IN,OUT,OUT,IN,OUT)
                //AND OTHER IMPROPER ATTENDANCE LOGS
                int x = 1;
                foreach (DataRow cutoffitem in cutoffdetailsdt.Rows)
                {

                    DataRow c = cutoffdt.NewRow();

                    DateTime d = Convert.ToDateTime(cutoffitem["date_"].ToString());
                    c.BeginEdit();
                    c["empid"] = e1.empid;
                    c["no"] = x;
                    c["date_"] = d.ToString("MM/dd/yyyy");

                    //CRREATE A DYNAMIC CONNECTION TO DB
                    non_static_dbcon cn = new non_static_dbcon();

                    //COMPARE CUTOFF DATE WITH ATTENDANCE HERE
                    //==============================================
                    String attendance;

                    String status;

                    if (cn.CONNECT())
                    {
                        Attendance att = new Attendance();
                        att.empid = e1.empid;

                        attendance = att.SELECT_STR_BY_EMPID_BY_DATE(d, cn);

                        String[] attarr= attendance.Split(',');

                        if (attendance != "")
                        {
                            if ((attarr.Length == 3) || (attarr.Length > 4))
                            {
                                status = "INAPPROPRIATE";
                            }
                            else if ((attarr.Length == 2) || attarr.Length == 4)
                            {
                                status = "GOOD";
                            }
                            else {
                                status = "INAPPROPRIATE";
                            }
                        }
                        else {
                            status = "";
                        }

                    }
                    else {
                        attendance = "";
                        status = "";
                    }

                    cn.DISCONNECT();

                    c["attendance_"] = attendance;
                    //===============================================
                    c["day_type"] = cutoffitem["day_type"].ToString();

                    c["status_"] = status;
                    cutoffdt.Rows.Add(c);

                    x++;
                }

                //=====================================
            }//end foreach item in dt.rows
            ReportDataSource r = new ReportDataSource("DataSet1", dt);

            this.rptViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);

            //SET REPORT PARAMETER
            ReportParameter from_date = new ReportParameter("cutoff_date_from", cutoff_date_from.ToString("MM/dd/yyyy"));
            ReportParameter to_date = new ReportParameter("cutoff_date_to", cutoff_date_to.ToString("MM/dd/yyyy"));

            rptViewer.LocalReport.SetParameters(from_date);
            rptViewer.LocalReport.SetParameters(to_date);

            this.rptViewer.LocalReport.DataSources.Add(r);

               // this.rptViewer.SetDisplayMode(DisplayMode.PrintLayout);
            this.rptViewer.RefreshReport();
        }