Exemple #1
0
        public PassportDialog(Person person)
        {
            InitializeComponent();
            currPerson = person;

            try
            {
                // Querying passport from person object passed as parameter
                PersonPassport passport = Global.context.Passports
                                          .Where(b => b.PersonPassportId == person.PersonId)
                                          .FirstOrDefault();

                if (passport != null)
                {
                    currPassport       = passport;
                    txtPassport.Text   = currPassport.PassportNumber;
                    imageViewer.Source = Utils.ByteArrayToBitmapImage(currPassport.Photo);
                }
            }
            catch (SystemException exc)
            {
                MessageBox.Show(exc.Message, "Error retrieving passport data from database!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            // Populating existing fields
            lblName.Content = person.Name;
        }
Exemple #2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Assuring fields are not blank and age are well entered.
            if (txtPassport.Text == "")
            {
                MessageBox.Show("Please, re-check the inserted information and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Checking if photo was selected before saving to db
            if (currPassportImage == null)
            {
                MessageBox.Show("Please choose a picture", "Validation error", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            string passportNumber = txtPassport.Text;

            // Validating with Regex for passport
            string pattern = @"^[A-Z]{2}[0-9]{7}$";
            Regex  rg      = new Regex(pattern);

            if (!rg.IsMatch(passportNumber))
            {
                MessageBox.Show("Passport number must follow this model : \n" +
                                "AB1234567", " Validation Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (currPassport == null)
            {
                PersonPassport personPassport = new PersonPassport()
                {
                    PassportNumber = passportNumber, Photo = currPassportImage, PersonPassportId = currPerson.PersonId
                };
                Global.context.Passports.Add(personPassport);
                Global.context.SaveChanges();
                MessageBox.Show("Data added with Success!");
            }
            else
            {
                currPassport.PassportNumber = txtPassport.Text;
                currPassport.Photo          = currPassportImage;
                Global.context.SaveChanges();
                MessageBox.Show("Data Updated with Success!", " Update Data", MessageBoxButton.OK, MessageBoxImage.None);
            }
        }