예제 #1
0
        private async Task <List <Medicine> > InitModelsInForm()
        {
            try
            {
                string request = tcpService.SerializeInitMedicinesInViewMedicinesForm(SingletoneObj.User);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                List <Medicine> models = tcpService.DeseializeInitMedicinesInViewMedicinesForm(response);
                return(models);
            }
            catch (Exception)
            {
                return(new List <Medicine>());
            }
        }
예제 #2
0
        private async Task <List <Role> > InitRolesInForm()
        {
            try
            {
                string request = tcpService.SerializeInitRolesInFormRequest(SingletoneObj.User);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                List <Role> roles = tcpService.DeserializeInitRolesInFormResponse(response);
                return(roles);
            }
            catch (Exception)
            {
                return(new List <Role>());
            }
        }
예제 #3
0
        private async void AddWardBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddWardBtn.IsEnabled = false;
                int     wardNumber;
                Comfort comfort;
                int     numberOfPlaces;

                if (!int.TryParse(WardNumberTextBox.Text, out wardNumber))
                {
                    throw new ArgumentNullException($"'{nameof(wardNumber)}' is incorrect");
                }
                if (!int.TryParse(CountOfPlacesTextBox.Text, out numberOfPlaces))
                {
                    throw new ArgumentNullException($"'{nameof(numberOfPlaces)}' is incorrect");
                }
                if (!Enum.TryParse(ComfortListBox.SelectedItem.ToString(), out comfort))
                {
                    throw new ArgumentNullException($"'{nameof(comfort)}' is incorrect");
                }

                Ward requestWard = new Ward
                {
                    WardNumber    = wardNumber,
                    NumberOfPaces = numberOfPlaces,
                    Comfort       = comfort
                };

                string request = tcpService.SerializeAddWardRequest(requestWard, SingletoneObj.User);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                var responseArgs = response.Split(';');
                if (responseArgs.Length > 1 && responseArgs[0].Contains("500"))
                {
                    throw new ArgumentException(responseArgs[1]);
                }
                this.Close();
            }
            catch (Exception ex)
            {
                AddWardBtn.IsEnabled = true;
                StatusLabel.Content  = "Status: " + ex.Message;
            }
        }
예제 #4
0
        private async void ExitBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddPatientBtn.IsEnabled    = false;
                AddDoctorBtn.IsEnabled     = false;
                AddUserBtn.IsEnabled       = false;
                ViewPatientsBtn.IsEnabled  = false;
                ViewDoctorsBtn.IsEnabled   = false;
                ViewUsersBtn.IsEnabled     = false;
                AddWardBtn.IsEnabled       = false;
                AddMedicineBtn.IsEnabled   = false;
                AddAddmitionBtn.IsEnabled  = false;
                ViewWardBtn.IsEnabled      = false;
                ViewMedicineBtn.IsEnabled  = false;
                ViewAddmitionBtn.IsEnabled = false;
                ExitBtn.IsEnabled          = false;

                string request = "LogOut";
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);
            }
            catch (Exception) { }
            finally
            {
                if (SingletoneObj.Stream != null)
                {
                    SingletoneObj.Stream.Close();
                }
                if (SingletoneObj.Client != null)
                {
                    SingletoneObj.Client.Close();
                }
                SingletoneObj.Windows.Add("MainForm", this);
                SingletoneObj.User = null;
                AuthorizationForm form = new AuthorizationForm();
                form.Show();
            }
        }
