Beispiel #1
0
        private void ListEmployee()
        {
            try
            {
                grdList.Visible = true;
                grdList.Rows.Clear();
                AttendanceDB      dbrecord     = new AttendanceDB();
                List <attendance> emplist      = new List <attendance>();
                List <attendance> empleavelist = new List <attendance>();
                List <attendance> empbiolist   = new List <attendance>();
                List <attendance> empMRlist    = new List <attendance>();
                int opt = 0;
                empstatuslist = new List <attendance>();
                if (Main.itemPriv[2])
                {
                    if (cmbfilterOffice.SelectedIndex != -1)
                    {
                        string officeid = ((Structures.ComboBoxItem)cmbfilterOffice.SelectedItem).HiddenValue;
                        emplist = dbrecord.getEmployeeListforoffice(officeid).OrderBy(x => x.EmployeeName).ToList();
                        if (dtpdate.Value.Date <= UpdateTable.getSQLDateTime().Date)
                        {
                            empstatuslist = dbrecord.getEmployeestatusListforoffice(officeid, dtpdate.Value);
                            if (empstatuslist.Count == 0)
                            {
                                empleavelist = dbrecord.getEmployeeLeaveList(dtpdate.Value);
                                empbiolist   = dbrecord.getEmployeeBiometricList(dtpdate.Value);
                                empMRlist    = dbrecord.getMrEmployeeList(dtpdate.Value);
                            }
                        }
                        else if (dtpdate.Value.Date > UpdateTable.getSQLDateTime().Date)
                        {
                            pnlEditButtons.Visible = false;
                            MessageBox.Show("Please select the date equal to or less than today!!!");
                            return;
                        }
                    }
                }
                else
                {
                    emplist       = dbrecord.getEmployeeList().OrderBy(x => x.EmployeeName).ToList();
                    empstatuslist = dbrecord.getEmployeestatusListforoffice(emplOfficeID, UpdateTable.getSQLDateTime());
                    if (empstatuslist.Count == 0)
                    {
                        empleavelist = dbrecord.getEmployeeLeaveList(UpdateTable.getSQLDateTime());
                        empbiolist   = dbrecord.getEmployeeBiometricList(UpdateTable.getSQLDateTime());
                        empMRlist    = dbrecord.getMrEmployeeList(UpdateTable.getSQLDateTime());
                    }
                }

                foreach (attendance elst in emplist)
                {
                    grdList.Rows.Add();
                    int kount = grdList.RowCount;
                    grdList.Rows[kount - 1].Cells["RowID"].Value        = kount;
                    grdList.Rows[kount - 1].Cells["EmployeeID"].Value   = Convert.ToInt32(elst.EmployeeID);
                    grdList.Rows[kount - 1].Cells["EmployeeName"].Value = elst.EmployeeName;
                    DataGridViewComboBoxCell cmbAttendanceStatus = (DataGridViewComboBoxCell)(grdList.Rows[kount - 1].Cells["AttendanceStatus"]);
                    CatalogueValueDB.fillCatalogValueGridViewComboNew(cmbAttendanceStatus, "AttendanceStatus");
                    attendance empstatlst = empstatuslist.FirstOrDefault(x => x.EmployeeID == elst.EmployeeID);
                    if (empstatlst == null)
                    {
                        attendance emplvlst  = empleavelist.FirstOrDefault(x => x.EmployeeID == elst.EmployeeID);
                        attendance empbiolst = empbiolist.FirstOrDefault(x => x.EmployeeID == elst.EmployeeID);
                        attendance empMRlst  = empMRlist.FirstOrDefault(x => x.EmployeeID == elst.EmployeeID);
                        if (emplvlst != null)
                        {
                            grdList.Rows[kount - 1].Cells["AttendanceStatus"].Value = "Leave";
                            Initval.Add(emplvlst.EmployeeID, "Leave");
                            changedval.Add(emplvlst.EmployeeID, "Leave");
                        }
                        else
                        {
                            if (empbiolst != null)
                            {
                                grdList.Rows[kount - 1].Cells["AttendanceStatus"].Value = "Present";
                                Initval.Add(empbiolst.EmployeeID, "Present");
                                changedval.Add(empbiolst.EmployeeID, "Present");
                            }
                            else if (empMRlst != null)
                            {
                                grdList.Rows[kount - 1].Cells["AttendanceStatus"].Value = "LocalTravel";
                                Initval.Add(empMRlst.EmployeeID, "LocalTravel");
                                changedval.Add(empMRlst.EmployeeID, "LocalTravel");
                            }
                        }
                    }
                    else
                    {
                        grdList.Rows[kount - 1].Cells["AttendanceStatus"].Value = empstatlst.AttendenceStatus;
                        Initval.Add(empstatlst.EmployeeID, empstatlst.AttendenceStatus);
                    }
                }
                pnlEditButtons.Visible = false;
                if (!Main.itemPriv[2])
                {
                    if (grdList.RowCount > 0 && UpdateTable.getSQLDateTime().Hour < 13)
                    {
                        pnlEditButtons.Visible = true;
                    }
                }
                else if (grdList.RowCount > 0)
                {
                    pnlEditButtons.Visible = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error");
            }
            enableBottomButtons();
            pnlMenuList.Visible = true;
        }