//------------------------------------------// //Eliminar un equip de la base de dades. public static string DeleteEquip(EQUIPS equip) { string mensaje = ""; GeneralORM.bd.EQUIPS.Remove(equip); mensaje = GeneralORM.SaveChanges(); return(mensaje); }
//------------------------------------------// //Insertar un equip a la base de dades. public static string InsertEquip(EQUIPS equip) { string mensaje = ""; GeneralORM.bd.EQUIPS.Add(equip); mensaje = GeneralORM.SaveChanges(); return(mensaje); }
//Eliminar equip public static void DeleteEquip(EQUIPS equip) { ORM.bd.EQUIPS.Remove(equip); try { ORM.bd.SaveChanges(); } catch (DbUpdateException ex) { SqlException sqlEx = (SqlException)ex.InnerException.InnerException; } }
//------------------------------------------// //Modificar un equip de la base de dades. public static String UpdateEquip(EQUIPS equip) { String missatgeError = ""; EQUIPS eq = GeneralORM.bd.EQUIPS.Find(equip.id); eq.nom = equip.nom; eq.te_discapacitat = equip.te_discapacitat; eq.id_entitat = equip.id_entitat; eq.temporada = equip.temporada; eq.id_competicio = equip.id_competicio; eq.id_categoria_edat = equip.id_categoria_edat; eq.id_categoria_equip = equip.id_categoria_equip; eq.id_sexe = equip.id_sexe; eq.id_esport = equip.id_esport; missatgeError = GeneralORM.SaveChanges(); return(missatgeError); }
//Modificar equip public static void UpdateEquipo(String nom, int id_esport, int id_competicio, int id_categoria, int id_categoriaEdat, int sexe, int id) { EQUIPS equip = ORM.bd.EQUIPS.Find(id); equip.nom = nom; equip.id_sport = id_esport; equip.id_competicio = id_competicio; equip.id_categoria = id_categoria; equip.id_categoria_edat = id_categoriaEdat; equip.id_sexe = sexe; try { ORM.bd.SaveChanges(); } catch (DbUpdateException ex) { //En caso de estar duplicado no podría crearse y petaria el programa } }
//LINQ //Agregar equipos public static void InsertEquipo(int id_enti, String nom, int id_esport, int id_competicio, int id_categoria, int id_categoria_edat, int sexe) { EQUIPS equip = new EQUIPS(); equip.id_entitat = id_enti; equip.nom = nom; equip.id_sport = id_esport; equip.id_competicio = id_competicio; equip.id_categoria = id_categoria; equip.id_categoria_edat = id_categoria_edat; equip.id_sexe = sexe; ORM.bd.EQUIPS.Add(equip); try { ORM.bd.SaveChanges(); } catch (Exception) { } }
//ens obre un formulari Equip per modificar-ne un. public static void obrirFormEquipPerModificar(EQUIPS modificar_equip) { FormEquip fEquip = new FormEquip("Modificar equip", modificar_equip); fEquip.ShowDialog(); }
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; } } } }
private void listBoxEspai_SelectedIndexChanged(object sender, EventArgs e) { dataGridViewHorari.Rows.Clear(); //-------------CALENDARI---------------------- List <HORES> horari = HoresORM.SelectHoresPrimaries(111); List <EQUIPS> equips = EquipsORM.SelectAllEquips(); 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-------------------- 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; } } } }
private void buttonSelectEquip_Click(object sender, EventArgs e) { EQUIPS equip = (EQUIPS)listBoxEquips.SelectedItem; ObridorFormulari.obrirFormEquipPerModificar(equip); }
//Al fer clic al botó acceptar [...] private void buttonAcceptar_Click(object sender, EventArgs e) { if (textBoxNomEquip.Text == "") { DialogResult mensaje = MessageBox.Show("Nom obligatori!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxNomEquip.Focus(); } else if (!radioButtonSi.Checked && !radioButtonNo.Checked) { DialogResult mensaje = MessageBox.Show("Marcar discapacitat incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (comboBoxEntitat.SelectedIndex == -1) { DialogResult mensaje = MessageBox.Show("Entitat incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBoxEntitat.Focus(); } else if (comboBoxCompeticio.SelectedIndex == -1) { DialogResult mensaje = MessageBox.Show("Competició incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBoxCompeticio.Focus(); } else if (comboBoxCategoriaEdat.SelectedIndex == -1) { DialogResult mensaje = MessageBox.Show("Categoria edat incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBoxCategoriaEdat.Focus(); } else if (comboBoxCategoriaEquip.SelectedIndex == -1) { DialogResult mensaje = MessageBox.Show("Categoria de l'equip incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBoxCategoriaEquip.Focus(); } else if (comboBoxSexe.SelectedIndex == -1) { DialogResult mensaje = MessageBox.Show("Sexe incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBoxSexe.Focus(); } else if (comboBoxEsport.SelectedIndex == -1) { DialogResult mensaje = MessageBox.Show("Esport incorrecte!", "ATENCIÓ", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBoxEsport.Focus(); } else { if (this.Text == "Afegir equip") { EQUIPS equip3 = new EQUIPS(); String missatge = ""; equip3.nom = textBoxNomEquip.Text; if (radioButtonSi.Checked) { equip3.te_discapacitat = true; } else { equip3.te_discapacitat = false; } equip3.id_entitat = int.Parse(comboBoxEntitat.SelectedValue.ToString()); equip3.temporada = Classes.Utilitats.tempActual(); equip3.id_competicio = int.Parse(comboBoxCompeticio.SelectedValue.ToString()); equip3.id_categoria_edat = int.Parse(comboBoxCategoriaEdat.SelectedValue.ToString()); equip3.id_categoria_equip = int.Parse(comboBoxCategoriaEquip.SelectedValue.ToString()); equip3.id_sexe = int.Parse(comboBoxSexe.SelectedValue.ToString()); equip3.id_esport = int.Parse(comboBoxEsport.SelectedValue.ToString()); missatge = ORM.EquipsORM.InsertEquip(equip3); if (missatge != "") { MessageBox.Show(missatge, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Equip introduït perfectament!", "INFORMACIÓ", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } else { String missatge = ""; equip2.nom = textBoxNomEquip.Text; if (radioButtonSi.Checked) { equip2.te_discapacitat = true; } else { equip2.te_discapacitat = false; } equip2.id_entitat = int.Parse(comboBoxEntitat.SelectedValue.ToString()); equip2.temporada = Classes.Utilitats.tempActual(); equip2.id_competicio = int.Parse(comboBoxCompeticio.SelectedValue.ToString()); equip2.id_categoria_edat = int.Parse(comboBoxCategoriaEdat.SelectedValue.ToString()); equip2.id_categoria_equip = int.Parse(comboBoxCategoriaEquip.SelectedValue.ToString()); equip2.id_sexe = int.Parse(comboBoxSexe.SelectedValue.ToString()); equip2.id_esport = int.Parse(comboBoxEsport.SelectedValue.ToString()); missatge = ORM.EquipsORM.UpdateEquip(equip2); if (missatge != "") { MessageBox.Show(missatge, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Equip modificat!", "INFORMACIÓ", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } } }
public FormEquip(string titulo, EQUIPS equip) { InitializeComponent(); this.Text = titulo; equip2 = equip; }
//Seleccionar equipos por id public static EQUIPS SelectEquiposByID(int id) { EQUIPS _equipos = ORM.bd.EQUIPS.Find(id); return(_equipos); }