public void update2(CazCaritabil entity)
        {
            log.InfoFormat("Entering update with values {0},{1} - CazCaritabil", entity);
            var con = DBUtils.getConnection();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "update cazuriCaritabile set denumire=@denumire, sumaTotala=@sumaTotala where id=@id";
                var paramId = comm.CreateParameter();
                paramId.ParameterName = "@id";
                paramId.Value         = entity.Id;
                comm.Parameters.Add(paramId);

                var paramDenumire = comm.CreateParameter();
                paramDenumire.ParameterName = "@denumire";
                paramDenumire.Value         = entity.Denumire;
                comm.Parameters.Add(paramDenumire);

                var paramSumaTotala = comm.CreateParameter();
                paramSumaTotala.ParameterName = "@sumaTotala";
                paramSumaTotala.Value         = entity.SumaTotala;
                comm.Parameters.Add(paramSumaTotala);


                var result = comm.ExecuteNonQuery();
                if (result == 0)
                {
                    throw new RepositoryException("No case updated !");
                }
            }

            log.Info("Exiting update - CazCaritabil");
        }
        public IEnumerable <CazCaritabil> findAll()
        {
            log.Info("Entering findAll - CazCaritabil");
            IDbConnection        con    = DBUtils.getConnection();
            IList <CazCaritabil> cazuri = new List <CazCaritabil>();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "select id, denumire, sumaTotala from cazuriCaritabile";

                using (var dataR = comm.ExecuteReader())
                {
                    while (dataR.Read())
                    {
                        int    id         = dataR.GetInt32(0);
                        String denumire   = dataR.GetString(1);
                        Double sumaTotala = dataR.GetDouble(2);

                        CazCaritabil caz = new CazCaritabil(id, denumire, sumaTotala);
                        cazuri.Add(caz);
                    }
                }
            }
            log.Info("Exiting findAll - CazCaritabil");
            return(cazuri);
        }
Esempio n. 3
0
        public List <CazCaritabil> findCazuriDupaDescriere(string descriere)
        {
            log.InfoFormat("getting cases with {}", descriere);
            IDbConnection       con    = dbUtils.DBUtils.getConnection();
            List <CazCaritabil> cazuri = new List <CazCaritabil>();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "select * from cazuri where descriere=@desc";
                IDbDataParameter paramDesc = comm.CreateParameter();
                paramDesc.ParameterName = "@desc";
                paramDesc.Value         = descriere;
                comm.Parameters.Add(paramDesc);
                using (var dataR = comm.ExecuteReader())
                {
                    while (dataR.Read())
                    {
                        CazCaritabil c = new CazCaritabil(dataR.GetString(1));
                        c.Id = dataR.GetInt32(0);
                        cazuri.Add(c);
                    }
                }
            }
            log.InfoFormat("exiting function with values {0}", cazuri);
            return(cazuri);
        }
Esempio n. 4
0
        public IEnumerable <CazCaritabil> findAll()
        {
            log.Info("getting all cases");
            lock (this)
            {
                IDbConnection           con  = dbUtils.DBUtils.getConnection();
                Npgsql.NpgsqlConnection con1 = (Npgsql.NpgsqlConnection)con;
                Npgsql.NpgsqlConnection.ClearPool(con1);

                List <CazCaritabil> cazuri = new List <CazCaritabil>();
                using (var comm = con1.CreateCommand())
                {
                    comm.CommandText = "select * from cazuri";

                    using (var dataR = comm.ExecuteReader())
                    {
                        while (dataR.Read())
                        {
                            CazCaritabil c = new CazCaritabil(dataR.GetString(1));
                            c.Id = dataR.GetInt32(0);
                            cazuri.Add(c);
                        }
                    }
                }
                log.InfoFormat("exiting findall with value", cazuri);
                return(cazuri);
            }
        }
        public void save(CazCaritabil entity)
        {
            log.InfoFormat("Entering save with entity {0}", entity);
            var con = DBUtils.getConnection();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "insert into cazuriCaritabile values (@id, @denumire, @sumaTotala)";
                var paramId = comm.CreateParameter();
                paramId.ParameterName = "@id";
                paramId.Value         = entity.Id;
                comm.Parameters.Add(paramId);

                var paramDenumire = comm.CreateParameter();
                paramDenumire.ParameterName = "@denumire";
                paramDenumire.Value         = entity.Denumire;
                comm.Parameters.Add(paramDenumire);

                var paramSumaTotala = comm.CreateParameter();
                paramSumaTotala.ParameterName = "@sumaTotala";
                paramSumaTotala.Value         = entity.SumaTotala;
                comm.Parameters.Add(paramSumaTotala);

                var result = comm.ExecuteNonQuery();
                if (result == 0)
                {
                    throw new RepositoryException("No cazCaritabil added !");
                }
            }
            log.Info("Exiting save - CazCaritabil");
        }
