private void ListFilteredLeave(string mnthyr) { try { DateTime dttemp = DateTime.Now; grdList.Rows.Clear(); grdList.Columns.Clear(); int status = 0; ReportAttendanceDB sdb = new ReportAttendanceDB(); grdList.Columns.Add("EmployeeID", "EmployeeID"); grdList.Columns.Add("EmployeeName", "Employee Name"); grdList.Columns["EmployeeID"].Frozen = true; grdList.Columns["EmployeeName"].Frozen = true; List <reportattendence> timings = sdb.getcompanydata(); reportattendence st = timings.FirstOrDefault(W => W.DataID == "OfficeOpenTime"); reportattendence et = timings.FirstOrDefault(W => W.DataID == "OfficeCloseTime"); DateTime EntrydateTime = Convert.ToDateTime(st.DataValue); DateTime ExitdateTime = Convert.ToDateTime(et.DataValue); List <DateTime> dates = GetDates(dtMonth.Value.Month, dtMonth.Value.Year); // get days for selected month and year 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; } } List <reportattendence> empllist = sdb.getEmployeeList(); // get list of employee in NVP foreach (reportattendence emp in empllist) { grdList.Rows.Add(); grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeID"].Value = Convert.ToInt32(emp.EmployeeID); grdList.Rows[grdList.Rows.Count - 1].Cells["EmployeeName"].Value = emp.EmployeeName; } int i = 0; string[] yrnmth = monthyr.Split('-'); List <reportattendence> presentlist = sdb.getEmployeePresentListnew(yrnmth[0], yrnmth[1]); // gets list of employee in biometric List <reportattendence> leavelist = sdb.getEmployeeLeaveList(yrnmth[0], yrnmth[1]); //gets list of leave for that particular month and year List <reportattendence> MRlist = sdb.getMrList(yrnmth[0], yrnmth[1]); //gets list of employee movement register foreach (DataGridViewColumn dgvc in grdList.Columns) { int j = 0; //no of rows if (i > 1) //after 2 columns { while (j < grdList.RowCount) //for employees { int stat = 0; int Instat = 0; DateTime date = Convert.ToDateTime(dgvc.Name); string empid = grdList.Rows[j].Cells["EmployeeID"].Value.ToString(); reportattendence leavels = leavelist.Where(W => W.EmployeeID == empid).FirstOrDefault (dt => date >= dt.fromdate && date <= dt.todate); ///check leave for employee for that particular date reportattendence mr = MRlist.Where (W => W.EmployeeID == empid && W.outime.ToString("yyyy-MM-dd") == dgvc.Name).FirstOrDefault(dt => dt.outime.ToString("yyyy-MM-dd") == dgvc.Name); if (leavels != null) { stat = 1; status = 1; } List <reportattendence> rpList = presentlist.Where (w => w.EmployeeID == empid && w.Etime.Date.ToString("yyyy-MM-dd") == dgvc.Name).ToList();// check if employee is present if (rpList.Count != 0) { status = 2; if (stat == 1) { status = 3; } reportattendence reprtlate = rpList.OrderBy(W => W.Etime.TimeOfDay).FirstOrDefault(); // check if employee entered Late if (reprtlate.Etime.TimeOfDay > EntrydateTime.TimeOfDay) { status = 4; Instat = 1; if (mr != null) { if (mr.PlannedIntime.TimeOfDay > EntrydateTime.TimeOfDay && mr.PlannedIntime.TimeOfDay < ExitdateTime.TimeOfDay) { if (mr.Intime != null && (mr.Intime.TimeOfDay < ExitdateTime.TimeOfDay && mr.Intime.TimeOfDay > EntrydateTime.TimeOfDay)) { Instat = 0; status = 13; } } } if (stat == 1) { status = 5; if (mr != null) { if (mr.PlannedIntime.TimeOfDay > EntrydateTime.TimeOfDay && mr.PlannedIntime.TimeOfDay < ExitdateTime.TimeOfDay) { if (mr.Intime != null && (mr.Intime.TimeOfDay < ExitdateTime.TimeOfDay && mr.Intime.TimeOfDay > EntrydateTime.TimeOfDay)) { Instat = 0; status = 14; } } } } } reportattendence replastExit = rpList.OrderByDescending(W => W.Etime.TimeOfDay).FirstOrDefault(); // check if employee left early if (replastExit.Etime.TimeOfDay < ExitdateTime.TimeOfDay) { status = 6; if (mr != null) { if (mr.outime.TimeOfDay < ExitdateTime.TimeOfDay) { if (mr.Intime == DateTime.MinValue || mr.Intime.TimeOfDay > ExitdateTime.TimeOfDay) { status = 15; } } } if (stat == 1 && Instat == 1) { status = 8; if (mr != null) { if (mr.outime.TimeOfDay < ExitdateTime.TimeOfDay) { if (mr.Intime == DateTime.MinValue || mr.Intime.TimeOfDay > ExitdateTime.TimeOfDay) { status = 17; // MR:if employee left early and in MR and was late to office } } } } else if (stat == 1) { status = 7; if (mr != null) { if (mr.outime.TimeOfDay < ExitdateTime.TimeOfDay) { if (mr.Intime == DateTime.MinValue || mr.Intime.TimeOfDay > ExitdateTime.TimeOfDay) { status = 16; } } } } if (Instat == 1) { status = 9; if (mr != null) { if (mr.outime.TimeOfDay < ExitdateTime.TimeOfDay) { if (mr.Intime == DateTime.MinValue || mr.Intime > ExitdateTime) { status = 18; } } } } } if (replastExit.Etime.TimeOfDay == reprtlate.Etime.TimeOfDay) // check if employee has single punch { status = 10; if (mr != null) { if ((mr.outime.TimeOfDay > EntrydateTime.TimeOfDay && mr.PlannedIntime.TimeOfDay > ExitdateTime.TimeOfDay) || (mr.outime.TimeOfDay > EntrydateTime.TimeOfDay && mr.Intime.TimeOfDay > ExitdateTime.TimeOfDay)) { status = 19;// for single punch on MR } } if (stat == 1) { status = 11; if (mr != null) { if ((mr.outime.TimeOfDay > EntrydateTime.TimeOfDay && mr.PlannedIntime.TimeOfDay > ExitdateTime.TimeOfDay) || (mr.Intime.TimeOfDay > EntrydateTime.TimeOfDay && mr.Intime.TimeOfDay > ExitdateTime.TimeOfDay)) { status = 20; } } } } } else if (stat != 1) // if employee absent { status = 12; if (mr != null) { status = 21; // no punch but has MR } } setcolor(status, j, dgvc.Name); j++; } } i++; } grdList.DefaultCellStyle.NullValue = ""; grdList.Visible = true; grdList.Visible = true; pnlgrdList.Visible = true; } catch (Exception ex) { MessageBox.Show("Error in Attendence listing"); } }
private void grdList_CellClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex < 2) { return; } ReportAttendanceDB sdb = new ReportAttendanceDB(); reportattendence empllist = new reportattendence(); string grdrow = grdList.Rows[e.RowIndex].Cells["EmployeeID"].Value.ToString(); string empname = grdList.Rows[e.RowIndex].Cells["EmployeeName"].Value.ToString(); Color color = grdList.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor; string date = grdList.Columns[e.ColumnIndex].Name; empllist = sdb.getEmployeeLatenEarlyList(date, grdrow); if (empllist.EmployeeID != null) { if (color != Color.Violet && color != Color.BlueViolet) { if (empllist.EntryTime.TimeOfDay == empllist.ExitTime.TimeOfDay) { string empdetail = "Employee ID : " + empllist.EmployeeID + "\n" + "Employee Name : " + empname + "\n" + "Date : " + empllist.EntryTime.Date.ToString("dd-MM-yyyy") + "\n" + "Entry Time : " + empllist.EntryTime.TimeOfDay + ""; DialogResult dialog = MessageBox.Show(empdetail, "Attendence Details", MessageBoxButtons.OK); if (dialog == DialogResult.OK) { this.DialogResult = DialogResult.Cancel; } } else { string empdetail = "Employee ID : " + empllist.EmployeeID + "\n" + "Employee Name : " + empname + "\n" + "Date : " + empllist.EntryTime.Date.ToString("dd-MM-yyyy") + "\n" + "Entry Time : " + empllist.EntryTime.TimeOfDay + "\n" + "Exit Time : " + empllist.ExitTime.TimeOfDay + ""; DialogResult dialog = MessageBox.Show(empdetail, "Attendence Details", MessageBoxButtons.OK); if (dialog == DialogResult.OK) { this.DialogResult = DialogResult.Cancel; } } } else { string empdetail = "Employee ID : " + empllist.EmployeeID + "\n" + "Employee Name : " + empname + "\n" + "Date : " + empllist.EntryTime.Date.ToString("dd-MM-yyyy") + "\n" + "Entry Time : " + empllist.EntryTime.TimeOfDay + ""; DialogResult dialog = MessageBox.Show(empdetail, "Attendence Details", MessageBoxButtons.OK); if (dialog == DialogResult.OK) { this.DialogResult = DialogResult.Cancel; } } } else { string empdetail = "Employee ID : " + grdrow + "\n" + "Employee Name : " + empname + "\n" + "Date : " + date + "\n" + "Entry Time : \n" + "Exit Time : "; DialogResult dialog = MessageBox.Show(empdetail, "Attendence Details", MessageBoxButtons.OK); if (dialog == DialogResult.OK) { this.DialogResult = DialogResult.Cancel; } } //if(empllist.EntryTime.Date.TimeOfDay==empllist.ExitTime.Date.TimeOfDay) //{ // string empdetail = "Employee ID : " + empllist.EmployeeID + "\n" + // "Employee Name : " + empname + "\n" + // "Date : " + empllist.EntryTime.Date.ToString("dd-MM-yyyy") + "\n" + // "Entry Time : " + empllist.EntryTime.TimeOfDay + ""; // DialogResult dialog = MessageBox.Show(empdetail, "Attendence Details", MessageBoxButtons.OK); // if (dialog == DialogResult.OK) // { // this.DialogResult = DialogResult.Cancel; // } //} grdList.ClearSelection(); } catch (Exception ex) { } }