/// <summary> /// Procedura calculeaza nr de ore lucrate de angajat pe luna /// </summary> /// <param name="luna">Luna pentru care se calculeaza</param> /// <returns>Returneaza nr de ore lucrate</returns> public TimeSpan GetAngajatNrOreLucrateLuna(int luna) { try { Data.PontajAngajat pa = new Data.PontajAngajat(settings.ConnectionString); DataSet ds = pa.GetAngajatNrOreLucrateLuna(angajatId, luna); return(TimpLuna(ds)); } catch { return(new TimeSpan(0)); } }
/// <summary> /// Preia intervalele libere dintr-o zi; sunt 2 cazuri: intervale libere din timpul zilei si weekend (8-22) /// si intervale din timpul noptii (22-6). /// </summary> /// <param name="oraMin"></param> /// <param name="oraMax"></param> /// <param name="data"></param> /// <returns></returns> public Data.IntervalOrar[] GetIntervaleLibereZi(int oraMin, int oraMax, DateTime data) { try { DateTime oraMinima = new DateTime(data.Year, data.Month, data.Day, oraMin, 0, 0); DateTime oraMaxima = new DateTime(data.Year, data.Month, data.Day, oraMax, 0, 0); Data.PontajAngajat pa = new Data.PontajAngajat(settings.ConnectionString); DataSet ds = pa.GetAngajatNrOreLucrateLuna(angajatId, data, data); DataView dv = new DataView(ds.Tables[0]); if (oraMin < oraMax) //cazul in care avem ore speciale normale (ziua in timpul saptamanii, weekend) { dv.RowFilter = "'" + oraMinima.ToString() + "'<OraStart and OraEnd<'" + oraMaxima.ToString() + "'"; dv.Sort = "OraStart"; //stabilirea numarului de intervale if (dv.Count > 0) { int intervalDimension = 0; if (oraMinima < (DateTime)dv[0]["OraStart"]) { intervalDimension++; } if (dv.Count > 1) { for (int i = 0; i < dv.Count - 1; i++) { if ((DateTime)dv[i]["OraEnd"] < (DateTime)dv[i + 1]["OraStart"]) { intervalDimension++; } } } if ((DateTime)dv[dv.Count - 1]["OraEnd"] < oraMaxima) { intervalDimension++; } Data.IntervalOrar [] intervalOrar = new Salaries.Data.IntervalOrar[intervalDimension]; //crearea de intervale int intervalIndex = 0; if (oraMinima < (DateTime)dv[0]["OraStart"]) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = oraMinima; intervalOrar[intervalIndex].OraEnd = (DateTime)dv[0]["OraStart"]; intervalIndex++; } if (dv.Count > 1) { for (int i = 0; i < dv.Count - 1; i++) { if ((DateTime)dv[i]["OraEnd"] < (DateTime)dv[i + 1]["OraStart"]) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = (DateTime)dv[i]["OraEnd"]; intervalOrar[intervalIndex].OraEnd = (DateTime)dv[i + 1]["OraStart"]; intervalIndex++; } } } if ((DateTime)dv[dv.Count - 1]["OraEnd"] < oraMaxima) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = (DateTime)dv[dv.Count - 1]["OraEnd"]; intervalOrar[intervalIndex].OraEnd = oraMaxima; } return(intervalOrar); } else { Data.IntervalOrar [] intervalOrar = new Salaries.Data.IntervalOrar[1]; intervalOrar[0].Data = data; intervalOrar[0].OraStart = oraMinima; intervalOrar[0].OraEnd = oraMaxima; return(intervalOrar); } } else //cazul in care avem ore suplimentare speciale (noaptea) { DateTime ora0 = new DateTime(data.Year, data.Month, data.Day, 0, 0, 0); DateTime ora24 = new DateTime(data.Year, data.Month, data.Day, 0, 0, 0); ora24 = ora24.AddDays(1); //intervalul de la 00:00 - 06:00 dv.RowFilter = "'" + ora0.ToString() + "'<=OraStart and OraEnd<='" + oraMaxima.ToString() + "'"; dv.Sort = "OraStart"; //stabilirea numarului de intervale int intervalDimension = 0; if (dv.Count > 0) { if (ora0 < (DateTime)dv[0]["OraStart"]) { intervalDimension++; } if (dv.Count > 1) { for (int i = 0; i < dv.Count - 1; i++) { if ((DateTime)dv[i]["OraEnd"] < (DateTime)dv[i + 1]["OraStart"]) { intervalDimension++; } } } if ((DateTime)dv[dv.Count - 1]["OraEnd"] < oraMaxima) { intervalDimension++; } } else { intervalDimension++; } //intervalul de la 22:00 - 24:00 dv.RowFilter = "'" + oraMinima.ToString() + "'<=OraStart and OraEnd<='" + ora24.ToString() + "'"; if (dv.Count > 0) { if (oraMinima < (DateTime)dv[0]["OraStart"]) { intervalDimension++; } if (dv.Count > 1) { for (int i = 0; i < dv.Count - 1; i++) { if ((DateTime)dv[i]["OraEnd"] < (DateTime)dv[i + 1]["OraStart"]) { intervalDimension++; } } } if ((DateTime)dv[dv.Count - 1]["OraEnd"] < ora24) { intervalDimension++; } } else { intervalDimension++; } //crearea de intervale Data.IntervalOrar [] intervalOrar = new Salaries.Data.IntervalOrar[intervalDimension]; dv.RowFilter = "'" + ora0.ToString() + "'<=OraStart and OraEnd<='" + oraMaxima.ToString() + "'"; int intervalIndex = 0; if (dv.Count > 0) { if (ora0 < (DateTime)dv[0]["OraStart"]) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = ora0; intervalOrar[intervalIndex].OraEnd = (DateTime)dv[0]["OraStart"]; intervalIndex++; } if (dv.Count > 1) { for (int i = 0; i < dv.Count - 1; i++) { if ((DateTime)dv[i]["OraEnd"] < (DateTime)dv[i + 1]["OraStart"]) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = (DateTime)dv[i]["OraEnd"]; intervalOrar[intervalIndex].OraEnd = (DateTime)dv[i + 1]["OraStart"]; intervalIndex++; } } } if ((DateTime)dv[dv.Count - 1]["OraEnd"] < oraMaxima) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = (DateTime)dv[dv.Count - 1]["OraEnd"]; intervalOrar[intervalIndex].OraEnd = oraMaxima; intervalIndex++; } } else { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = ora0; intervalOrar[intervalIndex].OraEnd = oraMaxima; intervalIndex++; } //intervalul de la 22:00 - 24:00 dv.RowFilter = "'" + oraMinima.ToString() + "'<=OraStart and OraEnd<='" + ora24.ToString() + "'"; if (dv.Count > 0) { if (oraMinima < (DateTime)dv[0]["OraStart"]) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = oraMinima; intervalOrar[intervalIndex].OraEnd = (DateTime)dv[0]["OraStart"]; intervalIndex++; } if (dv.Count > 1) { for (int i = 0; i < dv.Count - 1; i++) { if ((DateTime)dv[i]["OraEnd"] < (DateTime)dv[i + 1]["OraStart"]) { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = (DateTime)dv[i]["OraEnd"]; intervalOrar[intervalIndex].OraEnd = (DateTime)dv[i + 1]["OraStart"]; intervalIndex++; } } } if ((DateTime)dv[dv.Count - 1]["OraEnd"] < ora24) { intervalOrar[intervalIndex].Data = data; if ((DateTime)dv[dv.Count - 1]["OraEnd"] > oraMinima) { intervalOrar[intervalIndex].OraStart = (DateTime)dv[dv.Count - 1]["OraEnd"]; } else { intervalOrar[intervalIndex].OraStart = oraMinima; } intervalOrar[intervalIndex].OraEnd = ora24; } } else { intervalOrar[intervalIndex].Data = data; intervalOrar[intervalIndex].OraStart = oraMinima; intervalOrar[intervalIndex].OraEnd = ora24; intervalIndex++; } return(intervalOrar); } } catch { return(null); } }