Пример #1
0
        // Helper method to validate record details
        private bool ValidateRecord(EmployeeCl record)  /*****M*/
        {
            string validationErrors = string.Empty;
            bool   hasErrors        = false;

            if (string.IsNullOrWhiteSpace(record.EmpFirstname))
            {
                hasErrors        = true;
                validationErrors = "Name must not be empty\n";
            }

            if (string.IsNullOrWhiteSpace(record.EmpSurname))
            {
                hasErrors        = true;
                validationErrors = "Surname must not be empty\n";
            }

            // Email address is a series of characters that do not include a space or @
            // followed by @
            // followed by a series of characters that do not include a space or @
            // followed by .
            // followed by a series of characters that do not include a space or @
            Regex emailRegex = new Regex(@"^[^@ ]+@[^@ ]+\.[^@ ]+$");

            if (string.IsNullOrWhiteSpace(record.Email) ||
                !emailRegex.IsMatch(record.Email))
            {
                hasErrors         = true;
                validationErrors += "Invalid Email Address\n";
            }

            this.LastError = validationErrors;
            return(!hasErrors);
        }
Пример #2
0
 // Utility method for copying the details of a record
 private void CopyRecord(EmployeeCl source, EmployeeCl destination)  /*****M*/
 {
     destination.EmpID        = source.EmpID;
     destination.EmpFirstname = source.EmpFirstname;
     destination.EmpSurname   = source.EmpSurname;
     destination.RoleID       = source.RoleID;
     destination.Email        = source.Email;
 }
Пример #3
0
        // Create a new (empty) record
        // and put the form into Adding mode
        private void Add()
        {
            EmployeeCl newRecord = new EmployeeCl {
                EmpID = 0
            };                                                    /*****2*/

            this.recordList.Insert(recordIndex, newRecord);
            this.IsAdding = true;
            this.OnPropertyChanged(nameof(Current));
        }
Пример #4
0
 private EmployeeCl oldRecord;  /*****/
 private void Edit()
 {
     this.oldRecord = new EmployeeCl();  /*****/
     this.CopyRecord(this.Current, this.oldRecord);
     this.IsEditing = true;
 }