Esempio n. 6
0
        public void updateSumaCaz(CazCaritabil nou)
        {
            VoluntarEventArgs userArgs = new VoluntarEventArgs(VoluntarEvent.UpdatedCaz, nou);

            OnUserEvent(userArgs);
            server.updateCazCaritabil(nou);
        }
Esempio n. 7
0
        public static CazCaritabilDTO getDTO(CazCaritabil caz)
        {
            int    id         = caz.Id;
            string denumire   = caz.Denumire;
            double sumaTotala = caz.SumaTotala;

            return(new CazCaritabilDTO(id, denumire, sumaTotala));
        }
Esempio n. 8
0
 public static CazCaritabil[] getFromDTO(CazCaritabilDTO[] cazuri)
 {
     CazCaritabil[] cazuri2 = new CazCaritabil[cazuri.Length];
     for (int i = 0; i < cazuri.Length; i++)
     {
         cazuri2[i] = getFromDTO(cazuri[i]);
     }
     return(cazuri2);
 }
Esempio n. 9
0
        private float getSumaAdunata(CazCaritabil c)
        {
            float rez = 0F;

            foreach (Donatie d in donatiiDBRepository.findAll())
            {
                if (d.idCazCaritabil.ToString().Equals(c.Id.ToString()))
                {
                    rez += d.sumaDonata;
                }
            }
            return(rez);
        }
Esempio n. 10
0
        public void updateCazCaritabil(CazCaritabil nou)
        {
            CazCaritabilDTO newDTO = DTOUtils.getDTO(nou);

            sendRequest(new UpdateCazRequest(newDTO));
            Response response = readResponse();

            if (response is ErrorResponse)
            {
                ErrorResponse err = (ErrorResponse)response;
                throw new MyException(err.Message);
            }
        }
Esempio n. 11
0
        public void updateSC(CazCaritabil caz)
        {
            CazCaritabilDTO dto = DTOUtils.getDTO(caz);

            Console.WriteLine("CazCaritabil received  " + caz);
            try
            {
                sendResponse(new UpdateCazResponse(dto));
            }
            catch (Exception e)
            {
                throw new MyException("Sending error: " + e);
            }
        }
        public void updateCazCaritabil(CazCaritabil entity)
        {
            IEnumerable <Voluntar> allVol = voluntarRepo.findAll();


            foreach (Voluntar vol in allVol)
            {
                if (loggedClients.ContainsKey(vol.Id))
                {
                    IObserver Client = loggedClients[vol.Id];
                    Task.Run(() => Client.updateSC(entity));
                }
            }
            cazCaritabilRepo.update2(entity);
        }
