Example #1
0
        private void ListFilteredAttendanceList(DateTime month, string officeID)
        {
            try
            {
                grdList.Rows.Clear();
                grdList.Columns.Clear();
                AttendanceDB      Adb     = new AttendanceDB();
                List <DateTime>   dates   = GetDates(dtMonth.Value.Month, dtMonth.Value.Year); // get days for selected month and year
                List <attendance> AttStat = Adb.getEmployeeAttendanceList(month, officeID);
                if (AttStat.Count <= 0)
                {
                    MessageBox.Show("No data to show");
                    return;
                }
                grdList.Columns.Add("Slno", "Slno");
                grdList.Columns.Add("EmployeeID", "ID");
                grdList.Columns.Add("EmployeeName", "Employee Name");
                grdList.Columns.Add("Office", "Office");
                grdList.Columns["Slno"].Frozen         = true;
                grdList.Columns["EmployeeID"].Frozen   = true;
                grdList.Columns["EmployeeName"].Frozen = true;
                grdList.Columns["Office"].Frozen       = true;
                grdList.Columns["Slno"].Width          = 30;
                grdList.Columns["EmployeeID"].Width    = 50;
                foreach (DateTime dt in dates)
                {
                    //if (dt.Date < DateTime.Now)
                    //{
                    grdList.Columns.Add(dt.Date.ToString("yyyy-MM-dd"), dt.Date.ToString("dd"));
                    grdList.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    grdList.Columns[dt.Date.ToString("yyyy-MM-dd")].Width = 25;
                    //}
                }
                var emplst = AttStat.GroupBy(G => G.EmployeeID).Select(A => new
                {
                    EmployeeID   = A.Key,
                    EmployeeName = A.First().EmployeeName,
                    officeName   = A.First().officeName
                });
                foreach (var att in emplst)
                {
                    grdList.Rows.Add();
                    grdList.Rows[grdList.RowCount - 1].Cells["Slno"].Value         = grdList.RowCount;
                    grdList.Rows[grdList.RowCount - 1].Cells["EmployeeID"].Value   = Convert.ToInt32(att.EmployeeID);
                    grdList.Rows[grdList.RowCount - 1].Cells["EmployeeName"].Value = att.EmployeeName;
                    grdList.Rows[grdList.RowCount - 1].Cells["Office"].Value       = att.officeName;

                    foreach (DataGridViewColumn dgvc in grdList.Columns)
                    {
                        List <attendance> lst = AttStat.Where(x => x.EmployeeID == att.EmployeeID).ToList();
                        foreach (attendance lt in lst)
                        {
                            if (dgvc.Name == lt.StatusDate.ToString("yyyy-MM-dd"))
                            {
                                grdList.Rows[grdList.RowCount - 1].Cells[dgvc.Name].Value = getAtstatus(lt.AttendenceStatus);
                            }
                        }
                    }
                }

                if (grdList.Rows.Count != 0 && Main.itemPriv[1] == true && (Main.itemPriv[2] == true || Main.itemPriv[3] == true))
                {
                    btnExportToExcel.Visible = true;
                }
                else
                {
                    btnExportToExcel.Visible = false;
                }
                grdList.Visible    = true;
                pnlgrdList.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 3 : ListFilteredAttendanceListLeave() - " + ex.ToString());
            }
        }