public void participareAdaugata(Participare participare, Participant updatedParticipant, int nrComoara, int nrDesen, int nrPoezie) { ParticipareAdaugataInfo updateInfo = new ParticipareAdaugataInfo(participare, updatedParticipant, nrComoara, nrDesen, nrPoezie); ChatUserEventArgs userArgs = new ChatUserEventArgs(ChatUserEvent.ParticipareAdaugata, updateInfo); OnUserEvent(userArgs); }
private void notifyParticipareAdaugata(Participare participareAdaugata, Participant participantActualizat) { IEnumerable <Organizator> organizatori = RepoOrganizatori.FindAll(); foreach (Organizator organizator in organizatori) { if (loggedClients.ContainsKey(organizator.ID.ToString())) { IObserver client = loggedClients[organizator.ID.ToString()]; Task.Run(() => client.participareAdaugata(participareAdaugata, participantActualizat, RepoParticipari.NrParticipariProba("Cautare comoara"), RepoParticipari.NrParticipariProba("Desen"), RepoParticipari.NrParticipariProba("Poezie"))); } } }
public void participareAdaugata(Participare participare, Participant updatedParticipant, int nrComoara, int nrDesen, int nrPoezie) { Console.WriteLine("Controller: Participare Adaugata."); string[] lineParticipare = { participare.ID.ToString(), participare.IdParticipant.ToString(), participare.Proba, participare.CategorieVarsta }; /*string[] lineParticipant = { updatedParticipant.ID.ToString(), updatedParticipant.Nume, * updatedParticipant.Varsta.ToString(), updatedParticipant.NumarParticipari.ToString() };*/ this.dataGridViewParticipari.Invoke(new Action(() => { this.dataGridViewParticipari.Rows.Add(lineParticipare); })); for (int i = 0; i < dataGridViewParticipanti.Rows.Count; i++) { if (dataGridViewParticipanti.Rows[i].Cells[0].Value.ToString().Equals(participare.IdParticipant.ToString())) { //this.dataGridViewParticipanti.Invoke(new Action(() => { dataGridViewParticipanti.Rows.RemoveAt(i); })); //this.dataGridViewParticipanti.Invoke(new Action(() => { dataGridViewParticipanti.Rows.Insert(i, lineParticipant); })); dataGridViewParticipanti.Invoke(new Action(() => { dataGridViewParticipanti.Rows[i].Cells[3].Value = updatedParticipant.NumarParticipari.ToString(); })); break; } } //loadDataGridViewParticipari(Service.GetParticipari()); string probaNr = null; comboBoxMainProbaNrPart.Invoke( new Action(() => { probaNr = comboBoxMainProbaNrPart.GetItemText(comboBoxMainProbaNrPart.SelectedItem); })); //Console.WriteLine(probaNr + "-Comoara:" + nrComoara + "-Poezie:" + nrPoezie + "-Desen:" + nrDesen); if (probaNr != null && probaNr.Equals(participare.Proba)) { switch (probaNr) { case "Cautare comoara": //textBoxMainNrPartic.Invoke(new Action(() => textBoxMainNrPartic.Text = nrComoara.ToString())); signalNrParticipariField(nrComoara); break; case "Poezie": //textBoxMainNrPartic.Invoke(new Action(() => textBoxMainNrPartic.Text = nrPoezie.ToString())); signalNrParticipariField(nrPoezie); break; case "Desen": //textBoxMainNrPartic.Invoke(new Action(() => textBoxMainNrPartic.Text = nrDesen.ToString())); signalNrParticipariField(nrDesen); break; } } }
public void Save(Participare entity) { try { using (SQLiteConnection connection = new SQLiteConnection(DBurl)) { connection.Open(); using (var verifyCmd = new SQLiteCommand(connection)) { verifyCmd.CommandText = "select count(*) as [SIZE] from Participari where Participari.Proba=@proba " + "and Participari.IDparticipant=@id"; verifyCmd.Parameters.AddWithValue("@proba", entity.Proba); verifyCmd.Parameters.AddWithValue("id", entity.IdParticipant); verifyCmd.ExecuteNonQuery(); bool exists = false; using (SQLiteDataReader rdr = verifyCmd.ExecuteReader()) { rdr.Read(); exists = rdr.GetInt32(0) == 1; } if (exists) { throw new RepositoryException("Participantul cu ID-ul " + entity.IdParticipant + " este deja inscris la proba <<" + entity.Proba + ">>"); } using (var cmd = new SQLiteCommand(connection)) { cmd.CommandText = "insert into Participari(IDparticipant,Proba,CategorieVarsta) values (@id,@proba,@categorie)"; cmd.Parameters.AddWithValue("@id", entity.IdParticipant); cmd.Parameters.AddWithValue("proba", entity.Proba); cmd.Parameters.AddWithValue("@categorie", entity.CategorieVarsta); cmd.ExecuteNonQuery(); } } } } catch (SQLiteException ex) { Console.WriteLine(ex.Message); } }
public void Update(object sender, ChatUserEventArgs e) { if (e.UserEventType == ChatUserEvent.ParticipantAdaugat) { Participant participant = (Participant)e.Data; participantAdaugat(participant); } if (e.UserEventType == ChatUserEvent.ParticipareAdaugata) { ParticipareAdaugataInfo updateInfo = (ParticipareAdaugataInfo)e.Data; Participare participare = updateInfo.participare; Participant participant = updateInfo.participant; int nrComoara = updateInfo.nrComoara; int nrDesen = updateInfo.nrDesen; int nrPoezie = updateInfo.nrPoezie; participareAdaugata(participare, participant, nrComoara, nrDesen, nrPoezie); } }
public void AdaugaParticipare(Participant participant, String proba) { int varsta = participant.Varsta; String categorieVarsta = ""; if (participant.NumarParticipari < 2) { if (varsta >= 6 && varsta <= 8) { categorieVarsta = "6-8"; } else if (varsta >= 9 && varsta <= 11) { categorieVarsta = "9-11"; } else if (varsta >= 12 && varsta <= 15) { categorieVarsta = "12-15"; } Participare participare = new Participare(0, participant.ID, proba, categorieVarsta); try { RepoParticipari.Save(participare); int nrParticipari = participant.NumarParticipari + 1; Participant updated = new Participant(participant.ID, participant.Nume, participant.Varsta, nrParticipari); RepoParticipanti.Update(updated); notifyParticipareAdaugata(RepoParticipari.FindLastAdded(), updated); } catch (RepositoryException re) { throw new ServiceException(re.Message); } } else { throw new ServiceException("Participantul cu id-ul " + participant.ID + " are deja 2 participari!"); } }
public static void Initialize(ContextFacultate context) { context.Database.EnsureCreated(); if (context.Studenti.Any()) { return; // BD a fost creata anterior } var profesori = new Profesor[] { new Profesor { Nume = "Anton", Prenume = "Vasile", Email = "*****@*****.**" }, new Profesor { Nume = "Popa", Prenume = "Ana", Email = "*****@*****.**" }, new Profesor { Nume = "Marin", Prenume = "Angel", Email = "*****@*****.**" }, new Profesor { Nume = "Vamanu", Prenume = "Dana", Email = "*****@*****.**" }, new Profesor { Nume = "Morariu", Prenume = "Anamaria", Email = "*****@*****.**" }, new Profesor { Nume = "Popa", Prenume = "Andrei", Email = "*****@*****.**" }, }; foreach (Profesor p in profesori) { context.Profesori.Add(p); } context.SaveChanges(); var cursuri = new Curs[] { new Curs { ID = 1, Denumire = "Informatica Economica", Credite = 5, ProfesorID = 1 }, new Curs { ID = 2, Denumire = "Economie", Credite = 4, ProfesorID = 2 }, new Curs { ID = 3, Denumire = "Matematica", Credite = 5, ProfesorID = 3 }, new Curs { ID = 4, Denumire = "Statistica", Credite = 3, ProfesorID = 4 }, new Curs { ID = 5, Denumire = "Management", Credite = 4, ProfesorID = 5 }, new Curs { ID = 6, Denumire = "Finante", Credite = 5, ProfesorID = 6 } }; foreach (Curs c in cursuri) { context.Cursuri.Add(c); } context.SaveChanges(); var studenti = new Student[] { new Student { Nume = "Moculescu", Prenume = "Flaviu", DataNasterii = DateTime.Parse("1997-07-08"), An = 2 }, new Student { Nume = "Nita", Prenume = "Adi", DataNasterii = DateTime.Parse("1997-03-03"), An = 1 }, new Student { Nume = "Stanescu", Prenume = "Stela", DataNasterii = DateTime.Parse("1998-08-08"), An = 2 }, new Student { Nume = "Vlaicu", Prenume = "Corina", DataNasterii = DateTime.Parse("1997-07-23"), An = 3 }, new Student { Nume = "Stefan", Prenume = "Horatiu", DataNasterii = DateTime.Parse("1997-07-08"), An = 2 }, new Student { Nume = "Mironescu", Prenume = "Victor", DataNasterii = DateTime.Parse("1998-09-03"), An = 1 }, new Student { Nume = "Prunea", Prenume = "Delia", DataNasterii = DateTime.Parse("1997-07-08"), An = 1 }, new Student { Nume = "Apostu", Prenume = "Isabella", DataNasterii = DateTime.Parse("1996-04-03"), An = 3 }, new Student { Nume = "Stefanescu", Prenume = "Sorin", DataNasterii = DateTime.Parse("1997-07-08"), An = 2 }, new Student { Nume = "Bogza", Prenume = "Mihai", DataNasterii = DateTime.Parse("1997-06-05"), An = 3 }, }; foreach (Student st in studenti) { context.Studenti.Add(st); } context.SaveChanges(); var carti = new Carte[] { new Carte { Titlu = "Programare in C", DataPublicare = DateTime.Parse("1997-03-03"), ProfesorID = 1 }, new Carte { Titlu = "Economie", DataPublicare = DateTime.Parse("1995-02-02"), ProfesorID = 2 }, new Carte { Titlu = "Economie aplicata", DataPublicare = DateTime.Parse("1995-07-02"), ProfesorID = 2 }, new Carte { Titlu = "Finante", DataPublicare = DateTime.Parse("1997-09-09"), ProfesorID = 6 }, }; foreach (Carte b in carti) { context.Carti.Add(b); } context.SaveChanges(); var participari = new Participare[] { new Participare { CursID = 1, StudentID = 1, Nota = Decimal.Parse("7.2") }, new Participare { CursID = 2, StudentID = 2, Nota = Decimal.Parse("8") }, new Participare { CursID = 3, StudentID = 2, Nota = Decimal.Parse("5.5") }, new Participare { CursID = 5, StudentID = 1, Nota = Decimal.Parse("9") }, new Participare { CursID = 2, StudentID = 2, Nota = Decimal.Parse("10") }, new Participare { CursID = 3, StudentID = 3, Nota = Decimal.Parse("8.5") }, new Participare { CursID = 4, StudentID = 3, Nota = Decimal.Parse("6.7") }, new Participare { CursID = 2, StudentID = 4, Nota = Decimal.Parse("9.4") }, new Participare { CursID = 5, StudentID = 2, Nota = Decimal.Parse("4") }, new Participare { CursID = 1, StudentID = 6, Nota = Decimal.Parse("3.4") }, new Participare { CursID = 5, StudentID = 5, Nota = Decimal.Parse("4.6") }, new Participare { CursID = 1, StudentID = 5, Nota = Decimal.Parse("7") } }; foreach (Participare p in participari) { context.Participari.Add(p); } context.SaveChanges(); }
public void Update(Participare entity) { throw new NotImplementedException(); }