Esempio n. 13
0
        private void handleUpdate(UpdateResponse update)
        {
            if (update is UpdateCazResponse)
            {
                UpdateCazResponse frUpd = (UpdateCazResponse)update;
                CazCaritabil      caz   = DTOUtils.getFromDTO(frUpd.Caz);
                Console.WriteLine("Updated caz " + caz);
                try
                {
                    client.updateSC(caz);
                }
                catch (MyException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            if (update is SaveDonatorResponse)
            {
                SaveDonatorResponse donRes  = (SaveDonatorResponse)update;
                Donator             donator = DTOUtils.getFromDTO(donRes.Donator);
                try
                {
                    client.updateDonator(donator);
                }
                catch (MyException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            if (update is SaveDonatieResponse)
            {
                SaveDonatieResponse donRes  = (SaveDonatieResponse)update;
                Donatie             donatie = DTOUtils.getFromDTO(donRes.Add);
                try
                {
                    client.donatieAdded(donatie);
                }
                catch (MyException e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
        }
Esempio n. 14
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!StringExt.IsNumeric(textBoxNrTelefon.Text) || !StringExt.IsNumeric(textBoxSumaDonatie.Text))
            {
                MessageBox.Show("Nr Telefon / Suma trebuie sa fie un numar!");
                return;
            }
            CazCaritabil currentCaz     = (CazCaritabil)dataGridViewCazuri.CurrentRow.DataBoundItem;
            Donator      currentDonator = null;

            if (dataGridViewDonatori.CurrentRow != null)
            {
                currentDonator = (Donator)dataGridViewDonatori.CurrentRow.DataBoundItem;
            }
            else
            {
                currentDonator = new Donator(generateDonatorId(), textBoxNume.Text, textBoxAdresa.Text, Int64.Parse(textBoxNrTelefon.Text));

                try { ctr.saveDonator(currentDonator); }
                catch (ValidationException ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }


            int     id      = generateDonatieId();
            Donatie donatie = new Donatie(id, currentDonator.Id, currentCaz.Id, Double.Parse(textBoxSumaDonatie.Text));

            donatie.Id = id;
            try
            {
                ctr.donatieAdded(donatie);
                Double s = currentCaz.SumaTotala + Double.Parse(textBoxSumaDonatie.Text);
                ctr.updateSumaCaz(new CazCaritabil(currentCaz.Id, currentCaz.Denumire, s));
                MessageBox.Show("Donatia a fost inregistrata! Va multumim!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 15
0
 public void userUpdate(object sender, VoluntarEventArgs e)
 {
     if (e.UserEventType == VoluntarEvent.UpdatedCaz)
     {
         CazCaritabil caz   = (CazCaritabil)e.Data;
         int          index = cazuriL.IndexOf(caz);
         cazuriL[index] = caz;
         Console.WriteLine("[Window] caz Updated " + caz);
         dataGridViewCazuri.BeginInvoke(new UpdateDataGridViewCazuri(this.updateGridViewCazuri),
                                        new Object[] { dataGridViewCazuri, cazuriL });
     }
     if (e.UserEventType == VoluntarEvent.NewDonator)
     {
         Donator donator = (Donator)e.Data;
         donatoriL.Add(donator);
         Console.WriteLine("[Window] donator Added" + donator);
         dataGridViewDonatori.BeginInvoke(new UpdateDataGridViewDonatori(this.updateGridViewDonatori),
                                          new Object[] { dataGridViewDonatori, donatoriL });
     }
 }
Esempio n. 16
0
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is GetCazuriRequest)
            {
                Console.WriteLine("GetCazuriRequest.....");
                GetCazuriRequest getReq = (GetCazuriRequest)request;
                try
                {
                    CazCaritabil[] allCazuri;
                    lock (server)
                    {
                        allCazuri = server.getCazuri();
                    }

                    CazCaritabilDTO[] frDTO = DTOUtils.getDTO(allCazuri);
                    return(new GetCazuriResponse(frDTO));
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetDonatiiRequest)
            {
                Console.WriteLine("GetDonatiiRequest.....");
                GetDonatiiRequest getReq = (GetDonatiiRequest)request;
                try
                {
                    Donatie[] allDonatii;
                    lock (server)
                    {
                        allDonatii = server.getDonatii();
                    }

                    DonatieDTO[] frDTO = DTOUtils.getDTO(allDonatii);
                    return(new GetDonatiiResponse(frDTO));
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }


            if (request is GetDonatoriRequest)
            {
                Console.WriteLine("GetDonatoriRequest.....");
                GetDonatoriRequest getReq = (GetDonatoriRequest)request;
                try
                {
                    Donator[] allDonatori;
                    lock (server)
                    {
                        allDonatori = server.getDonatori();
                    }

                    DonatorDTO[] frDTO = DTOUtils.getDTO(allDonatori);
                    return(new GetDonatoriResponse(frDTO));
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                VoluntarDTO  udto   = logReq.User;
                Voluntar     user   = DTOUtils.getFromDTO(udto);
                try
                {
                    lock (server)
                    {
                        server.login(user, this);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is LogoutRequest)
            {
                Console.WriteLine("Logout request");
                LogoutRequest logReq = (LogoutRequest)request;
                VoluntarDTO   udto   = logReq.User;
                Voluntar      user   = DTOUtils.getFromDTO(udto);
                try
                {
                    lock (server)
                    {
                        server.logout(user, this);
                    }
                    connected = false;
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is SaveDonatorRequest)
            {
                Console.WriteLine("SaveDonatorRequest ...");
                SaveDonatorRequest senReq  = (SaveDonatorRequest)request;
                DonatorDTO         mdto    = senReq.Add;
                Donator            message = DTOUtils.getFromDTO(mdto);
                try
                {
                    lock (server)
                    {
                        server.addDonator(message);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is SaveDonatieRequest)
            {
                Console.WriteLine("SaveDonatieRequest ...");
                SaveDonatieRequest senReq  = (SaveDonatieRequest)request;
                DonatieDTO         mdto    = senReq.Add;
                Donatie            message = DTOUtils.getFromDTO(mdto);
                try
                {
                    lock (server)
                    {
                        server.addDonatie(message);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is UpdateCazRequest)
            {
                Console.WriteLine("UpdateCazRequest ...");
                UpdateCazRequest upReq  = (UpdateCazRequest)request;
                CazCaritabilDTO  cazDTO = upReq.Caz;
                CazCaritabil     caz    = DTOUtils.getFromDTO(cazDTO);
                try
                {
                    lock (server)
                    {
                        server.updateCazCaritabil(caz);
                    }
                    return(new OkResponse());
                }
                catch (MyException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            return(response);
        }
Esempio n. 17
0
        public void updateSC(CazCaritabil caz)
        {
            VoluntarEventArgs userArgs = new VoluntarEventArgs(VoluntarEvent.UpdatedCaz, caz);

            OnUserEvent(userArgs);
        }
Esempio n. 18
0
 public void save(CazCaritabil entity)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 public List <Donatie> findDonatiiDupaCaz(CazCaritabil cazCaritabil)
 {
     throw new NotImplementedException();
 }
 public void update(CazCaritabil old, CazCaritabil entity)
 {
     throw new NotImplementedException();
 }