/** * ENS INSERTA A LA BASE DE DADES UNA HORA NOVA **/ public static String InsertHora(HORES hora) { String missatgeError = ""; GeneralORM.bd.HORES.Add(hora); missatgeError = GeneralORM.SaveChanges(); return(missatgeError); }
/** * ENS BORRA UNA HORA DE LA BASE DE DADES QUE LI PASSEM PER PARAMETRE **/ public static String DeleteByHora(HORES hora) { String missatgeError = ""; GeneralORM.bd.HORES.Remove(hora); missatgeError = GeneralORM.SaveChanges(); return(missatgeError); }
private void buttonAceptar_Click(object sender, EventArgs e) { HORES inici = (HORES)comboBoxInici.SelectedItem; HORES final = (HORES)comboBoxFinal.SelectedItem; if (inici.inici == final.inici) { MessageBox.Show("Dos intervals no poden ser iguals!", "ADVERTÈNCIA", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); comboBoxFinal.Select(); } else if (inici.inici > final.inici) { MessageBox.Show("El interval inici no pot ser més petit que el final!", "ADVERTÈNCIA", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); comboBoxInici.Select(); } else if (this.Text.Equals("NOU INTERVAL D'HORES")) { String missatge = ""; this.intervalHores.inici = inici.inici; this.intervalHores.fi = final.inici; missatge = HoresORM.InsertHora(this.intervalHores); if (missatge != "") { MessageBox.Show(missatge, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Introduït perfectament!", "INFORMACIÓ", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } else if (this.Text.Equals("MODIFICAR INTERVAL D'HORES")) { String missatge = ""; this.intervalHores.inici = inici.inici; this.intervalHores.fi = final.inici; missatge = HoresORM.UpdateHora(this.intervalHores); if (missatge != "") { MessageBox.Show(missatge, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Introduït perfectament!", "INFORMACIÓ", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } }
/** * ENS ACTUALITZA UNA HORA DE LA BASE DE DADES **/ public static String UpdateHora(HORES hora) { String missatgeError = ""; HORES a = GeneralORM.bd.HORES.Find(hora.id); a.inici = hora.inici; a.fi = hora.fi; missatgeError = GeneralORM.SaveChanges(); return(missatgeError); }
/** * ENS INTRODUEXI DE FORMA AUTOMATICA ELS INTERVALS DE HORES **/ public static void InsertHores() { TimeSpan inici = new TimeSpan(0, 0, 0); TimeSpan final = new TimeSpan(0, 0, 0); HORES hores = new HORES(); for (int i = 0; i < 24; i++) { for (int j = 0; j < 4; j++) { if (i < 23) { if (j < 3) { inici = new TimeSpan(i, j * 15, 0); final = new TimeSpan(i, (j * 15) + 15, 0); hores.inici = inici; hores.fi = final; GeneralORM.InsertHoresInterval(hores); } else { inici = new TimeSpan(i, j * 15, 0); final = new TimeSpan(i + 1, 0, 0); hores.inici = inici; hores.fi = final; GeneralORM.InsertHoresInterval(hores); } } else { if (j < 3) { inici = new TimeSpan(i, j * 15, 0); final = new TimeSpan(i, (j * 15) + 15, 0); hores.inici = inici; hores.fi = final; GeneralORM.InsertHoresInterval(hores); } else { inici = new TimeSpan(i, j * 15, 0); final = new TimeSpan(0, 0, 0); hores.inici = inici; hores.fi = final; GeneralORM.InsertHoresInterval(hores); } } } } }
/** * METODE PER COMPARAR INTERVALS D'HORES **/ public static List <int> comparaHores(int idIntervalHores) { List <int> hores = new List <int>(); HORES interval = HoresORM.SelectHoresByid(idIntervalHores).First(); TimeSpan hInici = interval.inici; TimeSpan hFi = interval.fi; int idInici = HoresORM.SelectHoresByHinici(hInici).First().id; int idFi = HoresORM.SelectHoresByHfinal(hFi).First().id; for (int i = idInici; i <= idFi; i++) { hores.Add(i - 15); } return(hores); }
//Load para cargar datos en caso de que sea para modificar private void FormInstalacioAlta_Load(object sender, EventArgs e) { //Traer id idHoraInicio = ORM.HoresORM.selectIdHores(); //Cargar BindingSources bindingSourceDillunsInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDillunsFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); bindingSourceDimartsInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDimartsFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); bindingSourceDimecresInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDimecresFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); bindingSourceDijousInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDijousFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); bindingSourceDivendresInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDivendresFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); bindingSourceDissabteInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDissabteFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); bindingSourceDiumengeInici.DataSource = ORM.HoresORM.SelectIntervalHores(); bindingSourceDiumengeFinal.DataSource = ORM.HoresORM.SelectIntervalHoresFi(); if (modificar) { textBoxNom.Text = _instalacio.nom; textBoxContrasenya.Text = _instalacio.contrasenya; textBoxAdresa.Text = _instalacio.adresa; comboBoxTipus.SelectedItem = _instalacio.tipus; textBoxEmail.Text = _instalacio.email; textBoxRutaImatge.Text = _instalacio.ruta_imagen; textBoxAltitud.Text = _instalacio.altitut.ToString(); textBoxLatitud.Text = _instalacio.latitut.ToString(); List <HORARI_INSTALACIO> _ins = _instalacio.HORARI_INSTALACIO.ToList(); hInici = new List <TimeSpan>(); hFinal = new List <TimeSpan>(); foreach (HORARI_INSTALACIO i in _ins) { HORES h = i.HORES; hInici.Add(h.inici); hFinal.Add(h.fi); ids.Add(h.id); } rellenarCombosHorarios(); } gestionMapa(); }
//ens obre un formulari Hora per modificar public static void obrirFormHora(HORES hora) { FormHora fHora = new FormHora(hora); fHora.ShowDialog(); }
public FormHora(HORES intervalHores) { this.Text = "MODIFICAR INTERVAL D'HORES"; this.intervalHores = intervalHores; InitializeComponent(); }
public FormHora() { this.Text = "NOU INTERVAL D'HORES"; intervalHores = new HORES(); InitializeComponent(); }
private void FormDemanda_Load(object sender, EventArgs e) { bindingSourceInstalacions.DataSource = InstalacionsORM.selectInstalacions(); listBoxEspai.DataSource = EspaisORM.selectEspaisInstalacio((INSTALACIONS)comboBoxInst.SelectedItem); listBoxEspai.DisplayMember = "nom"; listBoxEspai.ValueMember = "id"; textBoxId.Text = demanda.id.ToString(); textBoxNom.Text = demanda.nom; textBoxDuracio.Text = demanda.duracio.ToString(); if (demanda.es_asignada == true) { radioButtonSi.Checked = true; } else { radioButtonNo.Checked = true; } EQUIPS equip = EquipsORM.SelectAllEquipByid(demanda.id_equip).First(); string nom = equip.nom; textBoxEquip.Text = nom; HORES hores = HoresORM.SelectHoresByid(demanda.HORES.id).First(); textBoxHinici.Text = hores.inici.ToString(); textBoxHfi.Text = hores.fi.ToString(); listBoxDies.DataSource = DiesSemanaORM.SelectAllDiesSemana(); listBoxDies.DisplayMember = "nom"; listBoxDies.ValueMember = "id"; foreach (DIA_SEMANA dia in demanda.DIA_SEMANA) { listBoxDies.SelectedItems.Add(dia); } dataGridViewHorari.Rows.Clear(); //-------------CALENDARI---------------------- List <HORES> horari = HoresORM.SelectHoresPrimaries(111); string[,] rows = new string[Utilitats.intervalsHores, 9]; for (int i = 0; i < Utilitats.intervalsHores; i++) { rows[i, 0] = horari[i].inici.ToString(); rows[i, 1] = horari[i].fi.ToString(); } List <DEMANDA_ACT> demandesAssignades = DemandaActORM.SelectAllDemandaActAssignades(); for (int k = 0; k < demandesAssignades.Count; k++) { ESPAIS espai = (ESPAIS)listBoxEspai.SelectedItem; if (demandesAssignades[k].id_espai == espai.id) { EQUIPS equipDemanda = EquipsORM.SelectAllEquipByid(demandesAssignades[k].id_equip).First(); foreach (DIA_SEMANA dia in demandesAssignades[k].DIA_SEMANA) { List <int> intervals = Utilitats.comparaHores(demandesAssignades[k].id_interval_hores); for (int m = 0; m < intervals.Count; m++) { rows[intervals[m], dia.id + 1] = equipDemanda.nom; } } } } //---------OMPLIR CALENDARI-------------------- dataGridViewHorari.Rows.Clear(); List <EQUIPS> equips = EquipsORM.SelectAllEquips(); INSTALACIONS instalacio = (INSTALACIONS)comboBoxInst.SelectedItem; List <HORARI_INSTALACIO> horariInst = new List <HORARI_INSTALACIO>(); horariInst.AddRange(instalacio.HORARI_INSTALACIO); for (int i = 0; i < rows.GetLength(0); i++) { string[] row = new string[rows.GetLength(1)]; for (int j = 0; j < rows.GetLength(1); j++) { row[j] = rows[i, j]; } dataGridViewHorari.Rows.Add(row); foreach (DataGridViewRow fila in dataGridViewHorari.Rows) { foreach (DataGridViewCell cela in fila.Cells) { if (cela.Value != null) { for (int j = 0; j < equips.Count; j++) { if (cela.Value.ToString() == equips[j].nom) { cela.Style.BackColor = System.Drawing.Color.Red; } } } } } } //------------PINTAR EN GRIS HORES FORA D'HORARI INSTALACIO---------------- List <int> diesObert = new List <int>(); foreach (HORARI_INSTALACIO h in horariInst) { diesObert.Add(h.id_dia); } int contador = 0; for (int i = 1; i < 8; i++) { if (diesObert.Contains(i)) { List <int> intervals = Utilitats.comparaHoresExcluides(horariInst[contador].id_hores); for (int j = 0; j < intervals.Count; j++) { dataGridViewHorari.Rows[intervals[j]].Cells[horariInst[contador].id_dia + 1].Style.BackColor = System.Drawing.Color.LightGray; } contador++; } else { for (int j = 0; j < Utilitats.intervalsHores; j++) { dataGridViewHorari.Rows[j].Cells[i + 1].Style.BackColor = System.Drawing.Color.LightGray; } } } }
//Añadir nuevo intervalo de horas private List <int> anadirIntervaloHoras() { List <int> ids = new List <int>(); //Lunes if (comboBoxDillunsInici.SelectedValue != comboBoxDillunsFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDillunsInici.Text); hora.fi = TimeSpan.Parse(comboBoxDillunsFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDillunsInici.SelectedValue); } //Martes if (comboBoxDimartsInici.SelectedValue != comboBoxDimartsFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDimartsInici.Text); hora.fi = TimeSpan.Parse(comboBoxDimartsFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDimartsInici.SelectedValue); } //Miercoles if (comboBoxDimecresInici.SelectedValue != comboBoxDimecresFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDimecresInici.Text); hora.fi = TimeSpan.Parse(comboBoxDimecresFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDimecresInici.SelectedValue); } //Jueves if (comboBoxDijousInici.SelectedValue != comboBoxDijousFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDijousInici.Text); hora.fi = TimeSpan.Parse(comboBoxDijousFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDijousInici.SelectedValue); } //Viernes if (comboBoxDivendresInici.SelectedValue != comboBoxDivendresFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDivendresInici.Text); hora.fi = TimeSpan.Parse(comboBoxDivendresFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDivendresInici.SelectedValue); } //Sábado if (comboBoxDissabteInici.SelectedValue != comboBoxDissabteFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDissabteInici.Text); hora.fi = TimeSpan.Parse(comboBoxDissabteFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDissabteInici.SelectedValue); } //Domingo if (comboBoxDiumengeInici.SelectedValue != comboBoxDiumengeFinal.SelectedValue) { HORES hora = new HORES(); hora.inici = TimeSpan.Parse(comboBoxDiumengeInici.Text); hora.fi = TimeSpan.Parse(comboBoxDiumengeFinal.Text); String msg = ORM.HoresORM.InsertHora(hora); ids.Add(hora.id); } else { ids.Add((int)comboBoxDiumengeInici.SelectedValue); } return(ids); }