コード例 #1
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)
                {
                }
            }
        }
コード例 #2
0
        private void Edit_Click(object sender, EventArgs e)
        {
            Worker            newWorker         = new Worker(NewName.Text, NewPosition.Text, long.Parse(NewSalary.Text));
            EditWorkerRequest editWorkerRequest = new EditWorkerRequest
            {
                NewWorker = newWorker,
                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();
                    WorkersArray workers        = JsonSerializer.Deserialize <WorkersArray>(serverResponse);

                    string output = "";

                    workers.Workers.ForEach(worker =>
                    {
                        output += worker.Name + " " + worker.Position + " " + worker.Salary + "\r\n";
                    });

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