Пример #1
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            var phone   = phoneBox.Text;
            var name    = nameBox.Text;
            var email   = emailBox.Text;
            var address = addressBox.Text;

            if (birthBox.SelectedDate != null && phone.All(char.IsDigit))
            {
                DateTime date = birthBox.SelectedDate ?? DateTime.Now;
                cl.EditClient(name, date, email, phone, address, clien.Id);
                UpdateClient?.Invoke();
                Close();
                MessageBox.Show("Changes have been saved");
            }
            else
            {
                MessageBox.Show("Invalid input data");
            }
        }
Пример #2
0
        private void StartReading()
        {
            Task.Factory.StartNew(() =>
            {
                _serialPort.ReceivedBytesThreshold = 250;
                _serialPort.DataReceived          += _serialPort_DataReceived;

                var buffer = new List <byte>();

                while (true)
                {
                    _readEvent.WaitOne(15000);
                    _readEvent.Reset();

                    try
                    {
                        var readBuffer = new byte[_serialPort.BytesToRead];

                        _serialPort.Read(readBuffer, 0, readBuffer.Length);
                        buffer.AddRange(readBuffer);

                        Debug.WriteLine($"Received {buffer.Count}");

                        if (buffer.Count > 200)
                        {
                            UpdateClient?.Invoke(buffer.ToArray());
                            buffer = new List <byte>();
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            }, TaskCreationOptions.LongRunning);
        }
Пример #3
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     phone   = phoneBox.Text;
     name    = nameBox.Text;
     email   = emailBox.Text;
     address = addressBox.Text;
     if (birthBox.SelectedDate != null && phone.All(char.IsDigit))
     {
         IClient  cl   = Factory.Instance.GClient();
         DateTime date = birthBox.SelectedDate ?? DateTime.Now;
         cl.AddClient(name, date, email, phone, address);
         UpdateClient?.Invoke();
         MessageBox.Show("You successfully added new client");
         phoneBox.Text   = null;
         nameBox.Text    = null;
         emailBox.Text   = null;
         addressBox.Text = null;
         birthBox.Text   = null;
     }
     else
     {
         MessageBox.Show("Invalid input data");
     }
 }