public void LLenardg() { for (int i = 0; i < Blackouts.Blackouts.Count; i++) { Blackout Boff = Blackouts.Blackouts[i]; int day = (int)Boff.BlackoutBeginning.DayOfWeek; int id = chart1.Series[0].Points.AddXY(day, Blackouts.Blackouts[i].BlackoutBeginning.Hour); CultureInfo ci = new CultureInfo("ES-ES"); DayOfWeek DiaIng = Blackouts.Blackouts[i].BlackoutBeginning.DayOfWeek; chart1.Series[0].Points[id].AxisLabel = ci.DateTimeFormat.GetDayName(DiaIng); int ide = chart2.Series[0].Points.AddXY(i, (Boff.Ending - Boff.BlackoutBeginning).TotalHours); chart2.Series[0].Points[ide].AxisLabel = Boff.BlackoutBeginning.ToLongDateString(); Blackout Bout = Blackouts.Blackouts[i]; TimeSpan span = (Bout.Ending - Bout.BlackoutBeginning); string diff = string.Format("{0} Horas, {1} Minutos", span.Hours, span.Minutes); DGFechas.Rows.Add(new object[] { false, "0", Bout.BlackoutBeginning.ToLongDateString(), Bout.BlackoutBeginning.ToString("hh:mm tt"), Bout.Ending.ToString("hh:mm tt"), diff }); } }
private void BtnNuevo_Click(object sender, EventArgs e) { Blackout b = new Blackout(); DateTime bBeg = DTBlackout.Value; b.BlackoutBeginning = new DateTime(bBeg.Year, bBeg.Month, bBeg.Day, bBeg.Hour, bBeg.Minute, 0); DateTime bEnd = DTEndBlackout.Value; b.Ending = new DateTime(bEnd.Year, bEnd.Month, bEnd.Day, bEnd.Hour, bEnd.Minute, 0); if (Tiporegistro == "Nuevo") { Blackouts.Blackouts.Add(b); } else if (Tiporegistro == "Editar") { Blackouts.Blackouts[index] = b; } Blackouts.Blackouts = Blackouts.Blackouts.OrderBy(x => x.BlackoutBeginning).ToList(); JsonLoader <ListOfBlackouts> .UpdateData(Blackouts, path); CalendarioPrincipal.Blackouts = Blackouts; CalendarioPrincipal.Limpiar(); CalendarioPrincipal.Llenar(); Close(); }
public void Llenar() { chart1.Series[0].Points.Clear(); chart2.Series[0].Points.Clear(); DateTime?latest = Blackouts.Blackouts.Max(r => r.BlackoutBeginning); DateTime?Firstest = Blackouts.Blackouts.Min(r => r.BlackoutBeginning); DateTime ad = (DateTime)Firstest; DateTime bd = (DateTime)latest; if (Desde >= ad) { ad = Desde; } if (Hasta <= bd) { bd = Hasta; } for (int i = 0; i < Blackouts.Blackouts.Count; i++) { Blackout Boff = Blackouts.Blackouts[i]; if ((Boff.BlackoutBeginning >= ad && Boff.BlackoutBeginning <= bd) && (dia == 7 || dia == (int)Boff.BlackoutBeginning.DayOfWeek)) { int day = (int)Boff.BlackoutBeginning.DayOfWeek; int id = chart1.Series[0].Points.AddXY(day, Blackouts.Blackouts[i].BlackoutBeginning.Hour); CultureInfo ci = new CultureInfo("ES-ES"); DayOfWeek DiaIng = Blackouts.Blackouts[i].BlackoutBeginning.DayOfWeek; chart1.Series[0].Points[id].AxisLabel = ci.DateTimeFormat.GetDayName(DiaIng); int ide = chart2.Series[0].Points.AddXY(i, (Boff.Ending - Boff.BlackoutBeginning).TotalHours); chart2.Series[0].Points[ide].AxisLabel = Boff.BlackoutBeginning.ToLongDateString(); } } int j = 0; for (DateTime date = ad; date.Date <= bd; date = date.AddDays(1)) { bool EA = false; for (int i = 0; i < Blackouts.Blackouts.Count; i++) { Blackout Bout = Blackouts.Blackouts[i]; DateTime a = new DateTime(date.Year, date.Month, date.Day); DateTime b = new DateTime(Bout.BlackoutBeginning.Year, Bout.BlackoutBeginning.Month, Bout.BlackoutBeginning.Day); if (!(dia == 7 || dia == (int)a.DayOfWeek)) { EA = true; break; } if (a == b) { Blackout Boff = Bout; TimeSpan span = (Boff.Ending - Boff.BlackoutBeginning); string diff = string.Format("{0} Horas, {1} Minutos", span.Hours, span.Minutes); DGFechas.Rows.Add(new object[] { false, i.ToString(), date.ToLongDateString(), Boff.BlackoutBeginning.ToString("hh:mm tt"), Boff.Ending.ToString("hh:mm tt"), diff }); j++; int ef = i + 1; if (ef >= Blackouts.Blackouts.Count()) { EA = true; break; } Bout = Blackouts.Blackouts[ef]; b = new DateTime(Bout.BlackoutBeginning.Year, Bout.BlackoutBeginning.Month, Bout.BlackoutBeginning.Day); while (a == b) { Boff = Bout; span = (Boff.Ending - Boff.BlackoutBeginning); diff = string.Format("{0} Horas, {1} Minutos", span.Hours, span.Minutes); DGFechas.Rows.Add(new object[] { false, i.ToString(), "", Boff.BlackoutBeginning.ToString("hh:mm tt"), Boff.Ending.ToString("hh:mm tt"), ((Boff.Ending - Boff.BlackoutBeginning).TotalHours).ToString() }); j++; ef++; if (ef >= Blackouts.Blackouts.Count()) { EA = true; break; } Bout = Blackouts.Blackouts[ef]; b = new DateTime(Bout.BlackoutBeginning.Year, Bout.BlackoutBeginning.Month, Bout.BlackoutBeginning.Day); } EA = true; break; } } if (!EA && j > 1) { DGFechas.Rows.Add(new object[] { false, "", date.ToLongDateString(), "Nada", "Nada", "Nada" }); } } }