示例#1
0
        private void ShowAll_Click(object sender, EventArgs e)
        {
            ServerRequest request = new ServerRequest
            {
                ActionType = 1,
            };

            string data = JsonSerializer.Serialize(request);

            if (isConnected)
            {
                try
                {
                    writer.WriteLine(data);
                    writer.Flush();

                    string    serverResponse = reader.ReadLine();
                    CarsArray cars           = JsonSerializer.Deserialize <CarsArray>(serverResponse);

                    string output = "";

                    cars.Cars.ForEach(car =>
                    {
                        output += car.Name + " " + car.Model + " " + car.Price + "\r\n";
                    });

                    SearchAllOutput.Text = output;
                }
                catch (IOException)
                {
                }
            }
        }
示例#2
0
        private void Edit_Click(object sender, EventArgs e)
        {
            Car newCar = new Car(NewName.Text, NewModel.Text, long.Parse(NewPrice.Text));
            EditWorkerRequest editWorkerRequest = new EditWorkerRequest
            {
                NewCar  = newCar,
                OldName = OldName.Text
            };

            ServerRequest request = new ServerRequest
            {
                ActionType = 5,
                Payload    = JsonSerializer.Serialize(editWorkerRequest)
            };

            string data = JsonSerializer.Serialize(request);

            if (isConnected)
            {
                try
                {
                    writer.WriteLine(data);
                    writer.Flush();

                    string    serverResponse = reader.ReadLine();
                    CarsArray cars           = JsonSerializer.Deserialize <CarsArray>(serverResponse);

                    string output = "";

                    cars.Cars.ForEach(car =>
                    {
                        output += car.Name + " " + car.Model + " " + car.Price + "\r\n";
                    });

                    SearchAllOutput.Text = output;
                }
                catch (IOException)
                {
                }
            }
        }