private void LoadFromFile() { List <Echipa> echipe = DataReader.ReadData <Echipa>(ConfigurationManager.AppSettings["echipeFileName"], EntityToFileMapping.CreateEchipa); List <Elev> elevi = DataReader.ReadData <Elev>(ConfigurationManager.AppSettings["eleviFileName"], EntityToFileMapping.CreateElev); using (StreamReader stream = new StreamReader(fileName)) { string record; while ((record = stream.ReadLine()) != null) { string[] fields = record.Split(','); Echipa echipa = echipe.Find(e => e.ID.Equals(fields[0])); Elev elev = elevi.Find(el => el.ID.Equals(fields[1])); string id = fields[0] + "_" + fields[1]; Jucator jucator = new Jucator() { ID = id, Echipa = echipa, Nume = elev.Nume, Scoala = elev.Scoala }; base.entities[jucator.ID] = jucator; } } }
public Echipa findOne(int id) { logger.InfoFormat("Se cauta echipa cu id-ul {0}", id); IDbConnection conn = DBUtils.getConnection(); using (var com = conn.CreateCommand()) { com.CommandText = "select idEchipa,nume from Echipa where idEchipa=@id"; IDbDataParameter paramId = com.CreateParameter(); paramId.ParameterName = "@id"; paramId.Value = id; com.Parameters.Add(paramId); using (var Data = com.ExecuteReader()) { if (Data.Read()) { int idEchipa = Data.GetInt32(0); string nume = Data.GetString(1); Echipa E = new Echipa(idEchipa, nume); logger.InfoFormat("S-a gasit echipa cu id-ul {0}", E.Id); return(E); } } } logger.InfoFormat("Nu s a gasit echipa cu id ul {0}", id); return(null); }
private void LoadFromFile() { List<Echipa> gazde = DataReader.ReadData<Echipa>(ConfigurationManager.AppSettings["echipeFileName"], EntityToFileMapping.CreateEchipa); List<Echipa> oaspeti = DataReader.ReadData<Echipa>(ConfigurationManager.AppSettings["echipeFileName"], EntityToFileMapping.CreateEchipa); using (StreamReader stream = new StreamReader(fileName)) { string record; while((record = stream.ReadLine()) != null) { string[] fields = record.Split(','); Echipa gazda = gazde.Find(g => g.ID.Equals(fields[1])); Echipa oaspete = oaspeti.Find(o => o.ID.Equals(fields[2])); string id = fields[0]; Meci meci = new Meci() { ID = id, Gazda = gazda, Oaspete = oaspete, Data = DateTime.ParseExact(fields[3], "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture) }; base.entities[meci.ID] = meci; } } }
public Participant[] getParticipantsByTeam(string teamName) { if (teamName == null || teamName == "") { teamName = "Fara echipa"; } Echipa e = echipaRepository.findTeamByName(teamName); if (e == null) { throw new Exception("Echipa invalida"); } IEnumerable <Participant> participants = participantRepository.getParticipantsByTeam(e.Id); List <Participant> participants1 = new List <Participant>(); foreach (Participant p in participants) { //setez cap cilindrica Cursa c = cursaRepository.findOne(p.IdCursa); p.CapCilindrica = c.CapacitateCilindrica; participants1.Add(p); } return(participants1.ToArray()); }
protected override Jucator ReadEntity(string line) { string[] fields = line.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); Echipa Echipa = repoEchipa.FindOne(int.Parse(fields[3])); return(new Jucator(int.Parse(fields[0]), fields[1], fields[2], Echipa)); }
private void ExecuteCommand2(string nrMeci, string nrEchipa) { try { if (nrMeci == null) { Console.WriteLine("Nu ai introdus numarul meciului!"); return; } string regex = ".*([0-9]+).*-.*([0-9]+).*"; string idMeci = nrMeci.Trim(' '); if (!Regex.IsMatch(idMeci, regex)) { Console.WriteLine("Numarul meciului trebuie sa fie de forma '[Nr echipa 1] - [Nr echipa 2]' !"); return; } Meci meci = _repoMeciuri.findOne(idMeci); if (meci == null) { Console.WriteLine("Nu s-a gasit meciul respectiv!"); return; } Echipa echipa = _repoEchipe.findOne(int.Parse(nrEchipa)); if (echipa == null) { Console.WriteLine("Nu s-a gasit echipa respectiva!"); return; } string[] substringMeci = idMeci.Split('-'); if (int.Parse(substringMeci[0]) != echipa.Id && int.Parse(substringMeci[1]) != echipa.Id) { Console.WriteLine("Echipa respectiva nu face parte din meciul introdus!"); return; } _repoJucatorActiv.findAll() .Where(x => x.IdMeci.Trim(' ') == meci.Id.Trim(' ')) .Where(x => _repoJucatori.findOne(x.IdJucator).Echipa.Id == echipa.Id) .ToList() .ForEach(x => Console.WriteLine( _repoJucatori.findOne(x.IdJucator).Nume + " a jucat ca " + x.Tip + " si a inscris " + x.NrPuncteInscrise + " puncte" )); Console.WriteLine(""); } catch (ArgumentNullException) { Console.WriteLine("Nu ai introdus numarul echipei!"); } catch (FormatException) { Console.WriteLine("Numarul echipei trebuie sa fie numar!"); } }
public static EchipaDTO getDTO(Echipa echipa) { int idEchipa = echipa.Id; string numeEchipa = echipa.NumeEchipa; return(new EchipaDTO(idEchipa, numeEchipa)); }
private void buttonJucator_Click(object sender, EventArgs e) { if (textBoxNume.Text.ToString() != null || textBoxPost.Text.ToString() != null || textBoxVarsta.Text.ToString() != null || textBoxNumar.Text.ToString() != null || textBoxEchipa.Text.ToString() != null) { Jucatori jucator = new Jucatori(textBoxNume.Text.ToString(), int.Parse(textBoxVarsta.Text.ToString()), textBoxPost.Text.ToString(), int.Parse(textBoxNumar.Text.ToString()), textBoxEchipa.Text.ToString()); jucatori.AdaugaJucator(jucator); echipa = echipe.GasesteEchipa(textBoxEchipa.Text.ToString()); if (echipa != null) { echipa.add_jucator(jucator); MessageBox.Show("Jucatorul a fost adaugat in echipa"); } else { MessageBox.Show("Jucatorul nu a fost adaugat in echipa"); } } else { MessageBox.Show("Nu ati completat toate campurile"); } }
public void save(Echipa entity) { logger.InfoFormat("Se salveaza echipa cu id-il {0}", entity.Id); IDbConnection conn = DBUtils.getConnection(); using (var com = conn.CreateCommand()) { com.CommandText = "insert into Echipa values (@idEchipa,@nume)"; IDbDataParameter paramIdEchipa = com.CreateParameter(); paramIdEchipa.ParameterName = "@idEchipa"; paramIdEchipa.Value = entity.Id; com.Parameters.Add(paramIdEchipa); IDbDataParameter paramNume = com.CreateParameter(); paramNume.ParameterName = "@nume"; paramNume.Value = entity.Nume; com.Parameters.Add(paramNume); var result = com.ExecuteNonQuery(); if (result == 0) { logger.Info("Error while adding"); throw new Exception("Nici o echipa adaugata!"); } } logger.InfoFormat("A fost adaugata echipa cu id-ul {0}", entity.Id); }
protected override Meci ReadEntity(string line) { string[] fields = line.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); Echipa Echipa1 = repoEchipa.FindOne(int.Parse(fields[1])); Echipa Echipa2 = repoEchipa.FindOne(int.Parse(fields[2])); return(new Meci(int.Parse(fields[0]), Echipa1, Echipa2, DateTime.Parse(fields[3]))); }
protected override JucatorActiv ReadEntity(string line) { string[] fields = line.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); Echipa Echipa = repoEchipa.FindOne(int.Parse(fields[3])); return(new JucatorActiv(int.Parse(fields[0]), fields[1], fields[2], Echipa, int.Parse(fields[5]), int.Parse(fields[6]), (Tip)Enum.Parse(typeof(Tip), fields[4]))); }
public static Echipa[] getFromDTO(EchipaDTO[] echipe) { Echipa[] teams = new Echipa[echipe.Length]; for (int i = 0; i < echipe.Length; i++) { teams[i] = getFromDTO(echipe[i]); } return(teams); }
public Jucator existaJucatorul(string cnp, Echipa e) { foreach (Jucator j in e.listaJucatori) { if (j.getCNP() == cnp) { return(j); } } return(null); }
public void saveParticipant(string capCilindrica, string numeEchipa, string nume) { Cursa c = cursaRepository.returnCursaByCapacitate(capCilindrica); Echipa e = echipaRepository.findTeamByName(numeEchipa); Participant p = new Participant(c.Id, e.Id, nume); validator.validate(p); participantRepository.save(p); notifyParticipantAdded(p.IdCursa); }
public override Meci ParseLine(string line) { try { string[] substring = line.Split(";"); Echipa echipa1 = _repoEchipe.findOne(int.Parse(substring[0])); Echipa echipa2 = _repoEchipe.findOne(int.Parse(substring[1])); return(new Meci(echipa1, echipa2, DateTime.Parse(substring[2]).Date)); } catch (Exception) { return(null); } }
public void refreshButtons() { if (comboBox1.SelectedIndex != -1) { Echipa e = listaEchipe.ElementAt(comboBox1.SelectedIndex); flowLayoutPanel1.Controls.Clear(); foreach (Jucator j in e.listaJucatori) { adaugaButon(j); } } }
public Echipa findTeamByName(string teamName) { Echipa toReturn = null; foreach (Echipa e in findAll()) { if (e.NumeEchipa == teamName) { toReturn = e; } } return(toReturn); }
public Echipa AdaugaEchipa(string nume) { Echipa e = existaEchipa(nume); if (e == null) { e = new Echipa(nume); listaEchipe.Add(e); comboBox1.Items.Add(e.nume); comboBox1.SelectedIndex = comboBox1.Items.Count - 1; Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory() + "\\LPF\\", nume)); } return(e); }
private void button2_Click(object sender, EventArgs e) { echipa = echipe.GasesteEchipa(textBoxCautareEchipa.Text.ToString()); if (echipa != null) { textBoxCampionat.Text = echipa.get_tara().ToString(); textBoxAn.Text = echipa.get_an_infiintare().ToString(); textBoxCulori.Text = echipa.get_culori().ToString(); textBoxNume_echipa.Text = echipa.get_nume().ToString(); MessageBox.Show("Echipa a fost gasita"); } else { MessageBox.Show("Echipa nu a fost gasita"); } }
public ScorDTO ScorMeci(string IDMeci) { Echipa Echipa1 = this.FindMeci(IDMeci).Gazda; Echipa Echipa2 = this.FindMeci(IDMeci).Oaspete; List <JucatorActivDTO> JucatoriEchipa1 = this.JucatoriActiviMeci(IDMeci, Echipa1.ID); List <JucatorActivDTO> JucatoriEchipa2 = this.JucatoriActiviMeci(IDMeci, Echipa2.ID); int ScorEchipa1 = 0; JucatoriEchipa1.ForEach(x => ScorEchipa1 += x.NrPuncteInscrise); int ScorEchipa2 = 0; JucatoriEchipa2.ForEach(x => ScorEchipa2 += x.NrPuncteInscrise); return(new ScorDTO(Echipa1, Echipa2, ScorEchipa1, ScorEchipa2)); }
private void buttonEchipa_Click(object sender, EventArgs e) { if (textBoxCampionat.Text.ToString() != null || textBoxAn.Text.ToString() != null || textBoxCulori.Text.ToString() != null || textBoxNume_echipa.Text.ToString() != null) { Echipa echipa2 = new Echipa(textBoxCampionat.Text.ToString(), int.Parse(textBoxAn.Text.ToString()), textBoxCulori.Text.ToString(), textBoxNume_echipa.Text.ToString()); echipe.AdaugaEchipa(echipa2); MessageBox.Show("Echipa a fost adaugata"); } else { MessageBox.Show("Nu ati completat toate campurile"); } }
private Jucator[] ParseLineJucator(string line, int index) { string[] substring = line.Split(";"); try { int curent = index; Echipa echipa = _repoEchipe.findOne(int.Parse(substring[1])); Jucator[] jucatori = new Jucator[16]; for (int i = 1; i <= 5; i++) { jucatori[i] = new Jucator(curent, generateNumeJucator(), substring[0], echipa); curent++; } return(jucatori); } catch (Exception) { return(null); } }
private void addTeams(object sender, RoutedEventArgs e) { string numeEchipa = NumeEchipa.Text.Equals("Nume Echipa") ? "" : NumeEchipa.Text; Echipa ee = new Echipa(numeEchipa); string[] jucatori = new string[7]; jucatori[1] = J1.Text; jucatori[2] = J2.Text; jucatori[3] = J3.Text; jucatori[4] = J4.Text; jucatori[5] = J5.Text; jucatori[6] = J6.Text; for (int i = 1; i <= 6; ++i) { ee.addJucator(Jucator.getFromTextBox(jucatori[i], conection)); } if (ee.isValid() && echipe.CanAdd(ee) && checkName(numeEchipa)) { Log.Text = "s-a adaugat " + ee.ToString(); echipe.Add(ee); } else { Log.Text = "Eroare "; if (!ee.isValid()) { Log.Text += "echipa are un numar incorect de jucatori"; } else if (!echipe.CanAdd(ee)) { Log.Text += "un jucator mai joaca si in alta echipa"; } else { Log.Text += "mai exista si o alta echipa cu acelasi nume"; } } }
public IEnumerable <Echipa> findAll() { //log.Info("Found all teams!"); List <Echipa> echipe = new List <Echipa>(); SQLiteConnection connection = sqliteConnection.getConnection(); string select = "select * from Echipa"; /*DataSet data = new DataSet(); * var dataAdapter = new SQLiteDataAdapter(select, connection); * dataAdapter.Fill(data); */ SQLiteCommand sQLiteCommand = new SQLiteCommand(select, connection); SQLiteDataReader reader = sQLiteCommand.ExecuteReader(); while (reader.Read()) { int idEchipa = Convert.ToInt32(reader["idEchipa"]); string numeEchipa = Convert.ToString(reader["numeEchipa"]); Echipa echipa = new Echipa(idEchipa, numeEchipa); echipe.Add(echipa); } return(echipe); }
private void ExecuteCommand1(string nrEchipa) { try { Echipa echipa = _repoEchipe.findOne(int.Parse(nrEchipa)); if (echipa == null) { Console.WriteLine("Nu s-a gasit echipa respectiva!"); return; } Console.WriteLine("Jucatorii echipei " + echipa.Nume); _repoJucatori.findAll().Where(x => x.Echipa.Id == echipa.Id).ToList().ForEach(x => Console.WriteLine(x.Id + " " + x.Nume)); } catch (ArgumentNullException) { Console.WriteLine("Nu ai introdus nr echipa!"); } catch (FormatException) { Console.WriteLine("Trebuie sa introduci numarul corespunzator echipei!"); } }
public String scorMeci(int idMeci, MeciService serviceMeci, JucatorService serviceJucator) { Meci meci = serviceMeci.getOne(idMeci); if (meci.ToString().Equals("")) { return(""); } Echipa ec1 = meci.echipa1; Echipa ec2 = meci.echipa2; var result1 = repo.findAll().Where(j => { Jucator jucator = serviceJucator.getOne(j.idJucator); return(jucator.echipa.id == ec1.id && j.idMeci == meci.id); }).Select(j => j); int r1 = 0, r2 = 0; foreach (var m in result1) { r1 = r1 + m.nrPuncteInscrise; } var result2 = repo.findAll().Where(j => { Jucator jucator = serviceJucator.getOne(j.idJucator); return(jucator.echipa.id == ec2.id && j.idMeci == meci.id); }).Select(j => j); foreach (var m in result2) { r2 = r2 + m.nrPuncteInscrise; } string scor = r1 + "-" + r2; return(scor); }
public bool test() { Echipa e1 = new Echipa(1, "The Misfits"); Echipa e2 = new Echipa(2, "The Misfits2"); Echipa e3 = new Echipa(3, "The Misfits3"); Echipa e4 = new Echipa(3, "The Misfits4"); InMemoryRepository <int, Echipa> repoEchipe = new InMemoryRepository <int, Echipa>(new EchipaValidator()); repoEchipe.save(e1); repoEchipe.save(e2); repoEchipe.save(e3); Echipa f1 = new Echipa(0, "The Misfits"); Echipa f2 = new Echipa(-9, "The Misfits"); Echipa f3 = new Echipa(1, ""); Echipa f4 = new Echipa(0, ""); try { repoEchipe.save(f1); return(false); } catch (ValidatorException) { } try { repoEchipe.save(f2); return(false); } catch (ValidatorException) { } try { repoEchipe.save(f3); return(false); } catch (ValidatorException) { } try { repoEchipe.save(f4); return(false); } catch (ValidatorException) { } int size = 0; foreach (var elem in repoEchipe.findAll()) { size++; } if (size != 3) { return(false); } repoEchipe.delete(2); repoEchipe.update(e4); return(false); }
public void AddEchipa(Echipa echipa) { this.echipe.save(echipa); }
public void save(Echipa entity) { throw new NotImplementedException(); }
public static void Main(string[] args) { AngajatRepository angajat = new AngajatRepository(); Console.WriteLine(angajat.findOne(1).User); CursaRepository cursa = new CursaRepository(); Console.WriteLine(cursa.findOne(1).Capacitate); EchipaRepository echipaRepository = new EchipaRepository(); Console.WriteLine(echipaRepository.findOne(1).Nume); ParticipantRepository participant = new ParticipantRepository(); Console.WriteLine(participant.findOne(1).Nume); Cursa C = new Cursa(100, 900); cursa.save(C); Console.WriteLine(cursa.findOne(100).Capacitate); Echipa E = new Echipa(200, "test"); echipaRepository.save(E); Console.WriteLine(echipaRepository.findOne(200).Nume); Participant P = new Participant(600, "test1", 200); participant.save(P); Console.WriteLine(participant.findOne(600).Nume); cursa.delete(100); echipaRepository.delete(200); participant.delete(600); int maxim = participant.FindMaxId(); Console.WriteLine(maxim); Console.WriteLine(cursa.findIdByCapacitate(500)); List <DTOBJCursa> list = cursa.GroupByCapacitate(); foreach (DTOBJCursa test in list) { Console.Write(test.Capacitate); Console.Write(" "); Console.WriteLine(test.NrInscrisi); } Console.WriteLine(angajat.LocalLogin("mgar1992", "12234")); Console.WriteLine(angajat.LocalLogin("mgar1992", "1234")); Console.WriteLine(echipaRepository.FindIdByName("BMW")); List <DTOBJPart> list2 = echipaRepository.cautare("Suzuki"); foreach (DTOBJPart test2 in list2) { Console.Write(test2.Nume); Console.Write(" "); Console.WriteLine(test2.Capacitate); } }