private void cellExitThree_TextChanged(object sender, TextChangedEventArgs e) { DailyMarking dailyMarking = ((FrameworkElement)sender).DataContext as DailyMarking; if (dailyMarking.exitThree != null) { String formated = Formatter.getInstance.formatHour(dailyMarking.exitThree); if ((!dailyMarking.exitThree.Equals(formated) && formated.Contains(":")) || "".Equals(formated)) { TimeSpan result; if (TimeSpan.TryParse(formated, out result)) { dailyMarking.exitThree = formated; resetDayOff(dailyMarking); GDScheduleDays.Items.Refresh(); } else { dailyMarking.exitThree = ""; GDScheduleDays.Items.Refresh(); } } } }
private void resetDayOff(DailyMarking dm) { if ("FOLGA".Equals(dm.entryOne)) { dm.entryOne = ""; } if ("FOLGA".Equals(dm.exitOne)) { dm.exitOne = ""; } if ("FOLGA".Equals(dm.entryTwo)) { dm.entryTwo = ""; } if ("FOLGA".Equals(dm.exitTwo)) { dm.exitTwo = ""; } if ("FOLGA".Equals(dm.entryThree)) { dm.entryThree = ""; } if ("FOLGA".Equals(dm.exitThree)) { dm.exitThree = ""; } }
private void setFieldsByMarkings(DailyMarking dm) { if (dm.markings.Count >= 1) { Marking mk = dm.markings[0]; dm.entryOne = Convert.ToString(mk.hour).PadLeft(2, '0') + ":" + Convert.ToString(mk.minute).PadLeft(2, '0'); } if (dm.markings.Count >= 2) { Marking mk = dm.markings[1]; dm.exitOne = Convert.ToString(mk.hour).PadLeft(2, '0') + ":" + Convert.ToString(mk.minute).PadLeft(2, '0'); } if (dm.markings.Count >= 3) { Marking mk = dm.markings[2]; dm.entryTwo = Convert.ToString(mk.hour).PadLeft(2, '0') + ":" + Convert.ToString(mk.minute).PadLeft(2, '0'); } if (dm.markings.Count >= 4) { Marking mk = dm.markings[3]; dm.exitTwo = Convert.ToString(mk.hour).PadLeft(2, '0') + ":" + Convert.ToString(mk.minute).PadLeft(2, '0'); } if (dm.markings.Count >= 5) { Marking mk = dm.markings[4]; dm.entryThree = Convert.ToString(mk.hour).PadLeft(2, '0') + ":" + Convert.ToString(mk.minute).PadLeft(2, '0'); } if (dm.markings.Count >= 6) { Marking mk = dm.markings[5]; dm.exitThree = Convert.ToString(mk.hour).PadLeft(2, '0') + ":" + Convert.ToString(mk.minute).PadLeft(2, '0'); } }
public static Boolean testRestrictionModification(string restriction, DailyMarking dm) { Boolean modified = false; if (!restriction.Equals(dm.entryOne) && dm.entryOne != null) { modified = true; } else if (!restriction.Equals(dm.exitOne) && dm.exitOne != null) { modified = true; } else if (!restriction.Equals(dm.entryTwo) && dm.entryTwo != null) { modified = true; } else if (!restriction.Equals(dm.exitTwo) && dm.exitTwo != null) { modified = true; } else if (!restriction.Equals(dm.entryThree) && dm.entryThree != null) { modified = true; } else if (!restriction.Equals(dm.exitThree) && dm.exitThree != null) { modified = true; } return(modified); }
private async void cellExitThree_TextChanged(object sender, TextChangedEventArgs e) { DailyMarking dailyMarking = ((FrameworkElement)sender).DataContext as DailyMarking; String formated = Formatter.getInstance.formatHour(dailyMarking.exitThree); if ((!dailyMarking.exitThree.Equals(formated) && formated.Contains(":")) || "".Equals(formated)) { TimeSpan result; if (TimeSpan.TryParse(formated, out result)) { dailyMarking.exitThree = formated; AddJustificationMessageDialog addJustificationMessageDialog = new AddJustificationMessageDialog(); Justification justification = (Justification)await DialogHost.Show(addJustificationMessageDialog, "DHMain"); if (justification != null && dailyMarking.markings.Count > 0) { dailyMarking.markings[5].idJustification = justification.idJustification; } GDScheduleDays.Items.Refresh(); } else { dailyMarking.exitThree = ""; GDScheduleDays.Items.Refresh(); } } }
private Dictionary <DateTime, DailyMarking> createDictionaryDates(Employee employee, DateTime startDate, DateTime endDate) { Dictionary <DateTime, DailyMarking> dicDates = new Dictionary <DateTime, DailyMarking>(); DateTime date = startDate; while (date.CompareTo(endDate) <= 0) { DailyMarking dm = new DailyMarking(employee, date); calculateHours(dm); dicDates.Add(date, dm); date = date.AddDays(1); } return(dicDates); }
public String dailyMarkingValidate(DailyMarking dm) { if (!MarkingUtil.isEmptyMarking(dm.entryOne) && !MarkingUtil.isEmptyMarking(dm.exitOne)) { if (TimeSpan.Parse(dm.exitOne).CompareTo(TimeSpan.Parse(dm.entryOne)) == -1) { return("Saída 1 menor que Entrada 1"); } } if (!MarkingUtil.isEmptyMarking(dm.exitOne) && !MarkingUtil.isEmptyMarking(dm.entryTwo)) { if (TimeSpan.Parse(dm.entryTwo).CompareTo(TimeSpan.Parse(dm.exitOne)) == -1) { return("Entrada 2 menor que Saída 1"); } } if (!MarkingUtil.isEmptyMarking(dm.exitTwo) && !MarkingUtil.isEmptyMarking(dm.entryTwo)) { if (TimeSpan.Parse(dm.exitTwo).CompareTo(TimeSpan.Parse(dm.entryTwo)) == -1) { return("Saída 2 menor que Entrada 2"); } } if (!MarkingUtil.isEmptyMarking(dm.entryThree) && !MarkingUtil.isEmptyMarking(dm.exitTwo)) { if (TimeSpan.Parse(dm.entryThree).CompareTo(TimeSpan.Parse(dm.exitTwo)) == -1) { return("Entrada 3 menor que Saída 2"); } } if (!MarkingUtil.isEmptyMarking(dm.exitThree) && !MarkingUtil.isEmptyMarking(dm.entryThree)) { if (TimeSpan.Parse(dm.exitThree).CompareTo(TimeSpan.Parse(dm.entryThree)) == -1) { return("Saída 3 menor que Entrada 3"); } } return(""); }
public List <DailyMarking> getMarkingCard(Employee employee, DateTime startDate, DateTime endDate) { List <DailyMarking> dailyMarkings = new List <DailyMarking>(); String pisPasep = employee.pisPasep.Replace(".", "").Replace("-", "").Replace(" ", ""); OleDbCommand cmd = DBConnection.getInstance.getDbCommand(); string commandText = "SELECT M.ID_MARKING, M.NSR, M.MARKING_COUNTER, M.PIS_PASEP, M.MARKING_DAY, M.MARKING_MONTH, M.MARKING_YEAR, M.MARKING_HOUR, M.MARKING_MINUTE FROM MARKING M " + "WHERE M.MARKING_DAY >= ? AND M.MARKING_DAY <= ? " + "AND M.MARKING_MONTH >= ? AND M.MARKING_MONTH <= ? " + "AND M.MARKING_YEAR >= ? AND M.MARKING_YEAR <=? " + "AND M.PIS_PASEP = ? AND ID_JUSTIFICATION IS NULL " + "ORDER BY M.MARKING_DAY, M.MARKING_MONTH, M.MARKING_YEAR, M.MARKING_HOUR, M.MARKING_MINUTE"; cmd.Parameters.Add("MARKING_DAY", OleDbType.Integer).Value = startDate.Day; cmd.Parameters.Add("MARKING_DAY", OleDbType.Integer).Value = endDate.Day; cmd.Parameters.Add("MARKING_MONTH", OleDbType.Integer).Value = startDate.Month; cmd.Parameters.Add("MARKING_MONTH", OleDbType.Integer).Value = endDate.Month; cmd.Parameters.Add("MARKING_YEAR", OleDbType.Integer).Value = startDate.Year; cmd.Parameters.Add("MARKING_YEAR", OleDbType.Integer).Value = endDate.Year; cmd.Parameters.Add("PIS_PASEP", OleDbType.VarChar).Value = pisPasep; cmd.CommandText = commandText; OleDbDataReader result = cmd.ExecuteReader(); if (result.HasRows) { int lastDay = -1; DailyMarking dailyMarking; List <Marking> markings = null; while (result.Read()) { if (lastDay == Convert.ToInt16(result[4])) { Marking marking = new Marking(); marking.idMarking = Convert.ToInt32(result[0]); marking.nsr = Convert.ToInt64(result[1]); marking.cont = Convert.ToInt64(result[2]); marking.pisPasep = Formatter.getInstance.formatPisPasep(result.GetString(3), ""); marking.day = Convert.ToInt16(result[4]); marking.month = Convert.ToInt16(result[5]); marking.year = Convert.ToInt16(result[6]); marking.hour = Convert.ToInt16(result[7]); marking.minute = Convert.ToInt16(result[8]); markings.Add(marking); } else { dailyMarking = new DailyMarking(); markings = new List <Marking>(); Marking marking = new Marking(); marking.idMarking = Convert.ToInt32(result[0]); marking.nsr = Convert.ToInt64(result[1]); marking.cont = Convert.ToInt64(result[2]); marking.pisPasep = Formatter.getInstance.formatPisPasep(result.GetString(3), "");; marking.day = Convert.ToInt16(result[4]); marking.month = Convert.ToInt16(result[5]); marking.year = Convert.ToInt16(result[6]); marking.hour = Convert.ToInt16(result[7]); marking.minute = Convert.ToInt16(result[8]); markings.Add(marking); dailyMarking.date = new DateTime(marking.year, marking.month, marking.day); dailyMarking.markings = markings; dailyMarking.employee = employee; dailyMarkings.Add(dailyMarking); lastDay = marking.day; } } } result.Close(); return(dailyMarkings); }
public List <DailyMarking> getDailyMarkings(Company company, Department department, Office office, Employee employee, Schedule schedule, DateTime date) { List <DailyMarking> dailyMarkings = new List <DailyMarking>(); OleDbCommand cmd = DBConnection.getInstance.getDbCommand(); string commandText = "SELECT E.ID_EMPLOYEE, E.PIS_PASEP, M.ID_MARKING, M.NSR, M.MARKING_COUNTER, M.PIS_PASEP, M.MARKING_DAY, M.MARKING_MONTH, M.MARKING_YEAR, M.MARKING_HOUR, M.MARKING_MINUTE FROM EMPLOYEE E LEFT JOIN MARKING M ON E.PIS_PASEP = M.PIS_PASEP "; Boolean where = false; if (company != null && !company.companyName.Equals("Todos")) { commandText += " WHERE ID_COMPANY=?"; cmd.Parameters.Add("ID_COMPANY", OleDbType.Integer).Value = company.idCompany; where = true; } if (department != null && !department.description.Equals("Todos")) { commandText += where ? " AND" : " WHERE"; commandText += " ID_DEPARTMENT=?"; cmd.Parameters.Add("ID_DEPARTMENT", OleDbType.Integer).Value = department.idDepartment; where = true; } if (office != null && !office.description.Equals("Todos")) { commandText += where ? " AND" : " WHERE"; commandText += " ID_OFFICE=?"; cmd.Parameters.Add("ID_OFFICE", OleDbType.Integer).Value = office.idOffice; where = true; } if (employee != null && !employee.employeeName.Equals("Todos")) { String pisPasep = employee.pisPasep.Replace(".", "").Replace("-", "").Replace(" ", ""); commandText += where ? " AND" : " WHERE"; commandText += " E.PIS_PASEP=?"; cmd.Parameters.Add("PIS_PASEP", OleDbType.VarChar).Value = pisPasep; where = true; } if (schedule != null && !schedule.description.Equals("Todos")) { commandText += where ? " AND" : " WHERE"; commandText += " E.ID_SCHEDULE=?"; cmd.Parameters.Add("E.ID_SCHEDULE", OleDbType.Integer).Value = schedule.idSchedule; where = true; } commandText += where ? " AND" : " WHERE"; commandText += " ID_JUSTIFICATION IS NULL"; commandText += " ORDER BY M.PIS_PASEP, M.MARKING_HOUR, M.MARKING_MINUTE"; cmd.CommandText = commandText; OleDbDataReader result = cmd.ExecuteReader(); if (result.HasRows) { string lastPisPasep = "-"; DailyMarking dailyMarking; List <Marking> markings = null; while (result.Read()) { if (lastPisPasep.Equals(result.GetString(1))) { if (date.Day == Convert.ToInt16(result[6]) && date.Month == Convert.ToInt16(result[7]) && date.Year == Convert.ToInt16(result[8])) { Marking marking = new Marking(); marking.idMarking = result[2] == DBNull.Value ? 0 : Convert.ToInt32(result[2]); marking.nsr = result[3] == DBNull.Value ? 0 : Convert.ToInt64(result[3]); marking.cont = result[4] == DBNull.Value ? 0 : Convert.ToInt64(result[4]); marking.pisPasep = result[5] == DBNull.Value ? "" : Formatter.getInstance.formatPisPasep(result.GetString(5), ""); marking.day = result[6] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[6]); marking.month = result[7] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[7]); marking.year = result[8] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[8]); marking.hour = result[9] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[9]); marking.minute = result[10] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[10]); markings.Add(marking); } } else { dailyMarking = new DailyMarking(); markings = new List <Marking>(); Marking marking = new Marking(); dailyMarking.employee = employeeControl.getEmployee(Convert.ToInt32(result[0])); dailyMarking.date = date; dailyMarking.markings = markings; if (result[2] != DBNull.Value && date.Day == Convert.ToInt16(result[6]) && date.Month == Convert.ToInt16(result[7]) && date.Year == Convert.ToInt16(result[8])) { marking.idMarking = result[2] == DBNull.Value ? 0 : Convert.ToInt32(result[2]); marking.nsr = result[3] == DBNull.Value ? 0 : Convert.ToInt64(result[3]); marking.cont = result[4] == DBNull.Value ? 0 : Convert.ToInt64(result[4]); marking.pisPasep = result[5] == DBNull.Value ? "" : Formatter.getInstance.formatPisPasep(result.GetString(5), ""); marking.day = result[6] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[6]); marking.month = result[7] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[7]); marking.year = result[8] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[8]); marking.hour = result[9] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[9]); marking.minute = result[10] == DBNull.Value ? (Int16)0 : Convert.ToInt16(result[10]); markings.Add(marking); } dailyMarkings.Add(dailyMarking); lastPisPasep = result.GetString(1); } } } result.Close(); return(dailyMarkings); }
public void calculateHours(DailyMarking dm) { setFieldsByMarkings(dm); List <DateTime> recessDates = recessControl.getAllRecessDates(); ScheduleDay scheduleDay = scheduleControl.getScheduleDay(dm.employee.schedule, MarkingUtil.getDayKey(dm.date.DayOfWeek)); Boolean usualDay = true; string entryTolerance = "0"; string exitTolerance = "0"; TimeSpan standartHoursTS = TimeSpan.Parse("00:00"); TimeSpan faultHoursTS = TimeSpan.Parse("00:00"); TimeSpan extraHoursTS = TimeSpan.Parse("00:00"); TimeSpan workloadTS = TimeSpan.Parse("00:00"); if (scheduleDay.workload != null && !"".Equals(scheduleDay.workload)) { if (absenceControl.getEmployeeInAbsence(dm.employee, dm.date)) { if (!MarkingUtil.testRestrictionModification("AFASTADO", dm)) { dm.entryOne = "AFASTADO"; dm.exitOne = "AFASTADO"; dm.entryTwo = "AFASTADO"; dm.exitTwo = "AFASTADO"; dm.entryThree = "AFASTADO"; dm.exitThree = "AFASTADO"; return; } else { usualDay = false; } } if (recessDates.Contains(dm.date)) { if (!MarkingUtil.testRestrictionModification("FERIADO", dm)) { dm.entryOne = "FERIADO"; dm.exitOne = "FERIADO"; dm.entryTwo = "FERIADO"; dm.exitTwo = "FERIADO"; dm.entryThree = "FERIADO"; dm.exitThree = "FERIADO"; return; } else { usualDay = false; } } if ("FOLGA".Equals(scheduleDay.workload)) { if (!MarkingUtil.testRestrictionModification("FOLGA", dm)) { dm.entryOne = "FOLGA"; dm.exitOne = "FOLGA"; dm.entryTwo = "FOLGA"; dm.exitTwo = "FOLGA"; dm.entryThree = "FOLGA"; dm.exitThree = "FOLGA"; return; } else { usualDay = false; } } if (usualDay) { workloadTS = TimeSpan.Parse(scheduleDay.workload); entryTolerance = scheduleDay.entryTolerance; exitTolerance = scheduleDay.exitTolerance; } if (dm.entryOne != null && dm.exitOne != null) { standartHoursTS += TimeSpan.Parse(dm.exitOne) - TimeSpan.Parse(dm.entryOne); } if (dm.entryTwo != null && dm.exitTwo != null) { standartHoursTS += TimeSpan.Parse(dm.exitTwo) - TimeSpan.Parse(dm.entryTwo); } if (dm.entryThree != null && dm.exitThree != null) { standartHoursTS += TimeSpan.Parse(dm.exitThree) - TimeSpan.Parse(dm.entryThree); } if (standartHoursTS != TimeSpan.Parse("00:00")) { if (scheduleDay.compensation) { if (standartHoursTS.CompareTo(workloadTS) > 0) { TimeSpan extra = standartHoursTS - workloadTS; if (extra.TotalMinutes > Convert.ToInt16(entryTolerance)) { extraHoursTS = extra; } else { standartHoursTS = workloadTS; } } else { TimeSpan fault = workloadTS - standartHoursTS; if (fault.TotalMinutes > Convert.ToInt16(exitTolerance)) { faultHoursTS = workloadTS - standartHoursTS; } else { standartHoursTS = workloadTS; } } } else { if (standartHoursTS.CompareTo(workloadTS) > 0) { extraHoursTS = standartHoursTS - workloadTS; } else { faultHoursTS = workloadTS - standartHoursTS; } } } else { if (scheduleDay.automaticDayOff) { dm.entryOne = "FOLGA"; dm.exitOne = "FOLGA"; dm.entryTwo = "FOLGA"; dm.exitTwo = "FOLGA"; dm.entryThree = "FOLGA"; dm.exitThree = "FOLGA"; standartHoursTS = TimeSpan.Parse("00:00"); faultHoursTS = TimeSpan.Parse("00:00"); extraHoursTS = TimeSpan.Parse("00:00"); workloadTS = TimeSpan.Parse("00:00"); return; } } dm.standartHours = standartHoursTS.ToString(@"hh\:mm"); dm.faultHours = faultHoursTS.ToString(@"hh\:mm"); dm.extraHours = extraHoursTS.ToString(@"hh\:mm"); dm.workload = workloadTS.ToString(@"hh\:mm"); } }
public void markingsUpdate(DailyMarking dm) { if (!MarkingUtil.isEmptyMarking(dm.entryOne)) { string[] time = dm.entryOne.Split(':'); if (dm.markings.Count >= 1) { dm.markings[0].hour = Convert.ToInt16(time[0]); dm.markings[0].minute = Convert.ToInt16(time[1]); } else { dm.markings.Add(new Marking(-1, -1, dm.employee.pisPasep, Convert.ToInt16(dm.date.Day), Convert.ToInt16(dm.date.Month), Convert.ToInt16(dm.date.Year), Convert.ToInt16(time[0]), Convert.ToInt16(time[1]))); } } if (!MarkingUtil.isEmptyMarking(dm.exitOne)) { string[] time = dm.exitOne.Split(':'); if (dm.markings.Count >= 2) { dm.markings[1].hour = Convert.ToInt16(time[0]); dm.markings[1].minute = Convert.ToInt16(time[1]); } else { dm.markings.Add(new Marking(-1, -1, dm.employee.pisPasep, Convert.ToInt16(dm.date.Day), Convert.ToInt16(dm.date.Month), Convert.ToInt16(dm.date.Year), Convert.ToInt16(time[0]), Convert.ToInt16(time[1]))); } } if (!MarkingUtil.isEmptyMarking(dm.entryTwo)) { string[] time = dm.entryTwo.Split(':'); if (dm.markings.Count >= 3) { dm.markings[2].hour = Convert.ToInt16(time[0]); dm.markings[2].minute = Convert.ToInt16(time[1]); } else { dm.markings.Add(new Marking(-1, -1, dm.employee.pisPasep, Convert.ToInt16(dm.date.Day), Convert.ToInt16(dm.date.Month), Convert.ToInt16(dm.date.Year), Convert.ToInt16(time[0]), Convert.ToInt16(time[1]))); } } if (!MarkingUtil.isEmptyMarking(dm.exitTwo)) { string[] time = dm.exitTwo.Split(':'); if (dm.markings.Count >= 4) { dm.markings[3].hour = Convert.ToInt16(time[0]); dm.markings[3].minute = Convert.ToInt16(time[1]); } else { dm.markings.Add(new Marking(-1, -1, dm.employee.pisPasep, Convert.ToInt16(dm.date.Day), Convert.ToInt16(dm.date.Month), Convert.ToInt16(dm.date.Year), Convert.ToInt16(time[0]), Convert.ToInt16(time[1]))); } } if (!MarkingUtil.isEmptyMarking(dm.entryThree)) { string[] time = dm.entryThree.Split(':'); if (dm.markings.Count >= 5) { dm.markings[4].hour = Convert.ToInt16(time[0]); dm.markings[4].minute = Convert.ToInt16(time[1]); } else { dm.markings.Add(new Marking(-1, -1, dm.employee.pisPasep, Convert.ToInt16(dm.date.Day), Convert.ToInt16(dm.date.Month), Convert.ToInt16(dm.date.Year), Convert.ToInt16(time[0]), Convert.ToInt16(time[1]))); } } if (!MarkingUtil.isEmptyMarking(dm.exitThree)) { string[] time = dm.exitThree.Split(':'); if (dm.markings.Count >= 6) { dm.markings[5].hour = Convert.ToInt16(time[0]); dm.markings[5].minute = Convert.ToInt16(time[1]); } else { dm.markings.Add(new Marking(-1, -1, dm.employee.pisPasep, Convert.ToInt16(dm.date.Day), Convert.ToInt16(dm.date.Month), Convert.ToInt16(dm.date.Year), Convert.ToInt16(time[0]), Convert.ToInt16(time[1]))); } } }