Exemple #1
0
        private void btnRezervare_Click(object sender, EventArgs e)
        {
            string numeClient = txtNumeClient.Text;
            int    nrLocuri   = int.Parse(txtNrLocuri.Text);
            int    idCursa;
            int    idClient;
            Cursa  cursa;

            if (listViewCurse.SelectedItems.Count == 1)
            {
                cursa = new Cursa()
                {
                    Id                = Convert.ToInt32(listViewCurse.SelectedItems[0].SubItems[0].Text),
                    Destinatie        = listViewCurse.SelectedItems[0].SubItems[1].Text,
                    DateTime          = Convert.ToDateTime(listViewCurse.SelectedItems[0].SubItems[2].Text),
                    LocuriDisponibile = Convert.ToInt32(listViewCurse.SelectedItems[0].SubItems[3].Text),
                    Oficiu            = 1
                };
                idCursa = Convert.ToInt32(listViewCurse.SelectedItems[0].SubItems[0].Text);
                if (Server.FindClient(numeClient) == null)
                {
                    Server.AddClient(new Client(numeClient));
                }
                idClient = Server.FindClient(numeClient).Id;
                Rezervare rezervare = new Rezervare(idCursa, idClient, nrLocuri);
                Server.AddRezervare(rezervare);
                cursa.LocuriDisponibile = cursa.LocuriDisponibile - nrLocuri;
                Server.UpdateCursa(cursa);
                ShowClienti(cursa.Id);
            }
        }
        private Response handleRequest(Request request)
        {
            Response response = null;

            if (request is LoginRequest)
            {
                Console.WriteLine("Login request ...");
                LoginRequest logReq = (LoginRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Operator op = logReq.Operator;
                try
                {
                    lock (server)
                    {
                        server.Login(op, this);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is GetCurseRequest)
            {
                Console.WriteLine("Get curse request");
                List <Cursa> curse;
                try
                {
                    lock (server)
                    {
                        curse = server.GetAllCurse();
                    }
                    connected = false;
                    return(new AllCurseResponse(curse));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetRezervariByCursaRequest)
            {
                Console.WriteLine("GetRezervariByCursaRequest ...");
                GetRezervariByCursaRequest senReq = (GetRezervariByCursaRequest)request;
                int idCUrsa = senReq.IdCursa;
                try
                {
                    List <Rezervare> rezervari;
                    lock (server)
                    {
                        rezervari = server.GetAllByCursa(idCUrsa);
                    }
                    return(new RezervariByCursaResponse(rezervari));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetClientByIdRequest)
            {
                Console.WriteLine("GetClientById Request ...");
                GetClientByIdRequest getReq = (GetClientByIdRequest)request;
                int idClient = getReq.IdClient;
                try
                {
                    Client client;
                    lock (server)
                    {
                        client = server.FindClient(idClient);
                    }
                    return(new ClientResponse(client));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is AddRezervareRequest)
            {
                Console.WriteLine("AddRezervare request ...");
                AddRezervareRequest addRezReq = (AddRezervareRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Rezervare rezervare = addRezReq.Rezervare;
                try
                {
                    lock (server)
                    {
                        server.AddRezervare(rezervare);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is GetClientByNameRequest)
            {
                Console.WriteLine("GetClientById Request ...");
                GetClientByNameRequest getReq = (GetClientByNameRequest)request;
                String NumeClient             = getReq.Nume;
                try
                {
                    Client client;
                    lock (server)
                    {
                        client = server.FindClient(NumeClient);
                    }
                    return(new ClientResponse(client));
                }
                catch (FirmaTransportException e)
                {
                    return(new ErrorResponse(e.Message));
                }
            }

            if (request is AddClientRequest)
            {
                Console.WriteLine("AddClient request ...");
                AddClientRequest addRezReq = (AddClientRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Client client = addRezReq.Client;
                try
                {
                    lock (server)
                    {
                        server.AddClient(client);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            if (request is UpdateCursaRequest)
            {
                Console.WriteLine("UpdateCursa request ...");
                UpdateCursaRequest addRezReq = (UpdateCursaRequest)request;
                //UserDTO udto = logReq.User;
                // User user = DTOUtils.getFromDTO(udto);
                Cursa cursa = addRezReq.cursa;
                try
                {
                    lock (server)
                    {
                        server.UpdateCursa(cursa);
                    }
                    return(new OkResponse());
                }
                catch (FirmaTransportException e)
                {
                    connected = false;
                    return(new ErrorResponse(e.Message));
                }
            }
            return(response);
        }