Example #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();
                    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)
                {
                }
            }
        }
Example #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)
                {
                }
            }
        }