예제 #5
0
        private async void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LoginBtn.IsEnabled = false;
                int port = int.Parse(this.PortTextBox.Text);
                if (port < 0)
                {
                    throw new ArgumentException("'port' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(this.IPTextBox.Text))
                {
                    throw new ArgumentException("'ip' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(this.LoginTextBox.Text))
                {
                    throw new ArgumentException("'login' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(this.PasswordBox.Password))
                {
                    throw new ArgumentException("'pasword' is incorrect");
                }
                string address  = this.IPTextBox.Text;
                string login    = this.LoginTextBox.Text;
                string password = this.PasswordBox.Password;

                SingletoneObj.Client = new TcpClient(address, port);
                SingletoneObj.Stream = SingletoneObj.Client.GetStream();


                string request = tcpService.SerializeAuthorizeRequest(login, password);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                User user = tcpService.DeserializeAuthorizeResponse(response);
                if (user.Login == null || user.Password == null || !user.Login.Equals(login) || !user.Password.Equals(password))
                {
                    throw new ArgumentException("login or password is incorrect");
                }
                SingletoneObj.User = user;
                SingletoneObj.IP   = address;
                SingletoneObj.Port = port;
                SingletoneObj.Windows.Add("AuthorizationForm", this);
                MainForm form = new MainForm();
                form.Left = (this.Width - form.Width) + this.Left;
                form.Top  = (this.Height - form.Height) + this.Top;
                form.Show();
            }
            catch (Exception ex)
            {
                LoginBtn.IsEnabled       = true;
                this.StatusLabel.Content = "Status: " + ex.Message;
                if (SingletoneObj.Client != null)
                {
                    SingletoneObj.Client.Close();
                }
                if (SingletoneObj.Stream != null)
                {
                    SingletoneObj.Stream.Close();
                }
            }
        }
예제 #6
0
        private async void AddPatientBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddPatientBtn.IsEnabled = false;
                string   firstName       = FirstNameTextBox.Text;
                string   lastName        = LastNameTextBox.Text;
                string   middleName      = MiddleNameTextBox.Text;
                string   address         = AddressTextBox.Text;
                string   insurancePolicy = InsurancePolicyTextBox.Text;
                DateTime dateOfBirth;
                if (string.IsNullOrWhiteSpace(firstName))
                {
                    throw new ArgumentNullException($"'{nameof(firstName)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(lastName))
                {
                    throw new ArgumentNullException($"'{nameof(lastName)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(middleName))
                {
                    throw new ArgumentNullException($"'{nameof(middleName)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(address))
                {
                    throw new ArgumentNullException($"'{nameof(address)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(insurancePolicy))
                {
                    throw new ArgumentNullException($"'{nameof(insurancePolicy)}' is incorrect");
                }
                if (!DateOfBirthDataPicker.SelectedDate.HasValue || DateOfBirthDataPicker.SelectedDate.Value > DateTime.Now)
                {
                    throw new ArgumentNullException($"'{nameof(dateOfBirth)}' is incorrect");
                }

                dateOfBirth = DateOfBirthDataPicker.SelectedDate.Value;

                Patient requestPatient = new Patient
                {
                    FirstName       = firstName,
                    LastName        = lastName,
                    MiddleName      = middleName,
                    Address         = address,
                    InsurancePolicy = insurancePolicy,
                    DateOfBirth     = dateOfBirth
                };

                string request = tcpService.SerializeAddPatientRequest(requestPatient, SingletoneObj.User);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                var responseArgs = response.Split(';');
                if (responseArgs.Length > 1 && responseArgs[0].Contains("500"))
                {
                    throw new ArgumentException(responseArgs[1]);
                }
                this.Close();
            }
            catch (Exception ex)
            {
                AddPatientBtn.IsEnabled = true;
                StatusLabel.Content     = "Status: " + ex.Message;
            }
        }
예제 #7
0
        private async void AddDoctorBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddDoctorBtn.IsEnabled = false;
                string   firstName      = FirstNameTextBox.Text;
                string   lastName       = LastNameTextBox.Text;
                string   middleName     = MiddleNameTextBox.Text;
                string   phone          = PhoneTextBox.Text;
                string   specialization = SpecializationTextBox.Text;
                DateTime dateOfBirth;
                if (string.IsNullOrWhiteSpace(firstName))
                {
                    throw new ArgumentNullException($"'{nameof(firstName)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(lastName))
                {
                    throw new ArgumentNullException($"'{nameof(lastName)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(middleName))
                {
                    throw new ArgumentNullException($"'{nameof(middleName)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(phone) || phone.Length != 10 || !Regex.IsMatch(phone, "0[0-9]{9}"))
                {
                    throw new ArgumentNullException($"'{nameof(phone)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(specialization))
                {
                    throw new ArgumentNullException($"'{nameof(specialization)}' is incorrect");
                }
                if (!DateOfBirthDataPicker.SelectedDate.HasValue || DateOfBirthDataPicker.SelectedDate.Value > DateTime.Now)
                {
                    throw new ArgumentNullException($"'{nameof(dateOfBirth)}' is incorrect");
                }

                dateOfBirth = DateOfBirthDataPicker.SelectedDate.Value;

                Doctor requestDoctor = new Doctor
                {
                    FirstName      = firstName,
                    LastName       = lastName,
                    MiddleName     = middleName,
                    Phone          = phone,
                    Specialization = specialization,
                    DateOfBirth    = dateOfBirth
                };

                string request = tcpService.SerializeAddDoctorRequest(requestDoctor, SingletoneObj.User);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                var responseArgs = response.Split(';');
                if (responseArgs.Length > 1 && responseArgs[0].Contains("500"))
                {
                    throw new ArgumentException(responseArgs[1]);
                }
                this.Close();
            }
            catch (Exception ex)
            {
                AddDoctorBtn.IsEnabled = true;
                StatusLabel.Content    = "Status: " + ex.Message;
            }
        }
예제 #8
0
        private async void AddDoctorBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddMedicineBtn.IsEnabled = false;
                string  name = NameTextBox.Text;
                string  sku  = SkuTextBox.Text;
                decimal price;
                string  indication = IndicationTextBox.Text;
                string  country    = CountryTextBox.Text;

                if (string.IsNullOrWhiteSpace(name))
                {
                    throw new ArgumentNullException($"'{nameof(name)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(sku))
                {
                    throw new ArgumentNullException($"'{nameof(sku)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(indication))
                {
                    throw new ArgumentNullException($"'{nameof(indication)}' is incorrect");
                }
                if (string.IsNullOrWhiteSpace(country))
                {
                    throw new ArgumentNullException($"'{nameof(country)}' is incorrect");
                }
                if (!decimal.TryParse(PriceTextBox.Text, out price))
                {
                    throw new ArgumentNullException($"'{nameof(price)}' is incorrect");
                }
                if (price < 0)
                {
                    throw new ArgumentNullException($"'{nameof(price)}' is incorrect");
                }

                Medicine requestMedicine = new Medicine
                {
                    Name       = name,
                    Price      = price,
                    Sku        = sku,
                    Indication = indication,
                    Country    = new Country
                    {
                        Name = country
                    }
                };

                string request = tcpService.SerializeAddMedicineRequest(requestMedicine, SingletoneObj.User);
                byte[] data    = await tcpService.CodeStreamAsync(request);

                await SingletoneObj.Stream.WriteAsync(data, 0, data.Length);

                string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream);

                var responseArgs = response.Split(';');
                if (responseArgs.Length > 1 && responseArgs[0].Contains("500"))
                {
                    throw new ArgumentException(responseArgs[1]);
                }
                this.Close();
            }
            catch (Exception ex)
            {
                AddMedicineBtn.IsEnabled = true;
                StatusLabel.Content      = "Status: " + ex.Message;
            }
        }